Procházet zdrojové kódy

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

This reverts commit 4c519acae8.
yogevbd před 6 roky
rodič
revize
98dc2928dd

+ 0
- 32
docs/docs/animations.md Zobrazit soubor

@@ -32,36 +32,4 @@ Navigation.push(this.props.componentId, {
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 Zobrazit soubor

@@ -166,19 +166,3 @@ class MyComponent extends Component {
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 Zobrazit soubor

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

+ 6
- 19
lib/ios/RNNCommandsHandler.m Zobrazit soubor

@@ -98,26 +98,16 @@ static NSString* const setDefaultOptions	= @"setDefaultOptions";
98 98
 	RNNRootViewController *newVc = (RNNRootViewController *)[_controllerFactory createLayoutAndSaveToStore:layout];
99 99
 	UIViewController *fromVC = [_store findComponentForId:componentId];
100 100
 	
101
-	if ([newVc.options.preview.reactTag floatValue] > 0) {
101
+	if (newVc.options.preview.elementId) {
102 102
 		UIViewController* vc = [_store findComponentForId:componentId];
103 103
 
104 104
 		if([vc isKindOfClass:[RNNRootViewController class]]) {
105 105
 			RNNRootViewController* rootVc = (RNNRootViewController*)vc;
106 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 111
 			CGSize size = CGSizeMake(rootVc.view.frame.size.width, rootVc.view.frame.size.height);
122 112
 			
123 113
 			if (newVc.options.preview.width) {
@@ -132,10 +122,7 @@ static NSString* const setDefaultOptions	= @"setDefaultOptions";
132 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 127
 	} else {
141 128
 		id animationDelegate = (newVc.options.animations.push.hasCustomAnimation || newVc.isCustomTransitioned) ? newVc : nil;

+ 0
- 2
lib/ios/RNNEventEmitter.h Zobrazit soubor

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

+ 1
- 10
lib/ios/RNNEventEmitter.m Zobrazit soubor

@@ -16,7 +16,6 @@ static NSString* const ComponentDidDisappear	= @"RNN.ComponentDidDisappear";
16 16
 static NSString* const NavigationButtonPressed	= @"RNN.NavigationButtonPressed";
17 17
 static NSString* const SearchBarUpdated 		= @"RNN.SearchBarUpdated";
18 18
 static NSString* const SearchBarCancelPressed 	= @"RNN.SearchBarCancelPressed";
19
-static NSString* const PreviewCompleted         = @"RNN.PreviewCompleted";
20 19
 
21 20
 -(NSArray<NSString *> *)supportedEvents {
22 21
 	return @[AppLaunched,
@@ -26,8 +25,7 @@ static NSString* const PreviewCompleted         = @"RNN.PreviewCompleted";
26 25
 			 ComponentDidDisappear,
27 26
 			 NavigationButtonPressed,
28 27
 			 SearchBarUpdated,
29
-			 SearchBarCancelPressed,
30
-			 PreviewCompleted];
28
+			 SearchBarCancelPressed];
31 29
 }
32 30
 
33 31
 # pragma mark public
@@ -92,13 +90,6 @@ static NSString* const PreviewCompleted         = @"RNN.PreviewCompleted";
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 93
 - (void)addListener:(NSString *)eventName {
103 94
 	[super addListener:eventName];
104 95
 	if ([eventName isEqualToString:AppLaunched]) {

+ 1
- 1
lib/ios/RNNPreviewOptions.h Zobrazit soubor

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

+ 1
- 2
lib/ios/RNNRootViewController.h Zobrazit soubor

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

+ 17
- 4
lib/ios/RNNRootViewController.m Zobrazit soubor

@@ -22,8 +22,6 @@
22 22
 
23 23
 @implementation RNNRootViewController
24 24
 
25
-@synthesize previewCallback;
26
-
27 25
 -(instancetype)initWithName:(NSString*)name
28 26
 				withOptions:(RNNNavigationOptions*)options
29 27
 			withComponentId:(NSString*)componentId
@@ -288,13 +286,28 @@
288 286
 }
289 287
 
290 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 296
 	return self.previewController;
292 297
 }
293 298
 
294 299
 
295 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 Zobrazit soubor

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

+ 0
- 5
lib/src/Navigation.ts Zobrazit soubor

@@ -13,13 +13,9 @@ import { CommandsObserver } from './events/CommandsObserver';
13 13
 import { Constants } from './adapters/Constants';
14 14
 import { ComponentType } from 'react';
15 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 17
 export class Navigation {
21 18
   public readonly Element: React.ComponentType<{ elementId: any; resizeMode?: any; }>;
22
-  // public readonly TouchablePreview: React.ComponentType<TouchablePreviewProps>;
23 19
   public readonly store: Store;
24 20
   private readonly nativeEventsReceiver: NativeEventsReceiver;
25 21
   private readonly uniqueIdProvider: UniqueIdProvider;
@@ -34,7 +30,6 @@ export class Navigation {
34 30
 
35 31
   constructor() {
36 32
     this.Element = Element;
37
-    // this.TouchablePreview = TouchablePreview;
38 33
     this.store = new Store();
39 34
     this.nativeEventsReceiver = new NativeEventsReceiver();
40 35
     this.uniqueIdProvider = new UniqueIdProvider();

+ 1
- 6
lib/src/adapters/NativeEventsReceiver.ts Zobrazit soubor

@@ -5,8 +5,7 @@ import {
5 5
   ComponentDidDisappearEvent,
6 6
   NavigationButtonPressedEvent,
7 7
   SearchBarUpdatedEvent,
8
-  SearchBarCancelPressedEvent,
9
-  PreviewCompletedEvent
8
+  SearchBarCancelPressedEvent
10 9
 } from '../interfaces/ComponentEvents';
11 10
 import { CommandCompletedEvent, BottomTabSelectedEvent } from '../interfaces/Events';
12 11
 
@@ -50,10 +49,6 @@ export class NativeEventsReceiver {
50 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 52
   public registerCommandCompletedListener(callback: (data: CommandCompletedEvent) => void): EventSubscription {
58 53
     return this.emitter.addListener('RNN.CommandCompleted', callback);
59 54
   }

+ 0
- 144
lib/src/adapters/TouchablePreview.tsx Zobrazit soubor

@@ -1,144 +0,0 @@
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 Zobrazit soubor

@@ -13,7 +13,6 @@ describe('ComponentEventsObserver', () => {
13 13
   const navigationButtonPressedFn = jest.fn();
14 14
   const searchBarUpdatedFn = jest.fn();
15 15
   const searchBarCancelPressedFn = jest.fn();
16
-  const previewCompletedFn = jest.fn();
17 16
   let subscription;
18 17
 
19 18
   class SimpleScreen extends React.Component<any, any> {
@@ -56,10 +55,6 @@ describe('ComponentEventsObserver', () => {
56 55
       searchBarCancelPressedFn(event);
57 56
     }
58 57
 
59
-    previewCompleted(event) {
60
-      previewCompletedFn(event);
61
-    }
62
-
63 58
     render() {
64 59
       return 'Hello';
65 60
     }
@@ -98,10 +93,6 @@ describe('ComponentEventsObserver', () => {
98 93
     expect(searchBarCancelPressedFn).toHaveBeenCalledTimes(1);
99 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 96
     tree.unmount();
106 97
     expect(willUnmountFn).toHaveBeenCalledTimes(1);
107 98
   });
@@ -177,7 +168,6 @@ describe('ComponentEventsObserver', () => {
177 168
     expect(mockEventsReceiver.registerNavigationButtonPressedListener).not.toHaveBeenCalled();
178 169
     expect(mockEventsReceiver.registerSearchBarUpdatedListener).not.toHaveBeenCalled();
179 170
     expect(mockEventsReceiver.registerSearchBarCancelPressedListener).not.toHaveBeenCalled();
180
-    expect(mockEventsReceiver.registerPreviewCompletedListener).not.toHaveBeenCalled();
181 171
     uut.registerOnceForAllComponentEvents();
182 172
     uut.registerOnceForAllComponentEvents();
183 173
     uut.registerOnceForAllComponentEvents();
@@ -187,6 +177,5 @@ describe('ComponentEventsObserver', () => {
187 177
     expect(mockEventsReceiver.registerNavigationButtonPressedListener).toHaveBeenCalledTimes(1);
188 178
     expect(mockEventsReceiver.registerSearchBarUpdatedListener).toHaveBeenCalledTimes(1);
189 179
     expect(mockEventsReceiver.registerSearchBarCancelPressedListener).toHaveBeenCalledTimes(1);
190
-    expect(mockEventsReceiver.registerPreviewCompletedListener).toHaveBeenCalledTimes(1);
191 180
   });
192 181
 });

+ 1
- 8
lib/src/events/ComponentEventsObserver.ts Zobrazit soubor

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

+ 0
- 7
lib/src/events/EventsRegistry.test.tsx Zobrazit soubor

@@ -74,13 +74,6 @@ describe('EventsRegistry', () => {
74 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 77
   it('delegates registerCommandListener to commandObserver', () => {
85 78
     const cb = jest.fn();
86 79
     const result = uut.registerCommandListener(cb);

+ 1
- 6
lib/src/events/EventsRegistry.ts Zobrazit soubor

@@ -7,8 +7,7 @@ import {
7 7
   ComponentDidDisappearEvent,
8 8
   NavigationButtonPressedEvent,
9 9
   SearchBarUpdatedEvent,
10
-  SearchBarCancelPressedEvent,
11
-  PreviewCompletedEvent
10
+  SearchBarCancelPressedEvent
12 11
 } from '../interfaces/ComponentEvents';
13 12
 import { CommandCompletedEvent, BottomTabSelectedEvent } from '../interfaces/Events';
14 13
 
@@ -47,10 +46,6 @@ export class EventsRegistry {
47 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 49
   public registerCommandListener(callback: (name: string, params: any) => void): EventSubscription {
55 50
     return this.commandsObserver.register(callback);
56 51
   }

+ 0
- 5
lib/src/interfaces/ComponentEvents.ts Zobrazit soubor

@@ -22,8 +22,3 @@ export interface SearchBarUpdatedEvent extends ComponentEvent {
22 22
 export interface SearchBarCancelPressedEvent extends ComponentEvent {
23 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 Zobrazit soubor

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

+ 7
- 3
playground/src/screens/PushedScreen.js Zobrazit soubor

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

+ 9
- 5
playground/src/screens/WelcomeScreen.js Zobrazit soubor

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