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

后端 未结 2 1339
不思量自难忘°
不思量自难忘° 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:25

    You want to implement a bridged UI component that mounts an empty UIView and is responsible primarily for presenting your UIViewController. The simplest example of this technique is in RCTModalHostView; check out the source code.

    Notably, React Native defines a category on UIView that adds a property called reactViewController which climbs the view hierarchy to find the closest UIViewController. Use this UIViewController to present your custom view controller:

    - (void)didMoveToWindow
    {
      [super didMoveToWindow];
    
      if (!_isPresented && self.window) {
        [self.reactViewController presentViewController:_customViewController
                                               animated:NO
                                             completion:nil];
        _isPresented = YES;
      }
    }
    

提交回复
热议问题