How to correctly reset navigation to another view

I am resetting the current view with this code

NavigationActions.reset({ index: 0, key: null, actions: [ NavigationActions.navigate({ routeName: 'Login' }) ] }); 

It works several times, and for a while I get a Signal Sigabrt error in the RCTUIManager.m file in Xcode. I can not understand when the problem arose. Error in this function.

 - (void)setSize:(CGSize)size forView:(UIView *)view { RCTAssertMainQueue(); NSNumber *reactTag = view.reactTag; dispatch_async(RCTGetUIManagerQueue(), ^{ RCTShadowView *shadowView = self->_shadowViewRegistry[reactTag]; RCTAssert(shadowView != nil, @"Could not locate shadow view with tag #%@", reactTag); // ERROR in this line if (CGSizeEqualToSize(size, shadowView.size)) { return; } shadowView.size = size; [self setNeedsLayout]; }); } 

If I delete the code in the function, everything works fine. When there are no failures, the console always prints a warning

View # 1430 of type RCTView has a set of shadows, but cannot calculate the shadow efficiently. Consider setting a background color to fix this, or applying a shadow to a more specific component.

But I do not have any View using the shadow, and I can not understand which element reacts to it.

Edit: if I check that the shadowView is not null, everything works fine

 if(shadowView){ RCTAssert(shadowView != nil, @"Could not locate view with tag #%@", reactTag); } 

Is this a mistake in RN?

+5
source share
1 answer

I found a solution to override the router's getStateForAction function and handle reset.

So you can send something like this:

 NavigationActions.reset({ index: 0, key: null, actions: { navigateTo: 'Login' }}); 

And handle this case in the custom function getStateForAction :

 const defaultGetStateForAction = YourNavigator.router.getStateForAction YourNavigator.router.getStateForAction = (action, state) => { if (action.type === NavigationActions.RESET && action.actions.navigateTo) { const updatedRoutes = [{routeName: action.actions.navigateTo}] return { ...state, routes: updatedRoutes, index: 0 } } return defaultGetStateForAction(action, state) } 

Here you can learn more about React Navigation - Custom Navigation Actions

+1
source

Source: https://habr.com/ru/post/1274818/


All Articles