@sdcx/bottom-sheet 0.16.0 → 1.0.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.
Files changed (30) hide show
  1. package/README.md +57 -51
  2. package/RNBottomSheet.podspec +5 -4
  3. package/android/build.gradle +42 -19
  4. package/android/src/main/java/com/reactnative/bottomsheet/BottomSheet.java +70 -73
  5. package/android/src/main/java/com/reactnative/bottomsheet/BottomSheetManager.java +12 -6
  6. package/android/src/main/java/com/reactnative/bottomsheet/{BottomSheetState.java → BottomSheetStatus.java} +1 -1
  7. package/android/src/main/java/com/reactnative/bottomsheet/{OffsetChangedEvent.java → OnSlideEvent.java} +5 -3
  8. package/android/src/main/java/com/reactnative/bottomsheet/{StateChangedEvent.java → OnStateChangedEvent.java} +5 -3
  9. package/dist/BottomSheetNativeComponent.d.ts +20 -0
  10. package/dist/BottomSheetNativeComponent.js +2 -0
  11. package/dist/index.d.ts +8 -15
  12. package/dist/index.js +9 -9
  13. package/ios/BottomSheet/{RNBottomSheetOffsetChangedEvent.m → Event/RNBottomSheetOffsetChangedEvent.mm} +3 -1
  14. package/ios/BottomSheet/{RNBottomSheetStateChangedEvent.h → Event/RNBottomSheetStateChangedEvent.h} +1 -3
  15. package/ios/BottomSheet/{RNBottomSheetStateChangedEvent.m → Event/RNBottomSheetStateChangedEvent.mm} +4 -4
  16. package/ios/BottomSheet/RNBottomSheetComponentView.h +10 -0
  17. package/ios/BottomSheet/RNBottomSheetComponentView.mm +555 -0
  18. package/package.json +50 -38
  19. package/src/BottomSheetNativeComponent.ts +26 -0
  20. package/src/index.tsx +51 -70
  21. package/docs/assets/pagerview.gif +0 -0
  22. package/docs/assets/scrollview.gif +0 -0
  23. package/docs/assets/struct.png +0 -0
  24. package/ios/BottomSheet/RNBottomSheet.h +0 -21
  25. package/ios/BottomSheet/RNBottomSheet.m +0 -401
  26. package/ios/BottomSheet/RNBottomSheetManager.h +0 -9
  27. package/ios/BottomSheet/RNBottomSheetManager.m +0 -24
  28. package/ios/BottomSheet/RNBottomSheetState.h +0 -17
  29. package/ios/BottomSheet/RNBottomSheetState.m +0 -38
  30. /package/ios/BottomSheet/{RNBottomSheetOffsetChangedEvent.h → Event/RNBottomSheetOffsetChangedEvent.h} +0 -0
package/src/index.tsx CHANGED
@@ -1,83 +1,64 @@
1
1
  import React from 'react';
2
- import {
3
- NativeSyntheticEvent,
4
- requireNativeComponent,
5
- StyleSheet,
6
- View,
7
- ViewProps,
8
- } from 'react-native';
2
+ import { NativeSyntheticEvent, StyleSheet, View, ViewProps } from 'react-native';
9
3
  import splitLayoutProps from './splitLayoutProps';
10
-
11
- export interface OffsetChangedEventData {
12
- progress: number;
13
- offset: number;
14
- expandedOffset: number;
15
- collapsedOffset: number;
16
- }
4
+ import BottomSheetNativeComponent from './BottomSheetNativeComponent';
5
+ import type { OnStateChangedEventPayload, OnSlideEventPayload } from './BottomSheetNativeComponent';
17
6
 
18
7
  export type BottomSheetState = 'collapsed' | 'expanded' | 'hidden';
8
+ export type BottomSheetOnSlideEvent = NativeSyntheticEvent<OnSlideEventPayload>;
9
+ export type BottomSheetOnStateChangedEvent = NativeSyntheticEvent<OnStateChangedEventPayload>;
19
10
 
20
- export interface StateChangedEventData {
21
- state: BottomSheetState;
11
+ interface BottomSheetProps extends ViewProps {
12
+ onSlide?: (event: BottomSheetOnSlideEvent) => void;
13
+ onStateChanged?: (event: BottomSheetOnStateChangedEvent) => void;
14
+ peekHeight?: number;
15
+ draggable?: boolean;
16
+ state?: BottomSheetState;
17
+ fitToContents?: boolean;
18
+ contentContainerStyle?: ViewProps['style'];
22
19
  }
23
20
 
24
- interface NativeBottomSheetProps extends ViewProps {
25
- onSlide?: (event: NativeSyntheticEvent<OffsetChangedEventData>) => void;
26
- onStateChanged?: (event: NativeSyntheticEvent<StateChangedEventData>) => void;
27
- peekHeight?: number;
28
- draggable?: boolean;
29
- state?: BottomSheetState;
30
- contentContainerStyle?: ViewProps['style'];
21
+ function BottomSheet(props: BottomSheetProps) {
22
+ const {
23
+ style,
24
+ contentContainerStyle,
25
+ children,
26
+ peekHeight = 200,
27
+ draggable = true,
28
+ state = 'collapsed',
29
+ fitToContents,
30
+ ...rest
31
+ } = props;
32
+ const { outer, inner } = splitLayoutProps(StyleSheet.flatten(style));
33
+ return (
34
+ <BottomSheetNativeComponent
35
+ style={[StyleSheet.absoluteFill, outer]}
36
+ peekHeight={peekHeight}
37
+ draggable={draggable}
38
+ status={state}
39
+ {...rest}
40
+ >
41
+ <View
42
+ style={[
43
+ fitToContents ? styles.fitToContents : StyleSheet.absoluteFill,
44
+ inner,
45
+ contentContainerStyle,
46
+ ]}
47
+ collapsable={false}
48
+ >
49
+ {children}
50
+ </View>
51
+ </BottomSheetNativeComponent>
52
+ );
31
53
  }
32
54
 
33
- type BottomSheetProps = NativeBottomSheetProps & {
34
- fitToContents?: boolean;
35
- };
36
-
37
- const NativeBottomSheet = requireNativeComponent<NativeBottomSheetProps>('BottomSheet');
38
-
39
- type NativeBottomSheetInstance = InstanceType<typeof NativeBottomSheet>;
40
-
41
- const BottomSheet = React.forwardRef<NativeBottomSheetInstance, BottomSheetProps>((props, ref) => {
42
- const {
43
- style,
44
- contentContainerStyle,
45
- children,
46
- peekHeight = 200,
47
- draggable = true,
48
- state = 'collapsed',
49
- fitToContents,
50
- ...rest
51
- } = props;
52
- const {outer, inner} = splitLayoutProps(StyleSheet.flatten(style));
53
- return (
54
- <NativeBottomSheet
55
- style={[StyleSheet.absoluteFill, outer]}
56
- peekHeight={peekHeight}
57
- draggable={draggable}
58
- state={state}
59
- {...rest}
60
- ref={ref}>
61
- <View
62
- style={[
63
- fitToContents ? styles.fitToContents : StyleSheet.absoluteFill,
64
- inner,
65
- contentContainerStyle,
66
- ]}
67
- collapsable={false}>
68
- {children}
69
- </View>
70
- </NativeBottomSheet>
71
- );
72
- });
73
-
74
55
  const styles = StyleSheet.create({
75
- fitToContents: {
76
- position: 'absolute',
77
- left: 0,
78
- right: 0,
79
- bottom: 0,
80
- },
56
+ fitToContents: {
57
+ position: 'absolute',
58
+ left: 0,
59
+ right: 0,
60
+ bottom: 0,
61
+ },
81
62
  });
82
63
 
83
64
  export default BottomSheet;
Binary file
Binary file
Binary file
@@ -1,21 +0,0 @@
1
- #import <UIKit/UIKit.h>
2
- #import <React/RCTView.h>
3
- #import <React/RCTEventDispatcher.h>
4
-
5
- #import "RNBottomSheetState.h"
6
-
7
- NS_ASSUME_NONNULL_BEGIN
8
-
9
- @interface RNBottomSheet : RCTView
10
-
11
- @property(nonatomic, copy) RCTDirectEventBlock onSlide;
12
- @property(nonatomic, copy) RCTDirectEventBlock onStateChanged;
13
- @property(nonatomic, assign) CGFloat peekHeight;
14
- @property(nonatomic, assign) RNBottomSheetState state;
15
- @property(nonatomic, assign) BOOL draggable;
16
-
17
- - (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher;
18
-
19
- @end
20
-
21
- NS_ASSUME_NONNULL_END
@@ -1,401 +0,0 @@
1
- #import "RNBottomSheet.h"
2
- #import "RNBottomSheetStateChangedEvent.h"
3
- #import "RNBottomSheetOffsetChangedEvent.h"
4
-
5
- #import <React/UIView+React.h>
6
- #import <React/RCTRootContentView.h>
7
- #import <React/RCTTouchHandler.h>
8
- #import <React/RCTLog.h>
9
-
10
- @interface RNBottomSheet () <UIGestureRecognizerDelegate>
11
-
12
- @property(nonatomic, strong) UIView *contentView;
13
-
14
- @property(nonatomic, strong) UIScrollView *target;
15
- @property(nonatomic, strong) UIPanGestureRecognizer *panGestureRecognizer;
16
-
17
- @property(nonatomic, assign) CGFloat minY;
18
- @property(nonatomic, assign) CGFloat maxY;
19
-
20
- @property(nonatomic, assign) BOOL nextReturn;
21
-
22
- @property(nonatomic, strong) CADisplayLink *displayLink;
23
- @property(nonatomic, strong) RCTEventDispatcher *eventDispatcher;
24
-
25
- @property(nonatomic, assign) RNBottomSheetState finalState;
26
-
27
- @end
28
-
29
- @implementation RNBottomSheet {
30
- __weak RCTRootContentView *_rootView;
31
- BOOL _isInitialRender;
32
- }
33
-
34
- - (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher {
35
- if (self = [super init]) {
36
- _panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
37
- _panGestureRecognizer.delegate = self;
38
- _state = RNBottomSheetStateCollapsed;
39
- _finalState = RNBottomSheetStateCollapsed;
40
- _eventDispatcher = eventDispatcher;
41
- _isInitialRender = YES;
42
- }
43
- return self;
44
- }
45
-
46
- - (void)insertReactSubview:(UIView *)subview atIndex:(NSInteger)atIndex {
47
- [super insertReactSubview:subview atIndex:atIndex];
48
- if (atIndex == 0) {
49
- self.contentView = subview;
50
- [subview addGestureRecognizer:_panGestureRecognizer];
51
- }
52
- }
53
-
54
- - (void)removeReactSubview:(UIView *)subview {
55
- [super removeReactSubview:subview];
56
- if (self.contentView == subview) {
57
- [subview removeGestureRecognizer:_panGestureRecognizer];
58
- }
59
- }
60
-
61
- - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
62
- if (gestureRecognizer == self.panGestureRecognizer && otherGestureRecognizer == self.target.panGestureRecognizer) {
63
- return YES;
64
- }
65
- return NO;
66
- }
67
-
68
- - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
69
- if (gestureRecognizer == self.panGestureRecognizer) {
70
- if ([super gestureRecognizerShouldBegin:gestureRecognizer]) {
71
- [self cancelRootViewTouches];
72
- return YES;
73
- }
74
- return NO;
75
- }
76
- return [super gestureRecognizerShouldBegin:gestureRecognizer];
77
- }
78
-
79
- - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
80
- if (gestureRecognizer != self.panGestureRecognizer) {
81
- return YES;
82
- }
83
-
84
- if (self.target) {
85
- [self.target removeObserver:self forKeyPath:@"contentOffset"];
86
- }
87
- self.target = nil;
88
-
89
- UIView *touchView = touch.view;
90
-
91
- while (touchView != nil && [touchView isDescendantOfView:self]) {
92
- if ([touchView isKindOfClass:[UIScrollView class]]) {
93
- UIScrollView *scrollView = (UIScrollView *)touchView;
94
- if (![self isHorizontal:scrollView]) {
95
- self.target = scrollView;
96
- [self.target addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:nil];
97
- break;
98
- }
99
- }
100
- touchView = touchView.superview;
101
- }
102
-
103
- return YES;
104
- }
105
-
106
- - (void)willMoveToSuperview:(UIView *)superview {
107
- [super willMoveToSuperview:superview];
108
- if (superview == nil && self.target) {
109
- [self.target removeObserver:self forKeyPath:@"contentOffset"];
110
- self.target = nil;
111
- }
112
- if (superview == nil) {
113
- [self stopWatchBottomSheetTransition];
114
- }
115
- }
116
-
117
- - (void)willMoveToWindow:(UIWindow *)newWindow {
118
- [super willMoveToWindow:newWindow];
119
- if (newWindow == nil) {
120
- [self stopWatchBottomSheetTransition];
121
- }
122
- }
123
-
124
- - (void)didMoveToWindow {
125
- [super didMoveToWindow];
126
- if (self.window) {
127
- [self cacheRootView];
128
- }
129
- }
130
-
131
- - (void)cacheRootView {
132
- UIView *rootView = self;
133
- while (rootView.superview && ![rootView isReactRootView]) {
134
- rootView = rootView.superview;
135
- }
136
- _rootView = rootView;
137
- }
138
-
139
- - (void)cancelRootViewTouches {
140
- RCTRootContentView *rootView = (RCTRootContentView *)_rootView;
141
- [rootView.touchHandler cancel];
142
- }
143
-
144
- - (BOOL)isHorizontal:(UIScrollView *)scrollView {
145
- return scrollView.contentSize.width > self.frame.size.width;
146
- }
147
-
148
-
149
- - (void)reactSetFrame:(CGRect)frame {
150
- [super reactSetFrame:frame];
151
- }
152
-
153
- - (void)layoutSubviews {
154
- [super layoutSubviews];
155
- if (!self.contentView) {
156
- return;
157
- }
158
-
159
- if (!CGRectEqualToRect(self.contentView.frame, CGRectZero)) {
160
- [self calculateOffset];
161
- if (self.state == RNBottomSheetStateCollapsed) {
162
- self.contentView.frame = CGRectOffset(self.contentView.frame, 0, self.maxY - self.contentView.frame.origin.y);
163
- } else if (self.state == RNBottomSheetStateExpanded) {
164
- self.contentView.frame = CGRectOffset(self.contentView.frame, 0, self.minY - self.contentView.frame.origin.y);
165
- } else if (self.state == RNBottomSheetStateHidden) {
166
- self.contentView.frame = CGRectOffset(self.contentView.frame, 0, self.frame.size.height - self.contentView.frame.origin.y);
167
- }
168
- [self dispatchOnSlide:self.contentView.frame.origin.y];
169
- }
170
-
171
- dispatch_async(dispatch_get_main_queue(), ^{
172
- if (self.finalState == RNBottomSheetStateExpanded && self->_isInitialRender) {
173
- [self settleToState:self.finalState withFling:YES];
174
- }
175
-
176
- self->_isInitialRender = NO;
177
- });
178
- }
179
-
180
- - (void)calculateOffset {
181
- CGFloat parentHeight = self.frame.size.height;
182
- self.minY = fmax(0, parentHeight - self.contentView.frame.size.height);
183
- self.maxY = fmax(self.minY, parentHeight - self.peekHeight);
184
- }
185
-
186
- - (void)handlePan:(UIPanGestureRecognizer *)pan {
187
- if (!self.draggable || self.state == RNBottomSheetStateSettling) {
188
- return;
189
- }
190
-
191
- CGFloat translationY = [pan translationInView:self.contentView].y;
192
- [pan setTranslation:CGPointZero inView:self.contentView];
193
-
194
- CGFloat top = self.contentView.frame.origin.y;
195
-
196
- if (pan.state == UIGestureRecognizerStateChanged) {
197
- [self setStateInternal:RNBottomSheetStateDragging];
198
- }
199
-
200
- // 如果有嵌套滚动
201
- if (self.target) {
202
- if(translationY > 0 && top < self.maxY && self.target.contentOffset.y <= 0) {
203
- //向下拖
204
- CGFloat y = fmin(top + translationY, self.maxY);
205
- self.contentView.frame = CGRectOffset(self.contentView.frame, 0, y - top);
206
- [self dispatchOnSlide:self.contentView.frame.origin.y];
207
- }
208
-
209
- if (translationY < 0 && top > self.minY) {
210
- //向上拖
211
- CGFloat y = fmax(top + translationY, self.minY);
212
- self.contentView.frame = CGRectOffset(self.contentView.frame, 0, y - top);
213
- [self dispatchOnSlide:self.contentView.frame.origin.y];
214
- }
215
- }
216
-
217
- // 没有嵌套滚动
218
- if (!self.target) {
219
- if(translationY > 0 && top < self.maxY) {
220
- //向下拖
221
- CGFloat y = fmin(top + translationY, self.maxY);
222
- self.contentView.frame = CGRectOffset(self.contentView.frame, 0, y - top);
223
- [self dispatchOnSlide:self.contentView.frame.origin.y];
224
- }
225
-
226
- if (translationY < 0 && top > self.minY) {
227
- //向上拖
228
- CGFloat y = fmax(top + translationY, self.minY);
229
- self.contentView.frame = CGRectOffset(self.contentView.frame, 0, y - top);
230
- [self dispatchOnSlide:self.contentView.frame.origin.y];
231
- }
232
- }
233
-
234
- if (pan.state == UIGestureRecognizerStateEnded || pan.state == UIGestureRecognizerStateCancelled) {
235
- // RCTLogInfo(@"velocity:%f", [pan velocityInView:self.contentView].y);
236
- CGFloat velocity = [pan velocityInView:self.contentView].y;
237
- if (velocity > 400) {
238
- if (self.target && self.target.contentOffset.y <= 0) {
239
- //如果是类似轻扫的那种
240
- [self settleToState:RNBottomSheetStateCollapsed withFling:YES];
241
- }
242
-
243
- if (!self.target) {
244
- //如果是类似轻扫的那种
245
- [self settleToState:RNBottomSheetStateCollapsed withFling:YES];
246
- }
247
- } else if (velocity < -400) {
248
- //如果是类似轻扫的那种
249
- [self settleToState:RNBottomSheetStateExpanded withFling:YES];
250
- } else {
251
- //如果是普通拖拽
252
- if(fabs(self.contentView.frame.origin.y - self.minY) > fabs(self.contentView.frame.origin.y - self.maxY)) {
253
- [self settleToState:RNBottomSheetStateCollapsed withFling:NO];
254
- } else {
255
- [self settleToState:RNBottomSheetStateExpanded withFling:NO];
256
- }
257
- }
258
- }
259
- }
260
-
261
- - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(UIScrollView *)target change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context{
262
- if (_nextReturn) {
263
- _nextReturn = false;
264
- return;
265
- }
266
-
267
- if (![keyPath isEqualToString:@"contentOffset"]) {
268
- return;
269
- }
270
-
271
- CGFloat new = [change[@"new"] CGPointValue].y;
272
- CGFloat old = [change[@"old"] CGPointValue].y;
273
-
274
- if (new == old) {
275
- return;
276
- }
277
-
278
- CGFloat dy = old - new;
279
-
280
- if (dy > 0) {
281
- //向下
282
- if(target.contentOffset.y < 0){
283
- _nextReturn = true;
284
- target.contentOffset = CGPointMake(0, 0);
285
- }
286
- }
287
-
288
- if (dy < 0) {
289
- //向上
290
- if (self.contentView.frame.origin.y > self.minY) {
291
- _nextReturn = true;
292
- target.contentOffset = CGPointMake(0, old);
293
- }
294
- }
295
- }
296
-
297
- - (void)setPeekHeight:(CGFloat)peekHeight {
298
- _peekHeight = peekHeight;
299
- if (!CGRectEqualToRect(self.contentView.frame, CGRectZero)) {
300
- [self calculateOffset];
301
- if (self.state == RNBottomSheetStateCollapsed) {
302
- [self settleToState:RNBottomSheetStateCollapsed withFling:NO];
303
- }
304
- }
305
- }
306
-
307
- - (void)setState:(RNBottomSheetState)state {
308
- if (_isInitialRender) {
309
- self.finalState = state;
310
- return;
311
- }
312
-
313
- if (self.finalState == state) {
314
- return;
315
- }
316
-
317
- if (_state == RNBottomSheetStateSettling) {
318
- return;
319
- }
320
-
321
- self.finalState = state;
322
-
323
- [self settleToState:state withFling:YES];
324
- }
325
-
326
- - (void)settleToState:(RNBottomSheetState)state withFling:(BOOL)fling {
327
- if (state == RNBottomSheetStateCollapsed) {
328
- [self settleToState:state top:self.maxY withFling:fling];
329
- } else if (state == RNBottomSheetStateExpanded) {
330
- [self settleToState:state top:self.minY withFling:fling];
331
- } else if (state == RNBottomSheetStateHidden) {
332
- [self settleToState:state top:self.frame.size.height withFling:fling];
333
- }
334
- }
335
-
336
- - (void)settleToState:(RNBottomSheetState)state top:(CGFloat)top withFling:(BOOL)fling {
337
- self.target.pagingEnabled = YES;
338
- [self setStateInternal:RNBottomSheetStateSettling];
339
- [self startWatchBottomSheetTransition];
340
- [self.layer removeAllAnimations];
341
- // CGFloat duration = fmin(fabs(self.contentView.frame.origin.y - top) / (self.maxY - self.minY) * 0.3, 0.3);
342
- [UIView animateWithDuration:fling ? 0.5 : 0.25 delay:0 usingSpringWithDamping:1 initialSpringVelocity:1 options:UIViewAnimationOptionTransitionNone animations:^{
343
- self.contentView.frame = CGRectOffset(self.contentView.frame, 0, top - self.contentView.frame.origin.y);
344
- } completion:^(BOOL finished) {
345
- self.target.pagingEnabled = NO;
346
- [self stopWatchBottomSheetTransition];
347
- [self setStateInternal:state];
348
- }];
349
- }
350
-
351
- - (void)setStateInternal:(RNBottomSheetState)state {
352
- if (_state == state) {
353
- return;
354
- }
355
- _state = state;
356
-
357
- if (state == RNBottomSheetStateExpanded) {
358
- [self dispatchOnSlide:self.minY];
359
- }
360
-
361
- if (state == RNBottomSheetStateHidden) {
362
- [self dispatchOnSlide:self.frame.size.height];
363
- }
364
-
365
- if (state == RNBottomSheetStateCollapsed) {
366
- [self dispatchOnSlide:self.maxY];
367
- }
368
-
369
- if (state == RNBottomSheetStateCollapsed || state == RNBottomSheetStateExpanded || state == RNBottomSheetStateHidden) {
370
- [self.eventDispatcher sendEvent:[[RNBottomSheetStateChangedEvent alloc] initWithViewTag:self.reactTag state:state]];
371
- }
372
- }
373
-
374
- - (void)dispatchOnSlide:(CGFloat)top {
375
- if (top < 0 || self.maxY == 0) {
376
- return;
377
- }
378
- CGFloat progress = fmin((top - self.minY) * 1.0f / (self.maxY - self.minY), 1);
379
- [self.eventDispatcher sendEvent:[[RNBottomSheetOffsetChangedEvent alloc] initWithViewTag:self.reactTag progress:progress offset:top minY:self.minY maxY:self.maxY]];
380
- }
381
-
382
- - (void)startWatchBottomSheetTransition {
383
- [self stopWatchBottomSheetTransition];
384
- _displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(watchBottomSheetTransition)];
385
- _displayLink.preferredFramesPerSecond = 120;
386
- [_displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
387
- }
388
-
389
- - (void)stopWatchBottomSheetTransition {
390
- if(_displayLink){
391
- [_displayLink invalidate];
392
- _displayLink = nil;
393
- }
394
- }
395
-
396
- - (void)watchBottomSheetTransition {
397
- CGFloat top = [self.contentView.layer presentationLayer].frame.origin.y;
398
- [self dispatchOnSlide:top];
399
- }
400
-
401
- @end
@@ -1,9 +0,0 @@
1
- #import <React/RCTViewManager.h>
2
-
3
- NS_ASSUME_NONNULL_BEGIN
4
-
5
- @interface RNBottomSheetManager : RCTViewManager
6
-
7
- @end
8
-
9
- NS_ASSUME_NONNULL_END
@@ -1,24 +0,0 @@
1
- #import "RNBottomSheetManager.h"
2
- #import "RNBottomSheet.h"
3
- #import "RNBottomSheetState.h"
4
-
5
- @implementation RNBottomSheetManager
6
-
7
- RCT_EXPORT_MODULE(BottomSheet)
8
-
9
- - (UIView *)view {
10
- RNBottomSheet *bottomSheet = [[RNBottomSheet alloc] initWithEventDispatcher:self.bridge.eventDispatcher];
11
- bottomSheet.pointerEvents = RCTPointerEventsBoxNone;
12
- return bottomSheet;
13
- }
14
-
15
- RCT_EXPORT_VIEW_PROPERTY(onSlide, RCTDirectEventBlock)
16
- RCT_EXPORT_VIEW_PROPERTY(onStateChanged, RCTDirectEventBlock)
17
- RCT_EXPORT_VIEW_PROPERTY(peekHeight, CGFloat)
18
- RCT_EXPORT_VIEW_PROPERTY(draggable, BOOL)
19
-
20
- RCT_CUSTOM_VIEW_PROPERTY(state, NSString, RNBottomSheet) {
21
- view.state = RNBottomSheetStateFromString([RCTConvert NSString:json]);
22
- }
23
-
24
- @end
@@ -1,17 +0,0 @@
1
- #import <React/RCTUtils.h>
2
-
3
- NS_ASSUME_NONNULL_BEGIN
4
-
5
- typedef NS_ENUM(NSUInteger, RNBottomSheetState) {
6
- RNBottomSheetStateCollapsed = 0,
7
- RNBottomSheetStateExpanded,
8
- RNBottomSheetStateHidden,
9
- RNBottomSheetStateDragging,
10
- RNBottomSheetStateSettling,
11
- };
12
-
13
- RCT_EXTERN RNBottomSheetState RNBottomSheetStateFromString(NSString *state);
14
-
15
- RCT_EXTERN NSString* RNBottomSheetStateToString(RNBottomSheetState state);
16
-
17
- NS_ASSUME_NONNULL_END
@@ -1,38 +0,0 @@
1
- #import "RNBottomSheetState.h"
2
-
3
- RNBottomSheetState RNBottomSheetStateFromString(NSString *state) {
4
- if ([state isEqualToString:@"collapsed"]) {
5
- return RNBottomSheetStateCollapsed;
6
- }
7
- if ([state isEqualToString:@"expanded"]) {
8
- return RNBottomSheetStateExpanded;
9
- }
10
- if ([state isEqualToString:@"settling"]) {
11
- return RNBottomSheetStateSettling;
12
- }
13
- if ([state isEqualToString:@"dragging"]) {
14
- return RNBottomSheetStateDragging;
15
- }
16
- return RNBottomSheetStateHidden;
17
- }
18
-
19
-
20
- NSString* RNBottomSheetStateToString(RNBottomSheetState state) {
21
- if (state == RNBottomSheetStateCollapsed) {
22
- return @"collapsed";
23
- }
24
-
25
- if (state == RNBottomSheetStateExpanded) {
26
- return @"expanded";
27
- }
28
-
29
- if (state == RNBottomSheetStateSettling) {
30
- return @"settling";
31
- }
32
-
33
- if (state == RNBottomSheetStateDragging) {
34
- return @"dragging";
35
- }
36
-
37
- return @"hidden";
38
- }