@@ -23,10 +23,6 @@ @implementation RNCPagerViewComponentView {
23
23
}
24
24
25
25
- (void )initializeNativePageViewController {
26
- if (_nativePageViewController) {
27
- [_nativePageViewController.view removeFromSuperview ];
28
- _nativePageViewController = nil ;
29
- }
30
26
const auto &viewProps = *std::static_pointer_cast<const RNCViewPagerProps>(_props);
31
27
NSDictionary *options = @{ UIPageViewControllerOptionInterPageSpacingKey: @(viewProps.pageMargin ) };
32
28
UIPageViewControllerNavigationOrientation orientation = UIPageViewControllerNavigationOrientationHorizontal;
@@ -45,7 +41,7 @@ - (void)initializeNativePageViewController {
45
41
_nativePageViewController.dataSource = self;
46
42
_nativePageViewController.delegate = self;
47
43
_nativePageViewController.view .frame = self.frame ;
48
- [ self addSubview: _nativePageViewController.view] ;
44
+ self. contentView = _nativePageViewController.view ;
49
45
50
46
for (UIView *subview in _nativePageViewController.view .subviews ) {
51
47
if ([subview isKindOfClass: UIScrollView.class ]){
@@ -70,12 +66,16 @@ - (instancetype)initWithFrame:(CGRect)frame
70
66
return self;
71
67
}
72
68
73
-
74
-
75
- - (void )layoutSubviews {
69
+ -(void )layoutSubviews {
76
70
[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
+ }
79
79
}
80
80
81
81
@@ -98,18 +98,15 @@ - (void)unmountChildComponentView:(UIView<RCTComponentViewProtocol> *)childCompo
98
98
}
99
99
}
100
100
101
- - (void )finalizeUpdates : (RNComponentViewUpdateMask)updateMask {
102
- [super finalizeUpdates: updateMask];
103
-
104
- if (!_nativePageViewController) {
105
- [self initializeNativePageViewController ];
106
- }
107
- }
108
101
109
- -(void )prepareForRecycle {
102
+ -(void )prepareForRecycle {
110
103
[super prepareForRecycle ];
111
104
112
- [self initializeNativePageViewController ];
105
+ _nativeChildrenViewControllers = [[NSMutableArray alloc ] init ];
106
+ [_nativePageViewController.view removeFromSuperview ];
107
+ _nativePageViewController = nil ;
108
+
109
+ _currentIndex = -1 ;
113
110
}
114
111
115
112
- (void )shouldDismissKeyboard : (RNCViewPagerKeyboardDismissMode)dismissKeyboard {
0 commit comments