-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
[V3] options:sideMenu:enabled: false overwritten to true on pan gesture #5444
Comments
* Enabled option was wrongly consumed after it was merged. That meant that the next time SideMenu options were applied, the wrong enabled value was applied * supportedInterfaceOrientations didn't take default orientation value into account * mergeOptions didn't save the new options in the ViewControllers current options * SideMenu always returned the centre ViewController as the current child and didn't take open SideMenu into account Fixes #5444
@Royce Could you please try version |
* Enabled option was wrongly consumed after it was merged. That meant that the next time SideMenu options were applied, the wrong enabled value was applied * supportedInterfaceOrientations didn't take default orientation value into account * mergeOptions didn't save the new options in the ViewControllers current options * SideMenu always returned the centre ViewController as the current child and didn't take open SideMenu into account Fixes #5444
@guyca I have updated to 3.1.2-snapshot.490 and can confirm the problem has gone away on iOS. Thanks! |
Reopened as this seems to be a problem on Android now 😕 |
In SideMenuPresenter applyLockMode treats private void applyLockMode(SideMenuRootOptions options) {
int leftLockMode = options.left.enabled.isTrueOrUndefined() ? DrawerLayout.LOCK_MODE_UNLOCKED : DrawerLayout.LOCK_MODE_LOCKED_CLOSED;
sideMenu.setDrawerLockMode(leftLockMode, Gravity.LEFT);
int rightLockMode = options.right.enabled.isTrueOrUndefined() ? DrawerLayout.LOCK_MODE_UNLOCKED : DrawerLayout.LOCK_MODE_LOCKED_CLOSED;
sideMenu.setDrawerLockMode(rightLockMode, Gravity.RIGHT);
}
@Override
public void applyChildOptions(Options options, ViewController child) {
super.applyChildOptions(options, child);
presenter.applyChildOptions(resolveCurrentOptions());
performOnParentController(parentController ->
((ParentController) parentController).applyChildOptions(this.options, child)
);
} Looking at resolveCurrentOptions leads us to ParentController.resolveCurrentOptions. Setting a breakpoint here (during a pan gesture, perhaps) show that the initialOptions, which contain public Options resolveCurrentOptions() {
if (CollectionUtils.isNullOrEmpty(getChildControllers())) return initialOptions;
return getCurrentChild()
.resolveCurrentOptions()
.copy()
.withDefaultOptions(initialOptions);
} And thus the side menu / drawers are unlocked when they shouldn't be. |
Thanks for looking into this one @Royce ! |
function start() {
registerScreens();
Navigation.events().registerAppLaunchedListener(async () => {
setDefaultOptions();
Navigation.setRoot({
root: {
sideMenu: {
id: "RootLayoutId",
options: {
// The options are the implicit defaults. So, not required.
sideMenu: {
left: { enabled: true },
right: { enabled: true },
},
},
left: { component: { name: Screens.SideMenuLeft, id: "LEFT" } },
right: { component: { name: Screens.SideMenuRight, id: "RIGHT" } },
center: {
stack: {
children: [{ component: { name: Screens.SideMenuCenter } }]
}
}
}
}
});
}
} Then programatically open one menu (and close it), then open the other.... Navigation.mergeOptions("RootLayoutId", { sideMenu: { left: { visible: true } } }); Swipe it close, or whatever.... then: Navigation.mergeOptions("RootLayoutId", { sideMenu: { right: { visible: true } } }); The problem:Both menu's become visible! (Only the right should become visible.) |
The above demo can be played with in this branch of the playground app: https://github.com/Royce/react-native-navigation/tree/demo-sticky-sidemenu-visible And this tweak to SideMenuOptions.java makes the problem go away. public void mergeWithDefault(SideMenuOptions defaultOptions) {
// Just need to forget the old visible flag. Like this, maybe.
//if (!visible.hasValue()) visible = defaultOptions.visible;
if (!animate.hasValue()) animate = defaultOptions.animate;
if (!enabled.hasValue()) enabled = defaultOptions.enabled;
if (!height.hasValue()) height = defaultOptions.height;
if (!width.hasValue()) width = defaultOptions.width;
} |
* Enabled option was wrongly consumed after it was merged. That meant that the next time SideMenu options were applied, the wrong enabled value was applied * supportedInterfaceOrientations didn't take default orientation value into account * mergeOptions didn't save the new options in the ViewControllers current options * SideMenu always returned the centre ViewController as the current child and didn't take open SideMenu into account Fixes wix#5444
sideMenu.enabled
flag overwritten when opening/closing menu.On iOS, the flags to control whether the side menus are enabled or disabled is reset to
true
when a pan gesture (to open the menu) occurs.Steps to Reproduce / Code Snippets / Screenshots
With the following setup. Both menu's disabled...
Then, triggered off a button or something, we explicitly enable one (and disable the other) of the two menu's:
The problem.
The function
SideMenuPresenter.applyOptions
contains the following code, and is called when weNavigation.setRoot
, but also whenSideMenuController.panGestureCallback
is triggered.The
getWithDefaultValue:YES
part means that enabled keeps getting set to true. No good!Workaround / hack.
Wrap an
if
around these lines of code.Royce@8d2b20c
But this may have side effects that I am not considering.
Environment
The text was updated successfully, but these errors were encountered: