Skip to content

Commit

Permalink
Fix custom back button missing id
Browse files Browse the repository at this point in the history
Id property wasn’t handled when copying back button in native
  • Loading branch information
guyca committed Feb 3, 2019
1 parent 4aa5cd1 commit 578f6a8
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
7 changes: 7 additions & 0 deletions e2e/ScreenStack.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,11 @@ describe('screen stack', () => {
await elementById(testIDs.PUSH_BOTTOM_TABS_BUTTON).tap();
await expect(elementById(testIDs.BOTTOM_TABS_ELEMENT)).toBeVisible();
});

test(':android: custom back button', async () => {
await elementById(testIDs.PUSH_BUTTON).tap();
await elementById(testIDs.PUSH_CUSTOM_BACK_BUTTON).tap();
await elementById(testIDs.CUSTOM_BACK_BUTTON).tap();
await expect(elementByLabel('back button clicked')).toBeVisible();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public boolean hasValue() {
}

public void mergeWith(BackButton other) {
if (!Constants.BACK_BUTTON_ID.equals(other.id)) id = other.id;
if (other.icon.hasValue()) icon = other.icon;
if (other.visible.hasValue()) visible = other.visible;
if (other.color.hasValue()) color = other.color;
Expand All @@ -50,6 +51,7 @@ public void mergeWith(BackButton other) {
}

void mergeWithDefault(final BackButton defaultOptions) {
if (Constants.BACK_BUTTON_ID.equals(id)) id = defaultOptions.id;
if (!icon.hasValue()) icon = defaultOptions.icon;
if (!visible.hasValue()) visible = defaultOptions.visible;
if (!color.hasValue()) color = defaultOptions.color;
Expand Down
31 changes: 31 additions & 0 deletions playground/src/screens/PushedScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class PushedScreen extends Component {

constructor(props) {
super(props);
Navigation.events().bindComponent(this);
if (this.props.simulateLongRunningTask) {
this.simulateLongRunningTask();
}
Expand All @@ -49,6 +50,12 @@ class PushedScreen extends Component {
for (let i = 0; i < Math.pow(2, 25); i++);
}

navigationButtonPressed({buttonId}) {
if (buttonId === 'backPress') {
alert('back button clicked')
}
}

listeners = [];

componentDidMount() {
Expand Down Expand Up @@ -89,6 +96,7 @@ class PushedScreen extends Component {
<Button title='Pop To Root' testID={testIDs.POP_TO_ROOT} onPress={this.onClickPopToRoot} />
<Button title='Set Stack Root' testID={testIDs.SET_STACK_ROOT_BUTTON} onPress={this.onClickSetStackRoot} />
<Button title='Push and Wait for Render' testID={testIDs.PUSH_BUTTON_WAIT_FOR_RENDER} onPress={this.onClickPushWaitForRender} />
<Button title='Push custom back button' testID={testIDs.PUSH_CUSTOM_BACK_BUTTON} onPress={this.onClickPushCustomBackButton} />
{stackPosition > 2 && <Button title='Pop To Stack Position 1' testID={testIDs.POP_STACK_POSITION_ONE_BUTTON} onPress={this.onClickPopToFirstPosition} />}
<Text style={styles.footer}>{`this.props.componentId = ${this.props.componentId}`}</Text>
</View>
Expand Down Expand Up @@ -242,6 +250,29 @@ class PushedScreen extends Component {
});
}

onClickPushCustomBackButton = async () => {
Navigation.push(this.props.componentId, {
component: {
name: 'navigation.playground.PushedScreen',
passProps: {
stackPosition: this.getStackPosition() + 1,
previousScreenIds: _.concat([], this.props.previousScreenIds || [], this.props.componentId),
},
options: {
topBar: {
backButton: {
id: 'backPress',
icon: require('../../img/navicon_add.png'),
visible: true,
color: 'black',
testID: testIDs.CUSTOM_BACK_BUTTON
}
}
}
}
});
}

async onClickPushBottomTabs() {
await Navigation.push(this.props.componentId, {
bottomTabs: {
Expand Down
2 changes: 2 additions & 0 deletions playground/src/testIDs.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module.exports = {
PUSH_DEFAULT_OPTIONS_BUTTON: `PUSH_DEFAULT_OPTIONS_BUTTON`,
SHOW_TOPBAR_REACT_VIEW: `SHOW_TOPBAR_REACT_VIEW`,
BACK_HANDLER_BUTTON: `BACK_HANDLER_BUTTON`,
CUSTOM_BACK_BUTTON: `CUSTOM_BACK_BUTTON`,
SHOW_MODAL_BUTTON: `SHOW_MODAL_BUTTON`,
SHOW_REDBOX_BUTTON: `SHOW_REDBOX_BUTTON`,
ORIENTATION_BUTTON: `ORIENTATION_BUTTON`,
Expand Down Expand Up @@ -49,6 +50,7 @@ module.exports = {
SET_TAB_BADGE_BUTTON_NULL: `SET_TAB_BADGE_BUTTON_NULL`,
PUSH_TO_TEST_DID_DISAPPEAR_BUTTON: `PUSH_TO_TEST_DID_DISAPPEAR_BUTTON`,
PUSH_BUTTON_WAIT_FOR_RENDER: `PUSH_AND_WAIT_FOR_RENDER`,
PUSH_CUSTOM_BACK_BUTTON: `PUSH_CUSTOM_BACK_BUTTON`,
SHOW_LEFT_SIDE_MENU_BUTTON: `SHOW_LEFT_SIDE_MENU_BUTTON`,
SHOW_RIGHT_SIDE_MENU_BUTTON: `SHOW_RIGHT_SIDE_MENU_BUTTON`,
HIDE_LEFT_SIDE_MENU_BUTTON: `HIDE_LEFT_SIDE_MENU_BUTTON`,
Expand Down

0 comments on commit 578f6a8

Please sign in to comment.