-
-
Notifications
You must be signed in to change notification settings - Fork 595
feat: android orientation management #679
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
Changes from all commits
85186e9
12843d6
cd74246
66643ad
7743d57
62a33fc
04d365f
beb5f06
c8492ac
690f2da
40379fd
46e73da
b26a29a
e240462
f93592c
ddaab72
0b0ad91
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,11 @@ | ||
| package com.swmansion.rnscreens; | ||
|
|
||
| import android.annotation.SuppressLint; | ||
| import android.content.Context; | ||
| import android.os.Bundle; | ||
| import android.view.LayoutInflater; | ||
| import android.view.View; | ||
| import android.view.ViewGroup; | ||
| import android.view.ViewParent; | ||
| import android.view.inputmethod.InputMethodManager; | ||
| import android.widget.FrameLayout; | ||
|
|
||
| import com.facebook.react.bridge.ReactContext; | ||
|
|
@@ -66,6 +64,52 @@ public Screen getScreen() { | |
| return mScreenView; | ||
| } | ||
|
|
||
| public void onContainerUpdate() { | ||
| if (!hasChildScreenWithConfig(getScreen())) { | ||
| // if there is no child with config, we look for a parent with config to set the orientation | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm still a bit confused by this. Why we check if children have config while There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's have a structure of Is this explanation clear enough? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, it is probably good to change the code to only look for the parent |
||
| ScreenStackHeaderConfig config = findHeaderConfig(); | ||
| if (config != null && config.getScreenFragment().getActivity() != null) { | ||
| config.getScreenFragment().getActivity().setRequestedOrientation(config.getScreenOrientation()); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private @Nullable ScreenStackHeaderConfig findHeaderConfig() { | ||
| ViewParent parent = getScreen().getContainer(); | ||
| while (parent != null) { | ||
| if (parent instanceof Screen) { | ||
| ScreenStackHeaderConfig headerConfig = ((Screen) parent).getHeaderConfig(); | ||
| if (headerConfig != null) { | ||
| return headerConfig; | ||
| } | ||
| } | ||
| parent = parent.getParent(); | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| protected boolean hasChildScreenWithConfig(Screen screen) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe it'd be worth keeping track of whether there are children with config upon container updates. It seem like this parameter can change when we add new children or when the "top screen changes". Maybe we could add some bottom-up notification mechanism that'd be triggered when such an even occur that'd allow to keep the up-to-date information whether there are children with config instead of doing this traversal which potentially runs on every level in screen container hierarchy and runs the same code for the same container instances multiple times. |
||
| if (screen == null) { | ||
| return false; | ||
| } | ||
| for (ScreenContainer sc : screen.getFragment().getChildScreenContainers()) { | ||
| // we check only the top screen for header config | ||
| Screen topScreen = sc.getTopScreen(); | ||
| ScreenStackHeaderConfig headerConfig = topScreen != null ? topScreen.getHeaderConfig(): null; | ||
| if (headerConfig != null) { | ||
| return true; | ||
| } | ||
| if (hasChildScreenWithConfig(topScreen)) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| public List<ScreenContainer> getChildScreenContainers() { | ||
| return mChildScreenContainers; | ||
| } | ||
|
|
||
| protected void dispatchOnWillAppear() { | ||
| ((ReactContext) mScreenView.getContext()) | ||
| .getNativeModule(UIManagerModule.class) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this be called directly from
perfomUpdate? Are there any other waysperformUpdatemethod is called when we don't wantnotifyto be triggered? If not why?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think not. I added this here since we call it both in
ScreenContainerandScreenStackthis way and if it is inperfomUpdate, then we need to use this method in both classes. I don't have a strong opinion on this.