Skip to content

Commit

Permalink
DRAFT CPP solution to pass static string as accessibilityUnit
Browse files Browse the repository at this point in the history
getOrCreateSpannableForText is not called. The method is called on the parent Text, but not on the Span Text.
Review implementation of accessibilityRole in [BaseViewManager](https://github.com/fabriziobertoglio1987/react-native/blob/ec4bc8eb5905f81cebbb4b623acda8245ee5683c/ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManager.java#L247) and [ReactMapBufferPropSetter.kt](http://www.apple.com/)
Probably the method setAccessibilityRole is called directly from kotlin MapBufferPropSetter
Add required changes and debug the functionality
accessibilityRole link is called, but time is not
they have the same cpp configuration, but one of them is not invoked in BaseViewManager. 
This suggest missing configs from the [accessibility link PR](facebook@7b5b114), maybe accessibilityRole Link is triggered with resetAccessibilityDelegate
Find logic in accessibility link PR that resets the Delegate
Before resetting the Delegate, TextLayoutManager adds the Span to the Text. The field is TextAttributes mIsAccessibilityLink. This field is set to true if accessibilityRole = link
mIsAccessibilityLink is set to true in the ReactBaseTextShadowNode #setIsAccessibilityLink sets the value
Debug the value of ReactBaseTextShadowNode #setAccessibilityUnit
Verify if accessibilityUnit is retrieve in that method, because this manager is also for nested text
Check if setIsAccessibiltyLink also is triggered for role time, if not understand why text does not trigger. Yes, it is triggered. We set there the accessibilityRole
- We could follow the same implementation, we add the span based on mIsAccessibilityTtsSpan
- We retrieve get spans of class ReactTtsSpan 
- We follow same implementation from accessibilityLinks
Implement same logic for accessibilityRole time
Verify accessibilityRole time is invoked
Use resetAccessibilityDelegate to add accessibilityUnit info to child Text
Copy missing changes from another prop (for ex. accessibilityRole). setAccessibilityRole is triggered, while setAccessibilityUnit is not triggered.
Review missing diff with [#2](https://github.com/fabriziobertoglio1987/react-native/pull/2/files)
Review the current diff with main branch
Add breakpoint in cpp
SOLUTION: adding the value in [attributedstring/conversion.h](https://github.com/fabriziobertoglio1987/react-native/blob/ec4bc8eb5905f81cebbb4b623acda8245ee5683c/ReactCommon/react/renderer/attributedstring/conversions.h#L1087) will then pass it to [TextAttributesProps as key 24](https://www.icloud.com/iclouddrive/0b8-oKB396zP7Astpyc3puGqQ#ACC_UNIT_passed_as_key_24)
  • Loading branch information
fabOnReact committed Nov 11, 2022
1 parent ec4bc8e commit a96ad8a
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

package com.facebook.react.uimanager;

import android.util.Log;
import android.view.View;
import androidx.annotation.Nullable;
import com.facebook.react.bridge.ColorPropConverter;
Expand All @@ -30,6 +31,8 @@ public BaseViewManagerDelegate(U viewManager) {

@Override
public void setProperty(T view, String propName, @Nullable Object value) {
Log.w("TESTING::BaseViewManagerDelegate", "propName: " + (propName));
Log.w("TESTING::BaseViewManagerDelegate", "value: " + (value));
switch (propName) {
case ViewProps.ACCESSIBILITY_ACTIONS:
mViewManager.setAccessibilityActions(view, (ReadableArray) value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import androidx.annotation.Nullable;
import com.facebook.infer.annotation.Assertions;
Expand Down Expand Up @@ -507,6 +508,8 @@ public void setBackgroundColor(@Nullable Integer color) {

@ReactProp(name = ViewProps.ACCESSIBILITY_ROLE)
public void setIsAccessibilityLink(@Nullable String accessibilityRole) {
Log.w("TESTING::ReactBaseTextShadowNode", "setIsAccessibilityLink");
Log.w("TESTING::ReactBaseTextShadowNode", "accessibilityRole: " + (accessibilityRole));
if (isVirtual()) {
String roleClassName =
AccessibilityRole.getValue(AccessibilityRole.fromValue(accessibilityRole));
Expand All @@ -519,6 +522,8 @@ public void setIsAccessibilityLink(@Nullable String accessibilityRole) {

@ReactProp(name = "accessibilityUnit")
public void setAccessibilityUnit(@Nullable String accessibilityUnit) {
Log.w("TESTING::ReactBaseTextShadowNode", "setAccessibilityUnit");
Log.w("TESTING::ReactBaseTextShadowNode", "accessibilityUnit: " + (accessibilityUnit));
if (isVirtual()) {
markUpdated();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.text.Layout;
import android.text.TextUtils;
import android.util.LayoutDirection;
import android.util.Log;
import android.view.Gravity;
import androidx.annotation.Nullable;
import com.facebook.react.bridge.JSApplicationIllegalArgumentException;
Expand Down Expand Up @@ -53,6 +54,7 @@ public class TextAttributeProps {
public static final short TA_KEY_IS_HIGHLIGHTED = 20;
public static final short TA_KEY_LAYOUT_DIRECTION = 21;
public static final short TA_KEY_ACCESSIBILITY_ROLE = 22;
public static final short TA_KEY_ACCESSIBILITY_UNIT = 47;

public static final int UNSET = -1;

Expand Down Expand Up @@ -144,6 +146,8 @@ public static TextAttributeProps fromMapBuffer(MapBuffer props) {

// TODO T83483191: Review constants that are not being set!
Iterator<MapBuffer.Entry> iterator = props.iterator();
Log.w("TESTING::TextAttributeProps", "fromMapBuffer");
Log.w("TESTING::TextAttributeProps", "props: " + (props));
while (iterator.hasNext()) {
MapBuffer.Entry entry = iterator.next();
switch (entry.getKey()) {
Expand Down Expand Up @@ -206,6 +210,9 @@ public static TextAttributeProps fromMapBuffer(MapBuffer props) {
case TA_KEY_ACCESSIBILITY_ROLE:
result.setAccessibilityRole(entry.getStringValue());
break;
case TA_KEY_ACCESSIBILITY_UNIT:
result.setAccessibilityUnit(entry.getStringValue());
break;
}
}

Expand Down Expand Up @@ -602,6 +609,8 @@ private void setTextTransform(@Nullable String textTransform) {

private void setAccessibilityRole(@Nullable String accessibilityRole) {
if (accessibilityRole != null) {
Log.w("TESTING::TextAttributeProps", "setAccessibilityRole");
Log.w("TESTING::TextAttributeProps", "accessibilityRole: " + (accessibilityRole));
mIsAccessibilityRoleSet = true;
mAccessibilityRole = AccessibilityRole.fromValue(accessibilityRole);
mIsAccessibilityLink = mAccessibilityRole.equals(AccessibilityRole.LINK);
Expand All @@ -613,6 +622,8 @@ private void setAccessibilityRole(@Nullable String accessibilityRole) {
}

private void setAccessibilityUnit(@Nullable String accessibilityUnit) {
Log.w("TESTING::TextAttributeProps", "setAccessibilityUnit");
Log.w("TESTING::TextAttributeProps", "accessibilityUnit: " + (accessibilityUnit));
// not yet implemented
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import android.text.StaticLayout;
import android.text.TextPaint;
import android.util.LayoutDirection;
import android.util.Log;
import android.util.LruCache;
import android.view.View;
import androidx.annotation.NonNull;
Expand Down Expand Up @@ -196,6 +197,7 @@ public static Spannable getOrCreateSpannableForText(
Context context,
ReadableMap attributedString,
@Nullable ReactTextViewManagerCallback reactTextViewManagerCallback) {
Log.w("TESTING::TextLayoutManager", "getOrCreateSpannableForText");

return createSpannableFromAttributedString(
context, attributedString, reactTextViewManagerCallback);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ object ReactMapBufferPropSetter {
viewManager.accessibilityState(view, entry.mapBufferValue)
}
VP_ACCESSIBILITY_UNIT -> {
viewManager.accessibilityUnit(view, entry.stringValue)
viewManager.setAccessibilityUnit(view, entry.stringValue.takeIf { it.isNotEmpty() })
}
VP_ACCESSIBILITY_VALUE -> {
viewManager.accessibilityValue(view, entry.stringValue)
Expand Down Expand Up @@ -285,11 +285,8 @@ object ReactMapBufferPropSetter {

private fun ReactViewManager.accessibilityUnit(view: ReactViewGroup, value: String) {
Log.w("TESTING::ReactMapBufferPropSetter", "accessibilityUnit");
/*
val accessibilityUnit = JavaOnlyMap()
accessibilityUnit.putString("hours", "10")
setAccessibilityUnit(view, accessibilityUnit)
*/
Log.w("TESTING::ReactMapBufferPropSetter", "value: " + ( value ));
setAccessibilityUnit(view,"random string")
}

private fun ReactViewManager.accessibilityState(view: ReactViewGroup, value: MapBuffer) {
Expand Down
5 changes: 5 additions & 0 deletions ReactCommon/react/renderer/attributedstring/conversions.h
Original file line number Diff line number Diff line change
Expand Up @@ -1083,6 +1083,7 @@ constexpr static MapBuffer::Key TA_KEY_IS_HIGHLIGHTED = 20;
constexpr static MapBuffer::Key TA_KEY_LAYOUT_DIRECTION = 21;
constexpr static MapBuffer::Key TA_KEY_ACCESSIBILITY_ROLE = 22;
constexpr static MapBuffer::Key TA_KEY_LINE_BREAK_STRATEGY = 23;
constexpr static MapBuffer::Key TA_KEY_ACCESSIBILITY_UNIT = 47;

// constants for ParagraphAttributes serialization
constexpr static MapBuffer::Key PA_KEY_MAX_NUMBER_OF_LINES = 0;
Expand Down Expand Up @@ -1226,8 +1227,12 @@ inline MapBuffer toMapBuffer(const TextAttributes &textAttributes) {
TA_KEY_LAYOUT_DIRECTION, toString(*textAttributes.layoutDirection));
}
if (textAttributes.accessibilityRole.has_value()) {

LOG(ERROR) << "TESTING:: attributedString conversions.h accessibilityRole: " << toString(*textAttributes.accessibilityRole);
builder.putString(
TA_KEY_ACCESSIBILITY_ROLE, toString(*textAttributes.accessibilityRole));
builder.putString(
TA_KEY_ACCESSIBILITY_UNIT, "random unit");
}
return builder.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,15 @@ class AccessibilityExample extends React.Component<{}> {
17:00
</Text>
</Text>
<Text accessible={true}>
This is a
<Text
accessibilityRole="link"
accessible={true}
style={{backgroundColor: 'red'}}>
link
</Text>
</Text>
</View>
<View>
<Text accessible={true} accessibilityRole="telephone">
Expand Down

0 comments on commit a96ad8a

Please sign in to comment.