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

How to exit from a react component into the native iOS app #22544

Closed
nipun0505 opened this issue Dec 6, 2018 · 1 comment
Closed

How to exit from a react component into the native iOS app #22544

nipun0505 opened this issue Dec 6, 2018 · 1 comment
Labels
Platform: iOS iOS applications. Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot.

Comments

@nipun0505
Copy link

I had this requirement of adding a new screen to an old iOS app made with Objective-C. The next thought was to make a react native reusable component and open it from my iOS app.

I used the reference from this page: https://facebook.github.io/react-native/docs/integration-with-existing-apps, to open my react native component.

The point where I am stuck right now is, how to go back to my native app? There's is nothing in the tutorial for that.

Here is my code:

1.) How to present a react native component from iOS app:

NSURL *jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.bundle?platform=ios"];

    RCTRootView *rootView =
    [[RCTRootView alloc] initWithBundleURL: jsCodeLocation
                                moduleName: @"MyListView"
                         initialProperties:nil
                             launchOptions: nil];
    UIViewController *vc = [[UIViewController alloc] init];
    vc.view = rootView;
    [self presentViewController:vc animated:YES completion:nil];

2.) How to expose an Objective-C class to React Native. Write the below code in the .m file:

RCT_EXPORT_MODULE()

RCT_EXPORT_METHOD(dismiss: (NSString *) name){
    NSLog(@"dismiss");

    dispatch_async(dispatch_get_main_queue(), ^{
        [self dismissViewControllerAnimated:YES completion:nil];
    });
}

3.) Now how to call dismiss method from React-Native to Objective C file:

var ViewController = NativeModules.ViewController;

backTap = () => {
    ViewController.dismiss('Blah');
  }

Now NativeModules.ViewController will always create a new instance of ViewController. How can I get the actual instance of ViewController, so I can dismiss the react-native component?

@react-native-bot react-native-bot added the Platform: iOS iOS applications. label Dec 6, 2018
@react-native-bot
Copy link
Collaborator

We are automatically closing this issue because it does not appear to follow any of the provided issue templates.

Please make use of the bug report template to let us know about a reproducible bug or regression in the core React Native library.

If you'd like to propose a change or discuss a feature request, there is a repository dedicated to Discussions and Proposals you may use for this purpose.

@react-native-bot react-native-bot added Ran Commands One of our bots successfully processed a command. 📋No Template labels Dec 6, 2018
@facebook facebook locked as resolved and limited conversation to collaborators Dec 6, 2019
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Dec 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Platform: iOS iOS applications. Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

2 participants