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

setOnNavigatorEvent callback not fired when switching tabs #3599

Closed
jneuendorf opened this issue Jul 21, 2018 · 6 comments
Closed

setOnNavigatorEvent callback not fired when switching tabs #3599

jneuendorf opened this issue Jul 21, 2018 · 6 comments

Comments

@jneuendorf
Copy link

jneuendorf commented Jul 21, 2018

Issue Description

I have originally posted my question on stackoverflow but had no success so far. Thus I want to try to get some more help here or some people to read my question on stackoverflow.

Basically I want to popToTRoot when the user switches tabs but it doesn't work:

class NavScreen extends React.PureComponent {
    constructor(props) {
        super(props)
        this.props.navigator.setOnNavigatorEvent(this.toRootOnTabSelect.bind(this))
    }

    toRootOnTabSelect(event) {
        const {id} = event
        if (["bottomTabSelected", "bottomTabReselected"].includes(id)) {
            this.props.navigator.popToRoot({
                animated: true,
                animationType: "fade",
            })
        }
    }

    render() {
        return <Text>Whatever...</Text>
    }
}

Steps to Reproduce / Code Snippets / Screenshots

For more details see my stackoverflow post.


Environment

  • React Native Navigation version: 1.1.474
  • React Native version: 0.55.4
  • Platform(s) (iOS, Android, or both?): iOS
  • Device info (Simulator/Device? OS version? Debug/Release?): Simulator (iPhone 6), iOS 11.4, Debug
@guyca guyca added the v1 label Jul 24, 2018
@nacidai
Copy link

nacidai commented Jul 27, 2018

This is due to the same root cause as #3443.

The fix would be in RCCViewController (rootView is not public) and RCCTabControllers:

`
+(void)sendTabEvent:(NSString )event controller:(UIViewController)viewController body:(NSDictionary*)body{
UIView *theView = viewController.view;
if ([viewController isKindOfClass:[RCCViewController class]]){
RCCViewController *rccvc = (RCCViewController *)viewController;
if (rccvc.rootView != nil) {
theView = rccvc.rootView;
}
}

if ([theView isKindOfClass:[RCTRootView class]]){
RCTRootView *rootView = (RCTRootView *)theView;

if (rootView.appProperties && rootView.appProperties[@"navigatorEventID"]) {
  NSString *navigatorID = rootView.appProperties[@"navigatorID"];
  NSString *screenInstanceID = rootView.appProperties[@"screenInstanceID"];
  
  
  NSMutableDictionary *screenDict = [NSMutableDictionary dictionaryWithDictionary:@
                                     {
                                       @"id": event,
                                       @"navigatorID": navigatorID,
                                       @"screenInstanceID": screenInstanceID
                                     }];
  
  
  if (body) {
    [screenDict addEntriesFromDictionary:body];
  }
  
  [[[RCCManager sharedInstance] getBridge].eventDispatcher sendAppEventWithName:rootView.appProperties[@"navigatorEventID"] body:screenDict];
}

}

if ([viewController isKindOfClass:[UINavigationController class]]) {
UINavigationController navigationController = (UINavigationController)viewController;
UIViewController *topViewController = [navigationController topViewController];
[RCCTabBarController sendTabEvent:event controller:topViewController body:body];
}
}
`

@jneuendorf
Copy link
Author

jneuendorf commented Jul 30, 2018

@nacidai Thanks for your reply. Unfortunately, I am very unfamiliar with native App coding (i.e. objective-C/swift).

So could you please clarify exactly what change has to be done in which file?

  • I am guessing the sendTabEvent method has to be added to Libraries/ReactNativeNavigation.xcodeproj/RCCTabBarController .m but I'm not really sure...
  • What exactly has to be done to fix rootView is not public?

Update

I just saw there is a PR that has already been merged. What version includes this fix?

@davidliu
Copy link
Contributor

@jneuendorf that PR doesn't address this one. It's a separate but closely related.

@davidliu
Copy link
Contributor

I've filed a PR #3808 based on @nacidai's proposal.

It exposes a public readonly property for rootView on RCCViewController to deal with the issue of it being internal.

@stale
Copy link

stale bot commented Oct 6, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If you believe the issue is still relevant, please test on the latest version and report back. Thank you for your contributions.

@stale stale bot added the 🏚 stale label Oct 6, 2018
@stale
Copy link

stale bot commented Oct 13, 2018

The issue has been closed for inactivity.

@stale stale bot closed this as completed Oct 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants