Skip to content

Commit 083661c

Browse files
committed
UI-LIB scrollview fix for new arch
#3775 (#3775)
1 parent 5c60668 commit 083661c

File tree

1 file changed

+45
-32
lines changed

1 file changed

+45
-32
lines changed

lib/ios/reactnativeuilib/keyboardtrackingview/KeyboardTrackingViewTempManager.m

Lines changed: 45 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111
#import "UIResponder+FirstResponderTemp.h"
1212

1313
#import <WebKit/WebKit.h>
14-
#import <React/RCTScrollView.h>
14+
1515
#import <React/RCTBridge.h>
1616
#import <React/RCTUIManager.h>
1717
#import <React/UIView+React.h>
1818
#import <React/RCTUIManagerUtils.h>
19+
#import <React/RCTSurfaceHostingView.h>
1920

2021
#import <objc/runtime.h>
2122

@@ -70,7 +71,7 @@ -(instancetype)init
7071

7172
if (self)
7273
{
73-
[self addObserver:self forKeyPath:@"bounds" options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew context:NULL];
74+
[self addObserver:self forKeyPath:@"frame" options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew context:NULL];
7475
_inputViewsMap = [NSMapTable weakToWeakObjectsMapTable];
7576
_deferedInitializeAccessoryViewsCount = 0;
7677

@@ -93,20 +94,21 @@ -(instancetype)init
9394
return self;
9495
}
9596

96-
-(RCTRootView*)getRootView
97+
-(UIView*)getRootView
9798
{
9899
UIView *view = self;
99100
while (view.superview != nil)
100101
{
101102
view = view.superview;
102-
if ([view isKindOfClass:[RCTRootView class]])
103+
if ([view isKindOfClass:[RCTSurfaceHostingView class]]) {
103104
break;
105+
}
104106
}
105107

106-
if ([view isKindOfClass:[RCTRootView class]])
107-
{
108-
return (RCTRootView*)view;
108+
if ([view isKindOfClass:[RCTSurfaceHostingView class]]) {
109+
return view;
109110
}
111+
110112
return nil;
111113
}
112114

@@ -169,37 +171,50 @@ -(void)layoutSubviews
169171
[self updateBottomViewFrame];
170172
}
171173

174+
- (UIScrollView*)extractUIScrollView:(UIView*)view
175+
{
176+
for (UIView* subview in view.subviews) {
177+
if ([subview isKindOfClass:[UIScrollView class]]) {
178+
return (UIScrollView*)subview;
179+
}
180+
}
181+
182+
return nil;
183+
}
184+
172185
- (void)initializeAccessoryViewsAndHandleInsets
173186
{
174187
NSArray<UIView*>* allSubviews = [self getBreadthFirstSubviewsForView:[self getRootView]];
175-
NSMutableArray<RCTScrollView*>* rctScrollViewsArray = [NSMutableArray array];
176188

177189
for (UIView* subview in allSubviews)
178190
{
179191
if(_manageScrollView)
180192
{
181193
if(_scrollViewToManage == nil)
182194
{
183-
if(_requiresSameParentToManageScrollView && [subview isKindOfClass:[RCTScrollView class]] && subview.superview == self.superview)
184-
{
185-
_scrollViewToManage = ((RCTScrollView*)subview).scrollView;
186-
}
187-
else if(!_requiresSameParentToManageScrollView && [subview isKindOfClass:[UIScrollView class]])
188-
{
189-
_scrollViewToManage = (UIScrollView*)subview;
195+
if ([NSStringFromClass([subview class]) isEqualToString:@"RCTScrollViewComponentView"]) {
196+
UIScrollView *scrollView = [self extractUIScrollView:subview];
197+
198+
if ([scrollView isKindOfClass:[UIScrollView class]])
199+
{
200+
if(_requiresSameParentToManageScrollView && subview.superview == self.superview)
201+
{
202+
_scrollViewToManage = scrollView;
203+
}
204+
else if(!_requiresSameParentToManageScrollView)
205+
{
206+
_scrollViewToManage = scrollView;
207+
}
208+
209+
if(_scrollViewToManage != nil)
210+
{
211+
_scrollIsInverted = CGAffineTransformEqualToTransform(_scrollViewToManage.superview.transform, CGAffineTransformMakeScale(1, -1));
212+
}
213+
}
190214
}
191-
192-
if(_scrollViewToManage != nil)
193-
{
194-
_scrollIsInverted = CGAffineTransformEqualToTransform(_scrollViewToManage.superview.transform, CGAffineTransformMakeScale(1, -1));
195-
}
196-
}
197-
198-
if([subview isKindOfClass:[RCTScrollView class]])
199-
{
200-
[rctScrollViewsArray addObject:(RCTScrollView*)subview];
201215
}
202216
}
217+
203218

204219
if ([subview isKindOfClass:NSClassFromString(@"RCTTextField")])
205220
{
@@ -247,13 +262,11 @@ - (void)initializeAccessoryViewsAndHandleInsets
247262
}
248263
}
249264

250-
for (RCTScrollView *scrollView in rctScrollViewsArray)
265+
if(_scrollViewToManage != nil)
251266
{
252-
if(scrollView.scrollView == _scrollViewToManage)
267+
if(_scrollViewToManage.delegate == nil)
253268
{
254-
[scrollView removeScrollListener:self];
255-
[scrollView addScrollListener:self];
256-
break;
269+
_scrollViewToManage.delegate = self;
257270
}
258271
}
259272

@@ -338,12 +351,12 @@ -(void)didMoveToWindow
338351

339352
-(void)dealloc
340353
{
341-
[self removeObserver:self forKeyPath:@"bounds"];
354+
[self removeObserver:self forKeyPath:@"frame"];
342355
}
343356

344357
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context
345358
{
346-
_ObservingInputAccessoryViewTemp.height = self.bounds.size.height;
359+
_ObservingInputAccessoryViewTemp.height = self.frame.size.height;
347360
}
348361

349362
- (void)ObservingInputAccessoryViewTempKeyboardWillDisappear:(ObservingInputAccessoryViewTemp *)ObservingInputAccessoryViewTemp

0 commit comments

Comments
 (0)