@sdcx/bottom-sheet 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/ios/BottomSheet/RNBottomSheet.m +36 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# BottomSheet
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[BottomSheet](https://github.com/sdcxtech/react-native-troika/blob/master/packages/bottom-sheet/README.md) 是一个类似于 Android 原生的 [BottomSheetBehavior](https://developer.android.com/reference/com/google/android/material/bottomsheet/BottomSheetBehavior) 组件,我们在 API 设计上也尽量和 Android 原生保持一致。
|
|
4
4
|
|
|
5
5
|
它位于屏幕底部,可拖拽,支持嵌套滚动,可以和可滚动视图(`FlatList`, `FlashList`, `WebView` 等等)一起使用。
|
|
6
6
|
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
#import "RNBottomSheet.h"
|
|
2
2
|
|
|
3
3
|
#import <React/UIView+React.h>
|
|
4
|
+
#import <React/RCTRootContentView.h>
|
|
5
|
+
#import <React/RCTTouchHandler.h>
|
|
4
6
|
#import <React/RCTLog.h>
|
|
5
7
|
|
|
6
8
|
@interface RNBottomSheet () <UIGestureRecognizerDelegate>
|
|
@@ -18,7 +20,9 @@
|
|
|
18
20
|
|
|
19
21
|
@end
|
|
20
22
|
|
|
21
|
-
@implementation RNBottomSheet
|
|
23
|
+
@implementation RNBottomSheet {
|
|
24
|
+
__weak RCTRootContentView *_cachedRootView;
|
|
25
|
+
}
|
|
22
26
|
|
|
23
27
|
- (instancetype)init {
|
|
24
28
|
if (self = [super init]) {
|
|
@@ -37,6 +41,17 @@
|
|
|
37
41
|
return NO;
|
|
38
42
|
}
|
|
39
43
|
|
|
44
|
+
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
|
|
45
|
+
if (gestureRecognizer == self.panGestureRecognizer) {
|
|
46
|
+
if ([super gestureRecognizerShouldBegin:gestureRecognizer]) {
|
|
47
|
+
[self cancelRootViewTouches];
|
|
48
|
+
return YES;
|
|
49
|
+
}
|
|
50
|
+
return NO;
|
|
51
|
+
}
|
|
52
|
+
return [super gestureRecognizerShouldBegin:gestureRecognizer];
|
|
53
|
+
}
|
|
54
|
+
|
|
40
55
|
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
|
|
41
56
|
if (gestureRecognizer != self.panGestureRecognizer) {
|
|
42
57
|
return YES;
|
|
@@ -82,6 +97,26 @@
|
|
|
82
97
|
}
|
|
83
98
|
}
|
|
84
99
|
|
|
100
|
+
- (void)didMoveToWindow {
|
|
101
|
+
[super didMoveToWindow];
|
|
102
|
+
if (self.window) {
|
|
103
|
+
[self _cacheRootView];
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
- (void)_cacheRootView {
|
|
108
|
+
UIView *rootView = self;
|
|
109
|
+
while (rootView.superview && ![rootView isReactRootView]) {
|
|
110
|
+
rootView = rootView.superview;
|
|
111
|
+
}
|
|
112
|
+
_cachedRootView = rootView;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
- (void)cancelRootViewTouches {
|
|
116
|
+
RCTRootContentView *rootView = (RCTRootContentView *)_cachedRootView;
|
|
117
|
+
[rootView.touchHandler cancel];
|
|
118
|
+
}
|
|
119
|
+
|
|
85
120
|
- (BOOL)isHorizontal:(UIScrollView *)scrollView {
|
|
86
121
|
return scrollView.contentSize.width > self.frame.size.width;
|
|
87
122
|
}
|