@swmansion/react-native-bottom-sheet 0.10.0-next.4 → 0.10.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.
@@ -3,6 +3,7 @@
3
3
  #import "../common/cpp/react/renderer/components/ReactNativeBottomSheetSpec/BottomSheetStateHelper.h"
4
4
  #import "../common/cpp/react/renderer/components/ReactNativeBottomSheetSpec/ComponentDescriptors.h"
5
5
 
6
+ #import <React/RCTAssert.h>
6
7
  #import <React/RCTConversions.h>
7
8
  #import <React/RCTFabricComponentsPlugins.h>
8
9
  #import <react/renderer/components/ReactNativeBottomSheetSpec/EventEmitters.h>
@@ -138,6 +139,11 @@ using namespace facebook::react;
138
139
  }
139
140
  }
140
141
 
142
+ - (void)bottomSheetView:(BottomSheetContentView *)view didReportError:(NSString *)message
143
+ {
144
+ RCTFatal([NSError errorWithDomain:RCTErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey : message}]);
145
+ }
146
+
141
147
  - (void)prepareForRecycle
142
148
  {
143
149
  [super prepareForRecycle];
@@ -8,6 +8,7 @@ NS_ASSUME_NONNULL_BEGIN
8
8
  - (void)bottomSheetView:(BottomSheetContentView *)view didChangeIndex:(NSInteger)index;
9
9
  - (void)bottomSheetView:(BottomSheetContentView *)view didSettle:(NSInteger)index;
10
10
  - (void)bottomSheetView:(BottomSheetContentView *)view didChangePosition:(CGFloat)position;
11
+ - (void)bottomSheetView:(BottomSheetContentView *)view didReportError:(NSString *)message;
11
12
  @end
12
13
 
13
14
  @interface BottomSheetContentView : UIView
@@ -115,6 +115,11 @@
115
115
  [self.delegate bottomSheetView:self didChangePosition:position];
116
116
  }
117
117
 
118
+ - (void)bottomSheetHostingView:(RNSBottomSheetHostingView *)view didReportError:(NSString *)message
119
+ {
120
+ [self.delegate bottomSheetView:self didReportError:message];
121
+ }
122
+
118
123
  - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
119
124
  {
120
125
  CGPoint implPoint = [self convertPoint:point toView:_impl];
@@ -4,6 +4,7 @@ import UIKit
4
4
  func bottomSheetHostingView(_ view: RNSBottomSheetHostingView, didChangeIndex index: Int)
5
5
  func bottomSheetHostingView(_ view: RNSBottomSheetHostingView, didSettle index: Int)
6
6
  func bottomSheetHostingView(_ view: RNSBottomSheetHostingView, didChangePosition position: CGFloat)
7
+ func bottomSheetHostingView(_ view: RNSBottomSheetHostingView, didReportError message: String)
7
8
  }
8
9
 
9
10
  private struct DetentSpec: Equatable {
@@ -60,6 +61,7 @@ public final class RNSBottomSheetHostingView: UIView {
60
61
  private var pendingIndex: Int?
61
62
  private var hasLaidOut = false
62
63
  private var isPanning = false
64
+ private var lastReportedInvalidDetentMessage: String?
63
65
  private var panStartingIndex: Int?
64
66
  private var isContentInteractionDisabled = false
65
67
  private var contentHeightMarker: UIView?
@@ -578,28 +580,35 @@ public final class RNSBottomSheetHostingView: UIView {
578
580
  detentSpecs.map(\.height).max()
579
581
  }
580
582
 
581
- private func resolveDetentSpecs() -> [DetentSpec] {
583
+ private func resolveDetentSpecs() -> [DetentSpec]? {
582
584
  let maxHeight = resolvedMaxDetentHeight
583
585
  let measuredContentHeight = maxHeight > 0 ? validContentHeight.map { min($0, maxHeight) } : nil
584
586
  let contentHeight = measuredContentHeight ?? maxHeight
585
- return rawDetentSpecs.enumerated().map { index, spec in
587
+ var resolvedDetents: [DetentSpec] = []
588
+ resolvedDetents.reserveCapacity(rawDetentSpecs.count)
589
+
590
+ for (index, spec) in rawDetentSpecs.enumerated() {
586
591
  let height: CGFloat
587
592
  switch spec.kind {
588
593
  case .points:
589
594
  if measuredContentHeight != nil, spec.value > contentHeight {
590
- NSException(
591
- name: NSExceptionName.invalidArgumentException,
592
- reason:
593
- "Invalid bottom sheet detent at index \(index): fixed detent \(spec.value) exceeds measured content height \(contentHeight).",
594
- userInfo: nil
595
- ).raise()
595
+ let message =
596
+ "Invalid bottom sheet detent at index \(index): fixed detent \(spec.value) exceeds measured content height \(contentHeight)."
597
+ if lastReportedInvalidDetentMessage != message {
598
+ lastReportedInvalidDetentMessage = message
599
+ eventDelegate?.bottomSheetHostingView(self, didReportError: message)
600
+ }
601
+ return nil
596
602
  }
597
603
  height = spec.value
598
604
  case .content:
599
605
  height = contentHeight
600
606
  }
601
- return DetentSpec(height: min(max(0, height), maxHeight), programmatic: spec.programmatic)
607
+ resolvedDetents.append(DetentSpec(height: min(max(0, height), maxHeight), programmatic: spec.programmatic))
602
608
  }
609
+
610
+ lastReportedInvalidDetentMessage = nil
611
+ return resolvedDetents
603
612
  }
604
613
 
605
614
  private func refreshDetentsFromLayout() {
@@ -609,7 +618,10 @@ public final class RNSBottomSheetHostingView: UIView {
609
618
  return
610
619
  }
611
620
 
612
- let resolvedDetents = resolveDetentSpecs()
621
+ guard let resolvedDetents = resolveDetentSpecs() else {
622
+ updateScrim()
623
+ return
624
+ }
613
625
  guard resolvedDetents != detentSpecs else {
614
626
  updateScrim()
615
627
  return
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swmansion/react-native-bottom-sheet",
3
- "version": "0.10.0-next.4",
3
+ "version": "0.10.0-next.5",
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",