Skip to content

Commit 0abef1f

Browse files
authored
fix(iOS): fix pager view height issue (#624)
1 parent 2779933 commit 0abef1f

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

ios/Fabric/RNCPagerViewComponentView.mm

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ @implementation RNCPagerViewComponentView {
2323
}
2424

2525
- (void)initializeNativePageViewController {
26-
if (_nativePageViewController) {
27-
[_nativePageViewController.view removeFromSuperview];
28-
_nativePageViewController = nil;
29-
}
3026
const auto &viewProps = *std::static_pointer_cast<const RNCViewPagerProps>(_props);
3127
NSDictionary *options = @{ UIPageViewControllerOptionInterPageSpacingKey: @(viewProps.pageMargin) };
3228
UIPageViewControllerNavigationOrientation orientation = UIPageViewControllerNavigationOrientationHorizontal;
@@ -45,7 +41,7 @@ - (void)initializeNativePageViewController {
4541
_nativePageViewController.dataSource = self;
4642
_nativePageViewController.delegate = self;
4743
_nativePageViewController.view.frame = self.frame;
48-
[self addSubview:_nativePageViewController.view];
44+
self.contentView = _nativePageViewController.view;
4945

5046
for (UIView *subview in _nativePageViewController.view.subviews) {
5147
if([subview isKindOfClass:UIScrollView.class]){
@@ -70,12 +66,16 @@ - (instancetype)initWithFrame:(CGRect)frame
7066
return self;
7167
}
7268

73-
74-
75-
- (void)layoutSubviews {
69+
-(void)layoutSubviews {
7670
[super layoutSubviews];
77-
//Workaround to fix incorrect frame issue
78-
[self goTo:_currentIndex animated:NO];
71+
72+
[_nativePageViewController setViewControllers:@[[_nativeChildrenViewControllers objectAtIndex:_currentIndex]] direction: [self isLtrLayout] ? UIPageViewControllerNavigationDirectionForward : UIPageViewControllerNavigationDirectionReverse animated:NO completion:nil];
73+
}
74+
75+
- (void)willMoveToSuperview:(UIView *)newSuperview {
76+
if (newSuperview != nil) {
77+
[self initializeNativePageViewController];
78+
}
7979
}
8080

8181

@@ -98,18 +98,15 @@ - (void)unmountChildComponentView:(UIView<RCTComponentViewProtocol> *)childCompo
9898
}
9999
}
100100

101-
- (void)finalizeUpdates:(RNComponentViewUpdateMask)updateMask {
102-
[super finalizeUpdates:updateMask];
103-
104-
if (!_nativePageViewController) {
105-
[self initializeNativePageViewController];
106-
}
107-
}
108101

109-
-(void)prepareForRecycle{
102+
-(void)prepareForRecycle {
110103
[super prepareForRecycle];
111104

112-
[self initializeNativePageViewController];
105+
_nativeChildrenViewControllers = [[NSMutableArray alloc] init];
106+
[_nativePageViewController.view removeFromSuperview];
107+
_nativePageViewController = nil;
108+
109+
_currentIndex = -1;
113110
}
114111

115112
- (void)shouldDismissKeyboard:(RNCViewPagerKeyboardDismissMode)dismissKeyboard {

0 commit comments

Comments
 (0)