Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

separating accessibilityUnit from accessibilityMinutes and accessibilityHours #4

Draft
wants to merge 6 commits into
base: tts-span-accessibility-unit-cpp-settings
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Libraries/Components/View/ReactNativeViewAttributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const UIView = {
accessibilityRole: true,
accessibilityState: true,
accessibilityUnit: true,
accessibilityHours: true,
accessibilityMinutes: true,
accessibilityValue: true,
accessibilityHint: true,
accessibilityLanguage: true,
Expand Down
2 changes: 2 additions & 0 deletions Libraries/Components/View/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ const View: React.AbstractComponent<
accessibilityRole,
accessibilityState,
accessibilityUnit,
accessibilityHours,
accessibilityMinutes,
accessibilityValue,
'aria-busy': ariaBusy,
'aria-checked': ariaChecked,
Expand Down
2 changes: 2 additions & 0 deletions Libraries/Components/View/ViewAccessibility.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ export interface AccessibilityProps
*/
accessibilityState?: AccessibilityState | undefined;
accessibilityUnit?: AccessibilityUnit | undefined;
accessibilityHours?: number | undefined;
accessibilityMinutes?: number | undefined;

/**
* alias for accessibilityState
Expand Down
2 changes: 2 additions & 0 deletions Libraries/Components/View/ViewPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,8 @@ export type ViewProps = $ReadOnly<{|
*/
accessibilityState?: ?AccessibilityState,
accessibilityUnit?: ?Stringish,
accessibilityHours?: ?number,
accessibilityMinutes?: ?number,
accessibilityValue?: ?AccessibilityValue,

/**
Expand Down
2 changes: 2 additions & 0 deletions Libraries/NativeComponent/BaseViewConfig.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ const validAttributesForNonEventProps = {
accessibilityCollectionItem: true,
accessibilityState: true,
accessibilityUnit: true,
accessibilityHours: true,
accessibilityMinutes: true,
accessibilityActions: true,
accessibilityValue: true,
importantForAccessibility: true,
Expand Down
2 changes: 2 additions & 0 deletions Libraries/NativeComponent/BaseViewConfig.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ const validAttributesForNonEventProps = {
accessibilityRole: true,
accessibilityState: true,
accessibilityUnit: false,
accessibilityHours: false,
accessibilityMinutes: false,
nativeID: true,
pointerEvents: true,
removeClippedSubviews: true,
Expand Down
4 changes: 4 additions & 0 deletions Libraries/Text/Text.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ const Text: React.AbstractComponent<
{...restProps}
accessibilityState={_accessibilityState}
accessibilityUnit={props.accessibilityUnit}
accessibilityHours={props.accessibilityHours}
accessibilityMinutes={props.accessibilityMinutes}
{...eventHandlersForText}
accessibilityLabel={ariaLabel ?? accessibilityLabel}
accessibilityRole={
Expand All @@ -245,6 +247,8 @@ const Text: React.AbstractComponent<
{...restProps}
{...eventHandlersForText}
accessibilityUnit={props.accessibilityUnit}
accessibilityHours={props.accessibilityHours}
accessibilityMinutes={props.accessibilityMinutes}
disabled={_disabled}
selectable={_selectable}
accessible={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public class TextAttributeProps {
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 short TA_KEY_ACCESSIBILITY_HOURS = 48;
public static final short TA_KEY_ACCESSIBILITY_MINUTES = 49;

public static final int UNSET = -1;

Expand Down Expand Up @@ -106,6 +108,7 @@ public class TextAttributeProps {
protected boolean mIsAccessibilityRoleSet = false;
protected @Nullable String mAccessibilityUnit = null;
protected boolean mIsAccessibilityLink = false;
protected boolean mIsAccessibilityTtsSpan = false;

protected int mFontStyle = UNSET;
protected int mFontWeight = UNSET;
Expand Down Expand Up @@ -211,6 +214,12 @@ public static TextAttributeProps fromMapBuffer(MapBuffer props) {
case TA_KEY_ACCESSIBILITY_UNIT:
result.setAccessibilityUnit(entry.getStringValue());
break;
case TA_KEY_ACCESSIBILITY_HOURS:
result.setAccessibilityHours(entry.getIntValue());
break;
case TA_KEY_ACCESSIBILITY_MINUTES:
result.setAccessibilityMinutes(entry.getIntValue());
break;
}
}

Expand Down Expand Up @@ -612,15 +621,27 @@ private void setAccessibilityRole(@Nullable String accessibilityRole) {
mIsAccessibilityLink = mAccessibilityRole.equals(AccessibilityRole.LINK);
String roleClassName =
AccessibilityRole.getValue(AccessibilityRole.fromValue(accessibilityRole));
mAccessibilityUnit =
ReactTtsSpan.SUPPORTED_UNIT_TYPES.contains(roleClassName) ? roleClassName : null;
mIsAccessibilityTtsSpan =
ReactTtsSpan.SUPPORTED_UNIT_TYPES.contains(roleClassName) && Build.VERSION.SDK_INT >= 21;
}
}

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

private void setAccessibilityHours(@Nullable Integer accessibilityHours) {
if (accessibilityHours != null) {
Log.w("TESTING::TextAttributeProps", "accessibilityHours: " + (accessibilityHours));
}
}

private void setAccessibilityMinutes(@Nullable Integer accessibilityMinutes) {
if (accessibilityMinutes != null) {
Log.w("TESTING::TextAttributeProps", "accessibilityMinutes: " + (accessibilityMinutes));
}
}

public static int getTextBreakStrategy(@Nullable String textBreakStrategy) {
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 @@ -143,8 +144,12 @@ private static void buildSpannableFromFragment(
if (textAttributes.mIsAccessibilityLink) {
ops.add(new SetSpanOperation(start, end, new ReactClickableSpan(reactTag)));
}
if (textAttributes.mAccessibilityUnit != null && Build.VERSION.SDK_INT >= 21) {
if (textAttributes.mIsAccessibilityTtsSpan) {
// check that textAttributes.mAccessibilityRole == "time"
ReactTtsSpan.Builder builder = new ReactTtsSpan.Builder(ReactTtsSpan.TYPE_TIME);
Log.w(
"TESTING::TextLayoutManagerMapBuffer",
"textAttributes.mAccessibilityUnit: " + (textAttributes.mAccessibilityUnit));
builder.setIntArgument(ReactTtsSpan.ARG_HOURS, 10);
builder.setIntArgument(ReactTtsSpan.ARG_MINUTES, 30);
ops.add(new SetSpanOperation(start, end, builder.build()));
Expand Down
12 changes: 11 additions & 1 deletion ReactCommon/react/renderer/attributedstring/TextAttributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,12 @@ void TextAttributes::apply(TextAttributes textAttributes) {
accessibilityRole = textAttributes.accessibilityRole.has_value()
? textAttributes.accessibilityRole
: accessibilityRole;
accessibilityUnit = !textAttributes.accessibilityUnit.has_value() ? textAttributes.accessibilityUnit
accessibilityUnit = !textAttributes.accessibilityUnit.empty() ? textAttributes.accessibilityUnit
: accessibilityUnit;
accessibilityHours = !textAttributes.accessibilityHours.empty() ? textAttributes.accessibilityHours
: accessibilityHours;
accessibilityMinutes = !textAttributes.accessibilityMinutes.empty() ? textAttributes.accessibilityMinutes
: accessibilityMinutes;
}

#pragma mark - Operators
Expand All @@ -125,6 +129,8 @@ bool TextAttributes::operator==(const TextAttributes &rhs) const {
layoutDirection,
accessibilityRole,
accessibilityUnit,
accessibilityHours,
accessibilityMinutes,
textTransform) ==
std::tie(
rhs.foregroundColor,
Expand All @@ -146,6 +152,8 @@ bool TextAttributes::operator==(const TextAttributes &rhs) const {
rhs.layoutDirection,
rhs.accessibilityRole,
rhs.accessibilityUnit,
rhs.accessibilityHours,
rhs.accessibilityMinutes,
rhs.textTransform) &&
floatEquality(opacity, rhs.opacity) &&
floatEquality(fontSize, rhs.fontSize) &&
Expand Down Expand Up @@ -214,6 +222,8 @@ SharedDebugStringConvertibleList TextAttributes::getDebugProps() const {
debugStringConvertibleItem("layoutDirection", layoutDirection),
debugStringConvertibleItem("accessibilityRole", accessibilityRole),
debugStringConvertibleItem("accessibilityUnit", accessibilityUnit),
debugStringConvertibleItem("accessibilityHours", accessibilityHours),
debugStringConvertibleItem("accessibilityMinutes", accessibilityMinutes),
};
}
#endif
Expand Down
8 changes: 6 additions & 2 deletions ReactCommon/react/renderer/attributedstring/TextAttributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ class TextAttributes : public DebugStringConvertible {
// construction.
std::optional<LayoutDirection> layoutDirection{};
std::optional<AccessibilityRole> accessibilityRole{};
AccessibilityUnit accessibilityUnit{};
std::string accessibilityUnit{};
std::string accessibilityHours{};
std::string accessibilityMinutes{};

#pragma mark - Operations

Expand Down Expand Up @@ -133,7 +135,9 @@ struct hash<facebook::react::TextAttributes> {
textAttributes.isHighlighted,
textAttributes.layoutDirection,
textAttributes.accessibilityRole,
textAttributes.accessibilityUnit);
textAttributes.accessibilityUnit,
textAttributes.accessibilityHours,
textAttributes.accessibilityMinutes);
}
};
} // namespace std
20 changes: 20 additions & 0 deletions ReactCommon/react/renderer/attributedstring/conversions.h
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,14 @@ inline folly::dynamic toDynamic(const TextAttributes &textAttributes) {
_textAttributes(
"accessibilityUnit", textAttributes.accessibilityUnit);
}
if (!textAttributes.accessibilityHours.empty()) {
_textAttributes(
"accessibilityHours", textAttributes.accessibilityHours);
}
if (!textAttributes.accessibilityMinutes.empty()) {
_textAttributes(
"accessibilityMinutes", textAttributes.accessibilityMinutes);
}
return _textAttributes;
}

Expand Down Expand Up @@ -1088,6 +1096,8 @@ 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;
constexpr static MapBuffer::Key TA_KEY_ACCESSIBILITY_HOURS = 48;
constexpr static MapBuffer::Key TA_KEY_ACCESSIBILITY_MINUTES = 49;

// constants for ParagraphAttributes serialization
constexpr static MapBuffer::Key PA_KEY_MAX_NUMBER_OF_LINES = 0;
Expand Down Expand Up @@ -1240,6 +1250,16 @@ inline MapBuffer toMapBuffer(const TextAttributes &textAttributes) {
builder.putString(
TA_KEY_ACCESSIBILITY_UNIT, textAttributes.accessibilityUnit);
}
if (!textAttributes.accessibilityHours.empty()) {

builder.putString(
TA_KEY_ACCESSIBILITY_HOURS, textAttributes.accessibilityHours);
}
if (!textAttributes.accessibilityMinutes.empty()) {

builder.putString(
TA_KEY_ACCESSIBILITY_MINUTES, textAttributes.accessibilityMinutes);
}
return builder.build();
}

Expand Down
4 changes: 0 additions & 4 deletions ReactCommon/react/renderer/attributedstring/primitives.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,6 @@ enum class AccessibilityRole {
Toolbar,
};

struct AccessibilityUnit {
std::string hours{""};
};

enum class TextTransform {
None,
Uppercase,
Expand Down
26 changes: 25 additions & 1 deletion ReactCommon/react/renderer/components/text/BaseTextProps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,18 @@ static TextAttributes convertRawProp(
"accessibilityUnit",
sourceTextAttributes.accessibilityUnit,
defaultTextAttributes.accessibilityUnit);
textAttributes.accessibilityHours = convertRawProp(
context,
rawProps,
"accessibilityHours",
sourceTextAttributes.accessibilityHours,
defaultTextAttributes.accessibilityHours);
textAttributes.accessibilityMinutes = convertRawProp(
context,
rawProps,
"accessibilityMinutes",
sourceTextAttributes.accessibilityMinutes,
defaultTextAttributes.accessibilityMinutes);

// Color (accessed in this order by ViewProps)
textAttributes.opacity = convertRawProp(
Expand Down Expand Up @@ -298,8 +310,20 @@ void BaseTextProps::setProp(
defaults,
value,
textAttributes,
accessibilityRole,
accessibilityUnit,
"accessibilityUnit");
REBUILD_FIELD_SWITCH_CASE(
defaults,
value,
textAttributes,
accessibilityHours,
"accessibilityHours");
REBUILD_FIELD_SWITCH_CASE(
defaults,
value,
textAttributes,
accessibilityMinutes,
"accessibilityMinutes");
REBUILD_FIELD_SWITCH_CASE(
defaults, value, textAttributes, opacity, "opacity");
REBUILD_FIELD_SWITCH_CASE(
Expand Down
20 changes: 20 additions & 0 deletions ReactCommon/react/renderer/components/view/AccessibilityProps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,24 @@ AccessibilityProps::AccessibilityProps(
"accessibilityUnit",
sourceProps.accessibilityUnit,
{})),
accessibilityHours(
CoreFeatures::enablePropIteratorSetter
? sourceProps.accessibilityHours
: convertRawProp(
context,
rawProps,
"accessibilityHours",
sourceProps.accessibilityHours,
{})),
accessibilityMinutes(
CoreFeatures::enablePropIteratorSetter
? sourceProps.accessibilityMinutes
: convertRawProp(
context,
rawProps,
"accessibilityMinutes",
sourceProps.accessibilityMinutes,
{})),
accessibilityLabel(
CoreFeatures::enablePropIteratorSetter
? sourceProps.accessibilityLabel
Expand Down Expand Up @@ -221,6 +239,8 @@ void AccessibilityProps::setProp(
RAW_SET_PROP_SWITCH_CASE_BASIC(accessible, false);
RAW_SET_PROP_SWITCH_CASE_BASIC(accessibilityState, {});
RAW_SET_PROP_SWITCH_CASE_BASIC(accessibilityUnit, {});
RAW_SET_PROP_SWITCH_CASE_BASIC(accessibilityHours, {});
RAW_SET_PROP_SWITCH_CASE_BASIC(accessibilityMinutes, {});
RAW_SET_PROP_SWITCH_CASE_BASIC(accessibilityLabel, std::string{""});
RAW_SET_PROP_SWITCH_CASE_BASIC(accessibilityLabelledBy, {});
RAW_SET_PROP_SWITCH_CASE_BASIC(accessibilityHint, std::string{""});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class AccessibilityProps {
bool accessible{false};
AccessibilityState accessibilityState;
AccessibilityUnit accessibilityUnit;
AccessibilityUnit accessibilityHours;
AccessibilityUnit accessibilityMinutes;
std::string accessibilityLabel{""};
AccessibilityLabelledBy accessibilityLabelledBy{};
AccessibilityLiveRegion accessibilityLiveRegion{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ constexpr MapBuffer::Key AP_ACCESSIBILITY_VALUE = 7;
constexpr MapBuffer::Key AP_ACCESSIBLE = 8;
constexpr MapBuffer::Key AP_IMPORTANT_FOR_ACCESSIBILITY = 19;
constexpr MapBuffer::Key AP_ACCESSIBILITY_UNIT = 47;
constexpr MapBuffer::Key AP_ACCESSIBILITY_HOURS = 48;
constexpr MapBuffer::Key AP_ACCESSIBILITY_MINUTES = 49;

// AccessibilityAction values
constexpr MapBuffer::Key ACCESSIBILITY_ACTION_NAME = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,13 @@ inline void fromRawValue(
*/
}

inline void fromRawValue(
const PropsParserContext &context,
const RawValue &value,
int &result) {
result = 9;
}

inline std::string toString(
const AccessibilityUnit &accessibilityUnit) {
return "default string";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class AccessibilityExample extends React.Component<{}> {
My number is
<Text
accessibilityRole="time"
accessibilityUnit="an example of prop"
accessibilityUnit="10:30"
accessible={true}
style={{backgroundColor: 'red'}}>
17:00
Expand Down