Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent show a hidden status bar when opening modals, fix #7474 #18004

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 58 additions & 1 deletion RNTester/js/StatusBarExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const {
Text,
TouchableHighlight,
View,
Modal,
} = ReactNative;

exports.framework = 'React';
Expand Down Expand Up @@ -100,6 +101,7 @@ class StatusBarHiddenExample extends React.Component<{}, $FlowFixMeState> {
</Text>
</View>
</TouchableHighlight>
<ModalExample />
</View>
);
}
Expand Down Expand Up @@ -380,6 +382,48 @@ class StatusBarStaticAndroidExample extends React.Component<{}> {
}
}


class ModalExample extends React.Component<{}, $FlowFixMeState> {
state = {
modalVisible: false,
};

_onChangeModalVisible = () => {
this.setState({modalVisible: !this.state.modalVisible});
};

render() {
return (
<View>
<TouchableHighlight
style={styles.wrapper}
onPress={this._onChangeModalVisible}>
<View style={styles.button}>
<Text>modal visible: {this.state.hidden ? 'true' : 'false'}</Text>
</View>
</TouchableHighlight>
<Modal
visible={this.state.modalVisible}
transparent={true}
onRequestClose={this._onChangeModalVisible}>
<View style={[styles.container]}>
<View style={[styles.innerContainer]}>
<Text>This modal was presented!</Text>
<TouchableHighlight
onPress={this._onChangeModalVisible}
style={styles.modalButton}>
<View style={styles.button}>
<Text>Close</Text>
</View>
</TouchableHighlight>
</View>
</View>
</Modal>
</View>
);
}
}

const examples = [{
title: 'StatusBar hidden',
render() {
Expand Down Expand Up @@ -436,6 +480,16 @@ const examples = [{
exports.examples = examples;

var styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
padding: 20,
backgroundColor: '#f5fcff'
},
innerContainer: {
borderRadius: 10,
alignItems: 'center',
},
wrapper: {
borderRadius: 5,
marginBottom: 5,
Expand All @@ -449,5 +503,8 @@ var styles = StyleSheet.create({
marginTop: 16,
marginBottom: 8,
fontWeight: 'bold',
}
},
modalButton: {
marginTop: 10,
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,17 @@ private View getContentView() {
private void updateProperties() {
Assertions.assertNotNull(mDialog, "mDialog must exist when we call updateProperties");

Activity currentActivity = getCurrentActivity();
if (currentActivity != null) {
int activityWindowFlags = currentActivity.getWindow().getAttributes().flags;
if ((activityWindowFlags
& WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0) {
mDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
} else {
mDialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
}

if (mTransparent) {
mDialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
} else {
Expand Down