Skip to content

Commit 076b1ce

Browse files
t4deufacebook-github-bot
authored andcommitted
Prevent show a hidden status bar when opening modals, fix #7474
Summary: <!-- Thank you for sending the PR! We appreciate you spending the time to work on these changes. Help us understand your motivation by explaining why you decided to make this change. You can learn more about contributing to React Native here: http://facebook.github.io/react-native/docs/contributing.html Happy contributing! --> Closes the old #7474, keeping the status bar hidden when displaying a modal or dialog, this is accomplished by verifying if the activity status bar is hidden or not. Added a test to [RNTester](https://github.com/facebook/react-native/tree/master/RNTester), so it can be tested from there: 1. Run [RNTester](https://github.com/facebook/react-native/tree/master/RNTester) project 2. Go to <StatusBar> tests 3. Set `hidden: true` in the *StatusBar hidden* samples 4. Set `modal visible: true` and see the result Here are some gifs to help see the results: ![fail](https://user-images.githubusercontent.com/1649955/36345378-f443ad7e-1407-11e8-850d-d6317fb34da4.gif) ![success](https://user-images.githubusercontent.com/1649955/36345392-1c590b56-1408-11e8-9244-a2e828f579ab.gif) none <!-- Help reviewers and the release process by writing your own release notes **INTERNAL and MINOR tagged notes will not be included in the next version's final release notes.** CATEGORY [----------] TYPE [ CLI ] [-------------] LOCATION [ DOCS ] [ BREAKING ] [-------------] [ GENERAL ] [ BUGFIX ] [-{Component}-] [ INTERNAL ] [ ENHANCEMENT ] [ {File} ] [ IOS ] [ FEATURE ] [ {Directory} ] |-----------| [ ANDROID ] [ MINOR ] [ {Framework} ] - | {Message} | [----------] [-------------] [-------------] |-----------| [ GENERAL ] [ BUGFIX ] [ [StatusBar] - Prevent show a hidden status bar when opening modals EXAMPLES: [IOS] [BREAKING] [FlatList] - Change a thing that breaks other things [ANDROID] [BUGFIX] [TextInput] - Did a thing to TextInput [CLI] [FEATURE] [local-cli/info/info.js] - CLI easier to do things with [DOCS] [BUGFIX] [GettingStarted.md] - Accidentally a thing/word [GENERAL] [ENHANCEMENT] [Yoga] - Added new yoga thing/position [INTERNAL] [FEATURE] [./scripts] - Added thing to script that nobody will see --> [ GENERAL ] [ BUGFIX ] [StatusBar] - Prevent show a hidden status bar when opening modals Closes #18004 Differential Revision: D7307564 Pulled By: hramos fbshipit-source-id: 47e481ead78204865811ddf2ef3d27da77ad8b8f
1 parent dbd4759 commit 076b1ce

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

RNTester/js/StatusBarExample.js

+58-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const {
1717
Text,
1818
TouchableHighlight,
1919
View,
20+
Modal,
2021
} = ReactNative;
2122

2223
exports.framework = 'React';
@@ -100,6 +101,7 @@ class StatusBarHiddenExample extends React.Component<{}, $FlowFixMeState> {
100101
</Text>
101102
</View>
102103
</TouchableHighlight>
104+
<ModalExample />
103105
</View>
104106
);
105107
}
@@ -380,6 +382,48 @@ class StatusBarStaticAndroidExample extends React.Component<{}> {
380382
}
381383
}
382384

385+
386+
class ModalExample extends React.Component<{}, $FlowFixMeState> {
387+
state = {
388+
modalVisible: false,
389+
};
390+
391+
_onChangeModalVisible = () => {
392+
this.setState({modalVisible: !this.state.modalVisible});
393+
};
394+
395+
render() {
396+
return (
397+
<View>
398+
<TouchableHighlight
399+
style={styles.wrapper}
400+
onPress={this._onChangeModalVisible}>
401+
<View style={styles.button}>
402+
<Text>modal visible: {this.state.hidden ? 'true' : 'false'}</Text>
403+
</View>
404+
</TouchableHighlight>
405+
<Modal
406+
visible={this.state.modalVisible}
407+
transparent={true}
408+
onRequestClose={this._onChangeModalVisible}>
409+
<View style={[styles.container]}>
410+
<View style={[styles.innerContainer]}>
411+
<Text>This modal was presented!</Text>
412+
<TouchableHighlight
413+
onPress={this._onChangeModalVisible}
414+
style={styles.modalButton}>
415+
<View style={styles.button}>
416+
<Text>Close</Text>
417+
</View>
418+
</TouchableHighlight>
419+
</View>
420+
</View>
421+
</Modal>
422+
</View>
423+
);
424+
}
425+
}
426+
383427
const examples = [{
384428
title: 'StatusBar hidden',
385429
render() {
@@ -436,6 +480,16 @@ const examples = [{
436480
exports.examples = examples;
437481

438482
var styles = StyleSheet.create({
483+
container: {
484+
flex: 1,
485+
justifyContent: 'center',
486+
padding: 20,
487+
backgroundColor: '#f5fcff'
488+
},
489+
innerContainer: {
490+
borderRadius: 10,
491+
alignItems: 'center',
492+
},
439493
wrapper: {
440494
borderRadius: 5,
441495
marginBottom: 5,
@@ -449,5 +503,8 @@ var styles = StyleSheet.create({
449503
marginTop: 16,
450504
marginBottom: 8,
451505
fontWeight: 'bold',
452-
}
506+
},
507+
modalButton: {
508+
marginTop: 10,
509+
},
453510
});

ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostView.java

+11
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,17 @@ private View getContentView() {
276276
private void updateProperties() {
277277
Assertions.assertNotNull(mDialog, "mDialog must exist when we call updateProperties");
278278

279+
Activity currentActivity = getCurrentActivity();
280+
if (currentActivity != null) {
281+
int activityWindowFlags = currentActivity.getWindow().getAttributes().flags;
282+
if ((activityWindowFlags
283+
& WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0) {
284+
mDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
285+
} else {
286+
mDialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
287+
}
288+
}
289+
279290
if (mTransparent) {
280291
mDialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
281292
} else {

0 commit comments

Comments
 (0)