From 028ca1d624798390c8289d4e0c943cb2a6d82673 Mon Sep 17 00:00:00 2001 From: enricolazarte-fh <150711895+enricolazarte-fh@users.noreply.github.com> Date: Wed, 12 Mar 2025 16:07:04 -0400 Subject: [PATCH 1/5] Update RNCPagerView.h --- ios/RNCPagerView.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ios/RNCPagerView.h b/ios/RNCPagerView.h index e523d230..18b0149a 100644 --- a/ios/RNCPagerView.h +++ b/ios/RNCPagerView.h @@ -1,14 +1,14 @@ +#import #import #import -#import #import #import "UIView+isHorizontalRtlLayout.h" NS_ASSUME_NONNULL_BEGIN -@interface RNCPagerView: UIView +@interface RNCPagerView: RCTView -- (instancetype)initWithEventDispatcher:(id )eventDispatcher; +- (instancetype)initWithBridge:(RCTBridge *)bridge; @property(nonatomic) NSInteger initialPage; @property(nonatomic) NSInteger lastReportedIndex; @@ -25,7 +25,7 @@ NS_ASSUME_NONNULL_BEGIN @property(nonatomic, copy) RCTDirectEventBlock onPageScrollStateChanged; @property(nonatomic) BOOL overdrag; @property(nonatomic) NSString* layoutDirection; -@property(nonatomic, assign) BOOL animating; +@property(nonatomic, assign) BOOL transitioning; - (void)goTo:(NSInteger)index animated:(BOOL)animated; - (void)shouldScroll:(BOOL)scrollEnabled; From 5547452297b9fcc3da2f73ee1300a10a9a515ed8 Mon Sep 17 00:00:00 2001 From: enricolazarte-fh <150711895+enricolazarte-fh@users.noreply.github.com> Date: Wed, 12 Mar 2025 16:10:56 -0400 Subject: [PATCH 2/5] Update RNCPagerView.m --- ios/RNCPagerView.m | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/ios/RNCPagerView.m b/ios/RNCPagerView.m index 507b45d8..27756bfd 100644 --- a/ios/RNCPagerView.m +++ b/ios/RNCPagerView.m @@ -1,6 +1,7 @@ #import "RNCPagerView.h" #import #import +#import #import "UIViewController+CreateExtension.h" #import "RCTOnPageScrollEvent.h" @@ -13,7 +14,7 @@ @interface RNCPagerView () eventDispatcher; @property(nonatomic, weak) UIScrollView *scrollView; @property(nonatomic, weak) UIView *currentView; @@ -30,10 +31,12 @@ - (void)shouldDismissKeyboard:(NSString *)dismissKeyboard; @implementation RNCPagerView { uint16_t _coalescingKey; + __weak RCTBridge * _bridge; } -- (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher { +- (instancetype)initWithBridge:(RCTBridge *)bridge { if (self = [super init]) { + _bridge = bridge; _scrollEnabled = YES; _pageMargin = 0; _lastReportedIndex = -1; @@ -44,7 +47,7 @@ - (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher { _dismissKeyboard = UIScrollViewKeyboardDismissModeNone; #endif _coalescingKey = 0; - _eventDispatcher = eventDispatcher; + _eventDispatcher = bridge.eventDispatcher; _cachedControllers = [NSHashTable hashTableWithOptions:NSHashTableStrongMemory]; _overdrag = NO; _layoutDirection = @"ltr"; @@ -178,7 +181,7 @@ - (void)setReactViewControllers:(NSInteger)index uint16_t coalescingKey = _coalescingKey++; if (animated == YES) { - self.animating = YES; + [self setTransitioning:YES]; } [self.reactPageViewController setViewControllers:@[controller] @@ -190,6 +193,8 @@ - (void)setReactViewControllers:(NSInteger)index strongSelf.currentView = controller.view; [strongSelf enableSwipe]; + + [strongSelf setTransitioning:NO]; if (finished) { strongSelf.animating = NO; @@ -241,6 +246,11 @@ - (void)disableSwipe { self.reactPageViewController.view.userInteractionEnabled = NO; } +- (void)setTransitioning:(BOOL)transitioning { + _transitioning = transitioning; + [_bridge.uiManager setLocalData:@{@"transitioning": @(transitioning)} forView:self]; +} + - (void)enableSwipe { self.reactPageViewController.view.userInteractionEnabled = YES; } @@ -267,7 +277,7 @@ - (void)goTo:(NSInteger)index animated:(BOOL)animated { long diff = labs(index - _currentIndex); - [self goToViewController:index direction:direction animated:(!self.animating && animated) shouldCallOnPageSelected: YES]; + [self goToViewController:index direction:direction animated:(!_transitioning && animated) shouldCallOnPageSelected: YES]; if (diff == 0) { [self goToViewController:index direction:direction animated:NO shouldCallOnPageSelected:YES]; From 68fff697d1486eeb3e084c5ca6631b774fad33ad Mon Sep 17 00:00:00 2001 From: enricolazarte-fh <150711895+enricolazarte-fh@users.noreply.github.com> Date: Wed, 12 Mar 2025 16:11:53 -0400 Subject: [PATCH 3/5] Update RNCPagerViewManager.m --- ios/RNCPagerViewManager.m | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/ios/RNCPagerViewManager.m b/ios/RNCPagerViewManager.m index 90404371..daef013e 100644 --- a/ios/RNCPagerViewManager.m +++ b/ios/RNCPagerViewManager.m @@ -1,6 +1,6 @@ #import "RNCPagerViewManager.h" - +#import "RNCPagerViewShadowView.h" @implementation RNCPagerViewManager #pragma mark - RTC @@ -30,7 +30,7 @@ - (void) goToPage RCTLogError(@"Cannot find RNCPagerView with tag #%@", reactTag); return; } - if (!animated || !view.animating) { + if (!animated || !view.transitioning) { [view goTo:index.integerValue animated:animated]; } }]; @@ -80,7 +80,12 @@ - (void) changeScrollEnabled - (UIView *)view { - return [[RNCPagerView alloc] initWithEventDispatcher:self.bridge.eventDispatcher]; + return [[RNCPagerView alloc] initWithBridge: self.bridge]; +} + + +- (RCTShadowView *)shadowView { + return [RNCPagerViewShadowView new]; } @end From 0f04dadda3aaf61b65f8188e2b70de972ad3c053 Mon Sep 17 00:00:00 2001 From: enricolazarte-fh <150711895+enricolazarte-fh@users.noreply.github.com> Date: Wed, 12 Mar 2025 16:12:27 -0400 Subject: [PATCH 4/5] Create RNCPagerViewShadowView.h --- ios/RNCPagerViewShadowView.h | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 ios/RNCPagerViewShadowView.h diff --git a/ios/RNCPagerViewShadowView.h b/ios/RNCPagerViewShadowView.h new file mode 100644 index 00000000..74ab3bcf --- /dev/null +++ b/ios/RNCPagerViewShadowView.h @@ -0,0 +1,5 @@ +#import + +@interface RNCPagerViewShadowView : RCTShadowView + +@end From 591d2ee390390554870c6ed855af5dd8aa9241de Mon Sep 17 00:00:00 2001 From: enricolazarte-fh <150711895+enricolazarte-fh@users.noreply.github.com> Date: Wed, 12 Mar 2025 16:12:53 -0400 Subject: [PATCH 5/5] Create RNCPagerViewShadowView.m --- ios/RNCPagerViewShadowView.m | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 ios/RNCPagerViewShadowView.m diff --git a/ios/RNCPagerViewShadowView.m b/ios/RNCPagerViewShadowView.m new file mode 100644 index 00000000..8b055a73 --- /dev/null +++ b/ios/RNCPagerViewShadowView.m @@ -0,0 +1,24 @@ +#import "RNCPagerViewShadowView.h" + +@implementation RNCPagerViewShadowView { + BOOL _transitioning; +} + +- (void)layoutWithMetrics:(RCTLayoutMetrics)layoutMetrics + layoutContext:(RCTLayoutContext)layoutContext { + // Prevent layout updates during a transition, as they cause the `setViewControllers` + // method to skip calling its completion block. + if (_transitioning) { + return; + } + + [super layoutWithMetrics:layoutMetrics layoutContext:layoutContext]; +} + +- (void)setLocalData:(NSDictionary *)localData { + [super setLocalData:localData]; + + _transitioning = [localData[@"transitioning"] boolValue]; +} + +@end