@sdcx/bottom-sheet 0.12.0 → 0.14.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/android/src/main/java/com/reactnative/bottomsheet/BottomSheet.java +13 -0
- package/android/src/main/java/com/reactnative/bottomsheet/BottomSheetManager.java +5 -0
- package/docs/assets/pagerview.gif +0 -0
- package/docs/assets/scrollview.gif +0 -0
- package/docs/assets/struct.png +0 -0
- package/ios/BottomSheet/RNBottomSheet.h +1 -0
- package/ios/BottomSheet/RNBottomSheet.m +26 -10
- package/ios/BottomSheet/RNBottomSheetManager.m +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +2 -2
- package/package.json +2 -1
- package/src/index.tsx +3 -0
|
@@ -55,6 +55,8 @@ public class BottomSheet extends ReactViewGroup implements NestedScrollingParent
|
|
|
55
55
|
|
|
56
56
|
private SettleRunnable settleRunnable = null;
|
|
57
57
|
|
|
58
|
+
private boolean draggable;
|
|
59
|
+
|
|
58
60
|
private int peekHeight;
|
|
59
61
|
|
|
60
62
|
private int expandedOffset;
|
|
@@ -156,6 +158,10 @@ public class BottomSheet extends ReactViewGroup implements NestedScrollingParent
|
|
|
156
158
|
}
|
|
157
159
|
}
|
|
158
160
|
|
|
161
|
+
public void setDraggable(boolean draggable) {
|
|
162
|
+
this.draggable = draggable;
|
|
163
|
+
}
|
|
164
|
+
|
|
159
165
|
public void setState(BottomSheetState state) {
|
|
160
166
|
if (state == this.state) {
|
|
161
167
|
return;
|
|
@@ -211,6 +217,9 @@ public class BottomSheet extends ReactViewGroup implements NestedScrollingParent
|
|
|
211
217
|
}
|
|
212
218
|
|
|
213
219
|
private boolean shouldInterceptTouchEvent(MotionEvent event) {
|
|
220
|
+
if (!draggable) {
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
214
223
|
int action = event.getActionMasked();
|
|
215
224
|
// Record the velocity
|
|
216
225
|
if (action == MotionEvent.ACTION_DOWN) {
|
|
@@ -270,6 +279,10 @@ public class BottomSheet extends ReactViewGroup implements NestedScrollingParent
|
|
|
270
279
|
|
|
271
280
|
@Override
|
|
272
281
|
public boolean onTouchEvent(MotionEvent event) {
|
|
282
|
+
if (!draggable) {
|
|
283
|
+
return false;
|
|
284
|
+
}
|
|
285
|
+
|
|
273
286
|
int action = event.getActionMasked();
|
|
274
287
|
if (state == DRAGGING && action == MotionEvent.ACTION_DOWN) {
|
|
275
288
|
return true;
|
|
@@ -42,4 +42,9 @@ public class BottomSheetManager extends ViewGroupManager<BottomSheet> {
|
|
|
42
42
|
view.setState(BottomSheetState.valueOf(state.toUpperCase()));
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
@ReactProp(name = "draggable")
|
|
46
|
+
public void setDraggable(BottomSheet view, boolean draggable) {
|
|
47
|
+
view.setDraggable(draggable);
|
|
48
|
+
}
|
|
49
|
+
|
|
45
50
|
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -12,6 +12,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
12
12
|
@property(nonatomic, copy) RCTDirectEventBlock onStateChanged;
|
|
13
13
|
@property(nonatomic, assign) CGFloat peekHeight;
|
|
14
14
|
@property(nonatomic, assign) RNBottomSheetState state;
|
|
15
|
+
@property(nonatomic, assign) BOOL draggable;
|
|
15
16
|
|
|
16
17
|
- (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher;
|
|
17
18
|
|
|
@@ -171,6 +171,10 @@
|
|
|
171
171
|
}
|
|
172
172
|
|
|
173
173
|
- (void)handlePan:(UIPanGestureRecognizer *)pan {
|
|
174
|
+
if (!self.draggable) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
|
|
174
178
|
CGFloat translationY = [pan translationInView:self.contentView].y;
|
|
175
179
|
[pan setTranslation:CGPointZero inView:self.contentView];
|
|
176
180
|
|
|
@@ -292,6 +296,11 @@
|
|
|
292
296
|
return;
|
|
293
297
|
}
|
|
294
298
|
|
|
299
|
+
if (self.state == RNBottomSheetStateSettling) {
|
|
300
|
+
[self.layer removeAllAnimations];
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
|
|
295
304
|
if (CGRectEqualToRect(self.contentView.frame, CGRectZero)) {
|
|
296
305
|
[self setStateInternal:state];
|
|
297
306
|
return;
|
|
@@ -302,21 +311,21 @@
|
|
|
302
311
|
|
|
303
312
|
- (void)settleToState:(RNBottomSheetState)state withFling:(BOOL)fling {
|
|
304
313
|
if (state == RNBottomSheetStateCollapsed) {
|
|
305
|
-
[self
|
|
314
|
+
[self settleToState:state top:self.maxY withFling:fling];
|
|
306
315
|
} else if (state == RNBottomSheetStateExpanded) {
|
|
307
|
-
[self
|
|
316
|
+
[self settleToState:state top:self.minY withFling:fling];
|
|
308
317
|
} else if (state == RNBottomSheetStateHidden) {
|
|
309
|
-
[self
|
|
318
|
+
[self settleToState:state top:self.frame.size.height withFling:fling];
|
|
310
319
|
}
|
|
311
320
|
}
|
|
312
321
|
|
|
313
|
-
- (void)
|
|
322
|
+
- (void)settleToState:(RNBottomSheetState)state top:(CGFloat)top withFling:(BOOL)fling {
|
|
314
323
|
self.target.pagingEnabled = YES;
|
|
315
324
|
[self setStateInternal:RNBottomSheetStateSettling];
|
|
316
325
|
[self startWatchBottomSheetTransition];
|
|
317
326
|
[self.layer removeAllAnimations];
|
|
318
327
|
// CGFloat duration = fmin(fabs(self.contentView.frame.origin.y - top) / (self.maxY - self.minY) * 0.3, 0.3);
|
|
319
|
-
[UIView animateWithDuration:fling ? 0.5 : 0.25 delay:0 usingSpringWithDamping:1 initialSpringVelocity:1 options:
|
|
328
|
+
[UIView animateWithDuration:fling ? 0.5 : 0.25 delay:0 usingSpringWithDamping:1 initialSpringVelocity:1 options:UIViewAnimationOptionTransitionNone animations:^{
|
|
320
329
|
self.contentView.frame = CGRectOffset(self.contentView.frame, 0, top - self.contentView.frame.origin.y);
|
|
321
330
|
} completion:^(BOOL finished) {
|
|
322
331
|
self.target.pagingEnabled = NO;
|
|
@@ -331,6 +340,18 @@
|
|
|
331
340
|
}
|
|
332
341
|
_state = state;
|
|
333
342
|
|
|
343
|
+
if (state == RNBottomSheetStateExpanded) {
|
|
344
|
+
[self dispatchOnSlide:self.minY];
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
if (state == RNBottomSheetStateHidden) {
|
|
348
|
+
[self dispatchOnSlide:self.frame.size.height];
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
if (state == RNBottomSheetStateCollapsed) {
|
|
352
|
+
[self dispatchOnSlide:self.maxY];
|
|
353
|
+
}
|
|
354
|
+
|
|
334
355
|
if (state == RNBottomSheetStateCollapsed || state == RNBottomSheetStateExpanded || state == RNBottomSheetStateHidden) {
|
|
335
356
|
[self.eventDispatcher sendEvent:[[RNBottomSheetStateChangedEvent alloc] initWithViewTag:self.reactTag state:state]];
|
|
336
357
|
}
|
|
@@ -352,11 +373,6 @@
|
|
|
352
373
|
}
|
|
353
374
|
|
|
354
375
|
- (void)stopWatchBottomSheetTransition {
|
|
355
|
-
if (self.state == RNBottomSheetStateCollapsed) {
|
|
356
|
-
[self dispatchOnSlide:self.maxY];
|
|
357
|
-
} else if (self.state == RNBottomSheetStateExpanded) {
|
|
358
|
-
[self dispatchOnSlide:self.minY];
|
|
359
|
-
}
|
|
360
376
|
if(_displayLink){
|
|
361
377
|
[_displayLink invalidate];
|
|
362
378
|
_displayLink = nil;
|
|
@@ -15,6 +15,7 @@ RCT_EXPORT_MODULE(BottomSheet)
|
|
|
15
15
|
RCT_EXPORT_VIEW_PROPERTY(onSlide, RCTDirectEventBlock)
|
|
16
16
|
RCT_EXPORT_VIEW_PROPERTY(onStateChanged, RCTDirectEventBlock)
|
|
17
17
|
RCT_EXPORT_VIEW_PROPERTY(peekHeight, CGFloat)
|
|
18
|
+
RCT_EXPORT_VIEW_PROPERTY(draggable, BOOL)
|
|
18
19
|
|
|
19
20
|
RCT_CUSTOM_VIEW_PROPERTY(state, NSString, RNBottomSheet) {
|
|
20
21
|
view.state = RNBottomSheetStateFromString([RCTConvert NSString:json]);
|
package/lib/index.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ interface NativeBottomSheetProps extends ViewProps {
|
|
|
14
14
|
onSlide?: (event: NativeSyntheticEvent<OffsetChangedEventData>) => void;
|
|
15
15
|
onStateChanged?: (event: NativeSyntheticEvent<StateChangedEventData>) => void;
|
|
16
16
|
peekHeight?: number;
|
|
17
|
+
draggable?: boolean;
|
|
17
18
|
state?: BottomSheetState;
|
|
18
19
|
contentContainerStyle?: ViewProps['style'];
|
|
19
20
|
}
|
package/lib/index.js
CHANGED
|
@@ -3,9 +3,9 @@ import { requireNativeComponent, StyleSheet, View } from 'react-native';
|
|
|
3
3
|
import splitLayoutProps from './splitLayoutProps';
|
|
4
4
|
const NativeBottomSheet = requireNativeComponent('BottomSheet');
|
|
5
5
|
const BottomSheet = React.forwardRef((props, ref) => {
|
|
6
|
-
const { style, contentContainerStyle, children, peekHeight = 200, state = 'collapsed', fitToContents, ...rest } = props;
|
|
6
|
+
const { style, contentContainerStyle, children, peekHeight = 200, draggable = true, state = 'collapsed', fitToContents, ...rest } = props;
|
|
7
7
|
const { outer, inner } = splitLayoutProps(StyleSheet.flatten(style));
|
|
8
|
-
return (<NativeBottomSheet style={[StyleSheet.absoluteFill, outer]} peekHeight={peekHeight} state={state} {...rest} ref={ref}>
|
|
8
|
+
return (<NativeBottomSheet style={[StyleSheet.absoluteFill, outer]} peekHeight={peekHeight} draggable={draggable} state={state} {...rest} ref={ref}>
|
|
9
9
|
<View style={[fitToContents ? styles.fitToContents : StyleSheet.absoluteFill, inner, contentContainerStyle]} collapsable={false}>
|
|
10
10
|
{children}
|
|
11
11
|
</View>
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sdcx/bottom-sheet",
|
|
3
3
|
"description": "A react-native BottomSheet component.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.14.0",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"typings": "./lib/index.d.ts",
|
|
7
7
|
"react-native": "src/index",
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"lib",
|
|
12
12
|
"android",
|
|
13
13
|
"ios",
|
|
14
|
+
"docs",
|
|
14
15
|
"RNBottomSheet.podspec",
|
|
15
16
|
"!android/build",
|
|
16
17
|
"!ios/build",
|
package/src/index.tsx
CHANGED
|
@@ -19,6 +19,7 @@ interface NativeBottomSheetProps extends ViewProps {
|
|
|
19
19
|
onSlide?: (event: NativeSyntheticEvent<OffsetChangedEventData>) => void
|
|
20
20
|
onStateChanged?: (event: NativeSyntheticEvent<StateChangedEventData>) => void
|
|
21
21
|
peekHeight?: number
|
|
22
|
+
draggable?: boolean
|
|
22
23
|
state?: BottomSheetState
|
|
23
24
|
contentContainerStyle?: ViewProps['style']
|
|
24
25
|
}
|
|
@@ -37,6 +38,7 @@ const BottomSheet = React.forwardRef<NativeBottomSheetInstance, BottomSheetProps
|
|
|
37
38
|
contentContainerStyle,
|
|
38
39
|
children,
|
|
39
40
|
peekHeight = 200,
|
|
41
|
+
draggable = true,
|
|
40
42
|
state = 'collapsed',
|
|
41
43
|
fitToContents,
|
|
42
44
|
...rest
|
|
@@ -46,6 +48,7 @@ const BottomSheet = React.forwardRef<NativeBottomSheetInstance, BottomSheetProps
|
|
|
46
48
|
<NativeBottomSheet
|
|
47
49
|
style={[StyleSheet.absoluteFill, outer]}
|
|
48
50
|
peekHeight={peekHeight}
|
|
51
|
+
draggable={draggable}
|
|
49
52
|
state={state}
|
|
50
53
|
{...rest}
|
|
51
54
|
ref={ref}>
|