Skip to content

Do not bring app out of immersive mode when a modal is presented#21078

Closed
olfek wants to merge 1 commit intofacebook:masterfrom
elderstudios:fix-dialog-rn-modal-brings-app-permanently-out-of-immersive-mode
Closed

Do not bring app out of immersive mode when a modal is presented#21078
olfek wants to merge 1 commit intofacebook:masterfrom
elderstudios:fix-dialog-rn-modal-brings-app-permanently-out-of-immersive-mode

Conversation

@olfek
Copy link
Copy Markdown

@olfek olfek commented Sep 12, 2018

This does fix the issue, however, another, perhaps related issue persists, the dialog/modal occasionally uses what would be the height of the app in non-immersive mode, in immersive mode. Meaning that the background, what ever it is set as, does not use the full available height.

See https://stackoverflow.com/a/23207365 for more info.

Known Problems:

  • Date/time picker still brings app out of immersive mode - The date/time picker dialog needs the same treatment (this MR) as RN Modal using a wrapper.
  • Focusing on text input, which brings up keyboard, also brings app out of immersive mode. Sometimes temporarily, sometimes permanently - Needs investigating. I have tried this, unfortunately it doesn't work. Workaround I'm using for this, is to call a native module method to re-apply immersive mode flags after keyboardDidHide on JS side.

Changelog:

[Android] [Fixed] - Dialog (RN Modal) brings app permanently out of immersive mode

Test Plan:

  • RN Modal no longer brings app out of immersive mode

@facebook-github-bot
Copy link
Copy Markdown
Contributor

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

@react-native-bot react-native-bot added Missing Test Plan This PR appears to be missing a test plan. ✅Release Notes labels Sep 12, 2018
@elicwhite
Copy link
Copy Markdown
Member

Looks like you have a bad rebase

@olfek
Copy link
Copy Markdown
Author

olfek commented Sep 18, 2018

@TheSavior So will this commit: bd668d72e84b7582f8931738ec47466c31562c79 be accepted?

Copy link
Copy Markdown
Contributor

@hramos hramos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you fix the PR? It looks like a lot of unrelated changes made it in. We can't review the PR in its current state.

@olfek
Copy link
Copy Markdown
Author

olfek commented Sep 26, 2018

@hramos Okay, I'll do it tomorrow, I'll place my commit on the master branch rather than v0.56.0 so it gets rid of all the noise.

I can only confirm that the changes I made work on top of v0.56.0, they probably will still work when applied to master, but you'll have to test that.

@hramos
Copy link
Copy Markdown
Contributor

hramos commented Sep 26, 2018

We'll let Circle CI run the tests then. It's your responsibility as the author of the PR to make sure your code does not break anything.

@olfek
Copy link
Copy Markdown
Author

olfek commented Sep 26, 2018

@hramos The original PR was tested with v0.56.0, you now want something different, so that responsibility is now yours.

@hramos
Copy link
Copy Markdown
Contributor

hramos commented Sep 27, 2018

We do not take pull requests against any of the release branches. React Native is continuously developed on master. If you're not willing to support your change on top of master, that's fine -- I'm letting you know what maintainers look for when deciding which pull requests to merge into core.

See the following link:
https://stackoverflow.com/a/23207365
for more info.

This does fix the issue, however, another, perhaps related issue
persists, the dialog/modal occasionally uses what would be the height of the
app in non-immersive mode, in immersive mode. Meaning that the background,
what ever it is set as, does not use the full available height.
@olfek
Copy link
Copy Markdown
Author

olfek commented Sep 27, 2018

@hramos I've updated the MR

@pull-bot
Copy link
Copy Markdown

Warnings
⚠️

📋 Test Plan - This PR appears to be missing a Test Plan.

Generated by 🚫 dangerJS

@olfek
Copy link
Copy Markdown
Author

olfek commented Oct 25, 2018

@hramos Hello, could I get an update on this, thanks.

@hramos
Copy link
Copy Markdown
Contributor

hramos commented Dec 11, 2018

Would you mind adding a test plan to your PR?

@olfek
Copy link
Copy Markdown
Author

olfek commented Dec 13, 2018

What do you mean by test plan? please be more specific.

@hramos
Copy link
Copy Markdown
Contributor

hramos commented Dec 13, 2018

The pull request template provides a "Test Plan" section: https://github.com/facebook/react-native/blob/master/.github/PULL_REQUEST_TEMPLATE.md

The general idea is to describe, in plain language, how you verified that your change works as intended. It's an important element of a code review, as it lets the reviewer know if there might be a blind spot in your testing where additional bugs may be introduced.

@olfek

This comment has been minimized.

@olfek
Copy link
Copy Markdown
Author

olfek commented Dec 21, 2018

@hramos I've added a test plan

@olfek
Copy link
Copy Markdown
Author

olfek commented Dec 21, 2018

This is how to start the app in immersive mode.

package [REDACTED];

import android.view.View;
import com.facebook.react.ReactActivity;

public class MainActivity extends ReactActivity {

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        if(hasFocus){
            hideSystemUI();
        }
    }

    public void hideSystemUI(){
        View decorView = getWindow().getDecorView();
        decorView.setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
            View.SYSTEM_UI_FLAG_FULLSCREEN |
            View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
        );
    }

    /**
     * Returns the name of the main component registered from JavaScript.
     * This is used to schedule rendering of the component.
     */
    @Override
    protected String getMainComponentName() {
        return "[REDACTED]";
    }
}

@olfek
Copy link
Copy Markdown
Author

olfek commented Dec 21, 2018

Workaround I'm using for this, is to call a native module method to re-apply immersive mode flags after keyboardDidHide on JS side. #21078 (comment)

package [REDACTED];

import android.content.Context;
import android.os.Handler;
import android.util.Log;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;

public class ReApplyImmersiveModeModule extends ReactContextBaseJavaModule {

    public ReApplyImmersiveModeModule(ReactApplicationContext reactContext) {
        super(reactContext);
    }

    @Override
    public String getName() {
        return "ReApplyImmersiveMode";
    }

    // Need this because of this issue: https://stackoverflow.com/q/24187728
    // The answer didn't work, so this is a workaround.
    @ReactMethod
    public void now(){

        final ReactApplicationContext context = getReactApplicationContext();

        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                MainActivity.hideSystemUI(context.getCurrentActivity().getWindow().getDecorView());
            }
        };

        if(context.getCurrentActivity()!=null) {
            Handler mainHandler = new Handler(context.getMainLooper());
            mainHandler.post(runnable);
        }
    }
}

@olfek
Copy link
Copy Markdown
Author

olfek commented Jan 29, 2019

@hramos ...

@react-native-bot react-native-bot added the No CLA Authors need to sign the CLA before a PR can be reviewed. label Jan 29, 2019
@hramos hramos changed the title Fix dialog rn modal brings app permanently out of immersive mode Do not bring app out of immersive mode when a modal is presented Jan 29, 2019
@hramos hramos added the Platform: Android Android applications. label Jan 29, 2019
@hramos
Copy link
Copy Markdown
Contributor

hramos commented Jan 29, 2019

Thanks for adding the test plan. It looks like it's lacking a bit of detail. I'm looking for a list of steps you followed to ensure your change fixes the issue, as well as steps followed to ensure no side effects or bugs are introduced.

We also will need a CLA to be signed before the code can be merged.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Feb 9, 2019
@facebook-github-bot
Copy link
Copy Markdown
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@react-native-bot react-native-bot removed the No CLA Authors need to sign the CLA before a PR can be reviewed. label Feb 9, 2019
@olfek
Copy link
Copy Markdown
Author

olfek commented Feb 9, 2019

My testing produced no evidence of any side effects or bugs being introduced.

I discovered this issue when attempting to display a dialog (RN Modal) in an immersive (full screen) application I was building.

When opening a dialog, it would bring the application out of immersive mode until the dialog was closed again.

After a quick Google search, I found that the issue was with Android and not RN (more info).

So I applied the fix mentioned in the q&a linked above which resolved the problem.

So no specific dedicated testing has been done apart from being able to see that the problem went away after applying the fix.

Regarding my previous attempt at writing a test plan, the 'Known Problems' section lists other issues that are similar to this one but are unrelated and are not as a result of this MR.

Changelog:

[Android] [Fixed] - Dialog (RN Modal) brings app permanently out of immersive mode

Test Plan:

  • RN Modal no longer brings app out of immersive mode

Known Problems:

  • Date/time picker still brings app out of immersive mode - The date/time picker dialog needs the same treatment (this MR) as RN Modal using a wrapper.
  • Focusing on text input, which brings up keyboard, also brings app out of immersive mode. Sometimes temporarily, sometimes permanently - Needs investigating. I have tried this, unfortunately it doesn't work. Workaround I'm using for this, is to call a native module method to re-apply immersive mode flags after keyboardDidHide on JS side.

@hramos hramos added PR: Includes Test Plan and removed Missing Test Plan This PR appears to be missing a test plan. labels Feb 11, 2019
Copy link
Copy Markdown
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cpojer has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot facebook-github-bot added the Import Started This pull request has been imported. This does not imply the PR has been approved. label Feb 21, 2019
@react-native-bot
Copy link
Copy Markdown
Collaborator

@olfek merged commit f8a4d28 into facebook:master.

@facebook facebook locked as resolved and limited conversation to collaborators Feb 21, 2019
@react-native-bot react-native-bot added the Merged This PR has been merged. label Feb 21, 2019
mbardauskas pushed a commit to mbardauskas/react-native that referenced this pull request Feb 21, 2019
…ebook#21078)

Summary:
This does fix the issue, however, another, perhaps related issue persists, the dialog/modal occasionally uses what would be the height of the app in non-immersive mode, in immersive mode. Meaning that the background, what ever it is set as, does not use the full available height.

See https://stackoverflow.com/a/23207365 for more info.

Known Problems:
---------
* [Date/time picker](https://facebook.github.io/react-native/docs/datepickerandroid) still brings app out of immersive mode - The date/time picker dialog needs the same treatment (this MR) as `RN Modal` using a wrapper.
* Focusing on text input, which brings up keyboard, also brings app out of immersive mode. Sometimes temporarily, sometimes permanently - Needs investigating. I have tried [this](https://stackoverflow.com/a/25129542), unfortunately it doesn't work. **Workaround I'm using for this, is to call a native module method to re-apply immersive mode flags after `keyboardDidHide` on JS side.**

Changelog:
----------

[Android] [Fixed] - Dialog (RN Modal) brings app permanently out of immersive mode
Pull Request resolved: facebook#21078

Differential Revision: D14163127

Pulled By: cpojer

fbshipit-source-id: e0b67c91fa81880b19438a939bca26c128309799
@hramos hramos removed Import Started This pull request has been imported. This does not imply the PR has been approved. labels Feb 23, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Platform: Android Android applications.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants