Browse Source

Revert "[v2] Refactor peek and pop [ready to merge] (#3620)"

This reverts commit 4c519acae8.
yogevbd 6 years ago
parent
commit
98dc2928dd

+ 0
- 32
docs/docs/animations.md View File

32
     }
32
     }
33
   }
33
   }
34
 });
34
 });
35
-```
36
-
37
-## Peek and Pop (iOS 11.4+)
38
-
39
-react-native-navigation supports the [Peek and pop](
40
-https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/Adopting3DTouchOniPhone/#//apple_ref/doc/uid/TP40016543-CH1-SW3) feature in iOS 11.4 and newer.
41
-
42
-This works by passing a ref a componentent you would want to transform into a peek view. We have included a handly component to handle all the touches and ref for you.
43
-
44
-```jsx
45
-const handlePress ({ reactTag }) => {
46
-  Navigation.push(this.props.componentId, {
47
-    component {
48
-      name: 'previewed.screen',
49
-      options: {
50
-        preview: {
51
-          reactTag,
52
-        },
53
-      },
54
-    },
55
-  });
56
-};
57
-
58
-const Button = (
59
-  <Navigation.TouchablePreview
60
-    touchableComponent={TouchableHighlight}
61
-    onPress={handlePress}
62
-    onPressIn={handlePress}
63
-  >
64
-    <Text>My button</Text>
65
-  </Navigation.TouchablePreview>
66
-);
67
 ```
35
 ```

+ 0
- 16
docs/docs/events.md View File

166
   }
166
   }
167
 }
167
 }
168
 ```
168
 ```
169
-
170
-## previewCompleted (iOS 11.4+ only)
171
-Called when preview peek is completed
172
-
173
-```js
174
-class MyComponent extends Component {
175
-  constructor(props) {
176
-    super(props);
177
-    Navigation.events().bindComponent(this);
178
-  }
179
-
180
-  previewCompleted({ previewComponentId }) {
181
-
182
-  }
183
-}
184
-```

+ 1
- 1
docs/docs/styling.md View File

153
     interceptTouchOutside: true
153
     interceptTouchOutside: true
154
   },
154
   },
155
   preview: {
155
   preview: {
156
-    reactTag: 0, // result from findNodeHandle(ref)
156
+    elementId: 'PreviewId',
157
     width: 100,
157
     width: 100,
158
     height: 100,
158
     height: 100,
159
     commit: false,
159
     commit: false,

+ 6
- 19
lib/ios/RNNCommandsHandler.m View File

98
 	RNNRootViewController *newVc = (RNNRootViewController *)[_controllerFactory createLayoutAndSaveToStore:layout];
98
 	RNNRootViewController *newVc = (RNNRootViewController *)[_controllerFactory createLayoutAndSaveToStore:layout];
99
 	UIViewController *fromVC = [_store findComponentForId:componentId];
99
 	UIViewController *fromVC = [_store findComponentForId:componentId];
100
 	
100
 	
101
-	if ([newVc.options.preview.reactTag floatValue] > 0) {
101
+	if (newVc.options.preview.elementId) {
102
 		UIViewController* vc = [_store findComponentForId:componentId];
102
 		UIViewController* vc = [_store findComponentForId:componentId];
103
 
103
 
104
 		if([vc isKindOfClass:[RNNRootViewController class]]) {
104
 		if([vc isKindOfClass:[RNNRootViewController class]]) {
105
 			RNNRootViewController* rootVc = (RNNRootViewController*)vc;
105
 			RNNRootViewController* rootVc = (RNNRootViewController*)vc;
106
 			rootVc.previewController = newVc;
106
 			rootVc.previewController = newVc;
107
-			rootVc.previewCallback = ^(UIViewController *vcc) {
108
-				RNNRootViewController* rvc  = (RNNRootViewController*)vcc;
109
-				[self->_eventEmitter sendOnPreviewCompleted:componentId previewComponentId:newVc.componentId];
110
-				if ([newVc.options.preview.commit floatValue] > 0) {
111
-					[CATransaction begin];
112
-					[CATransaction setCompletionBlock:^{
113
-						[self->_eventEmitter sendOnNavigationCommandCompletion:push params:@{@"componentId": componentId}];
114
-						completion();
115
-					}];
116
-					[rvc.navigationController pushViewController:newVc animated:YES];
117
-					[CATransaction commit];
118
-				}
119
-			};
120
-			
107
+
108
+			RNNElementFinder* elementFinder = [[RNNElementFinder alloc] initWithFromVC:vc];
109
+			RNNElementView* elementView = [elementFinder findElementForId:newVc.options.preview.elementId];
110
+
121
 			CGSize size = CGSizeMake(rootVc.view.frame.size.width, rootVc.view.frame.size.height);
111
 			CGSize size = CGSizeMake(rootVc.view.frame.size.width, rootVc.view.frame.size.height);
122
 			
112
 			
123
 			if (newVc.options.preview.width) {
113
 			if (newVc.options.preview.width) {
132
 				newVc.preferredContentSize = size;
122
 				newVc.preferredContentSize = size;
133
 			}
123
 			}
134
 
124
 
135
-			RCTExecuteOnMainQueue(^{
136
-				UIView *view = [[ReactNativeNavigation getBridge].uiManager viewForReactTag:newVc.options.preview.reactTag];
137
-				[rootVc registerForPreviewingWithDelegate:(id)rootVc sourceView:view];
138
-			});
125
+			[rootVc registerForPreviewingWithDelegate:(id)rootVc sourceView:elementView];
139
 		}
126
 		}
140
 	} else {
127
 	} else {
141
 		id animationDelegate = (newVc.options.animations.push.hasCustomAnimation || newVc.isCustomTransitioned) ? newVc : nil;
128
 		id animationDelegate = (newVc.options.animations.push.hasCustomAnimation || newVc.isCustomTransitioned) ? newVc : nil;

+ 0
- 2
lib/ios/RNNEventEmitter.h View File

22
 
22
 
23
 -(void)sendOnSearchBarCancelPressed:(NSString *)componentId;
23
 -(void)sendOnSearchBarCancelPressed:(NSString *)componentId;
24
 
24
 
25
--(void)sendOnPreviewCompleted:(NSString *)componentId previewComponentId:(NSString *)previewComponentId;
26
-
27
 @end
25
 @end

+ 1
- 10
lib/ios/RNNEventEmitter.m View File

16
 static NSString* const NavigationButtonPressed	= @"RNN.NavigationButtonPressed";
16
 static NSString* const NavigationButtonPressed	= @"RNN.NavigationButtonPressed";
17
 static NSString* const SearchBarUpdated 		= @"RNN.SearchBarUpdated";
17
 static NSString* const SearchBarUpdated 		= @"RNN.SearchBarUpdated";
18
 static NSString* const SearchBarCancelPressed 	= @"RNN.SearchBarCancelPressed";
18
 static NSString* const SearchBarCancelPressed 	= @"RNN.SearchBarCancelPressed";
19
-static NSString* const PreviewCompleted         = @"RNN.PreviewCompleted";
20
 
19
 
21
 -(NSArray<NSString *> *)supportedEvents {
20
 -(NSArray<NSString *> *)supportedEvents {
22
 	return @[AppLaunched,
21
 	return @[AppLaunched,
26
 			 ComponentDidDisappear,
25
 			 ComponentDidDisappear,
27
 			 NavigationButtonPressed,
26
 			 NavigationButtonPressed,
28
 			 SearchBarUpdated,
27
 			 SearchBarUpdated,
29
-			 SearchBarCancelPressed,
30
-			 PreviewCompleted];
28
+			 SearchBarCancelPressed];
31
 }
29
 }
32
 
30
 
33
 # pragma mark public
31
 # pragma mark public
92
 											}];
90
 											}];
93
 }
91
 }
94
 
92
 
95
-- (void)sendOnPreviewCompleted:(NSString *)componentId previewComponentId:(NSString *)previewComponentId {
96
-	[self send:PreviewCompleted body:@{
97
-											 @"componentId": componentId,
98
-											 @"previewComponentId": previewComponentId
99
-											 }];
100
-}
101
-
102
 - (void)addListener:(NSString *)eventName {
93
 - (void)addListener:(NSString *)eventName {
103
 	[super addListener:eventName];
94
 	[super addListener:eventName];
104
 	if ([eventName isEqualToString:AppLaunched]) {
95
 	if ([eventName isEqualToString:AppLaunched]) {

+ 1
- 1
lib/ios/RNNPreviewOptions.h View File

2
 
2
 
3
 @interface RNNPreviewOptions : RNNOptions
3
 @interface RNNPreviewOptions : RNNOptions
4
 
4
 
5
-@property (nonatomic, strong) NSNumber* reactTag;
5
+@property (nonatomic, strong) NSString* elementId;
6
 @property (nonatomic, strong) NSNumber* width;
6
 @property (nonatomic, strong) NSNumber* width;
7
 @property (nonatomic, strong) NSNumber* height;
7
 @property (nonatomic, strong) NSNumber* height;
8
 @property (nonatomic, strong) NSNumber* commit;
8
 @property (nonatomic, strong) NSNumber* commit;

+ 1
- 2
lib/ios/RNNRootViewController.h View File

7
 #import "RNNAnimator.h"
7
 #import "RNNAnimator.h"
8
 
8
 
9
 typedef void (^RNNReactViewReadyCompletionBlock)(void);
9
 typedef void (^RNNReactViewReadyCompletionBlock)(void);
10
-typedef void (^PreviewCallback)(UIViewController *vc);
11
 
10
 
12
 @interface RNNRootViewController : UIViewController	<UIViewControllerPreviewingDelegate, UISearchResultsUpdating, UISearchBarDelegate, UINavigationControllerDelegate, UISplitViewControllerDelegate>
11
 @interface RNNRootViewController : UIViewController	<UIViewControllerPreviewingDelegate, UISearchResultsUpdating, UISearchBarDelegate, UINavigationControllerDelegate, UISplitViewControllerDelegate>
13
 
12
 
17
 @property (nonatomic) id<RNNRootViewCreator> creator;
16
 @property (nonatomic) id<RNNRootViewCreator> creator;
18
 @property (nonatomic, strong) RNNAnimator* animator;
17
 @property (nonatomic, strong) RNNAnimator* animator;
19
 @property (nonatomic, strong) UIViewController* previewController;
18
 @property (nonatomic, strong) UIViewController* previewController;
20
-@property (nonatomic, copy) PreviewCallback previewCallback;
19
+
21
 
20
 
22
 - (instancetype)initWithName:(NSString*)name
21
 - (instancetype)initWithName:(NSString*)name
23
 				withOptions:(RNNNavigationOptions*)options
22
 				withOptions:(RNNNavigationOptions*)options

+ 17
- 4
lib/ios/RNNRootViewController.m View File

22
 
22
 
23
 @implementation RNNRootViewController
23
 @implementation RNNRootViewController
24
 
24
 
25
-@synthesize previewCallback;
26
-
27
 -(instancetype)initWithName:(NSString*)name
25
 -(instancetype)initWithName:(NSString*)name
28
 				withOptions:(RNNNavigationOptions*)options
26
 				withOptions:(RNNNavigationOptions*)options
29
 			withComponentId:(NSString*)componentId
27
 			withComponentId:(NSString*)componentId
288
 }
286
 }
289
 
287
 
290
 - (UIViewController *)previewingContext:(id<UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location{
288
 - (UIViewController *)previewingContext:(id<UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location{
289
+	if (self.previewController) {
290
+//		RNNRootViewController * vc = (RNNRootViewController*) self.previewController;
291
+//		[_eventEmitter sendOnNavigationEvent:@"previewContext" params:@{
292
+//																		@"previewComponentId": vc.componentId,
293
+//																		@"componentId": self.componentId
294
+//																		}];
295
+	}
291
 	return self.previewController;
296
 	return self.previewController;
292
 }
297
 }
293
 
298
 
294
 
299
 
295
 - (void)previewingContext:(id<UIViewControllerPreviewing>)previewingContext commitViewController:(UIViewController *)viewControllerToCommit {
300
 - (void)previewingContext:(id<UIViewControllerPreviewing>)previewingContext commitViewController:(UIViewController *)viewControllerToCommit {
296
-	if (self.previewCallback) {
297
-		self.previewCallback(self);
301
+	RNNRootViewController * vc = (RNNRootViewController*) self.previewController;
302
+//	NSDictionary * params = @{
303
+//							  @"previewComponentId": vc.componentId,
304
+//							  @"componentId": self.componentId
305
+//							  };
306
+	if (vc.options.preview.commit) {
307
+//		[_eventEmitter sendOnNavigationEvent:@"previewCommit" params:params];
308
+		[self.navigationController pushViewController:vc animated:false];
309
+	} else {
310
+//		[_eventEmitter sendOnNavigationEvent:@"previewDismissed" params:params];
298
 	}
311
 	}
299
 }
312
 }
300
 
313
 

+ 0
- 1
lib/ios/ReactNativeNavigation.h View File

1
 #import <Foundation/Foundation.h>
1
 #import <Foundation/Foundation.h>
2
 #import <UIKit/UIKit.h>
2
 #import <UIKit/UIKit.h>
3
 #import <React/RCTBridge.h>
3
 #import <React/RCTBridge.h>
4
-#import <React/RCTUIManager.h>
5
 #import "RNNBridgeManagerDelegate.h"
4
 #import "RNNBridgeManagerDelegate.h"
6
 
5
 
7
 typedef UIViewController * (^RNNExternalViewCreator)(NSDictionary* props, RCTBridge* bridge);
6
 typedef UIViewController * (^RNNExternalViewCreator)(NSDictionary* props, RCTBridge* bridge);

+ 0
- 5
lib/src/Navigation.ts View File

13
 import { Constants } from './adapters/Constants';
13
 import { Constants } from './adapters/Constants';
14
 import { ComponentType } from 'react';
14
 import { ComponentType } from 'react';
15
 import { ComponentEventsObserver } from './events/ComponentEventsObserver';
15
 import { ComponentEventsObserver } from './events/ComponentEventsObserver';
16
-import { LayoutRoot, Layout } from './interfaces/Layout';
17
-import { Options } from './interfaces/Options';
18
-// import { TouchablePreview, Props as TouchablePreviewProps } from './adapters/TouchablePreview';
19
 
16
 
20
 export class Navigation {
17
 export class Navigation {
21
   public readonly Element: React.ComponentType<{ elementId: any; resizeMode?: any; }>;
18
   public readonly Element: React.ComponentType<{ elementId: any; resizeMode?: any; }>;
22
-  // public readonly TouchablePreview: React.ComponentType<TouchablePreviewProps>;
23
   public readonly store: Store;
19
   public readonly store: Store;
24
   private readonly nativeEventsReceiver: NativeEventsReceiver;
20
   private readonly nativeEventsReceiver: NativeEventsReceiver;
25
   private readonly uniqueIdProvider: UniqueIdProvider;
21
   private readonly uniqueIdProvider: UniqueIdProvider;
34
 
30
 
35
   constructor() {
31
   constructor() {
36
     this.Element = Element;
32
     this.Element = Element;
37
-    // this.TouchablePreview = TouchablePreview;
38
     this.store = new Store();
33
     this.store = new Store();
39
     this.nativeEventsReceiver = new NativeEventsReceiver();
34
     this.nativeEventsReceiver = new NativeEventsReceiver();
40
     this.uniqueIdProvider = new UniqueIdProvider();
35
     this.uniqueIdProvider = new UniqueIdProvider();

+ 1
- 6
lib/src/adapters/NativeEventsReceiver.ts View File

5
   ComponentDidDisappearEvent,
5
   ComponentDidDisappearEvent,
6
   NavigationButtonPressedEvent,
6
   NavigationButtonPressedEvent,
7
   SearchBarUpdatedEvent,
7
   SearchBarUpdatedEvent,
8
-  SearchBarCancelPressedEvent,
9
-  PreviewCompletedEvent
8
+  SearchBarCancelPressedEvent
10
 } from '../interfaces/ComponentEvents';
9
 } from '../interfaces/ComponentEvents';
11
 import { CommandCompletedEvent, BottomTabSelectedEvent } from '../interfaces/Events';
10
 import { CommandCompletedEvent, BottomTabSelectedEvent } from '../interfaces/Events';
12
 
11
 
50
     return this.emitter.addListener('RNN.SearchBarCancelPressed', callback);
49
     return this.emitter.addListener('RNN.SearchBarCancelPressed', callback);
51
   }
50
   }
52
 
51
 
53
-  public registerPreviewCompletedListener(callback: (event: PreviewCompletedEvent) => void): EventSubscription {
54
-    return this.emitter.addListener('RNN.PreviewCompleted', callback);
55
-  }
56
-
57
   public registerCommandCompletedListener(callback: (data: CommandCompletedEvent) => void): EventSubscription {
52
   public registerCommandCompletedListener(callback: (data: CommandCompletedEvent) => void): EventSubscription {
58
     return this.emitter.addListener('RNN.CommandCompleted', callback);
53
     return this.emitter.addListener('RNN.CommandCompleted', callback);
59
   }
54
   }

+ 0
- 144
lib/src/adapters/TouchablePreview.tsx View File

1
-import * as React from 'react';
2
-import * as PropTypes from 'prop-types';
3
-import {
4
-  View,
5
-  Platform,
6
-  findNodeHandle,
7
-  TouchableOpacity,
8
-  TouchableHighlight,
9
-  TouchableNativeFeedback,
10
-  TouchableWithoutFeedback,
11
-  GestureResponderEvent,
12
-  NativeTouchEvent,
13
-  NativeSyntheticEvent,
14
-} from 'react-native';
15
-
16
-// Polyfill GestureResponderEvent type with additional `force` property (iOS)
17
-interface NativeTouchEventWithForce extends NativeTouchEvent { force: number; }
18
-interface GestureResponderEventWithForce extends NativeSyntheticEvent<NativeTouchEventWithForce> {}
19
-
20
-export interface Props {
21
-  children: React.ReactNode;
22
-  touchableComponent?: TouchableHighlight | TouchableOpacity | TouchableNativeFeedback | TouchableWithoutFeedback | React.ReactNode;
23
-  onPress?: () => void;
24
-  onPressIn?: (reactTag?) => void;
25
-  onPeekIn?: () => void;
26
-  onPeekOut?: () => void;
27
-}
28
-
29
-const PREVIEW_DELAY = 350;
30
-const PREVIEW_MIN_FORCE = 0.1;
31
-const PREVIEW_TIMEOUT = 1250;
32
-
33
-export class TouchablePreview extends React.PureComponent<Props, any> {
34
-
35
-  static propTypes = {
36
-    children: PropTypes.node,
37
-    touchableComponent: PropTypes.func,
38
-    onPress: PropTypes.func,
39
-    onPressIn: PropTypes.func,
40
-    onPeekIn: PropTypes.func,
41
-    onPeekOut: PropTypes.func,
42
-  };
43
-
44
-  static defaultProps = {
45
-    touchableComponent: TouchableWithoutFeedback,
46
-  };
47
-
48
-  static peeking = false;
49
-
50
-  private ref: React.Component<any> | null = null;
51
-  private timeout: number | undefined;
52
-  private ts: number = 0;
53
-
54
-  onRef = (ref: React.Component<any>) => {
55
-    this.ref = ref;
56
-  }
57
-
58
-  onPress = () => {
59
-    const { onPress } = this.props;
60
-
61
-    if (typeof onPress !== 'function' || TouchablePreview.peeking) {
62
-      return;
63
-    }
64
-
65
-    return onPress();
66
-  }
67
-
68
-  onPressIn = () => {
69
-    if (Platform.OS === 'ios') {
70
-      const { onPressIn } = this.props;
71
-
72
-      if (!onPressIn) {
73
-        return;
74
-      }
75
-
76
-      const reactTag = findNodeHandle(this.ref);
77
-
78
-      return onPressIn({ reactTag });
79
-    }
80
-
81
-    // Other platforms don't support 3D Touch Preview API
82
-    return null;
83
-  }
84
-
85
-  onTouchStart = (event: GestureResponderEvent) => {
86
-    // Store a timstamp of the initial touch start
87
-    this.ts = event.nativeEvent.timestamp;
88
-  }
89
-
90
-  onTouchMove = (event: GestureResponderEventWithForce) => {
91
-    clearTimeout(this.timeout);
92
-    const { force, timestamp } = event.nativeEvent;
93
-    const diff = (timestamp - this.ts);
94
-
95
-    if (force > PREVIEW_MIN_FORCE && diff > PREVIEW_DELAY) {
96
-      TouchablePreview.peeking = true;
97
-
98
-      if (typeof this.props.onPeekIn === 'function') {
99
-        this.props.onPeekIn();
100
-      }
101
-    }
102
-
103
-    this.timeout = setTimeout(this.onTouchEnd, PREVIEW_TIMEOUT);
104
-  }
105
-
106
-  onTouchEnd = () => {
107
-    clearTimeout(this.timeout);
108
-    TouchablePreview.peeking = false;
109
-
110
-    if (typeof this.props.onPeekOut === 'function') {
111
-      this.props.onPeekOut();
112
-    }
113
-  }
114
-
115
-  render() {
116
-    const { children, touchableComponent, onPress, onPressIn, ...props } = this.props;
117
-
118
-    // Default to TouchableWithoutFeedback for iOS if set to TouchableNativeFeedback
119
-    const Touchable = (
120
-      Platform.OS === 'ios' && touchableComponent instanceof TouchableNativeFeedback
121
-        ? TouchableWithoutFeedback
122
-        : touchableComponent
123
-    ) as typeof TouchableWithoutFeedback;
124
-
125
-    // Wrap component with Touchable for handling platform touches
126
-    // and a single react View for detecting force and timing.
127
-    return (
128
-      <Touchable
129
-        ref={this.onRef}
130
-        onPress={this.onPress}
131
-        onPressIn={this.onPressIn}
132
-        {...props}
133
-      >
134
-        <View
135
-          onTouchStart={this.onTouchStart}
136
-          onTouchMove={this.onTouchMove as (event: GestureResponderEvent) => void}
137
-          onTouchEnd={this.onTouchEnd}
138
-        >
139
-          {children}
140
-        </View>
141
-      </Touchable>
142
-    );
143
-  }
144
-}

+ 0
- 11
lib/src/events/ComponentEventsObserver.test.tsx View File

13
   const navigationButtonPressedFn = jest.fn();
13
   const navigationButtonPressedFn = jest.fn();
14
   const searchBarUpdatedFn = jest.fn();
14
   const searchBarUpdatedFn = jest.fn();
15
   const searchBarCancelPressedFn = jest.fn();
15
   const searchBarCancelPressedFn = jest.fn();
16
-  const previewCompletedFn = jest.fn();
17
   let subscription;
16
   let subscription;
18
 
17
 
19
   class SimpleScreen extends React.Component<any, any> {
18
   class SimpleScreen extends React.Component<any, any> {
56
       searchBarCancelPressedFn(event);
55
       searchBarCancelPressedFn(event);
57
     }
56
     }
58
 
57
 
59
-    previewCompleted(event) {
60
-      previewCompletedFn(event);
61
-    }
62
-
63
     render() {
58
     render() {
64
       return 'Hello';
59
       return 'Hello';
65
     }
60
     }
98
     expect(searchBarCancelPressedFn).toHaveBeenCalledTimes(1);
93
     expect(searchBarCancelPressedFn).toHaveBeenCalledTimes(1);
99
     expect(searchBarCancelPressedFn).toHaveBeenCalledWith({ componentId: 'myCompId' });
94
     expect(searchBarCancelPressedFn).toHaveBeenCalledWith({ componentId: 'myCompId' });
100
 
95
 
101
-    uut.notifyPreviewCompleted({ componentId: 'myCompId' });
102
-    expect(previewCompletedFn).toHaveBeenCalledTimes(1);
103
-    expect(previewCompletedFn).toHaveBeenCalledWith({ componentId: 'myCompId' });
104
-
105
     tree.unmount();
96
     tree.unmount();
106
     expect(willUnmountFn).toHaveBeenCalledTimes(1);
97
     expect(willUnmountFn).toHaveBeenCalledTimes(1);
107
   });
98
   });
177
     expect(mockEventsReceiver.registerNavigationButtonPressedListener).not.toHaveBeenCalled();
168
     expect(mockEventsReceiver.registerNavigationButtonPressedListener).not.toHaveBeenCalled();
178
     expect(mockEventsReceiver.registerSearchBarUpdatedListener).not.toHaveBeenCalled();
169
     expect(mockEventsReceiver.registerSearchBarUpdatedListener).not.toHaveBeenCalled();
179
     expect(mockEventsReceiver.registerSearchBarCancelPressedListener).not.toHaveBeenCalled();
170
     expect(mockEventsReceiver.registerSearchBarCancelPressedListener).not.toHaveBeenCalled();
180
-    expect(mockEventsReceiver.registerPreviewCompletedListener).not.toHaveBeenCalled();
181
     uut.registerOnceForAllComponentEvents();
171
     uut.registerOnceForAllComponentEvents();
182
     uut.registerOnceForAllComponentEvents();
172
     uut.registerOnceForAllComponentEvents();
183
     uut.registerOnceForAllComponentEvents();
173
     uut.registerOnceForAllComponentEvents();
187
     expect(mockEventsReceiver.registerNavigationButtonPressedListener).toHaveBeenCalledTimes(1);
177
     expect(mockEventsReceiver.registerNavigationButtonPressedListener).toHaveBeenCalledTimes(1);
188
     expect(mockEventsReceiver.registerSearchBarUpdatedListener).toHaveBeenCalledTimes(1);
178
     expect(mockEventsReceiver.registerSearchBarUpdatedListener).toHaveBeenCalledTimes(1);
189
     expect(mockEventsReceiver.registerSearchBarCancelPressedListener).toHaveBeenCalledTimes(1);
179
     expect(mockEventsReceiver.registerSearchBarCancelPressedListener).toHaveBeenCalledTimes(1);
190
-    expect(mockEventsReceiver.registerPreviewCompletedListener).toHaveBeenCalledTimes(1);
191
   });
180
   });
192
 });
181
 });

+ 1
- 8
lib/src/events/ComponentEventsObserver.ts View File

6
   NavigationButtonPressedEvent,
6
   NavigationButtonPressedEvent,
7
   SearchBarUpdatedEvent,
7
   SearchBarUpdatedEvent,
8
   SearchBarCancelPressedEvent,
8
   SearchBarCancelPressedEvent,
9
-  ComponentEvent,
10
-  PreviewCompletedEvent
9
+  ComponentEvent
11
 } from '../interfaces/ComponentEvents';
10
 } from '../interfaces/ComponentEvents';
12
 import { NativeEventsReceiver } from '../adapters/NativeEventsReceiver';
11
 import { NativeEventsReceiver } from '../adapters/NativeEventsReceiver';
13
 
12
 
21
     this.notifyNavigationButtonPressed = this.notifyNavigationButtonPressed.bind(this);
20
     this.notifyNavigationButtonPressed = this.notifyNavigationButtonPressed.bind(this);
22
     this.notifySearchBarUpdated = this.notifySearchBarUpdated.bind(this);
21
     this.notifySearchBarUpdated = this.notifySearchBarUpdated.bind(this);
23
     this.notifySearchBarCancelPressed = this.notifySearchBarCancelPressed.bind(this);
22
     this.notifySearchBarCancelPressed = this.notifySearchBarCancelPressed.bind(this);
24
-    this.notifyPreviewCompleted = this.notifyPreviewCompleted.bind(this);
25
   }
23
   }
26
 
24
 
27
   public registerOnceForAllComponentEvents() {
25
   public registerOnceForAllComponentEvents() {
32
     this.nativeEventsReceiver.registerNavigationButtonPressedListener(this.notifyNavigationButtonPressed);
30
     this.nativeEventsReceiver.registerNavigationButtonPressedListener(this.notifyNavigationButtonPressed);
33
     this.nativeEventsReceiver.registerSearchBarUpdatedListener(this.notifySearchBarUpdated);
31
     this.nativeEventsReceiver.registerSearchBarUpdatedListener(this.notifySearchBarUpdated);
34
     this.nativeEventsReceiver.registerSearchBarCancelPressedListener(this.notifySearchBarCancelPressed);
32
     this.nativeEventsReceiver.registerSearchBarCancelPressedListener(this.notifySearchBarCancelPressed);
35
-    this.nativeEventsReceiver.registerPreviewCompletedListener(this.notifyPreviewCompleted);
36
   }
33
   }
37
 
34
 
38
   public bindComponent(component: React.Component<any>): EventSubscription {
35
   public bindComponent(component: React.Component<any>): EventSubscription {
73
     this.triggerOnAllListenersByComponentId(event, 'searchBarCancelPressed');
70
     this.triggerOnAllListenersByComponentId(event, 'searchBarCancelPressed');
74
   }
71
   }
75
 
72
 
76
-  notifyPreviewCompleted(event: PreviewCompletedEvent) {
77
-    this.triggerOnAllListenersByComponentId(event, 'previewCompleted');
78
-  }
79
-
80
   private triggerOnAllListenersByComponentId(event: ComponentEvent, method: string) {
73
   private triggerOnAllListenersByComponentId(event: ComponentEvent, method: string) {
81
     _.forEach(this.listeners[event.componentId], (component) => {
74
     _.forEach(this.listeners[event.componentId], (component) => {
82
       if (_.isObject(component) && _.isFunction(component[method])) {
75
       if (_.isObject(component) && _.isFunction(component[method])) {

+ 0
- 7
lib/src/events/EventsRegistry.test.tsx View File

74
     expect(mockNativeEventsReceiver.registerSearchBarCancelPressedListener).toHaveBeenCalledWith(cb);
74
     expect(mockNativeEventsReceiver.registerSearchBarCancelPressedListener).toHaveBeenCalledWith(cb);
75
   });
75
   });
76
 
76
 
77
-  it('delegates previewCompleted to nativeEventsReceiver', () => {
78
-    const cb = jest.fn();
79
-    uut.registerPreviewCompletedListener(cb);
80
-    expect(mockNativeEventsReceiver.registerPreviewCompletedListener).toHaveBeenCalledTimes(1);
81
-    expect(mockNativeEventsReceiver.registerPreviewCompletedListener).toHaveBeenCalledWith(cb);
82
-  });
83
-
84
   it('delegates registerCommandListener to commandObserver', () => {
77
   it('delegates registerCommandListener to commandObserver', () => {
85
     const cb = jest.fn();
78
     const cb = jest.fn();
86
     const result = uut.registerCommandListener(cb);
79
     const result = uut.registerCommandListener(cb);

+ 1
- 6
lib/src/events/EventsRegistry.ts View File

7
   ComponentDidDisappearEvent,
7
   ComponentDidDisappearEvent,
8
   NavigationButtonPressedEvent,
8
   NavigationButtonPressedEvent,
9
   SearchBarUpdatedEvent,
9
   SearchBarUpdatedEvent,
10
-  SearchBarCancelPressedEvent,
11
-  PreviewCompletedEvent
10
+  SearchBarCancelPressedEvent
12
 } from '../interfaces/ComponentEvents';
11
 } from '../interfaces/ComponentEvents';
13
 import { CommandCompletedEvent, BottomTabSelectedEvent } from '../interfaces/Events';
12
 import { CommandCompletedEvent, BottomTabSelectedEvent } from '../interfaces/Events';
14
 
13
 
47
     return this.nativeEventsReceiver.registerSearchBarCancelPressedListener(callback);
46
     return this.nativeEventsReceiver.registerSearchBarCancelPressedListener(callback);
48
   }
47
   }
49
 
48
 
50
-  public registerPreviewCompletedListener(callback: (event: PreviewCompletedEvent) => void): EventSubscription {
51
-    return this.nativeEventsReceiver.registerPreviewCompletedListener(callback);
52
-  }
53
-
54
   public registerCommandListener(callback: (name: string, params: any) => void): EventSubscription {
49
   public registerCommandListener(callback: (name: string, params: any) => void): EventSubscription {
55
     return this.commandsObserver.register(callback);
50
     return this.commandsObserver.register(callback);
56
   }
51
   }

+ 0
- 5
lib/src/interfaces/ComponentEvents.ts View File

22
 export interface SearchBarCancelPressedEvent extends ComponentEvent {
22
 export interface SearchBarCancelPressedEvent extends ComponentEvent {
23
   componentName?: string;
23
   componentName?: string;
24
 }
24
 }
25
-
26
-export interface PreviewCompletedEvent extends ComponentEvent {
27
-  componentName?: string;
28
-  previewComponentId?: string;
29
-}

+ 1
- 7
playground/src/screens/Button.js View File

2
 const { Component } = require('react');
2
 const { Component } = require('react');
3
 const PropTypes = require('prop-types');
3
 const PropTypes = require('prop-types');
4
 const { Platform, ColorPropType, StyleSheet, TouchableNativeFeedback, TouchableOpacity, View, Text } = require('react-native');
4
 const { Platform, ColorPropType, StyleSheet, TouchableNativeFeedback, TouchableOpacity, View, Text } = require('react-native');
5
-const { Navigation } = require('react-native-navigation');
6
 
5
 
7
 class Button extends Component {
6
 class Button extends Component {
8
 
7
 
48
 
47
 
49
     const formattedTitle =
48
     const formattedTitle =
50
       Platform.OS === 'android' ? title.toUpperCase() : title;
49
       Platform.OS === 'android' ? title.toUpperCase() : title;
51
-    let Touchable =
50
+    const Touchable =
52
       Platform.OS === 'android' ? TouchableNativeFeedback : TouchableOpacity;
51
       Platform.OS === 'android' ? TouchableNativeFeedback : TouchableOpacity;
53
-
54
-    if (typeof onPressIn === 'function') {
55
-      Touchable = Navigation.TouchablePreview;
56
-    }
57
-
58
     return (
52
     return (
59
       <Touchable
53
       <Touchable
60
         accessibilityComponentType='button'
54
         accessibilityComponentType='button'

+ 7
- 3
playground/src/screens/PushedScreen.js View File

79
         <Text testID={testIDs.PUSHED_SCREEN_HEADER} style={styles.h1}>{`Pushed Screen`}</Text>
79
         <Text testID={testIDs.PUSHED_SCREEN_HEADER} style={styles.h1}>{`Pushed Screen`}</Text>
80
         <Text style={styles.h2}>{`Stack Position: ${stackPosition}`}</Text>
80
         <Text style={styles.h2}>{`Stack Position: ${stackPosition}`}</Text>
81
         <Button title='Push' testID={testIDs.PUSH_BUTTON} onPress={this.onClickPush} />
81
         <Button title='Push' testID={testIDs.PUSH_BUTTON} onPress={this.onClickPush} />
82
-        {Platform.OS === 'ios' && <Button testID={testIDs.SHOW_PREVIEW_BUTTON} onPress={this.onClickPush} onPressIn={this.onClickShowPreview} title='Push Preview' />}
82
+        {Platform.OS === 'ios' && (
83
+          <Navigation.Element elementId='PreviewElement'>
84
+            <Button testID={testIDs.SHOW_PREVIEW_BUTTON} onPress={this.onClickPush} onPressIn={this.onClickShowPreview} title='Push Preview' />
85
+          </Navigation.Element>
86
+        )}
83
         <Button title='Pop' testID={testIDs.POP_BUTTON} onPress={this.onClickPop} />
87
         <Button title='Pop' testID={testIDs.POP_BUTTON} onPress={this.onClickPop} />
84
         <Button title='Pop Previous' testID={testIDs.POP_PREVIOUS_BUTTON} onPress={this.onClickPopPrevious} />
88
         <Button title='Pop Previous' testID={testIDs.POP_PREVIOUS_BUTTON} onPress={this.onClickPopPrevious} />
85
         <Button title='Pop To Root' testID={testIDs.POP_TO_ROOT} onPress={this.onClickPopToRoot} />
89
         <Button title='Pop To Root' testID={testIDs.POP_TO_ROOT} onPress={this.onClickPopToRoot} />
91
     );
95
     );
92
   }
96
   }
93
 
97
 
94
-  onClickShowPreview = async ({ reactTag }) => {
98
+  onClickShowPreview = async () => {
95
     await Navigation.push(this.props.componentId, {
99
     await Navigation.push(this.props.componentId, {
96
       component: {
100
       component: {
97
         name: 'navigation.playground.PushedScreen',
101
         name: 'navigation.playground.PushedScreen',
111
             }
115
             }
112
           },
116
           },
113
           preview: {
117
           preview: {
114
-            reactTag,
118
+            elementId: 'PreviewElement',
115
             height: 400,
119
             height: 400,
116
             commit: true,
120
             commit: true,
117
             actions: [{
121
             actions: [{

+ 9
- 5
playground/src/screens/WelcomeScreen.js View File

41
           <Button title='Push Lifecycle Screen' testID={testIDs.PUSH_LIFECYCLE_BUTTON} onPress={this.onClickLifecycleScreen} />
41
           <Button title='Push Lifecycle Screen' testID={testIDs.PUSH_LIFECYCLE_BUTTON} onPress={this.onClickLifecycleScreen} />
42
           <Button title='Static Lifecycle Events' testID={testIDs.PUSH_STATIC_LIFECYCLE_BUTTON} onPress={this.onClickShowStaticLifecycleOverlay} />
42
           <Button title='Static Lifecycle Events' testID={testIDs.PUSH_STATIC_LIFECYCLE_BUTTON} onPress={this.onClickShowStaticLifecycleOverlay} />
43
           <Button title='Push' testID={testIDs.PUSH_BUTTON} onPress={this.onClickPush} />
43
           <Button title='Push' testID={testIDs.PUSH_BUTTON} onPress={this.onClickPush} />
44
-          {Platform.OS === 'ios' && <Button testID={testIDs.SHOW_PREVIEW_BUTTON} onPress={this.onClickPush} onPressIn={this.onClickShowPreview} title='Push Preview' />}
44
+          {Platform.OS === 'ios' && (
45
+            <Navigation.Element elementId='PreviewElement'>
46
+              <Button testID={testIDs.SHOW_PREVIEW_BUTTON} onPressIn={this.onClickShowPreview} title='Push Preview' />
47
+            </Navigation.Element>
48
+          )}
45
           <Button title='Push Options Screen' testID={testIDs.PUSH_OPTIONS_BUTTON} onPress={this.onClickPushOptionsScreen} />
49
           <Button title='Push Options Screen' testID={testIDs.PUSH_OPTIONS_BUTTON} onPress={this.onClickPushOptionsScreen} />
46
           <Button title='Push External Component' testID={testIDs.PUSH_EXTERNAL_COMPONENT_BUTTON} onPress={this.onClickPushExternalComponent} />
50
           <Button title='Push External Component' testID={testIDs.PUSH_EXTERNAL_COMPONENT_BUTTON} onPress={this.onClickPushExternalComponent} />
47
           {Platform.OS === 'android' && <Button title='Push Top Tabs screen' testID={testIDs.PUSH_TOP_TABS_BUTTON} onPress={this.onClickPushTopTabsScreen} />}
51
           {Platform.OS === 'android' && <Button title='Push Top Tabs screen' testID={testIDs.PUSH_TOP_TABS_BUTTON} onPress={this.onClickPushTopTabsScreen} />}
330
     undefined();
334
     undefined();
331
   }
335
   }
332
 
336
 
333
-  onClickShowPreview = async ({ reactTag }) => {
337
+  onClickShowPreview = async () => {
334
     await Navigation.push(this.props.componentId, {
338
     await Navigation.push(this.props.componentId, {
335
       component: {
339
       component: {
336
         name: 'navigation.playground.PushedScreen',
340
         name: 'navigation.playground.PushedScreen',
340
               enable: false
344
               enable: false
341
             }
345
             }
342
           },
346
           },
343
-          preview: reactTag ? {
344
-            reactTag,
347
+          preview: {
348
+            elementId: 'PreviewElement',
345
             height: 300,
349
             height: 300,
346
             commit: true,
350
             commit: true,
347
             actions: [{
351
             actions: [{
356
                 style: 'destructive'
360
                 style: 'destructive'
357
               }]
361
               }]
358
             }]
362
             }]
359
-          } : undefined,
363
+          }
360
         }
364
         }
361
       }
365
       }
362
     });
366
     });