Skip to content

Commit

Permalink
Add property to force HW acceleration on Android for modal windows
Browse files Browse the repository at this point in the history
Summary:
When using React Native on Android on top of a game as an overlay, dialog windows sometimes get created with hardware acceleration disabled. This causes the UI to be unresponsive and anything that uses a TextureView stops working. Added a property for the modal view to make sure hardware acceleration flag is enabled when it's set to true.

**Test plan (required)**

set `hardwareAccelerated` property for Modal to force hardware acceleration on dialog windows on Android. Does nothing on iOS.
Closes facebook#11421

Differential Revision: D4312912

Pulled By: andreicoman11

fbshipit-source-id: 9db6b2eca361421b92b24234b3501b5de0eecea7
  • Loading branch information
Üstün Ergenoglu authored and Facebook Github Bot committed Dec 14, 2016
1 parent db63537 commit 3785db2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Libraries/Modal/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ class Modal extends React.Component {
* The `transparent` prop determines whether your modal will fill the entire view. Setting this to `true` will render the modal over a transparent background.
*/
transparent: PropTypes.bool,
/**
* The `hardwareAccelerated` prop controls whether to force hardware acceleration for the underlying window.
* @platform android
*/
hardwareAccelerated: PropTypes.bool,
/**
* The `visible` prop determines whether your modal is visible.
*/
Expand Down Expand Up @@ -126,6 +131,7 @@ class Modal extends React.Component {

static defaultProps = {
visible: true,
hardwareAccelerated: false,
};

static contextTypes = {
Expand Down Expand Up @@ -160,6 +166,7 @@ class Modal extends React.Component {
<RCTModalHostView
animationType={animationType}
transparent={this.props.transparent}
hardwareAccelerated={this.props.hardwareAccelerated}
onRequestClose={this.props.onRequestClose}
onShow={this.props.onShow}
style={styles.modal}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ public void setTransparent(ReactModalHostView view, boolean transparent) {
view.setTransparent(transparent);
}

@ReactProp(name = "hardwareAccelerated")
public void setHardwareAccelerated(ReactModalHostView view, boolean hardwareAccelerated) {
view.setHardwareAccelerated(hardwareAccelerated);
}

@Override
protected void addEventEmitters(
ThemedReactContext reactContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public interface OnRequestCloseListener {
private @Nullable Dialog mDialog;
private boolean mTransparent;
private String mAnimationType;
private boolean mHardwareAccelerated;
// Set this flag to true if changing a particular property on the view requires a new Dialog to
// be created. For instance, animation does since it affects Dialog creation through the theme
// but transparency does not since we can access the window to update the property.
Expand Down Expand Up @@ -153,6 +154,11 @@ protected void setAnimationType(String animationType) {
mPropertyRequiresNewDialog = true;
}

protected void setHardwareAccelerated(boolean hardwareAccelerated) {
mHardwareAccelerated = hardwareAccelerated;
mPropertyRequiresNewDialog = true;
}

@Override
public void onHostResume() {
// We show the dialog again when the host resumes
Expand Down Expand Up @@ -237,6 +243,9 @@ public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
});

mDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
if (mHardwareAccelerated) {
mDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
}
mDialog.show();
}

Expand Down

0 comments on commit 3785db2

Please sign in to comment.