@swmansion/react-native-bottom-sheet 0.9.5 → 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,20 @@ class BottomSheetView(context: Context) : ReactViewGroup(context) {
260
260
 
261
261
  private fun resolveDetentSpecs(): List<DetentSpec> {
262
262
  val maxHeight = resolvedMaxDetentHeight()
263
- val contentHeight =
264
- validContentHeight().takeIf { it.isFinite() }?.coerceAtMost(maxHeight) ?: maxHeight
265
- 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 ->
266
267
  val height =
267
268
  when (spec.kind) {
268
- DetentKind.POINTS -> spec.value.coerceAtMost(contentHeight)
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
+ }
269
277
  DetentKind.CONTENT -> contentHeight
270
278
  }.coerceIn(0f, maxHeight)
271
279
  DetentSpec(height = height, programmatic = spec.programmatic)
@@ -541,12 +541,21 @@ 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:
549
- height = min(spec.value, contentHeight)
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
+ }
558
+ height = spec.value
550
559
  case .content:
551
560
  height = contentHeight
552
561
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swmansion/react-native-bottom-sheet",
3
- "version": "0.9.5",
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",