Skip to content

UI-LIB scrollview fix for new arch #3775 #3776

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
#import "UIResponder+FirstResponderTemp.h"

#import <WebKit/WebKit.h>
#import <React/RCTScrollView.h>

#import <React/RCTBridge.h>
#import <React/RCTUIManager.h>
#import <React/UIView+React.h>
#import <React/RCTUIManagerUtils.h>
#import <React/RCTSurfaceHostingView.h>

#import <objc/runtime.h>

Expand Down Expand Up @@ -70,7 +71,7 @@ -(instancetype)init

if (self)
{
[self addObserver:self forKeyPath:@"bounds" options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew context:NULL];
[self addObserver:self forKeyPath:@"frame" options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew context:NULL];
_inputViewsMap = [NSMapTable weakToWeakObjectsMapTable];
_deferedInitializeAccessoryViewsCount = 0;

Expand All @@ -93,20 +94,21 @@ -(instancetype)init
return self;
}

-(RCTRootView*)getRootView
-(UIView*)getRootView
{
UIView *view = self;
while (view.superview != nil)
{
view = view.superview;
if ([view isKindOfClass:[RCTRootView class]])
if ([view isKindOfClass:[RCTSurfaceHostingView class]]) {
break;
}
}

if ([view isKindOfClass:[RCTRootView class]])
{
return (RCTRootView*)view;
if ([view isKindOfClass:[RCTSurfaceHostingView class]]) {
return view;
}

return nil;
}

Expand Down Expand Up @@ -169,37 +171,50 @@ -(void)layoutSubviews
[self updateBottomViewFrame];
}

- (UIScrollView*)extractUIScrollView:(UIView*)view
{
for (UIView* subview in view.subviews) {
if ([subview isKindOfClass:[UIScrollView class]]) {
return (UIScrollView*)subview;
}
}

return nil;
}

- (void)initializeAccessoryViewsAndHandleInsets
{
NSArray<UIView*>* allSubviews = [self getBreadthFirstSubviewsForView:[self getRootView]];
NSMutableArray<RCTScrollView*>* rctScrollViewsArray = [NSMutableArray array];

for (UIView* subview in allSubviews)
{
if(_manageScrollView)
{
if(_scrollViewToManage == nil)
{
if(_requiresSameParentToManageScrollView && [subview isKindOfClass:[RCTScrollView class]] && subview.superview == self.superview)
{
_scrollViewToManage = ((RCTScrollView*)subview).scrollView;
}
else if(!_requiresSameParentToManageScrollView && [subview isKindOfClass:[UIScrollView class]])
{
_scrollViewToManage = (UIScrollView*)subview;
if ([NSStringFromClass([subview class]) isEqualToString:@"RCTScrollViewComponentView"]) {
UIScrollView *scrollView = [self extractUIScrollView:subview];

if ([scrollView isKindOfClass:[UIScrollView class]])
{
if(_requiresSameParentToManageScrollView && subview.superview == self.superview)
{
_scrollViewToManage = scrollView;
}
else if(!_requiresSameParentToManageScrollView)
{
_scrollViewToManage = scrollView;
}

if(_scrollViewToManage != nil)
{
_scrollIsInverted = CGAffineTransformEqualToTransform(subview.superview.transform, CGAffineTransformMakeScale(1, -1));
}
}
}

if(_scrollViewToManage != nil)
{
_scrollIsInverted = CGAffineTransformEqualToTransform(_scrollViewToManage.superview.transform, CGAffineTransformMakeScale(1, -1));
}
}

if([subview isKindOfClass:[RCTScrollView class]])
{
[rctScrollViewsArray addObject:(RCTScrollView*)subview];
}
}


if ([subview isKindOfClass:NSClassFromString(@"RCTTextField")])
{
Expand Down Expand Up @@ -247,13 +262,11 @@ - (void)initializeAccessoryViewsAndHandleInsets
}
}

for (RCTScrollView *scrollView in rctScrollViewsArray)
if(_scrollViewToManage != nil)
{
if(scrollView.scrollView == _scrollViewToManage)
if(_scrollViewToManage.delegate == nil)
{
[scrollView removeScrollListener:self];
[scrollView addScrollListener:self];
break;
_scrollViewToManage.delegate = self;
}
}

Expand Down Expand Up @@ -338,12 +351,12 @@ -(void)didMoveToWindow

-(void)dealloc
{
[self removeObserver:self forKeyPath:@"bounds"];
[self removeObserver:self forKeyPath:@"frame"];
}

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

- (void)ObservingInputAccessoryViewTempKeyboardWillDisappear:(ObservingInputAccessoryViewTemp *)ObservingInputAccessoryViewTemp
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"react-native-redash": "^12.0.3",
"semver": "^5.5.0",
"tinycolor2": "^1.4.2",
"uilib-native": "5.0.0-snapshot.7216",
"uilib-native": "5.0.0-snapshot.7240",
"url-parse": "^1.2.0",
"wix-react-native-text-size": "1.0.9"
},
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10938,7 +10938,7 @@ __metadata:
shell-utils: ^1.0.10
tinycolor2: ^1.4.2
typescript: 5.0.4
uilib-native: 5.0.0-snapshot.7216
uilib-native: 5.0.0-snapshot.7240
url-parse: ^1.2.0
wix-react-native-text-size: 1.0.9
peerDependencies:
Expand Down Expand Up @@ -12570,16 +12570,16 @@ __metadata:
languageName: node
linkType: hard

"uilib-native@npm:5.0.0-snapshot.7216":
version: 5.0.0-snapshot.7216
resolution: "uilib-native@npm:5.0.0-snapshot.7216"
"uilib-native@npm:5.0.0-snapshot.7240":
version: 5.0.0-snapshot.7240
resolution: "uilib-native@npm:5.0.0-snapshot.7240"
dependencies:
lodash: ^4.17.21
prop-types: ^15.5.10
peerDependencies:
react: ">=17.0.1"
react-native: ">=0.64.1"
checksum: 3ca207bae3865fc4275393135f5cd4a46c52678100d4308fe1008d0167d8d5ae8bd1cab558b364d7ad60e5c96cb38497cd10b0109e15376c623ef9849cfb3a32
checksum: e18a273800b231479aea3fac4a43c7f2c4a6f74c995f44e7b9ab5642b666d94060ff09a2c0f76cf6e871cbd8fc57baaee92a4879c28e20be3358fbb4fd02dc0f
languageName: node
linkType: hard

Expand Down