@@ -43,17 +43,17 @@ - (instancetype)initWithEventDispatcher:(id<RCTEventDispatcherProtocol>)eventDis
43
43
- (void )didMoveToWindow {
44
44
// Disable scroll view pan gesture for navigation controller screen edge go back gesture
45
45
if (self.reactViewController .navigationController != nil && self.reactViewController .navigationController .interactivePopGestureRecognizer != nil ) {
46
- [self .scrollView.panGestureRecognizer requireGestureRecognizerToFail: self .reactViewController.navigationController.interactivePopGestureRecognizer];
47
- }
46
+ [self .scrollView.panGestureRecognizer requireGestureRecognizerToFail: self .reactViewController.navigationController.interactivePopGestureRecognizer];
47
+ }
48
48
}
49
49
50
- - (void )layoutSubviews {
51
- [super layoutSubviews ];
52
- [self calculateContentSize ];
50
+ - (void )didUpdateReactSubviews {
51
+ [self updateContentSizeIfNeeded ];
53
52
}
54
53
55
- - (void )didUpdateReactSubviews {
56
- [self calculateContentSize ];
54
+ - (void )reactSetFrame : (CGRect)frame {
55
+ [super reactSetFrame: frame];
56
+ [self updateContentSizeIfNeeded ];
57
57
}
58
58
59
59
-(void ) insertReactSubview : (UIView *)subview atIndex : (NSInteger )atIndex {
@@ -104,29 +104,23 @@ - (void)shouldDismissKeyboard:(NSString *)dismissKeyboard {
104
104
105
105
#pragma mark - Internal methods
106
106
107
- - (void ) calculateContentSize {
108
- UIView *initialView = self.containerView .subviews .firstObject ;
109
- if (!initialView) {
110
- return ;
111
- }
112
-
113
- CGFloat totalSubviewsWidth = initialView.frame .size .width * self.containerView .subviews .count ;
114
- CGFloat totalSubviewsHeight = initialView.frame .size .height * self.containerView .subviews .count ;
115
-
116
-
117
- if ([self isHorizontal ]) {
118
- _scrollView.contentSize = CGSizeMake (totalSubviewsWidth, 0 );
119
- _containerView.frame = CGRectMake (0 , 0 , totalSubviewsWidth, initialView.bounds .size .height );
120
- } else {
121
- _scrollView.contentSize = CGSizeMake (0 , totalSubviewsHeight);
122
- _containerView.frame = CGRectMake (0 , 0 , initialView.bounds .size .width , totalSubviewsHeight);
123
- }
124
-
125
- _scrollView.frame = self.bounds ;
126
- [self .scrollView layoutIfNeeded ];
127
-
128
- if (self.initialPage != 0 ) {
129
- [self goTo: self .initialPage animated: false ];
107
+ - (CGSize)contentSize
108
+ {
109
+ UIView *initialView = _containerView.subviews .firstObject ;
110
+ CGFloat subviewsCount = _containerView.subviews .count ;
111
+ return CGSizeMake (initialView.bounds .size .width * subviewsCount, initialView.bounds .size .height * subviewsCount);
112
+ }
113
+
114
+ - (void )updateContentSizeIfNeeded
115
+ {
116
+ CGSize contentSize = self.contentSize ;
117
+ if (!CGSizeEqualToSize (_scrollView.contentSize , contentSize)){
118
+ _scrollView.contentSize = [self isHorizontal ] ? CGSizeMake (contentSize.width , 0 ) : CGSizeMake (0 , contentSize.height );
119
+ _containerView.frame = CGRectMake (0 , 0 , contentSize.width , contentSize.height );
120
+
121
+ if (self.initialPage != 0 ) {
122
+ [self goTo: self .initialPage animated: false ];
123
+ }
130
124
}
131
125
}
132
126
@@ -140,7 +134,7 @@ - (void)enableSwipe {
140
134
141
135
- (void )goTo : (NSInteger )index animated : (BOOL )animated {
142
136
CGPoint targetOffset = [self isHorizontal ] ? CGPointMake (_scrollView.frame .size .width * index, 0 ) : CGPointMake (0 , _scrollView.frame .size .height * index);
143
-
137
+
144
138
if (animated) {
145
139
self.animating = true ;
146
140
}
0 commit comments