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 @@ -8,7 +8,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

### Changed

- We updated react-native-segmented-control-tab to 3.4.1.
- Replaced external dependency `react-native-segmented-control-tab` with in-house SegmentedControl component.
- Fixed accessibility: component now uses modern React Native accessibility props (`accessibilityRole="tab"`, `accessibilityState.selected`) instead of deprecated `accessibilityTraits` and `accessibilityComponentType`.

## [2.3.0] - 2024-12-3

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,67 @@ 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",
"borderRadius": 3,
"borderWidth": 1,
"flex": 1,
"justifyContent": "center",
"opacity": 1,
"paddingVertical": 5,
},
{
"borderColor": "#CCC",
"borderRadius": 0,
},
{
"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 +115,51 @@ 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",
"borderRadius": 3,
"borderWidth": 1,
"flex": 1,
"justifyContent": "center",
"opacity": 1,
"paddingVertical": 5,
},
{
"borderColor": "#CCC",
"borderRadius": 0,
},
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,76 @@
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;

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,
borderRadius,
backgroundColor: "transparent",
opacity: pressed ? 0.6 : 1
},
buttonStyle,
isSelected && activeButtonStyle
]}
testID={`${testID}$button-${index}`}
>
<Text numberOfLines={1} style={[textStyle, isSelected && activeTextStyle]}>
{value}
</Text>
</Pressable>
);
})}
</View>
);
}
Loading
Loading