@sdcx/bottom-sheet 0.4.0 → 0.6.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
CHANGED
|
@@ -4,6 +4,10 @@
|
|
|
4
4
|
|
|
5
5
|
它位于屏幕底部,可拖拽,支持嵌套滚动,可以和可滚动视图(`FlatList`, `FlashList`, `WebView` 等等)一起使用。
|
|
6
6
|
|
|
7
|
+
| | |
|
|
8
|
+
| --------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- |
|
|
9
|
+
| <img src="https://todoit.oss-cn-shanghai.aliyuncs.com/assets/troika-2023-04-27-14-47-39.gif" width="320"> | <img src="https://todoit.oss-cn-shanghai.aliyuncs.com/assets/troika-2023-04-27-14-48-40.gif" width="320"> |
|
|
10
|
+
|
|
7
11
|
## Installation
|
|
8
12
|
|
|
9
13
|
```bash
|
|
@@ -51,30 +55,45 @@ const App = () => {
|
|
|
51
55
|
|
|
52
56
|
### 属性
|
|
53
57
|
|
|
54
|
-
`peekHeight
|
|
55
|
-
|
|
56
|
-
`fitToContents` 是指内层的高度是否适应内容。默认情况下,内层的高度是和外层一样的。
|
|
58
|
+
- `peekHeight`, 是指 BottomSheet 收起时,在屏幕上露出的高度,默认是 200。
|
|
57
59
|
|
|
58
|
-
|
|
60
|
+
- `state`, 是指 BottomSheet 的状态,有三种状态:
|
|
59
61
|
|
|
60
|
-
`
|
|
62
|
+
- `'collapsed'`,收起状态,此时 BottomSheet 的高度为 `peekHeight`。
|
|
61
63
|
|
|
62
|
-
- `
|
|
64
|
+
- `'expanded'`,展开状态,此时 BottomSheet 的高度为父组件的高度或内容的高度,参考 `fitToContents` 属性。
|
|
63
65
|
|
|
64
|
-
- `
|
|
66
|
+
- `'hidden'`,隐藏状态,此时 BottomSheet 的高度为 0。
|
|
65
67
|
|
|
66
|
-
- `
|
|
68
|
+
- `fitToContents`,是指 BottomSheet 在展开时,是否适应内容的高度,默认是 `false`。当和可滚动列表,譬如 ScrollView 一起使用时,请保持默认值。
|
|
67
69
|
|
|
68
70
|
### 回调
|
|
69
71
|
|
|
70
|
-
`onStateChanged
|
|
72
|
+
- `onStateChanged`, 是指 BottomSheet 状态变化时的回调,它和 `state` 属性是一对,用来实现受控模式。
|
|
73
|
+
|
|
74
|
+
```tsx
|
|
75
|
+
export type BottomSheetState = 'collapsed' | 'expanded' | 'hidden'
|
|
71
76
|
|
|
72
|
-
|
|
77
|
+
export interface StateChangedEventData {
|
|
78
|
+
state: BottomSheetState
|
|
79
|
+
}
|
|
73
80
|
|
|
74
|
-
|
|
81
|
+
interface NativeBottomSheetProps extends ViewProps {
|
|
82
|
+
onStateChanged?: (event: NativeSyntheticEvent<StateChangedEventData>) => void
|
|
83
|
+
}
|
|
84
|
+
```
|
|
75
85
|
|
|
76
|
-
- `
|
|
86
|
+
- `onSlide`, 是指 BottomSheet 滑动时的回调,可以用它来实现一些动画效果。
|
|
77
87
|
|
|
78
|
-
|
|
88
|
+
```tsx
|
|
89
|
+
export interface OffsetChangedEventData {
|
|
90
|
+
progress: number // 是指 `BottomSheet` 当前的位置在 `collapsedOffset` 和 `expandedOffset` 之间的比例,它的值在 0 和 1 之间。
|
|
91
|
+
offset: number // 是指 `BottomSheet` 当前的位置,它的值在 `collapsedOffset` 和 `expandedOffset` 之间。
|
|
92
|
+
expandedOffset: number // 是指 `BottomSheet` 完全展开时,内层顶部距离外层顶部的距离,通常是 0。但如果设置了 `fitToContents` 属性,则可能大于 0。
|
|
93
|
+
collapsedOffset: number // 是指 `BottomSheet` 完全收起时,内层顶部距离外层顶部的距离。可以看到,它的值等于外层的高度减去 `peekHeight`。
|
|
94
|
+
}
|
|
79
95
|
|
|
80
|
-
|
|
96
|
+
interface NativeBottomSheetProps extends ViewProps {
|
|
97
|
+
onSlide?: (event: NativeSyntheticEvent<OffsetChangedEventData>) => void
|
|
98
|
+
}
|
|
99
|
+
```
|
|
@@ -170,7 +170,7 @@ public class BottomSheet extends ReactViewGroup implements NestedScrollingParent
|
|
|
170
170
|
@VisibleForTesting
|
|
171
171
|
View findScrollingChild(View view) {
|
|
172
172
|
if (ViewCompat.isNestedScrollingEnabled(view)) {
|
|
173
|
-
if (!view.canScrollHorizontally(1) && !view.canScrollHorizontally(-1)) {
|
|
173
|
+
if (!view.canScrollHorizontally(1) && !view.canScrollHorizontally(-1) && (view.canScrollVertically(-1) || view.canScrollVertically(1))) {
|
|
174
174
|
return view;
|
|
175
175
|
}
|
|
176
176
|
}
|
|
@@ -187,6 +187,7 @@ public class BottomSheet extends ReactViewGroup implements NestedScrollingParent
|
|
|
187
187
|
}
|
|
188
188
|
}
|
|
189
189
|
}
|
|
190
|
+
|
|
190
191
|
return null;
|
|
191
192
|
}
|
|
192
193
|
|
package/lib/index.d.ts
CHANGED
package/package.json
CHANGED
package/src/index.tsx
CHANGED