1
1
#import " RNCPagerView.h"
2
2
#import < React/RCTLog.h>
3
3
#import < React/RCTViewManager.h>
4
+ #import < React/RCTUIManager.h>
4
5
5
6
#import " UIViewController+CreateExtension.h"
6
7
#import " RCTOnPageScrollEvent.h"
@@ -13,7 +14,7 @@ @interface RNCPagerView () <UIPageViewControllerDataSource, UIPageViewController
13
14
@property (nonatomic , assign ) UIPanGestureRecognizer* panGestureRecognizer;
14
15
15
16
@property (nonatomic , strong ) UIPageViewController *reactPageViewController;
16
- @property (nonatomic , strong ) RCTEventDispatcher * eventDispatcher;
17
+ @property (nonatomic , strong ) id <RCTEventDispatcherProtocol> eventDispatcher;
17
18
18
19
@property (nonatomic , weak ) UIScrollView *scrollView;
19
20
@property (nonatomic , weak ) UIView *currentView;
@@ -30,10 +31,12 @@ - (void)shouldDismissKeyboard:(NSString *)dismissKeyboard;
30
31
31
32
@implementation RNCPagerView {
32
33
uint16_t _coalescingKey;
34
+ __weak RCTBridge * _bridge;
33
35
}
34
36
35
- - (instancetype )initWithEventDispatcher : (RCTEventDispatcher *)eventDispatcher {
37
+ - (instancetype )initWithBridge : (RCTBridge *)bridge {
36
38
if (self = [super init ]) {
39
+ _bridge = bridge;
37
40
_scrollEnabled = YES ;
38
41
_pageMargin = 0 ;
39
42
_lastReportedIndex = -1 ;
@@ -44,7 +47,7 @@ - (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher {
44
47
_dismissKeyboard = UIScrollViewKeyboardDismissModeNone;
45
48
#endif
46
49
_coalescingKey = 0 ;
47
- _eventDispatcher = eventDispatcher;
50
+ _eventDispatcher = bridge. eventDispatcher ;
48
51
_cachedControllers = [NSHashTable hashTableWithOptions: NSHashTableStrongMemory ];
49
52
_overdrag = NO ;
50
53
_layoutDirection = @" ltr" ;
@@ -178,7 +181,7 @@ - (void)setReactViewControllers:(NSInteger)index
178
181
uint16_t coalescingKey = _coalescingKey++;
179
182
180
183
if (animated == YES ) {
181
- self. animating = YES ;
184
+ [ self setTransitioning: YES ] ;
182
185
}
183
186
184
187
[self .reactPageViewController setViewControllers: @[controller]
@@ -190,10 +193,8 @@ - (void)setReactViewControllers:(NSInteger)index
190
193
strongSelf.currentView = controller.view ;
191
194
192
195
[strongSelf enableSwipe ];
193
-
194
- if (finished) {
195
- strongSelf.animating = NO ;
196
- }
196
+
197
+ [strongSelf setTransitioning: NO ];
197
198
198
199
if (strongSelf.eventDispatcher ) {
199
200
if (strongSelf.lastReportedIndex != strongSelf.currentIndex ) {
@@ -245,6 +246,11 @@ - (void)enableSwipe {
245
246
self.reactPageViewController .view .userInteractionEnabled = YES ;
246
247
}
247
248
249
+ - (void )setTransitioning : (BOOL )transitioning {
250
+ _transitioning = transitioning;
251
+ [_bridge.uiManager setLocalData: @{@" transitioning" : @(transitioning)} forView: self ];
252
+ }
253
+
248
254
- (void )goTo : (NSInteger )index animated : (BOOL )animated {
249
255
NSInteger numberOfPages = self.reactSubviews .count ;
250
256
@@ -267,7 +273,7 @@ - (void)goTo:(NSInteger)index animated:(BOOL)animated {
267
273
268
274
long diff = labs (index - _currentIndex);
269
275
270
- [self goToViewController: index direction: direction animated: (!self .animating && animated) shouldCallOnPageSelected: YES ];
276
+ [self goToViewController: index direction: direction animated: (!_transitioning && animated) shouldCallOnPageSelected: YES ];
271
277
272
278
if (diff == 0 ) {
273
279
[self goToViewController: index direction: direction animated: NO shouldCallOnPageSelected: YES ];
0 commit comments