Skip to content

Commit

Permalink
fix(fabric): prevent freeze on layout content change during transition (
Browse files Browse the repository at this point in the history
  • Loading branch information
krozniata authored Nov 30, 2024
1 parent 2879d0a commit 421c4ba
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions ios/Fabric/RNCPagerViewComponentView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ @interface RNCPagerViewComponentView () <RCTRNCViewPagerViewProtocol, UIPageView

@implementation RNCPagerViewComponentView {
LayoutMetrics _layoutMetrics;
LayoutMetrics _oldLayoutMetrics;
UIScrollView *scrollView;
BOOL transitioning;
}

// Needed because of this: https://github.com/facebook/react-native/pull/37274
Expand Down Expand Up @@ -111,9 +113,14 @@ - (void)unmountChildComponentView:(UIView<RCTComponentViewProtocol> *)childCompo


-(void)updateLayoutMetrics:(const facebook::react::LayoutMetrics &)layoutMetrics oldLayoutMetrics:(const facebook::react::LayoutMetrics &)oldLayoutMetrics {
[super updateLayoutMetrics:layoutMetrics oldLayoutMetrics:_layoutMetrics];
self.contentView.frame = RCTCGRectFromRect(layoutMetrics.getContentFrame());
_oldLayoutMetrics = oldLayoutMetrics;
_layoutMetrics = layoutMetrics;

if (transitioning) {
return;
}

[super updateLayoutMetrics:layoutMetrics oldLayoutMetrics:_layoutMetrics];
}


Expand Down Expand Up @@ -223,12 +230,15 @@ - (void)setPagerViewControllers:(NSInteger)index
[self enableSwipe];
return;
}


transitioning = YES;

__weak RNCPagerViewComponentView *weakSelf = self;
[_nativePageViewController setViewControllers:@[[_nativeChildrenViewControllers objectAtIndex:index]]
direction:direction
animated:animated
completion:^(BOOL finished) {
self->transitioning = NO;
__strong RNCPagerViewComponentView *strongSelf = weakSelf;
[strongSelf enableSwipe];
if (strongSelf->_eventEmitter != nullptr ) {
Expand All @@ -237,6 +247,7 @@ - (void)setPagerViewControllers:(NSInteger)index
strongEventEmitter.onPageSelected(RNCViewPagerEventEmitter::OnPageSelected{.position = static_cast<double>(position)});
strongSelf->_currentIndex = index;
}
[strongSelf updateLayoutMetrics:strongSelf->_layoutMetrics oldLayoutMetrics:strongSelf->_oldLayoutMetrics];
}];
}

Expand Down

0 comments on commit 421c4ba

Please sign in to comment.