How can I present a native UIViewController in React Native? (Can't use just a UIView)

后端 未结 2 1340
不思量自难忘°
不思量自难忘° 2020-12-28 17:47

I\'m trying to use ABNewPersonViewController in my React Native app. This is how it\'s used in Objective-C:

ABNewPersonViewController *picker = [[ABNewPerson         


        
2条回答
  •  渐次进展
    2020-12-28 18:29

    Here's what ended up working for me.

    CreateContact.h:

    #import 
    #import 
    #import 
    #import 
    #import "RCTBridgeModule.h"
    
    @interface CreateContact : NSObject 
    
    @end
    

    CreateContact.m:

    #import "CreateContact.h"
    #import "AppDelegate.h"
    
    @implementation CreateContact
    
    RCT_EXPORT_MODULE(CreateContact);
    
    
    RCT_EXPORT_METHOD(presentContact) {
    
        dispatch_async(dispatch_get_main_queue(), ^{
            ABNewPersonViewController *picker = [[ABNewPersonViewController alloc] init];
            picker.newPersonViewDelegate = self;
            UINavigationController* contactNavigator = [[UINavigationController alloc] initWithRootViewController:picker];
            AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
            [delegate.window.rootViewController presentViewController:contactNavigator animated:NO completion:nil];
        });
    }
    
    - (void)newPersonViewController:(ABNewPersonViewController *)newPersonViewController didCompleteWithNewPerson:(ABRecordRef)person
    {
        [newPersonViewController dismissViewControllerAnimated:YES completion:nil];
    }
    @end
    

    This tutorial has more detail: http://moduscreate.com/leverage-existing-ios-views-react-native-app/

    I'll update as I implement the best way to communicate information back to RN.

提交回复
热议问题