react-native-nitro-modal 0.3.6-rc → 0.3.8-rc
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.
|
@@ -74,6 +74,8 @@ internal class BottomSheetPresenter(
|
|
|
74
74
|
private var lastDetentIndex = -1
|
|
75
75
|
private var reportedRestingTop = Int.MIN_VALUE
|
|
76
76
|
|
|
77
|
+
private var settlingTo = -1
|
|
78
|
+
|
|
77
79
|
/** The behavior is dragging the sheet (as opposed to a nested scroll moving it). */
|
|
78
80
|
private var sheetDragging = false
|
|
79
81
|
|
|
@@ -96,6 +98,8 @@ internal class BottomSheetPresenter(
|
|
|
96
98
|
return
|
|
97
99
|
}
|
|
98
100
|
if (newState == BottomSheetBehavior.STATE_DRAGGING) {
|
|
101
|
+
// The user took over; the behavior picks where it settles.
|
|
102
|
+
settlingTo = -1
|
|
99
103
|
sheetDragging = true
|
|
100
104
|
coordinator.notifyNativeGesture(started = true)
|
|
101
105
|
// A refreshing sheet follows the finger from its lowest detent.
|
|
@@ -106,6 +110,7 @@ internal class BottomSheetPresenter(
|
|
|
106
110
|
}
|
|
107
111
|
val position = states().indexOf(newState)
|
|
108
112
|
if (position < 0 || isDismissing) return
|
|
113
|
+
settlingTo = -1
|
|
109
114
|
presented = true
|
|
110
115
|
// Hideable while entering/exiting; at rest, swipe-to-dismiss follows the prop.
|
|
111
116
|
behavior.isHideable = this@BottomSheetPresenter.config.dismissOnSwipe
|
|
@@ -195,11 +200,12 @@ internal class BottomSheetPresenter(
|
|
|
195
200
|
// Settles with the behavior's own animation, from HIDDEN on show or from
|
|
196
201
|
// wherever a reversed exit got to (back to the detent it left).
|
|
197
202
|
val index = if (lastDetentIndex >= 0) lastDetentIndex else config.clampedInitialDetentIndex
|
|
198
|
-
|
|
203
|
+
settleTo(index)
|
|
199
204
|
}
|
|
200
205
|
}
|
|
201
206
|
|
|
202
207
|
override fun animateOut(fromBackGesture: Boolean, onEnd: () -> Unit) {
|
|
208
|
+
settlingTo = -1
|
|
203
209
|
coordinator.cancelPull()
|
|
204
210
|
if (behavior.state == BottomSheetBehavior.STATE_HIDDEN || !coordinator.isLaidOut) {
|
|
205
211
|
onEnd()
|
|
@@ -261,11 +267,16 @@ internal class BottomSheetPresenter(
|
|
|
261
267
|
|
|
262
268
|
override fun snapToDetent(index: Int) {
|
|
263
269
|
if (!presented || isDismissing) return
|
|
264
|
-
|
|
270
|
+
settleTo(index)
|
|
265
271
|
}
|
|
266
272
|
|
|
267
273
|
override fun onTeardown() = coordinator.release()
|
|
268
274
|
|
|
275
|
+
private fun settleTo(index: Int) {
|
|
276
|
+
settlingTo = index
|
|
277
|
+
behavior.state = stateFor(index)
|
|
278
|
+
}
|
|
279
|
+
|
|
269
280
|
private fun applyAppearance() {
|
|
270
281
|
val radius = activity.dpToPx(config.cornerRadius ?: DEFAULT_CORNER_RADIUS_DP)
|
|
271
282
|
if (radius != cornerRadiusPx) {
|
|
@@ -291,6 +302,7 @@ internal class BottomSheetPresenter(
|
|
|
291
302
|
val bottomInset = systemInsets.bottom
|
|
292
303
|
maxContentHeight = (parentHeight - systemInsets.top - bottomInset).coerceAtLeast(1)
|
|
293
304
|
|
|
305
|
+
val previousHeights = sortedDetents.map { it.height }
|
|
294
306
|
val requested = config.detents.ifEmpty { listOf(Detent.FitContent) }
|
|
295
307
|
val detents = requested
|
|
296
308
|
.mapIndexed { index, detent -> RestingHeight(index, contentHeightFor(detent) + bottomInset) }
|
|
@@ -330,6 +342,16 @@ internal class BottomSheetPresenter(
|
|
|
330
342
|
}
|
|
331
343
|
}
|
|
332
344
|
|
|
345
|
+
// A settle heads for where its detent was when it started, and the
|
|
346
|
+
// behavior only moves a sheet at rest when its detents change: content
|
|
347
|
+
// that grows while the sheet slides in would leave it stopped short.
|
|
348
|
+
// Send the settle to where the detent is now.
|
|
349
|
+
if (heights != previousHeights && settlingTo >= 0 && !isDismissing &&
|
|
350
|
+
behavior.state == BottomSheetBehavior.STATE_SETTLING
|
|
351
|
+
) {
|
|
352
|
+
behavior.state = stateFor(settlingTo)
|
|
353
|
+
}
|
|
354
|
+
|
|
333
355
|
val availableHeight =
|
|
334
356
|
if (Detent.FitContent in requested) maxContentHeight else sheetHeight - bottomInset
|
|
335
357
|
val areaHeight = availableHeight -
|
|
@@ -445,18 +467,31 @@ internal class BottomSheetPresenter(
|
|
|
445
467
|
}
|
|
446
468
|
|
|
447
469
|
/**
|
|
448
|
-
* Gives up dragging the sheet down on nested scrollable content
|
|
449
|
-
*
|
|
450
|
-
* a new gesture collapses the sheet.
|
|
470
|
+
* Gives up dragging the sheet down on nested scrollable content that can
|
|
471
|
+
* still scroll up, or that scrolled during the gesture: it scrolls back to
|
|
472
|
+
* its top, and only a new gesture collapses the sheet.
|
|
473
|
+
*
|
|
474
|
+
* The behavior asks the nested scroll's target whether it can scroll up,
|
|
475
|
+
* but the target may only wrap the scroll view: a ScrollView with a
|
|
476
|
+
* RefreshControl reports its SwipeRefreshLayout, which never scrolls
|
|
477
|
+
* itself. The views under the finger are asked instead.
|
|
451
478
|
*/
|
|
452
479
|
private inner class SheetBehavior : BottomSheetBehavior<FrameLayout>() {
|
|
453
480
|
private var contentScrolled = false
|
|
454
481
|
|
|
482
|
+
/** Where the gesture started, in the sheet's coordinates. */
|
|
483
|
+
private var downX = 0f
|
|
484
|
+
private var downY = 0f
|
|
485
|
+
|
|
455
486
|
override fun onInterceptTouchEvent(parent: CoordinatorLayout, child: FrameLayout, event: MotionEvent): Boolean {
|
|
456
|
-
if (event.actionMasked == MotionEvent.ACTION_DOWN
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
487
|
+
if (event.actionMasked == MotionEvent.ACTION_DOWN) {
|
|
488
|
+
downX = event.x - child.left - child.translationX
|
|
489
|
+
downY = event.y - child.top - child.translationY
|
|
490
|
+
if (state in states()) {
|
|
491
|
+
// React may have mounted the scrollable content after the last layout
|
|
492
|
+
// pass; laying out again re-finds it. The resting sheet doesn't move.
|
|
493
|
+
onLayoutChild(parent, child, parent.layoutDirection)
|
|
494
|
+
}
|
|
460
495
|
}
|
|
461
496
|
return super.onInterceptTouchEvent(parent, child, event)
|
|
462
497
|
}
|
|
@@ -482,7 +517,7 @@ internal class BottomSheetPresenter(
|
|
|
482
517
|
consumed: IntArray,
|
|
483
518
|
type: Int,
|
|
484
519
|
) {
|
|
485
|
-
if (dy < 0 && contentScrolled) return
|
|
520
|
+
if (dy < 0 && (contentScrolled || canScrollUpAt(child, downX, downY))) return
|
|
486
521
|
super.onNestedPreScroll(coordinatorLayout, child, target, dx, dy, consumed, type)
|
|
487
522
|
}
|
|
488
523
|
|