Browse Source

Add unregisterForPreviewingWithContext (#2239)

* Preview API

* Added preview actions and fail-guard wrappers

* Remove old setters

* Moved from passProps to actionParams

* Move findNodeHandle to internal method

* Removing findNodeHandle

* Added height and option to dont 'pop' the view controller

* Documentation update for peek and pop

* Document how to access button press events

* Commit by default in example. Because it's cool

* Docs and if elses ifs then

* Unregister previous ViewController on attempt to preview.

* Merge conflict fail
Birkir Rafn Guðjónsson 6 years ago
parent
commit
36ed3b0af5
2 changed files with 4 additions and 1 deletions
  1. 3
    1
      ios/RCCNavigationController.m
  2. 1
    0
      ios/RCCViewController.h

+ 3
- 1
ios/RCCNavigationController.m View File

172
       if ([self.topViewController isKindOfClass:[RCCViewController class]])
172
       if ([self.topViewController isKindOfClass:[RCCViewController class]])
173
       {
173
       {
174
         RCCViewController *topViewController = ((RCCViewController*)self.topViewController);
174
         RCCViewController *topViewController = ((RCCViewController*)self.topViewController);
175
+        topViewController.previewController = nil;
176
+        [topViewController.navigationController unregisterForPreviewingWithContext:topViewController.previewContext];
175
         viewController.previewActions = previewActions;
177
         viewController.previewActions = previewActions;
176
         viewController.previewCommit = actionParams[@"previewCommit"] ? [actionParams[@"previewCommit"] boolValue] : YES;
178
         viewController.previewCommit = actionParams[@"previewCommit"] ? [actionParams[@"previewCommit"] boolValue] : YES;
177
         NSNumber *previewHeight = actionParams[@"previewHeight"];
179
         NSNumber *previewHeight = actionParams[@"previewHeight"];
184
             [bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
186
             [bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
185
               UIView *view = viewRegistry[previewViewID];
187
               UIView *view = viewRegistry[previewViewID];
186
               topViewController.previewView = view;
188
               topViewController.previewView = view;
187
-              [topViewController registerForPreviewingWithDelegate:(id)topViewController sourceView:view];
189
+              topViewController.previewContext = [topViewController registerForPreviewingWithDelegate:(id)topViewController sourceView:view];
188
             }];
190
             }];
189
           });
191
           });
190
           topViewController.previewController = viewController;
192
           topViewController.previewController = viewController;

+ 1
- 0
ios/RCCViewController.h View File

22
 @property (nonatomic) UIView *previewView;
22
 @property (nonatomic) UIView *previewView;
23
 @property (nonatomic) NSArray *previewActions;
23
 @property (nonatomic) NSArray *previewActions;
24
 @property (nonatomic) BOOL previewCommit;
24
 @property (nonatomic) BOOL previewCommit;
25
+@property (nonatomic) id previewContext;
25
 
26
 
26
 + (UIViewController*)controllerWithLayout:(NSDictionary *)layout globalProps:(NSDictionary *)globalProps bridge:(RCTBridge *)bridge;
27
 + (UIViewController*)controllerWithLayout:(NSDictionary *)layout globalProps:(NSDictionary *)globalProps bridge:(RCTBridge *)bridge;
27
 
28