I am trying to get the statusBarHeight and topBarHeight but when used Navigation.constants()
anywhere in my code throws Fatal error:
Exception '-[RNNSideMenuController tabBar]: unrecognized selector sent to instance 0x7f81a7070a00' was thrown while invoking getConstants on target RNNBridgeModule with params (
216,
217
)
const NavConstants = await Navigation.constants();
const statusBarHeight = NavConstants.statusBarHeight;
const topBarHeight = NavConstants.topBarHeight;
console.log(statusBarheight, topBarHeight);
Same here
Have you tried getting Navigation.constants
after root is displayed?
You can use the https://wix.github.io/react-native-navigation/#/docs/events?id=registercommandcompletedlistener listener for that
For me it's produced error on a root without a visible topbar and bottom tab.
Have you tried getting
Navigation.constants
after root is displayed?You can use the https://wix.github.io/react-native-navigation/#/docs/events?id=registercommandcompletedlistener listener for that
Yes , actually im calling it after everything.
By the way, my previous RNN version was "2.1.3-snapshot.41" and it was fine-working, when i updated "2.13.0" then error showed up.
Thank you i will try with listener
Have you tried getting
Navigation.constants
after root is displayed?You can use the https://wix.github.io/react-native-navigation/#/docs/events?id=registercommandcompletedlistener listener for that
Yes, also tried getting constants
with listeners but same error.
However I am not sure if I used the listeners properly. Here's the code I used:
const commandCompletedListener = Navigation.events().registerCommandCompletedListener(
({ commandId, completionTime, params }) => {
console.log(commandId, params);
if (
commandId === "setRoot" &&
params.layout.root.id === "MainSideMenu" // ID of my root sideMenu Stack
) {
Navigation.constants().then(result => {
console.log(result);
});
}
}
);
Same here.
I added in the Navigation.events().registerAppLaunchedListener() but same error. :'(
when i reaload the app, the error disappear
just barely got the same problem, with or without listener produce the same error.
As i understand this issue reproduce if contants() fired when no tabBars
here patch to Fix (just try catch on bottomTabsHeight)
patch-package
--- a/node_modules/react-native-navigation/lib/ios/Constants.m
+++ b/node_modules/react-native-navigation/lib/ios/Constants.m
@@ -15,7 +15,11 @@ + (CGFloat)statusBarHeight {
}
+ (CGFloat)bottomTabsHeight {
- return CGRectGetHeight(((UITabBarController *)((UIWindow *)(UIApplication.sharedApplication.windows[0])).rootViewController).tabBar.frame);
+ @try {
+ return CGRectGetHeight(((UITabBarController *)((UIWindow *)(UIApplication.sharedApplication.windows[0])).rootViewController).tabBar.frame);
+ } @catch (NSException *exception) {
+ return 0;
+ }
}
@end
@matpaul fix is working, is there PR for this?
@Axxxx0n no, my patch is crutch fix ))
same here
This is still happening with version 2.17.0 :(...
Fixing this in my app was much simpler than I expected. I was grabbing constants during async componentDidMount(). I moved the code into async componentDidAppear() and have not seen the error since.
I found that if I just call it inside registerAppLaunchedListener
it can be called later on in componentDidMount
/ componentDidAppear
without causing the crash.
Navigation.events().registerAppLaunchedListener(() => {
Navigation.setRoot({...})
Navigation.constants().then(res => console.log(res));
})
edit: I spoke too soon - crash still happens on first open ( but not on subsequent debugger reloads ).
Still happening with RNN v 2.20.2
Still happening. This is a critical bug.
I was having the same issue when using Navigation.constants()
on a project with no tab bar. Adding a try/catch as suggested by @matpaul resolved the issue for me, and seems like a perfectly valid permanent fix, so I submitted a PR: https://github.com/wix/react-native-navigation/pull/5201
Most helpful comment
Same here.
I added in the Navigation.events().registerAppLaunchedListener() but same error. :'(
when i reaload the app, the error disappear