Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]

### Changed

- Replaced external dependency `react-native-segmented-control-tab` with in-house SegmentedControl component.

### Fixed

- toggle button now uses modern React Native accessibility props (`accessibilityRole="tab"`, `accessibilityState.selected`) instead of deprecated `accessibilityTraits` and `accessibilityComponentType`.

## [2.5.0] - 2026-9-2

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
},
"dependencies": {
"@mendix/piw-native-utils-internal": "*",
"@mendix/piw-utils-internal": "*",
"react-native-segmented-control-tab": "3.4.1"
"@mendix/piw-utils-internal": "*"
},
"devDependencies": {
"@babel/plugin-transform-flow-strip-types": "^7.4.4",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { flattenStyles } from "@mendix/piw-native-utils-internal";
import { Component, JSX } from "react";
import { Text, View } from "react-native";
import SegmentedControlTab from "react-native-segmented-control-tab";

import { ToggleButtonsProps } from "../typings/ToggleButtonsProps";
import { defaultToggleButtonsStyle, ToggleButtonsStyle } from "./ui/Styles";
import { executeAction } from "@mendix/piw-utils-internal";
import { SegmentedControl } from "./components/SegmentedControl";

export type Props = ToggleButtonsProps<ToggleButtonsStyle>;

Expand All @@ -25,16 +25,17 @@ export class ToggleButtons extends Component<Props> {

return (
<View style={enabled ? this.styles.container : this.styles.containerDisabled} testID={this.props.name}>
<SegmentedControlTab
<SegmentedControl
values={captions}
selectedIndex={selectedIndex}
enabled={enabled}
onTabPress={this.onChangeHandler}
borderRadius={Number(this.styles.container.borderRadius)}
tabStyle={this.styles.button}
tabTextStyle={this.styles.text}
activeTabStyle={this.styles.activeButton}
activeTabTextStyle={this.styles.activeButtonText}
buttonStyle={this.styles.button}
textStyle={this.styles.text}
activeButtonStyle={this.styles.activeButton}
activeTextStyle={this.styles.activeButtonText}
testID={this.props.name}
/>
{this.props.enum.validation && (
<Text style={this.styles.validationMessage}>{this.props.enum.validation}</Text>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,24 @@ exports[`ToggleButtons renders 1`] = `
testID="toggle-buttons-test"
>
<View
removeClippedSubviews={false}
accessibilityRole="tablist"
accessible={false}
style={
[
{
"backgroundColor": "transparent",
"flexDirection": "row",
},
{},
]
{
"flexDirection": "row",
}
}
>
<View
accessibilityLabel="Formatted a"
accessibilityRole="tab"
accessibilityState={
{
"busy": undefined,
"checked": undefined,
"disabled": false,
"expanded": undefined,
"selected": undefined,
"selected": true,
}
}
accessibilityValue={
Expand All @@ -43,75 +41,68 @@ exports[`ToggleButtons renders 1`] = `
accessible={true}
collapsable={false}
focusable={true}
onBlur={[Function]}
onClick={[Function]}
onFocus={[Function]}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
style={
{
"alignItems": "center",
"backgroundColor": "rgb(98, 0, 238)",
"borderBottomLeftRadius": 3,
"borderColor": "rgb(98, 0, 238)",
"borderRadius": 0,
"borderRightWidth": 1,
"borderTopLeftRadius": 3,
"borderWidth": 1,
"flex": 1,
"justifyContent": "center",
"opacity": 1,
"paddingVertical": 5,
}
[
{
"alignItems": "center",
"backgroundColor": "transparent",
"borderBottomLeftRadius": 3,
"borderTopLeftRadius": 3,
"borderWidth": 1,
"flex": 1,
"justifyContent": "center",
"opacity": 1,
"paddingVertical": 5,
},
{
"backgroundColor": "#fff",
"borderColor": "#CCC",
},
{
"backgroundColor": "rgb(98, 0, 238)",
"borderColor": "rgb(98, 0, 238)",
},
]
}
testID="toggle-buttons-test$button-0"
>
<View
<Text
numberOfLines={1}
style={
{
"flexDirection": "row",
}
[
{
"color": "#666",
"fontWeight": "600",
"paddingVertical": 3,
},
{
"color": "#fff",
},
]
}
>
<Text
allowFontScaling={true}
ellipsizeMode="tail"
numberOfLines={1}
style={
[
{
"color": "#0076FF",
},
{
"color": "#666",
"fontWeight": "600",
"paddingVertical": 3,
},
[
{
"color": "white",
},
{
"color": "#fff",
},
],
]
}
>
Formatted a
</Text>
</View>
Formatted a
</Text>
</View>
<View
accessibilityLabel="Formatted b"
accessibilityRole="tab"
accessibilityState={
{
"busy": undefined,
"checked": undefined,
"disabled": false,
"expanded": undefined,
"selected": undefined,
"selected": false,
}
}
accessibilityValue={
Expand All @@ -125,58 +116,53 @@ exports[`ToggleButtons renders 1`] = `
accessible={true}
collapsable={false}
focusable={true}
onBlur={[Function]}
onClick={[Function]}
onFocus={[Function]}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
style={
{
"alignItems": "center",
"backgroundColor": "white",
"borderBottomRightRadius": 3,
"borderColor": "#CCC",
"borderLeftWidth": 0,
"borderRadius": 0,
"borderTopRightRadius": 3,
"borderWidth": 1,
"flex": 1,
"justifyContent": "center",
"opacity": 1,
"paddingVertical": 5,
}
[
{
"alignItems": "center",
"backgroundColor": "transparent",
"borderBottomRightRadius": 3,
"borderTopRightRadius": 3,
"borderWidth": 1,
"flex": 1,
"justifyContent": "center",
"marginLeft": -1,
"opacity": 1,
"paddingVertical": 5,
},
{
"backgroundColor": "#fff",
"borderColor": "#CCC",
},
false,
]
}
testID="toggle-buttons-test$button-1"
>
<View
<Text
numberOfLines={1}
style={
{
"flexDirection": "row",
}
[
{
"color": "#666",
"fontWeight": "600",
"paddingVertical": 3,
},
false,
]
}
>
<Text
allowFontScaling={true}
ellipsizeMode="tail"
numberOfLines={1}
style={
[
{
"color": "#0076FF",
},
{
"color": "#666",
"fontWeight": "600",
"paddingVertical": 3,
},
{},
]
}
>
Formatted b
</Text>
</View>
Formatted b
</Text>
</View>
</View>
</View>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { ReactElement } from "react";
import { Pressable, Text, View, ViewStyle, TextStyle } from "react-native";

export interface SegmentedControlProps {
values: string[];
selectedIndex: number;
enabled: boolean;
onTabPress: (index: number) => void;
borderRadius: number;
buttonStyle: ViewStyle;
textStyle: TextStyle;
activeButtonStyle: ViewStyle;
activeTextStyle: TextStyle;
testID: string;
}

export function SegmentedControl(props: SegmentedControlProps): ReactElement {
const {
values,
selectedIndex,
enabled,
onTabPress,
borderRadius,
buttonStyle,
textStyle,
activeButtonStyle,
activeTextStyle,
testID
} = props;

const handlePress = (index: number) => {
if (!enabled || index === selectedIndex) {
return;
}
onTabPress(index);
};

return (
<View style={{ flexDirection: "row" }} accessible={false} accessibilityRole="tablist">
{values.map((value, index) => {
const isSelected = index === selectedIndex;
const isFirst = index === 0;
const isLast = index === values.length - 1;

return (
<Pressable
key={index}
accessible
accessibilityRole="tab"
accessibilityState={{ selected: isSelected }}
accessibilityLabel={value}
onPress={() => handlePress(index)}
disabled={!enabled}
style={({ pressed }) => [
{
flex: 1,
alignItems: "center",
justifyContent: "center",
paddingVertical: 5,
borderWidth: 1,
backgroundColor: "transparent",
opacity: pressed ? 0.6 : 1,
...(isFirst && {
borderTopLeftRadius: borderRadius,
borderBottomLeftRadius: borderRadius
}),
...(isLast && {
borderTopRightRadius: borderRadius,
borderBottomRightRadius: borderRadius
}),
...(!isFirst && { marginLeft: -1 })
},
buttonStyle,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This note is part of automatic LLM review so I am not entirely sure of validity. But, posting it here so that at least we test it, since it might pass the maestro screenshot comparison threshold.

Image

isSelected && activeButtonStyle
]}
testID={`${testID}$button-${index}`}
>
<Text numberOfLines={1} style={[textStyle, isSelected && activeTextStyle]}>
Comment thread
MxKevinBeqo marked this conversation as resolved.
{value}
</Text>
</Pressable>
);
})}
</View>
);
}
Loading
Loading