Skip to content

Commit 9440b8c

Browse files
committed
Support injecting extra ui comonent to the settings screen.
1 parent 8ebd8d5 commit 9440b8c

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

demo/src/screens/MainScreen.js

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ class MainScreen extends Component {
1515
static propTypes = {
1616
containerStyle: ViewPropTypes.style,
1717
renderItem: PropTypes.func,
18-
pageStyle: ViewPropTypes.style
18+
pageStyle: ViewPropTypes.style,
19+
showRefreshAppMessage: PropTypes.bool
1920
};
2021

2122
static options() {
@@ -33,23 +34,32 @@ class MainScreen extends Component {
3334
};
3435
}
3536

37+
settingsScreenName = 'unicorn.Settings';
38+
3639
constructor(props) {
3740
super(props);
3841

3942
const data = props.navigationData || navigationData;
4043
const extraSettingsUI = props.extraSettingsUI;
41-
44+
const showRefreshAppMessage = props.showRefreshAppMessage;
45+
4246
this.state = {
4347
currentPage: 0,
4448
filteredNavigationData: data,
45-
extraSettingsUI
49+
extraSettingsUI,
50+
showRefreshAppMessage
4651
};
4752

4853
this.filterExplorerScreens = _.throttle(this.filterExplorerScreens, 300);
4954

5055
Navigation.events().bindComponent(this);
5156
}
5257

58+
shouldComponentUpdate = (nextProps, nextState) => {
59+
this.updateShowRefreshAppMessage(nextProps.showRefreshAppMessage);
60+
return true;
61+
}
62+
5363
onSearchBoxBlur = () => {
5464
this.closeSearchBox();
5565
// this.filterExplorerScreens('');
@@ -65,16 +75,27 @@ class MainScreen extends Component {
6575

6676
if (buttonId === 'uilib.settingsButton') {
6777
this.pushScreen({
68-
name: 'unicorn.Settings',
69-
passProps: {navigationData: data, playground: this.props.playground, extraSettingsUI: this.state.extraSettingsUI}
78+
name: this.settingsScreenName,
79+
passProps: {navigationData: data,
80+
playground: this.props.playground,
81+
extraSettingsUI: this.state.extraSettingsUI,
82+
showRefreshAppMessage: false
83+
}
7084
});
7185
}
7286
};
7387

88+
updateShowRefreshAppMessage = (show) => {
89+
Navigation.updateProps(MainScreen.settingsScreenName, {
90+
showRefreshAppMessage: show
91+
});
92+
}
93+
7494
pushScreen = options => {
7595
Navigation.push(this.props.componentId, {
7696
component: {
7797
name: options.name || options.screen,
98+
id: this.settingsScreenName,
7899
passProps: options.passProps,
79100
options: {
80101
topBar: {

0 commit comments

Comments
 (0)