@sdcx/bottom-sheet 0.16.0 → 0.17.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.
@@ -167,10 +167,6 @@ public class BottomSheet extends ReactViewGroup implements NestedScrollingParent
167
167
  return;
168
168
  }
169
169
 
170
- if (this.state == SETTLING) {
171
- return;
172
- }
173
-
174
170
  if (contentView == null) {
175
171
  // The view is not laid out yet; modify mState and let onLayoutChild handle it later
176
172
  if (state == COLLAPSED || state == EXPANDED || state == HIDDEN) {
@@ -186,7 +182,7 @@ public class BottomSheet extends ReactViewGroup implements NestedScrollingParent
186
182
  View findScrollingChild(View view) {
187
183
  if (ViewCompat.isNestedScrollingEnabled(view)) {
188
184
  if (!view.canScrollHorizontally(1) && !view.canScrollHorizontally(-1) &&
189
- (view.canScrollVertically(-1) || view.canScrollVertically(1))) {
185
+ (view.canScrollVertically(-1) || view.canScrollVertically(1))) {
190
186
  return view;
191
187
  }
192
188
  }
@@ -259,7 +255,7 @@ public class BottomSheet extends ReactViewGroup implements NestedScrollingParent
259
255
  }
260
256
 
261
257
  ignoreEvents = activePointerId == MotionEvent.INVALID_POINTER_ID
262
- && !isPointInChildBounds(contentView, initialX, initialY);
258
+ && !isPointInChildBounds(contentView, initialX, initialY);
263
259
  break;
264
260
  default: // fall out
265
261
  }
@@ -273,12 +269,12 @@ public class BottomSheet extends ReactViewGroup implements NestedScrollingParent
273
269
  // happening over the scrolling content as nested scrolling logic handles that case.
274
270
  View scroll = nestedScrollingChildRef != null ? nestedScrollingChildRef.get() : null;
275
271
  return action == MotionEvent.ACTION_MOVE
276
- && scroll != null
277
- && !ignoreEvents
278
- && state != DRAGGING
279
- && !isPointInChildBounds(scroll, (int) event.getX(), (int) event.getY())
280
- && viewDragHelper != null
281
- && Math.abs(initialY - event.getY()) > viewDragHelper.getTouchSlop();
272
+ && scroll != null
273
+ && !ignoreEvents
274
+ && state != DRAGGING
275
+ && !isPointInChildBounds(scroll, (int) event.getX(), (int) event.getY())
276
+ && viewDragHelper != null
277
+ && Math.abs(initialY - event.getY()) > viewDragHelper.getTouchSlop();
282
278
  }
283
279
 
284
280
  @Override
@@ -551,10 +547,10 @@ public class BottomSheet extends ReactViewGroup implements NestedScrollingParent
551
547
 
552
548
  void startSettlingAnimation(View child, BottomSheetState state, int top, boolean settleFromViewDragHelper) {
553
549
  boolean startedSettling =
554
- viewDragHelper != null
555
- && (settleFromViewDragHelper
556
- ? viewDragHelper.settleCapturedViewAt(child.getLeft(), top)
557
- : viewDragHelper.smoothSlideViewTo(child, child.getLeft(), top));
550
+ viewDragHelper != null
551
+ && (settleFromViewDragHelper
552
+ ? viewDragHelper.settleCapturedViewAt(child.getLeft(), top)
553
+ : viewDragHelper.smoothSlideViewTo(child, child.getLeft(), top));
558
554
  if (startedSettling) {
559
555
  setStateInternal(SETTLING);
560
556
  // STATE_SETTLING won't animate the material shape, so do that here with the target state.
@@ -24,10 +24,12 @@
24
24
 
25
25
  @property(nonatomic, assign) RNBottomSheetState finalState;
26
26
 
27
+ @property(nonatomic, strong) UIViewPropertyAnimator *animator;
28
+
27
29
  @end
28
30
 
29
31
  @implementation RNBottomSheet {
30
- __weak RCTRootContentView *_rootView;
32
+ __weak UIView *_rootView;
31
33
  BOOL _isInitialRender;
32
34
  }
33
35
 
@@ -80,14 +82,14 @@
80
82
  if (gestureRecognizer != self.panGestureRecognizer) {
81
83
  return YES;
82
84
  }
83
-
85
+
84
86
  if (self.target) {
85
87
  [self.target removeObserver:self forKeyPath:@"contentOffset"];
86
88
  }
87
89
  self.target = nil;
88
-
90
+
89
91
  UIView *touchView = touch.view;
90
-
92
+
91
93
  while (touchView != nil && [touchView isDescendantOfView:self]) {
92
94
  if ([touchView isKindOfClass:[UIScrollView class]]) {
93
95
  UIScrollView *scrollView = (UIScrollView *)touchView;
@@ -155,7 +157,7 @@
155
157
  if (!self.contentView) {
156
158
  return;
157
159
  }
158
-
160
+
159
161
  if (!CGRectEqualToRect(self.contentView.frame, CGRectZero)) {
160
162
  [self calculateOffset];
161
163
  if (self.state == RNBottomSheetStateCollapsed) {
@@ -167,12 +169,12 @@
167
169
  }
168
170
  [self dispatchOnSlide:self.contentView.frame.origin.y];
169
171
  }
170
-
172
+
171
173
  dispatch_async(dispatch_get_main_queue(), ^{
172
174
  if (self.finalState == RNBottomSheetStateExpanded && self->_isInitialRender) {
173
175
  [self settleToState:self.finalState withFling:YES];
174
176
  }
175
-
177
+
176
178
  self->_isInitialRender = NO;
177
179
  });
178
180
  }
@@ -187,16 +189,16 @@
187
189
  if (!self.draggable || self.state == RNBottomSheetStateSettling) {
188
190
  return;
189
191
  }
190
-
192
+
191
193
  CGFloat translationY = [pan translationInView:self.contentView].y;
192
194
  [pan setTranslation:CGPointZero inView:self.contentView];
193
-
195
+
194
196
  CGFloat top = self.contentView.frame.origin.y;
195
-
197
+
196
198
  if (pan.state == UIGestureRecognizerStateChanged) {
197
199
  [self setStateInternal:RNBottomSheetStateDragging];
198
200
  }
199
-
201
+
200
202
  // 如果有嵌套滚动
201
203
  if (self.target) {
202
204
  if(translationY > 0 && top < self.maxY && self.target.contentOffset.y <= 0) {
@@ -205,7 +207,7 @@
205
207
  self.contentView.frame = CGRectOffset(self.contentView.frame, 0, y - top);
206
208
  [self dispatchOnSlide:self.contentView.frame.origin.y];
207
209
  }
208
-
210
+
209
211
  if (translationY < 0 && top > self.minY) {
210
212
  //向上拖
211
213
  CGFloat y = fmax(top + translationY, self.minY);
@@ -213,7 +215,7 @@
213
215
  [self dispatchOnSlide:self.contentView.frame.origin.y];
214
216
  }
215
217
  }
216
-
218
+
217
219
  // 没有嵌套滚动
218
220
  if (!self.target) {
219
221
  if(translationY > 0 && top < self.maxY) {
@@ -222,7 +224,7 @@
222
224
  self.contentView.frame = CGRectOffset(self.contentView.frame, 0, y - top);
223
225
  [self dispatchOnSlide:self.contentView.frame.origin.y];
224
226
  }
225
-
227
+
226
228
  if (translationY < 0 && top > self.minY) {
227
229
  //向上拖
228
230
  CGFloat y = fmax(top + translationY, self.minY);
@@ -230,7 +232,7 @@
230
232
  [self dispatchOnSlide:self.contentView.frame.origin.y];
231
233
  }
232
234
  }
233
-
235
+
234
236
  if (pan.state == UIGestureRecognizerStateEnded || pan.state == UIGestureRecognizerStateCancelled) {
235
237
  // RCTLogInfo(@"velocity:%f", [pan velocityInView:self.contentView].y);
236
238
  CGFloat velocity = [pan velocityInView:self.contentView].y;
@@ -239,7 +241,7 @@
239
241
  //如果是类似轻扫的那种
240
242
  [self settleToState:RNBottomSheetStateCollapsed withFling:YES];
241
243
  }
242
-
244
+
243
245
  if (!self.target) {
244
246
  //如果是类似轻扫的那种
245
247
  [self settleToState:RNBottomSheetStateCollapsed withFling:YES];
@@ -263,18 +265,18 @@
263
265
  _nextReturn = false;
264
266
  return;
265
267
  }
266
-
268
+
267
269
  if (![keyPath isEqualToString:@"contentOffset"]) {
268
270
  return;
269
271
  }
270
-
272
+
271
273
  CGFloat new = [change[@"new"] CGPointValue].y;
272
274
  CGFloat old = [change[@"old"] CGPointValue].y;
273
275
 
274
276
  if (new == old) {
275
277
  return;
276
278
  }
277
-
279
+
278
280
  CGFloat dy = old - new;
279
281
 
280
282
  if (dy > 0) {
@@ -284,7 +286,7 @@
284
286
  target.contentOffset = CGPointMake(0, 0);
285
287
  }
286
288
  }
287
-
289
+
288
290
  if (dy < 0) {
289
291
  //向上
290
292
  if (self.contentView.frame.origin.y > self.minY) {
@@ -309,17 +311,13 @@
309
311
  self.finalState = state;
310
312
  return;
311
313
  }
312
-
314
+
313
315
  if (self.finalState == state) {
314
316
  return;
315
317
  }
316
-
317
- if (_state == RNBottomSheetStateSettling) {
318
- return;
319
- }
320
-
318
+
321
319
  self.finalState = state;
322
-
320
+
323
321
  [self settleToState:state withFling:YES];
324
322
  }
325
323
 
@@ -337,14 +335,22 @@
337
335
  self.target.pagingEnabled = YES;
338
336
  [self setStateInternal:RNBottomSheetStateSettling];
339
337
  [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:^{
338
+
339
+ if (self.animator) {
340
+ [self.animator stopAnimation:YES];
341
+ }
342
+
343
+ UIViewAnimationOptions options = UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveEaseOut;
344
+
345
+ self.animator = [UIViewPropertyAnimator runningPropertyAnimatorWithDuration:0.3 delay:0 options:options animations:^{
343
346
  self.contentView.frame = CGRectOffset(self.contentView.frame, 0, top - self.contentView.frame.origin.y);
344
- } completion:^(BOOL finished) {
347
+ } completion:^(UIViewAnimatingPosition finalPosition) {
345
348
  self.target.pagingEnabled = NO;
349
+ self.animator = nil;
346
350
  [self stopWatchBottomSheetTransition];
347
- [self setStateInternal:state];
351
+ if (self.finalState == state) {
352
+ [self setStateInternal:state];
353
+ }
348
354
  }];
349
355
  }
350
356
 
@@ -353,19 +359,19 @@
353
359
  return;
354
360
  }
355
361
  _state = state;
356
-
362
+
357
363
  if (state == RNBottomSheetStateExpanded) {
358
364
  [self dispatchOnSlide:self.minY];
359
365
  }
360
-
366
+
361
367
  if (state == RNBottomSheetStateHidden) {
362
368
  [self dispatchOnSlide:self.frame.size.height];
363
369
  }
364
-
370
+
365
371
  if (state == RNBottomSheetStateCollapsed) {
366
372
  [self dispatchOnSlide:self.maxY];
367
373
  }
368
-
374
+
369
375
  if (state == RNBottomSheetStateCollapsed || state == RNBottomSheetStateExpanded || state == RNBottomSheetStateHidden) {
370
376
  [self.eventDispatcher sendEvent:[[RNBottomSheetStateChangedEvent alloc] initWithViewTag:self.reactTag state:state]];
371
377
  }
@@ -397,5 +403,5 @@
397
403
  CGFloat top = [self.contentView.layer presentationLayer].frame.origin.y;
398
404
  [self dispatchOnSlide:top];
399
405
  }
400
-
406
+
401
407
  @end
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.16.0",
4
+ "version": "0.17.0",
5
5
  "main": "./dist/index.js",
6
6
  "typings": "./dist/index.d.ts",
7
7
  "react-native": "src/index",