@swmansion/react-native-bottom-sheet 0.9.4 → 0.10.0-next.1

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.
@@ -260,12 +260,21 @@ class BottomSheetView(context: Context) : ReactViewGroup(context) {
260
260
 
261
261
  private fun resolveDetentSpecs(): List<DetentSpec> {
262
262
  val maxHeight = resolvedMaxDetentHeight()
263
- val contentHeight = validContentHeight().takeIf { it.isFinite() } ?: maxHeight
264
- return rawDetentSpecs.map { spec ->
263
+ val measuredContentHeight =
264
+ validContentHeight().takeIf { maxHeight > 0f && it.isFinite() }?.coerceAtMost(maxHeight)
265
+ val contentHeight = measuredContentHeight ?: maxHeight
266
+ return rawDetentSpecs.mapIndexed { index, spec ->
265
267
  val height =
266
268
  when (spec.kind) {
267
- DetentKind.POINTS -> spec.value
268
- DetentKind.CONTENT -> contentHeight.coerceAtMost(maxHeight)
269
+ DetentKind.POINTS -> {
270
+ if (measuredContentHeight != null && spec.value > contentHeight) {
271
+ throw IllegalArgumentException(
272
+ "Invalid bottom sheet detent at index $index: fixed detent ${spec.value / density} exceeds measured content height ${contentHeight / density}."
273
+ )
274
+ }
275
+ spec.value
276
+ }
277
+ DetentKind.CONTENT -> contentHeight
269
278
  }.coerceIn(0f, maxHeight)
270
279
  DetentSpec(height = height, programmatic = spec.programmatic)
271
280
  }
@@ -451,6 +460,7 @@ class BottomSheetView(context: Context) : ReactViewGroup(context) {
451
460
  }
452
461
 
453
462
  val targetTy = translationY(index)
463
+ val currentTy = sheetContainer.translationY
454
464
  activeAnimationEmitsSettle = emitSettle
455
465
  activeAnimation?.cancel()
456
466
 
@@ -461,8 +471,8 @@ class BottomSheetView(context: Context) : ReactViewGroup(context) {
461
471
  dampingRatio = SpringForce.DAMPING_RATIO_NO_BOUNCY
462
472
  stiffness = SpringForce.STIFFNESS_MEDIUM
463
473
  }
464
- setMinValue(minDetentTranslationY)
465
- setMaxValue(maxDetentTranslationY)
474
+ setMinValue(minOf(minDetentTranslationY, currentTy, targetTy))
475
+ setMaxValue(maxOf(maxDetentTranslationY, currentTy, targetTy))
466
476
  setStartVelocity(velocity)
467
477
  addEndListener { _, canceled, _, _ ->
468
478
  if (canceled) {
@@ -130,7 +130,7 @@ public final class RNSBottomSheetHostingView: UIView {
130
130
  let indexToApply = pendingIndex ?? targetIndex
131
131
  let clampedIndex = max(0, min(detentSpecs.count - 1, indexToApply))
132
132
 
133
- if animateIn && isInvalidContentDetentTarget(clampedIndex) {
133
+ if animateIn, isInvalidContentDetentTarget(clampedIndex) {
134
134
  targetIndex = clampedIndex
135
135
  pendingIndex = clampedIndex
136
136
  let closedTy = maximumResolvedDetentHeight ?? bounds.height
@@ -541,11 +541,20 @@ public final class RNSBottomSheetHostingView: UIView {
541
541
 
542
542
  private func resolveDetentSpecs() -> [DetentSpec] {
543
543
  let maxHeight = resolvedMaxDetentHeight
544
- let contentHeight = validContentHeight.map { min($0, maxHeight) } ?? maxHeight
545
- return rawDetentSpecs.map { spec in
544
+ let measuredContentHeight = maxHeight > 0 ? validContentHeight.map { min($0, maxHeight) } : nil
545
+ let contentHeight = measuredContentHeight ?? maxHeight
546
+ return rawDetentSpecs.enumerated().map { index, spec in
546
547
  let height: CGFloat
547
548
  switch spec.kind {
548
549
  case .points:
550
+ if measuredContentHeight != nil, spec.value > contentHeight {
551
+ NSException(
552
+ name: NSExceptionName.invalidArgumentException,
553
+ reason:
554
+ "Invalid bottom sheet detent at index \(index): fixed detent \(spec.value) exceeds measured content height \(contentHeight).",
555
+ userInfo: nil
556
+ ).raise()
557
+ }
549
558
  height = spec.value
550
559
  case .content:
551
560
  height = contentHeight
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swmansion/react-native-bottom-sheet",
3
- "version": "0.9.4",
3
+ "version": "0.10.0-next.1",
4
4
  "description": "Provides bottom-sheet components for React Native.",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",