Skip to content
Merged
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
1 change: 1 addition & 0 deletions ios/RNCSegmentedControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
@interface RNCSegmentedControl : UISegmentedControl
@property(nonatomic, assign) NSInteger selectedIndex;
@property(nonatomic, copy) RCTBubblingEventBlock onChange;
@property(nonatomic, copy) NSArray *testIDS;

@end
13 changes: 13 additions & 0 deletions ios/RNCSegmentedControl.m
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,17 @@ - (void)setAppearance:(NSString *)appearanceString {
#endif
}

- (NSArray *)accessibilityElements {
NSArray *elements = [super accessibilityElements];
[elements enumerateObjectsUsingBlock:^(UIView *obj, NSUInteger idx, BOOL *stop) {
@try {
obj.accessibilityIdentifier = self.testIDS[idx];
} @catch (NSException *exception) {
NSLog(@"%@", exception);
}
}];

return elements;
}

@end
1 change: 1 addition & 0 deletions ios/RNCSegmentedControlManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ - (UIView *)view {
RCT_EXPORT_VIEW_PROPERTY(enabled, BOOL)
RCT_EXPORT_VIEW_PROPERTY(onChange, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(appearance, NSString)
RCT_EXPORT_VIEW_PROPERTY(testIDS, NSArray)

RCT_CUSTOM_VIEW_PROPERTY(fontStyle, NSObject, RNCSegmentedControl) {
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && defined(__IPHONE_13_0) && \
Expand Down
2 changes: 2 additions & 0 deletions js/SegmentedControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const SegmentedControl = ({
activeFontStyle,
appearance,
accessibilityHintSeperator = 'out of',
testIDS,
}: SegmentedControlProps): React.Node => {
const colorSchemeHook = useColorScheme();
const colorScheme = appearance || colorSchemeHook;
Expand Down Expand Up @@ -113,6 +114,7 @@ const SegmentedControl = ({
return (
<SegmentedControlTab
enabled={enabled}
testID={(testIDS?.length ?? 0) > index ? testIDS[index] : `${index}`}
selected={selectedIndex === index}
accessibilityHint={`${
index + 1
Expand Down
5 changes: 3 additions & 2 deletions js/SegmentedControlTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ export const SegmentedControlTab = ({
onPress={onSelect}
accessibilityHint={accessibilityHint}
accessibilityRole="button"
accessibilityState={{selected: selected, disabled: !enabled}}>
<View testID={testID} style={styles.default}>
accessibilityState={{selected: selected, disabled: !enabled}}
testID={testID}>
<View style={styles.default}>
{typeof value === 'number' || typeof value === 'object' ? (
<Image source={value} style={styles.segmentImage} />
) : isBase64(value) ? (
Expand Down
6 changes: 6 additions & 0 deletions js/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,10 @@ export type SegmentedControlProps = $ReadOnly<{|
* Touchable style properties for Segmented Control Tab
*/
tabStyle?: ViewStyle,


/**
* array testID to each segment button
*/
testIDS: $ReadOnlyArray<string | number | Object>,
|}>;