We're adding react native to an existing app and are having trouble pushing a native view controller on top of another native view controller housing a react native view.
The main view controller's viewDidLoad looks like this:
-(void)viewDidLoad {
...
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation moduleName: @"ListingsView" launchOptions:nil];
self.view = rootView;
}
The react view is a ListView where the TouchableHighlight's onPress is exported to this method on the same view controller:
RCT_EXPORT_METHOD(productClicked:(NSDictionary *)productDict)
{
dispatch_async(dispatch_get_main_queue(),
^{
SNKProduct *product = [[SNKProduct alloc] initWithDictionary:productDict];
SNKProductViewController *vc = [[SNKProductViewController alloc] initWithProduct:product];
[self.navigationController pushViewController:vc animated:YES];
});
}
The method is definitely called, but the SNKProductViewController is never pushed onto the screen (no log messages). I also tried modally presenting the view controller, and am getting this console message:
Warning: Attempt to present <SNKProductViewController: 0x7feadf247d10> on <SNKProductsViewController: 0x7feada5e2a20> whose view is not in the window hierarchy!
Any help would be appreciated, thanks much!
After call RCT_EXPORT_MODULE
macros by Reac-Native this created new instance of this module. And after call RCT_EXPORT_METHOD
method this method called from another instance of module. To solve this problem, I found only one solution yet. in called method place from js search my ViewController in Hierarchy controllers:
RCT_EXPORT_MODULE(AuthController);
- (instancetype)init {
self = [super init];
if (self) {
}
return self;
}
- (void)loadView {
self.view = [[RCTRootView alloc] initWithBundleURL:[[BCEConfigs sharedInstance] getBundleOfReactResources]
moduleName:@"AuthorizationView"
launchOptions:nil];
}
- (void)viewDidLoad {
[super viewDidLoad];
}
RCT_EXPORT_METHOD(a_registrationButton) {
[self presentRegistrationViewController];
}
- (void)presentRegistrationViewController {
UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
UIViewController *mainViewController = keyWindow.rootViewController.childViewControllers[0];
BCERegistrationViewController *bceRegistrationViewController = [BCERegistrationViewController new];
dispatch_async(dispatch_get_main_queue(), ^{
[mainViewController presentViewController:bceRegistrationViewController animated:YES completion:nil];
});
}
In this example my controller, which i needed, has a place this window>rootViewController>authViewController
UPD
this i found some solution how we can get current ViewController
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With