mirror of
https://github.com/status-im/react-navigation.git
synced 2025-02-24 17:18:09 +00:00
Issue-2662: Add support for testID and accessibilityLabel for tab bar items (#2684)
This commit is contained in:
parent
3ae4b31a9d
commit
82c2cdbe09
@ -28,6 +28,10 @@ const MyHomeScreen = ({ navigation }) => (
|
|||||||
);
|
);
|
||||||
|
|
||||||
MyHomeScreen.navigationOptions = {
|
MyHomeScreen.navigationOptions = {
|
||||||
|
tabBarTestIDProps: {
|
||||||
|
testID: 'TEST_ID_HOME',
|
||||||
|
accessibilityLabel: 'TEST_ID_HOME_ACLBL',
|
||||||
|
},
|
||||||
tabBarLabel: 'Home',
|
tabBarLabel: 'Home',
|
||||||
tabBarIcon: ({ tintColor, focused }) => (
|
tabBarIcon: ({ tintColor, focused }) => (
|
||||||
<Ionicons
|
<Ionicons
|
||||||
|
@ -336,6 +336,7 @@ export type NavigationTabScreenOptions = {
|
|||||||
*
|
*
|
||||||
>),
|
>),
|
||||||
tabBarVisible?: boolean,
|
tabBarVisible?: boolean,
|
||||||
|
tabBarTestIDProps?: { testID?: string, accessibilityLabel?: string },
|
||||||
tabBarOnPress?: (
|
tabBarOnPress?: (
|
||||||
scene: TabScene,
|
scene: TabScene,
|
||||||
jumpToIndex: (index: number) => void
|
jumpToIndex: (index: number) => void
|
||||||
|
@ -40,6 +40,7 @@ type Props = {
|
|||||||
getOnPress: (
|
getOnPress: (
|
||||||
scene: TabScene
|
scene: TabScene
|
||||||
) => (scene: TabScene, jumpToIndex: (index: number) => void) => void,
|
) => (scene: TabScene, jumpToIndex: (index: number) => void) => void,
|
||||||
|
getTestIDProps: (scene: TabScene) => (scene: TabScene) => any,
|
||||||
renderIcon: (scene: TabScene) => React.Element<*>,
|
renderIcon: (scene: TabScene) => React.Element<*>,
|
||||||
style?: ViewStyleProp,
|
style?: ViewStyleProp,
|
||||||
labelStyle?: TextStyleProp,
|
labelStyle?: TextStyleProp,
|
||||||
@ -135,12 +136,19 @@ export default class TabBarBottom extends PureComponent<
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
_renderTestIDProps = (scene: TabScene) => {
|
||||||
|
const testIDProps =
|
||||||
|
this.props.getTestIDProps && this.props.getTestIDProps(scene);
|
||||||
|
return testIDProps;
|
||||||
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {
|
const {
|
||||||
position,
|
position,
|
||||||
navigation,
|
navigation,
|
||||||
jumpToIndex,
|
jumpToIndex,
|
||||||
getOnPress,
|
getOnPress,
|
||||||
|
getTestIDProps,
|
||||||
activeBackgroundColor,
|
activeBackgroundColor,
|
||||||
inactiveBackgroundColor,
|
inactiveBackgroundColor,
|
||||||
style,
|
style,
|
||||||
@ -166,9 +174,13 @@ export default class TabBarBottom extends PureComponent<
|
|||||||
outputRange: (outputRange: Array<string>),
|
outputRange: (outputRange: Array<string>),
|
||||||
});
|
});
|
||||||
const justifyContent = this.props.showIcon ? 'flex-end' : 'center';
|
const justifyContent = this.props.showIcon ? 'flex-end' : 'center';
|
||||||
|
const extraProps = this._renderTestIDProps(scene) || {};
|
||||||
|
const { testID, accessibilityLabel } = extraProps;
|
||||||
return (
|
return (
|
||||||
<TouchableWithoutFeedback
|
<TouchableWithoutFeedback
|
||||||
key={route.key}
|
key={route.key}
|
||||||
|
testID={testID}
|
||||||
|
accessibilityLabel={accessibilityLabel}
|
||||||
onPress={() =>
|
onPress={() =>
|
||||||
onPress ? onPress(scene, jumpToIndex) : jumpToIndex(index)}
|
onPress ? onPress(scene, jumpToIndex) : jumpToIndex(index)}
|
||||||
>
|
>
|
||||||
|
@ -104,6 +104,15 @@ class TabView extends PureComponent<void, Props, void> {
|
|||||||
return options.tabBarOnPress;
|
return options.tabBarOnPress;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
_getTestIDProps = ({ route }: TabScene) => {
|
||||||
|
const options = this.props.router.getScreenOptions(
|
||||||
|
this.props.childNavigationProps[route.key],
|
||||||
|
this.props.screenProps || {}
|
||||||
|
);
|
||||||
|
|
||||||
|
return options.tabBarTestIDProps;
|
||||||
|
};
|
||||||
|
|
||||||
_renderIcon = ({ focused, route, tintColor }: TabScene) => {
|
_renderIcon = ({ focused, route, tintColor }: TabScene) => {
|
||||||
const options = this.props.router.getScreenOptions(
|
const options = this.props.router.getScreenOptions(
|
||||||
this.props.childNavigationProps[route.key],
|
this.props.childNavigationProps[route.key],
|
||||||
@ -133,6 +142,7 @@ class TabView extends PureComponent<void, Props, void> {
|
|||||||
screenProps={this.props.screenProps}
|
screenProps={this.props.screenProps}
|
||||||
navigation={this.props.navigation}
|
navigation={this.props.navigation}
|
||||||
getLabel={this._getLabel}
|
getLabel={this._getLabel}
|
||||||
|
getTestIDProps={this._getTestIDProps}
|
||||||
getOnPress={this._getOnPress}
|
getOnPress={this._getOnPress}
|
||||||
renderIcon={this._renderIcon}
|
renderIcon={this._renderIcon}
|
||||||
animationEnabled={animationEnabled}
|
animationEnabled={animationEnabled}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user