@sdcx/bottom-sheet 0.13.0 → 0.15.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.
Binary file
Binary file
Binary file
@@ -22,10 +22,13 @@
22
22
  @property(nonatomic, strong) CADisplayLink *displayLink;
23
23
  @property(nonatomic, strong) RCTEventDispatcher *eventDispatcher;
24
24
 
25
+ @property(nonatomic, assign) RNBottomSheetState finalState;
26
+
25
27
  @end
26
28
 
27
29
  @implementation RNBottomSheet {
28
30
  __weak RCTRootContentView *_rootView;
31
+ BOOL _isInitialRender;
29
32
  }
30
33
 
31
34
  - (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher {
@@ -33,7 +36,9 @@
33
36
  _panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
34
37
  _panGestureRecognizer.delegate = self;
35
38
  _state = RNBottomSheetStateCollapsed;
39
+ _finalState = RNBottomSheetStateCollapsed;
36
40
  _eventDispatcher = eventDispatcher;
41
+ _isInitialRender = YES;
37
42
  }
38
43
  return self;
39
44
  }
@@ -162,6 +167,14 @@
162
167
  }
163
168
  [self dispatchOnSlide:self.contentView.frame.origin.y];
164
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
+ });
165
178
  }
166
179
 
167
180
  - (void)calculateOffset {
@@ -171,7 +184,7 @@
171
184
  }
172
185
 
173
186
  - (void)handlePan:(UIPanGestureRecognizer *)pan {
174
- if (!self.draggable) {
187
+ if (!self.draggable || self.state == RNBottomSheetStateSettling) {
175
188
  return;
176
189
  }
177
190
 
@@ -292,15 +305,17 @@
292
305
  }
293
306
 
294
307
  - (void)setState:(RNBottomSheetState)state {
295
- if (_state == state) {
308
+ if (_isInitialRender) {
309
+ self.finalState = state;
296
310
  return;
297
311
  }
298
-
299
- if (CGRectEqualToRect(self.contentView.frame, CGRectZero)) {
300
- [self setStateInternal:state];
312
+
313
+ if (self.finalState == state) {
301
314
  return;
302
315
  }
303
316
 
317
+ self.finalState = state;
318
+
304
319
  [self settleToState:state withFling:YES];
305
320
  }
306
321
 
@@ -320,7 +335,7 @@
320
335
  [self startWatchBottomSheetTransition];
321
336
  [self.layer removeAllAnimations];
322
337
  // CGFloat duration = fmin(fabs(self.contentView.frame.origin.y - top) / (self.maxY - self.minY) * 0.3, 0.3);
323
- [UIView animateWithDuration:fling ? 0.5 : 0.25 delay:0 usingSpringWithDamping:1 initialSpringVelocity:1 options:NULL animations:^{
338
+ [UIView animateWithDuration:fling ? 0.5 : 0.25 delay:0 usingSpringWithDamping:1 initialSpringVelocity:1 options:UIViewAnimationOptionTransitionNone animations:^{
324
339
  self.contentView.frame = CGRectOffset(self.contentView.frame, 0, top - self.contentView.frame.origin.y);
325
340
  } completion:^(BOOL finished) {
326
341
  self.target.pagingEnabled = NO;
@@ -335,6 +350,18 @@
335
350
  }
336
351
  _state = state;
337
352
 
353
+ if (state == RNBottomSheetStateExpanded) {
354
+ [self dispatchOnSlide:self.minY];
355
+ }
356
+
357
+ if (state == RNBottomSheetStateHidden) {
358
+ [self dispatchOnSlide:self.frame.size.height];
359
+ }
360
+
361
+ if (state == RNBottomSheetStateCollapsed) {
362
+ [self dispatchOnSlide:self.maxY];
363
+ }
364
+
338
365
  if (state == RNBottomSheetStateCollapsed || state == RNBottomSheetStateExpanded || state == RNBottomSheetStateHidden) {
339
366
  [self.eventDispatcher sendEvent:[[RNBottomSheetStateChangedEvent alloc] initWithViewTag:self.reactTag state:state]];
340
367
  }
@@ -356,11 +383,6 @@
356
383
  }
357
384
 
358
385
  - (void)stopWatchBottomSheetTransition {
359
- if (self.state == RNBottomSheetStateCollapsed) {
360
- [self dispatchOnSlide:self.maxY];
361
- } else if (self.state == RNBottomSheetStateExpanded) {
362
- [self dispatchOnSlide:self.minY];
363
- }
364
386
  if(_displayLink){
365
387
  [_displayLink invalidate];
366
388
  _displayLink = nil;
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.13.0",
4
+ "version": "0.15.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",