feat: don't hardcode header back test ID

BREAKING CHANGE: Now the back button test ID can be customized using headerBackTestID option
This commit is contained in:
Satyajit Sahoo
2021-01-15 11:35:29 +01:00
parent 4954d6aae3
commit 22a8afac74
3 changed files with 12 additions and 1 deletions

View File

@@ -147,6 +147,10 @@ export type StackHeaderOptions = {
* Accessibility label for the header back button.
*/
headerBackAccessibilityLabel?: string;
/**
* ID to locate this back button in tests.
*/
headerBackTestID?: string;
/**
* Title string used by the back button on iOS. Defaults to the previous scene's `headerTitle`.
* Use `headerBackTitleVisible: false` to hide it.
@@ -449,6 +453,10 @@ export type StackHeaderLeftButtonProps = {
* Accessibility label for the button for screen readers.
*/
accessibilityLabel?: string;
/**
* ID to locate this button in tests.
*/
testID?: string;
/**
* Style object for the button.
*/

View File

@@ -30,6 +30,7 @@ export default function HeaderBackButton({
titleLayout,
truncatedLabel = 'Back',
accessibilityLabel = label && label !== 'Back' ? `${label}, back` : 'Go back',
testID,
style,
}: Props) {
const { dark, colors } = useTheme();
@@ -155,7 +156,7 @@ export default function HeaderBackButton({
accessible
accessibilityRole="button"
accessibilityLabel={accessibilityLabel}
testID="header-back"
testID={testID}
delayPressIn={0}
onPress={disabled ? undefined : handlePress}
pressColor={pressColorAndroid}

View File

@@ -163,6 +163,7 @@ export default function HeaderSegment(props: Props) {
headerTruncatedBackTitle: truncatedLabel,
headerPressColorAndroid: pressColorAndroid,
headerBackAccessibilityLabel: backAccessibilityLabel,
headerBackTestID: backTestID,
headerBackAllowFontScaling: backAllowFontScaling,
headerTitleAllowFontScaling: titleAllowFontScaling,
headerTitleStyle: customTitleStyle,
@@ -292,6 +293,7 @@ export default function HeaderSegment(props: Props) {
backImage,
pressColorAndroid,
accessibilityLabel: backAccessibilityLabel,
testID: backTestID,
allowFontScaling: backAllowFontScaling,
onPress: onGoBack,
labelVisible: headerBackTitleVisible,