Skip to content

Commit

Permalink
passing prop accessibilityUnit as string from cpp to java
Browse files Browse the repository at this point in the history
"Complete draft CPP accessibilityUnit settings:
Commit the changes and push
Add more clear log statements and further verify value passed to  accessibilityUnit
Log the value passed from javascript in conversion.h
Add changes from PR [#2](https://github.com/fabriziobertoglio1987/react-native/pull/2/files)
Change logic in conversion.h to add the value passed from javascript"
  • Loading branch information
fabOnReact committed Nov 11, 2022
1 parent a96ad8a commit 3b16542
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,6 @@ 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 @@ -609,8 +607,6 @@ 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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class TextAttributes : public DebugStringConvertible {
// construction.
std::optional<LayoutDirection> layoutDirection{};
std::optional<AccessibilityRole> accessibilityRole{};
std::string accessibilityUnit{""};
std::string accessibilityUnit{};

#pragma mark - Operations

Expand Down
10 changes: 8 additions & 2 deletions ReactCommon/react/renderer/attributedstring/conversions.h
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,10 @@ inline folly::dynamic toDynamic(const TextAttributes &textAttributes) {
_textAttributes(
"accessibilityRole", toString(*textAttributes.accessibilityRole));
}
if (!textAttributes.accessibilityUnit.empty()) {
_textAttributes(
"accessibilityUnit", textAttributes.accessibilityUnit);
}
return _textAttributes;
}

Expand Down Expand Up @@ -1228,11 +1232,13 @@ inline MapBuffer toMapBuffer(const TextAttributes &textAttributes) {
}
if (textAttributes.accessibilityRole.has_value()) {

LOG(ERROR) << "TESTING:: attributedString conversions.h accessibilityRole: " << toString(*textAttributes.accessibilityRole);
builder.putString(
TA_KEY_ACCESSIBILITY_ROLE, toString(*textAttributes.accessibilityRole));
}
if (!textAttributes.accessibilityUnit.empty()) {

builder.putString(
TA_KEY_ACCESSIBILITY_UNIT, "random unit");
TA_KEY_ACCESSIBILITY_UNIT, textAttributes.accessibilityUnit);
}
return builder.build();
}
Expand Down
13 changes: 13 additions & 0 deletions ReactCommon/react/renderer/components/text/BaseTextProps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,13 @@ static TextAttributes convertRawProp(
sourceTextAttributes.accessibilityRole,
defaultTextAttributes.accessibilityRole);

textAttributes.accessibilityUnit = convertRawProp(
context,
rawProps,
"accessibilityUnit",
sourceTextAttributes.accessibilityUnit,
defaultTextAttributes.accessibilityUnit);

// Color (accessed in this order by ViewProps)
textAttributes.opacity = convertRawProp(
context,
Expand Down Expand Up @@ -287,6 +294,12 @@ void BaseTextProps::setProp(
textAttributes,
accessibilityRole,
"accessibilityRole");
REBUILD_FIELD_SWITCH_CASE(
defaults,
value,
textAttributes,
accessibilityRole,
"accessibilityUnit");
REBUILD_FIELD_SWITCH_CASE(
defaults, value, textAttributes, opacity, "opacity");
REBUILD_FIELD_SWITCH_CASE(
Expand Down

0 comments on commit 3b16542

Please sign in to comment.