@swmansion/react-native-bottom-sheet 0.15.0-next.4 → 0.15.0-next.5
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.
|
@@ -4,7 +4,6 @@ import android.content.Context
|
|
|
4
4
|
import android.graphics.Canvas
|
|
5
5
|
import android.graphics.Color
|
|
6
6
|
import android.graphics.Paint
|
|
7
|
-
import android.view.Choreographer
|
|
8
7
|
import android.view.MotionEvent
|
|
9
8
|
import android.view.VelocityTracker
|
|
10
9
|
import android.view.View
|
|
@@ -71,7 +70,6 @@ class BottomSheetView(context: Context) : ReactViewGroup(context) {
|
|
|
71
70
|
private var activeAnimation: SpringAnimation? = null
|
|
72
71
|
private var activeAnimationEmitsSettle = false
|
|
73
72
|
private var velocityTracker: VelocityTracker? = null
|
|
74
|
-
private var choreographerCallback: Choreographer.FrameCallback? = null
|
|
75
73
|
private val density = context.resources.displayMetrics.density
|
|
76
74
|
private val touchSlop = ViewConfiguration.get(context).scaledTouchSlop
|
|
77
75
|
|
|
@@ -94,7 +92,9 @@ class BottomSheetView(context: Context) : ReactViewGroup(context) {
|
|
|
94
92
|
private var surfaceView: View? = null
|
|
95
93
|
|
|
96
94
|
private val contentHeightMarkerLayoutListener =
|
|
97
|
-
View.OnLayoutChangeListener { _, _, _, _, _, _, _, _, _ ->
|
|
95
|
+
View.OnLayoutChangeListener { _, _, _, _, _, _, _, _, _ ->
|
|
96
|
+
refreshDetentsFromLayout()
|
|
97
|
+
}
|
|
98
98
|
|
|
99
99
|
init {
|
|
100
100
|
clipChildren = false
|
|
@@ -226,17 +226,16 @@ class BottomSheetView(context: Context) : ReactViewGroup(context) {
|
|
|
226
226
|
// MARK: - Prop setters
|
|
227
227
|
|
|
228
228
|
fun setDetents(raw: List<Map<String, Any>>) {
|
|
229
|
-
rawDetentSpecs =
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
}
|
|
229
|
+
rawDetentSpecs = raw.mapNotNull { dict ->
|
|
230
|
+
val value = (dict["value"] as? Number)?.toDouble() ?: return@mapNotNull null
|
|
231
|
+
val kind =
|
|
232
|
+
when ((dict["kind"] as? String)?.lowercase()) {
|
|
233
|
+
"content" -> DetentKind.CONTENT
|
|
234
|
+
else -> DetentKind.POINTS
|
|
235
|
+
}
|
|
236
|
+
val programmatic = dict["programmatic"] as? Boolean ?: false
|
|
237
|
+
RawDetentSpec(value = (value * density).toFloat(), kind = kind, programmatic = programmatic)
|
|
238
|
+
}
|
|
240
239
|
refreshDetentsFromLayout()
|
|
241
240
|
}
|
|
242
241
|
|
|
@@ -342,7 +341,6 @@ class BottomSheetView(context: Context) : ReactViewGroup(context) {
|
|
|
342
341
|
activeAnimation?.cancel()
|
|
343
342
|
activeAnimation = null
|
|
344
343
|
activeAnimationEmitsSettle = false
|
|
345
|
-
stopChoreographer()
|
|
346
344
|
// Re-anchor the in-flight position to the new container height so the
|
|
347
345
|
// sheet surface keeps the same on-screen height across the resize.
|
|
348
346
|
val visibleHeight = previousMaxHeight - currentTy
|
|
@@ -513,26 +511,6 @@ class BottomSheetView(context: Context) : ReactViewGroup(context) {
|
|
|
513
511
|
sw.updateState(map)
|
|
514
512
|
}
|
|
515
513
|
|
|
516
|
-
// MARK: - Choreographer (position tracking during animation)
|
|
517
|
-
|
|
518
|
-
private fun startChoreographer() {
|
|
519
|
-
if (choreographerCallback != null) return
|
|
520
|
-
val callback =
|
|
521
|
-
object : Choreographer.FrameCallback {
|
|
522
|
-
override fun doFrame(frameTimeNanos: Long) {
|
|
523
|
-
emitPosition()
|
|
524
|
-
choreographerCallback?.let { Choreographer.getInstance().postFrameCallback(it) }
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
choreographerCallback = callback
|
|
528
|
-
Choreographer.getInstance().postFrameCallback(callback)
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
private fun stopChoreographer() {
|
|
532
|
-
choreographerCallback?.let { Choreographer.getInstance().removeFrameCallback(it) }
|
|
533
|
-
choreographerCallback = null
|
|
534
|
-
}
|
|
535
|
-
|
|
536
514
|
// MARK: - Spring animation
|
|
537
515
|
|
|
538
516
|
private fun snapToIndex(
|
|
@@ -566,11 +544,15 @@ class BottomSheetView(context: Context) : ReactViewGroup(context) {
|
|
|
566
544
|
setMinValue(minOf(minDetentTranslationY, currentTy, targetTy))
|
|
567
545
|
setMaxValue(maxOf(maxDetentTranslationY, currentTy, targetTy))
|
|
568
546
|
setStartVelocity(velocity)
|
|
547
|
+
// Forward the position on every frame of the settle. The listener fires
|
|
548
|
+
// immediately after the spring writes `translationY`, so `emitPosition`
|
|
549
|
+
// reads the value being shown this frame — keeping followers that track
|
|
550
|
+
// `onPositionChange` (e.g. a Reanimated view) in lockstep with the sheet.
|
|
551
|
+
addUpdateListener { _, _, _ -> emitPosition() }
|
|
569
552
|
addEndListener { _, canceled, _, _ ->
|
|
570
553
|
if (canceled) {
|
|
571
554
|
return@addEndListener
|
|
572
555
|
}
|
|
573
|
-
stopChoreographer()
|
|
574
556
|
activeAnimation = null
|
|
575
557
|
activeAnimationEmitsSettle = false
|
|
576
558
|
suppressScrimForClosingTarget = false
|
|
@@ -586,7 +568,6 @@ class BottomSheetView(context: Context) : ReactViewGroup(context) {
|
|
|
586
568
|
}
|
|
587
569
|
|
|
588
570
|
activeAnimation = spring
|
|
589
|
-
startChoreographer()
|
|
590
571
|
// Report the index change as soon as the snap is committed, not when it
|
|
591
572
|
// finishes: targetIndex is already set, and a programmatic snap's start is
|
|
592
573
|
// known to the caller. onSettle remains the signal for movement end.
|
|
@@ -777,7 +758,6 @@ class BottomSheetView(context: Context) : ReactViewGroup(context) {
|
|
|
777
758
|
activeAnimation?.let {
|
|
778
759
|
it.cancel()
|
|
779
760
|
activeAnimation = null
|
|
780
|
-
stopChoreographer()
|
|
781
761
|
}
|
|
782
762
|
}
|
|
783
763
|
|
|
@@ -850,7 +830,6 @@ class BottomSheetView(context: Context) : ReactViewGroup(context) {
|
|
|
850
830
|
fun destroy() {
|
|
851
831
|
activeAnimation?.cancel()
|
|
852
832
|
activeAnimation = null
|
|
853
|
-
stopChoreographer()
|
|
854
833
|
velocityTracker?.recycle()
|
|
855
834
|
velocityTracker = null
|
|
856
835
|
contentHeightMarker?.removeOnLayoutChangeListener(contentHeightMarkerLayoutListener)
|
package/package.json
CHANGED