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

Best practice for Request-Screen-Orientation-Change? #176

Closed
frank-fan opened this issue Nov 5, 2015 · 2 comments
Closed

Best practice for Request-Screen-Orientation-Change? #176

frank-fan opened this issue Nov 5, 2015 · 2 comments

Comments

@frank-fan
Copy link

Hi, I manage all my app screens in one activity using mortar & flow.
But I got a problem when I have a different orientation screen:

I try to invoke this to change orientation in ViewPresenter.onLoad();

mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

The orientation is changed, but it's the previous screen.
I think when ViewPresenter.onLoad, the screen-view is not fully attached.Too soon to request orientation changes, may interrupt the attach-process.

So I add a delay with handler,

private Handler mHandler = new Handler(Looper.getMainLooper());
....
 mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
            }
        }, 500);    

It worked, the orientation changed, and the screen is right.
But a delay make the experiences miserable.

I'm new to Mortar & path, please help me to solve this problem, thanks!

@creativepsyco
Copy link

Thats coz the traversal hasn't completed for the new screen and screen orientation causes the activity to be recreated, which makes the old history be restored. You can try to make the newer history be stored and let the orientation dictate the dispatching:

  • Hook into the onTraversalCompleted callback in your dispatcher to invoke any necessary orientation changes after the traversal completes, i.e. queue it up
  • Short-circuit the traversal (call onTraversalCompleted) if there is a orientation change required and let the orientation change construct the screen with the new history.
  • Instead of doing a delay post just posting on the UI thread suffices.

@rjrjr
Copy link
Collaborator

rjrjr commented Sep 2, 2016

square/flow#204

@rjrjr rjrjr closed this as completed Sep 2, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants