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

integrate react-native component with UINavigationController did not work #3324

Closed
jabez128 opened this issue Oct 10, 2015 · 5 comments
Closed
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@jabez128
Copy link

I want combine react-native component with an existing app, and use an react-native component as a view of a viewcontroller. one problem I met is that how to integrate react-native component with UINavigationController. In react-native, I can use the NavigatorIOS or Navigator component, but now that I use react-native component as the view part, I don't want mixin a navigator in the component. so I think if I can solve the problem.

In AppDelegate.m file:

  ...
  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  UIViewController *PageOneVC = [[PageOne alloc] init];
  UINavigationController *rootController = [[UINavigationController alloc] initWithRootViewController: PageOneVC];
  ...

and then I write a custom module to let js call objective-c method:

#import "POM.h"
#import "AppDelegate.h"
#import "PageTwo.h"

@implementation POM
 RCT_EXPORT_MODULE();
 RCT_EXPORT_METHOD(gopagetwo: (NSString *) gopagetwo) {
  NSLog(@"123");
  AppDelegate *share = (AppDelegate *)[UIApplication sharedApplication].delegate;
  UINavigationController *nav = (UINavigationController *) share.window.rootViewController;
  PageTwo *pagetwo = [[PageTwo alloc] init];
  [nav pushViewController:pagetwo animated:TRUE];
}
@end

and in my react-native component, I require this module and call the gopagetwo method.

When I run the app, there is no error or warning, and the gopagetwo method is called indeed because the NSLog method did work, but the UINavigationController's pushViewController method doesn't work.

did I do something wrong? any suggestion could help. thx.

@bakso
Copy link

bakso commented Oct 10, 2015

It's cool

@jabez128
Copy link
Author

I solve this problem by run viewcontroller switch operation on main thread:

@implementation POM
 RCT_EXPORT_MODULE();

 - (dispatch_queue_t)methodQueue
  {
   return dispatch_get_main_queue();
 }

 RCT_EXPORT_METHOD(gopagetwo: (NSString *) gopagetwo) {
  NSLog(@"123");
  AppDelegate *share = (AppDelegate *)[UIApplication sharedApplication].delegate;
  UINavigationController *nav = (UINavigationController *) share.window.rootViewController;
  PageTwo *pagetwo = [[PageTwo alloc] init];
  [nav pushViewController:pagetwo animated:TRUE];
  //[share.emitter emit:@"gopagetwo"];
}
@end

lol !

@xhacker5000
Copy link

still not work in my app :(

react was error display ...

//
// PrinterManager.m
// fastui
//
// Created by Xhacker on 16/1/16.
// Copyright © 2016年 Facebook. All rights reserved.
//

#import "PrinterManager.h"
#import "RCTConvert.h"
#import "RCTBridge.h"
#import "RCTEventDispatcher.h"
#import <PrinterSDK/PrinterSDK.h>
#import "OCDirector.h"
#import "HJPrinterDemoViewController.h"

@implementation PrinterManager

RCT_EXPORT_MODULE();

  • (dispatch_queue_t)methodQueue
    {
    return dispatch_get_main_queue();
    }

RCT_EXPORT_METHOD(gotoPrinterSetting:(RCTResponseSenderBlock)callback)
{

RCTLogInfo(@"gotoPringer");

UINavigationController *nav =  (UINavigationController*)[UIApplication sharedApplication].delegate.window.rootViewController;

HJPrinterDemoViewController *loginVC = [[HJPrinterDemoViewController alloc] init];

[nav pushViewController:loginVC animated:TRUE];

}

@EnD

2016-01-16 16:08:34.315 [trace][tid:main][PrinterManager.m:33] gotoPringer
2016-01-16 16:08:34.315 fastui[786:221044] -[UIViewController pushViewController:animated:]: unrecognized selector sent to instance 0x15f63c630
2016-01-16 16:08:34.316 [error][tid:main] Exception thrown while invoking gotoPrinterSetting on target PrinterManager with params (
17
): -[UIViewController pushViewController:animated:]: unrecognized selector sent to instance 0x15f63c630

@ramakrishna013
Copy link

ramakrishna013 commented Sep 23, 2016

@jabez128 Answer will work to push to next view controller. And we have to do the operation on the main queue otherwise, it will show some error.

@razvanilin
Copy link

@jabez128 Just wanted to let you know that I was stuck on this for more than a week and your answer saved my sanity. Thanks! I owe you 20+ beers

@facebook facebook locked as resolved and limited conversation to collaborators Jul 21, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

6 participants