Skip to content

Commit c35a419

Browse files
pfulopfacebook-github-bot
authored andcommitted
Make android modal to appear underneath translucent StatusBar (#26706)
Summary: As described in #26559 , the modal is not appearing underneath translucent StatusBar so you can see previous view underneath the StatusBar instead. As a solution you can now provide prop to set the modal to have translucent StatusBar and therefore the content will appear underneath. I tried to reuse layout flags that are possibly set if you use StatusBar component but sadly values in them do not reflect the props set by StatusBar component. ## Changelog [Android] [added] - Added statusBarTranslucent prop to Modal component, to indicate if StatusBar should appear translucent. Pull Request resolved: #26706 Test Plan: ### With StatusBar translucent ![image](https://user-images.githubusercontent.com/3984319/66131336-8bfdf200-e5f3-11e9-940e-c6bb3f67ea6f.png) ``` <Modal statusBarTranslucent>``` ### Without ![image](https://user-images.githubusercontent.com/3984319/66131403-a768fd00-e5f3-11e9-9814-ff7592b4ceac.png) ``` <Modal>``` Differential Revision: D17872874 Pulled By: mdvacca fbshipit-source-id: 8c4b48a75cddf86c4429b62d0c63313e7a2dd1b8
1 parent 7c20dc6 commit c35a419

File tree

6 files changed

+41
-1
lines changed

6 files changed

+41
-1
lines changed

Libraries/Modal/Modal.js

+11
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,20 @@ export type Props = $ReadOnly<{|
6868
*/
6969
transparent?: ?boolean,
7070

71+
/**
72+
* The `statusBarTranslucent` prop determines whether your modal should go under
73+
* the system statusbar.
74+
*
75+
* See https://facebook.github.io/react-native/docs/modal.html#transparent
76+
*/
77+
statusBarTranslucent?: ?boolean,
78+
7179
/**
7280
* The `hardwareAccelerated` prop controls whether to force hardware
7381
* acceleration for the underlying window.
7482
*
83+
* This prop works inly on Android.
84+
*
7585
* See https://facebook.github.io/react-native/docs/modal.html#hardwareaccelerated
7686
*/
7787
hardwareAccelerated?: ?boolean,
@@ -234,6 +244,7 @@ class Modal extends React.Component<Props> {
234244
hardwareAccelerated={this.props.hardwareAccelerated}
235245
onRequestClose={this.props.onRequestClose}
236246
onShow={this.props.onShow}
247+
statusBarTranslucent={this.props.statusBarTranslucent}
237248
identifier={this._identifier}
238249
style={styles.modal}
239250
onStartShouldSetResponder={this._shouldSetResponder}

Libraries/Modal/RCTModalHostViewNativeComponent.js

+8
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ type NativeProps = $ReadOnly<{|
5252
*/
5353
transparent?: WithDefault<boolean, false>,
5454

55+
/**
56+
* The `statusBarTranslucent` prop determines whether your modal should go under
57+
* the system statusbar.
58+
*
59+
* See https://facebook.github.io/react-native/docs/modal.html#statusBarTranslucent
60+
*/
61+
statusBarTranslucent?: WithDefault<boolean, false>,
62+
5563
/**
5664
* The `hardwareAccelerated` prop controls whether to force hardware
5765
* acceleration for the underlying window.

ReactAndroid/src/main/java/com/facebook/react/viewmanagers/ModalHostViewManagerDelegate.java

+3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ public void setProperty(T view, String propName, @Nullable Object value) {
3232
case "transparent":
3333
mViewManager.setTransparent(view, value == null ? false : (boolean) value);
3434
break;
35+
case "statusBarTranslucent":
36+
mViewManager.setStatusBarTranslucent(view, value == null ? false : (boolean) value);
37+
break;
3538
case "hardwareAccelerated":
3639
mViewManager.setHardwareAccelerated(view, value == null ? false : (boolean) value);
3740
break;

ReactAndroid/src/main/java/com/facebook/react/viewmanagers/ModalHostViewManagerInterface.java

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public interface ModalHostViewManagerInterface<T extends View> {
1717
void setAnimationType(T view, @Nullable String value);
1818
void setPresentationStyle(T view, @Nullable String value);
1919
void setTransparent(T view, boolean value);
20+
void setStatusBarTranslucent(T view, boolean value);
2021
void setHardwareAccelerated(T view, boolean value);
2122
void setAnimated(T view, boolean value);
2223
void setSupportedOrientations(T view, @Nullable ReadableArray value);

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

+7
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ public void setTransparent(ReactModalHostView view, boolean transparent) {
7878
view.setTransparent(transparent);
7979
}
8080

81+
@Override
82+
@ReactProp(name = "statusBarTranslucent")
83+
public void setStatusBarTranslucent(ReactModalHostView view, boolean statusBarTranslucent) {
84+
view.setStatusBarTranslucent(statusBarTranslucent);
85+
}
86+
87+
8188
@Override
8289
@ReactProp(name = "hardwareAccelerated")
8390
public void setHardwareAccelerated(ReactModalHostView view, boolean hardwareAccelerated) {

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

+11-1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public interface OnRequestCloseListener {
6666
private DialogRootViewGroup mHostView;
6767
private @Nullable Dialog mDialog;
6868
private boolean mTransparent;
69+
private boolean mStatusBarTranslucent;
6970
private String mAnimationType;
7071
private boolean mHardwareAccelerated;
7172
// Set this flag to true if changing a particular property on the view requires a new Dialog to
@@ -167,6 +168,11 @@ protected void setTransparent(boolean transparent) {
167168
mTransparent = transparent;
168169
}
169170

171+
protected void setStatusBarTranslucent(boolean statusBarTranslucent) {
172+
mStatusBarTranslucent = statusBarTranslucent;
173+
mPropertyRequiresNewDialog = true;
174+
}
175+
170176
protected void setAnimationType(String animationType) {
171177
mAnimationType = animationType;
172178
mPropertyRequiresNewDialog = true;
@@ -306,7 +312,11 @@ public void updateState(StateWrapper stateWrapper, int width, int height) {
306312
private View getContentView() {
307313
FrameLayout frameLayout = new FrameLayout(getContext());
308314
frameLayout.addView(mHostView);
309-
frameLayout.setFitsSystemWindows(true);
315+
if (mStatusBarTranslucent) {
316+
frameLayout.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
317+
} else {
318+
frameLayout.setFitsSystemWindows(true);
319+
}
310320
return frameLayout;
311321
}
312322

0 commit comments

Comments
 (0)