-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathScrollViewComponentWrapper.mm
66 lines (53 loc) · 1.77 KB
/
ScrollViewComponentWrapper.mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#import "ScrollViewComponentWrapper.h"
#ifdef RCT_NEW_ARCH_ENABLED
#import <React/RCTScrollViewComponentView.h>
#define ReactScrollViewBase RCTScrollViewComponentView
#else
#import <React/RCTScrollView.h>
#define ReactScrollViewBase RCTScrollView
#endif
@implementation ScrollViewComponentWrapper {
__weak ReactScrollViewBase *_scrollViewComponentView;
}
- (instancetype)initWithView:(UIView *)view {
if (![view isKindOfClass:[ReactScrollViewBase class]]) {
return nil;
}
self = [super init];
_scrollViewComponentView = (ReactScrollViewBase *)view;
return self;
}
- (void)setInsetsFromKeyboardHeight:(CGFloat)keyboardHeight
updateOffset:(BOOL)updateOffset {
if (!_scrollViewComponentView) {
return;
}
CGPoint contentOffset = _scrollViewComponentView.scrollView.contentOffset;
UIEdgeInsets currentContentInset =
_scrollViewComponentView.scrollView.contentInset;
UIEdgeInsets newContentInset =
_scrollViewComponentView.scrollView.contentInset;
bool isInverted = [self isInverted];
if (isInverted) {
newContentInset.bottom = keyboardHeight;
} else {
newContentInset.top = keyboardHeight;
}
if (UIEdgeInsetsEqualToEdgeInsets(newContentInset, currentContentInset)) {
return;
}
_scrollViewComponentView.scrollView.contentInset = newContentInset;
_scrollViewComponentView.scrollView.scrollIndicatorInsets = newContentInset;
if (updateOffset) {
contentOffset.y -= isInverted ? 0 : keyboardHeight;
_scrollViewComponentView.scrollView.contentOffset = contentOffset;
}
}
- (bool)isInverted {
// Look into the entry at position 2,2 to check if scaleY is applied
return _scrollViewComponentView.layer.transform.m22 == -1;
}
- (nullable UIView *)view {
return (UIView *)_scrollViewComponentView;
}
@end