@sdcx/bottom-sheet 0.11.0 → 0.13.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.
@@ -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
  }
@@ -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
 
@@ -143,7 +143,6 @@
143
143
 
144
144
  - (void)reactSetFrame:(CGRect)frame {
145
145
  [super reactSetFrame:frame];
146
-
147
146
  }
148
147
 
149
148
  - (void)layoutSubviews {
@@ -172,6 +171,10 @@
172
171
  }
173
172
 
174
173
  - (void)handlePan:(UIPanGestureRecognizer *)pan {
174
+ if (!self.draggable) {
175
+ return;
176
+ }
177
+
175
178
  CGFloat translationY = [pan translationInView:self.contentView].y;
176
179
  [pan setTranslation:CGPointZero inView:self.contentView];
177
180
 
@@ -298,20 +301,20 @@
298
301
  return;
299
302
  }
300
303
 
301
- [self settleToState:state withFling:NO];
304
+ [self settleToState:state withFling:YES];
302
305
  }
303
306
 
304
307
  - (void)settleToState:(RNBottomSheetState)state withFling:(BOOL)fling {
305
308
  if (state == RNBottomSheetStateCollapsed) {
306
- [self startSettlingToState:state top:self.maxY withFling:fling];
309
+ [self settleToState:state top:self.maxY withFling:fling];
307
310
  } else if (state == RNBottomSheetStateExpanded) {
308
- [self startSettlingToState:state top:self.minY withFling:fling];
311
+ [self settleToState:state top:self.minY withFling:fling];
309
312
  } else if (state == RNBottomSheetStateHidden) {
310
- [self startSettlingToState:state top:self.frame.size.height withFling:fling];
313
+ [self settleToState:state top:self.frame.size.height withFling:fling];
311
314
  }
312
315
  }
313
316
 
314
- - (void)startSettlingToState:(RNBottomSheetState)state top:(CGFloat)top withFling:(BOOL)fling {
317
+ - (void)settleToState:(RNBottomSheetState)state top:(CGFloat)top withFling:(BOOL)fling {
315
318
  self.target.pagingEnabled = YES;
316
319
  [self setStateInternal:RNBottomSheetStateSettling];
317
320
  [self startWatchBottomSheetTransition];
@@ -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]);
@@ -3,7 +3,7 @@
3
3
  @interface RNBottomSheetOffsetChangedEvent ()
4
4
 
5
5
  @property (nonatomic, assign) CGFloat progress;
6
- @property (nonatomic, assign) CGFloat offest;
6
+ @property (nonatomic, assign) CGFloat offset;
7
7
  @property (nonatomic, assign) CGFloat minY;
8
8
  @property (nonatomic, assign) CGFloat maxY;
9
9
 
@@ -22,7 +22,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
22
22
  if (self = [super init]) {
23
23
  _viewTag = viewTag;
24
24
  _progress = progress;
25
- _offest = offset;
25
+ _offset = offset;
26
26
  _minY = minY;
27
27
  _maxY = maxY;
28
28
  }
@@ -44,7 +44,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
44
44
  - (NSArray *)arguments {
45
45
  return @[self.viewTag, RCTNormalizeInputEventName(self.eventName), @{
46
46
  @"progress": @(self.progress),
47
- @"offset": @(self.offest),
47
+ @"offset": @(self.offset),
48
48
  @"expandedOffset": @(self.minY),
49
49
  @"collapsedOffset": @(self.maxY)
50
50
  }];
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.11.0",
4
+ "version": "0.13.0",
5
5
  "main": "./lib/index.js",
6
6
  "typings": "./lib/index.d.ts",
7
7
  "react-native": "src/index",
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}>