react-native-sheet2 6.1.18 → 7.12.4

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.
Files changed (110) hide show
  1. package/README.md +754 -80
  2. package/{Sheet.podspec → Sheet2.podspec} +2 -2
  3. package/android/build.gradle +2 -25
  4. package/android/check.jks +0 -0
  5. package/android/src/main/AndroidManifest.xml +1 -2
  6. package/android/src/main/cpp/react/renderer/components/SheetViewSpec/SheetViewComponentDescriptor.h +12 -0
  7. package/android/src/main/cpp/react/renderer/components/SheetViewSpec/SheetViewShadowNode.cpp +17 -0
  8. package/android/src/main/cpp/react/renderer/components/SheetViewSpec/SheetViewShadowNode.h +36 -0
  9. package/android/src/main/cpp/react/renderer/components/SheetViewSpec/SheetViewState.h +52 -0
  10. package/android/src/main/java/com/behavior/BottomSheetBehavior.java +84 -16
  11. package/android/src/main/java/com/sheet2/AppFittedSheet.kt +431 -0
  12. package/android/src/main/java/com/{sheet → sheet2}/BaseRNView.kt +38 -31
  13. package/android/src/main/java/com/sheet2/CenteredSheetDialog.kt +272 -0
  14. package/android/src/main/java/com/{sheet → sheet2}/CustomBottomSheetDialog.java +32 -4
  15. package/android/src/main/java/com/{sheet → sheet2}/DialogRootViewGroup.kt +54 -12
  16. package/android/src/main/java/com/sheet2/FragmentModalBottomSheet.kt +161 -0
  17. package/android/src/main/java/com/sheet2/InlineFooterPresenter.kt +74 -0
  18. package/android/src/main/java/com/sheet2/InlineSheetPresenter.kt +249 -0
  19. package/android/src/main/java/com/sheet2/PassThroughLayouts.kt +17 -0
  20. package/android/src/main/java/com/{sheet → sheet2}/SafeAreaUtils.kt +4 -5
  21. package/android/src/main/java/com/sheet2/Sheet2Package.kt +44 -0
  22. package/android/src/main/java/com/sheet2/Sheet2View.kt +5 -0
  23. package/android/src/main/java/com/sheet2/Sheet2ViewManager.kt +163 -0
  24. package/android/src/main/java/com/{sheet → sheet2}/SheetDismissEvent.kt +1 -1
  25. package/android/src/main/java/com/{sheet → sheet2}/SheetModule.kt +14 -3
  26. package/android/src/main/java/com/{sheet → sheet2}/SheetPackage.kt +2 -3
  27. package/android/src/main/java/com/sheet2/SheetTreeLog.kt +78 -0
  28. package/android/src/main/java/com/{sheet → sheet2}/utils.kt +1 -2
  29. package/android/src/main/jni/CMakeLists.txt +72 -0
  30. package/android/src/main/jni/SheetViewSpec.h +40 -0
  31. package/ios/FittedSheets/SheetOptions.swift +5 -0
  32. package/ios/FittedSheets/SheetTransition.swift +83 -4
  33. package/ios/FittedSheets/SheetViewController.swift +222 -24
  34. package/ios/HostFittedSheet.swift +440 -51
  35. package/ios/SheetModule.h +5 -4
  36. package/ios/SheetModule.mm +11 -1
  37. package/ios/SheetTreeLog.swift +52 -0
  38. package/ios/SheetView.mm +118 -31
  39. package/ios/SheetViewComponentDescriptor.h +24 -0
  40. package/ios/SheetViewShadowNode.cpp +17 -0
  41. package/ios/SheetViewShadowNode.h +37 -0
  42. package/ios/SheetViewState.h +54 -0
  43. package/package.json +44 -74
  44. package/react-native.config.js +6 -4
  45. package/src/FittedSheet.tsx +131 -71
  46. package/src/GlobalSheetView.tsx +209 -0
  47. package/src/NativeSheet.ts +4 -0
  48. package/src/PublicSheetView.tsx +2 -1
  49. package/src/SheetTreeLog.ts +39 -0
  50. package/src/SheetViewNativeComponent.ts +25 -4
  51. package/src/index.tsx +34 -4
  52. package/src/logger.ts +16 -0
  53. package/android/generated/java/com/facebook/react/viewmanagers/SheetViewManagerDelegate.java +0 -67
  54. package/android/generated/java/com/facebook/react/viewmanagers/SheetViewManagerInterface.java +0 -27
  55. package/android/generated/java/com/sheet/NativeSheetSpec.java +0 -78
  56. package/android/generated/jni/CMakeLists.txt +0 -36
  57. package/android/generated/jni/RNSheetViewSpec-generated.cpp +0 -50
  58. package/android/generated/jni/RNSheetViewSpec.h +0 -31
  59. package/android/generated/jni/react/renderer/components/RNSheetViewSpec/ComponentDescriptors.cpp +0 -22
  60. package/android/generated/jni/react/renderer/components/RNSheetViewSpec/ComponentDescriptors.h +0 -24
  61. package/android/generated/jni/react/renderer/components/RNSheetViewSpec/EventEmitters.cpp +0 -24
  62. package/android/generated/jni/react/renderer/components/RNSheetViewSpec/EventEmitters.h +0 -25
  63. package/android/generated/jni/react/renderer/components/RNSheetViewSpec/Props.cpp +0 -33
  64. package/android/generated/jni/react/renderer/components/RNSheetViewSpec/Props.h +0 -36
  65. package/android/generated/jni/react/renderer/components/RNSheetViewSpec/RNSheetViewSpecJSI-generated.cpp +0 -46
  66. package/android/generated/jni/react/renderer/components/RNSheetViewSpec/RNSheetViewSpecJSI.h +0 -98
  67. package/android/generated/jni/react/renderer/components/RNSheetViewSpec/ShadowNodes.cpp +0 -17
  68. package/android/generated/jni/react/renderer/components/RNSheetViewSpec/ShadowNodes.h +0 -32
  69. package/android/generated/jni/react/renderer/components/RNSheetViewSpec/States.cpp +0 -16
  70. package/android/generated/jni/react/renderer/components/RNSheetViewSpec/States.h +0 -29
  71. package/android/src/main/AndroidManifestNew.xml +0 -2
  72. package/android/src/main/java/com/sheet/AppFittedSheet.kt +0 -214
  73. package/android/src/main/java/com/sheet/FragmentModalBottomSheet.kt +0 -67
  74. package/android/src/main/java/com/sheet/SheetView.kt +0 -5
  75. package/android/src/main/java/com/sheet/SheetViewManager.kt +0 -106
  76. package/ios/generated/RNSheetViewSpec/ComponentDescriptors.cpp +0 -22
  77. package/ios/generated/RNSheetViewSpec/ComponentDescriptors.h +0 -24
  78. package/ios/generated/RNSheetViewSpec/EventEmitters.cpp +0 -24
  79. package/ios/generated/RNSheetViewSpec/EventEmitters.h +0 -25
  80. package/ios/generated/RNSheetViewSpec/Props.cpp +0 -33
  81. package/ios/generated/RNSheetViewSpec/Props.h +0 -36
  82. package/ios/generated/RNSheetViewSpec/RCTComponentViewHelpers.h +0 -44
  83. package/ios/generated/RNSheetViewSpec/RNSheetViewSpec-generated.mm +0 -60
  84. package/ios/generated/RNSheetViewSpec/RNSheetViewSpec.h +0 -100
  85. package/ios/generated/RNSheetViewSpec/ShadowNodes.cpp +0 -17
  86. package/ios/generated/RNSheetViewSpec/ShadowNodes.h +0 -32
  87. package/ios/generated/RNSheetViewSpec/States.cpp +0 -16
  88. package/ios/generated/RNSheetViewSpec/States.h +0 -29
  89. package/ios/generated/RNSheetViewSpecJSI-generated.cpp +0 -46
  90. package/ios/generated/RNSheetViewSpecJSI.h +0 -98
  91. package/lib/module/FittedSheet.js +0 -153
  92. package/lib/module/FittedSheet.js.map +0 -1
  93. package/lib/module/NativeSheet.ts +0 -17
  94. package/lib/module/PublicSheetView.js +0 -48
  95. package/lib/module/PublicSheetView.js.map +0 -1
  96. package/lib/module/SheetViewNativeComponent.ts +0 -31
  97. package/lib/module/index.js +0 -13
  98. package/lib/module/index.js.map +0 -1
  99. package/lib/module/package.json +0 -1
  100. package/lib/typescript/package.json +0 -1
  101. package/lib/typescript/src/FittedSheet.d.ts +0 -51
  102. package/lib/typescript/src/FittedSheet.d.ts.map +0 -1
  103. package/lib/typescript/src/NativeSheet.d.ts +0 -16
  104. package/lib/typescript/src/NativeSheet.d.ts.map +0 -1
  105. package/lib/typescript/src/PublicSheetView.d.ts +0 -12
  106. package/lib/typescript/src/PublicSheetView.d.ts.map +0 -1
  107. package/lib/typescript/src/SheetViewNativeComponent.d.ts +0 -22
  108. package/lib/typescript/src/SheetViewNativeComponent.d.ts.map +0 -1
  109. package/lib/typescript/src/index.d.ts +0 -8
  110. package/lib/typescript/src/index.d.ts.map +0 -1
@@ -0,0 +1,72 @@
1
+ cmake_minimum_required(VERSION 3.13)
2
+ set(CMAKE_VERBOSE_MAKEFILE ON)
3
+
4
+ # The React Native gradle plugin uses the codegen name of the library
5
+ # (`codegenConfig.name` in package.json = `SheetViewSpec`) as the build-target
6
+ # stem and expects a library target called `react_codegen_SheetViewSpec`.
7
+ # Our custom CMakeLists replaces the auto-generated one so we can compile
8
+ # our custom C++ sources alongside the codegen-produced files AND put our
9
+ # `jni/` directory earlier in the include path (this shadows the default
10
+ # `<SheetViewSpec.h>` and `<react/renderer/components/SheetViewSpec/...>`
11
+ # headers generated by codegen when they would otherwise pull in the
12
+ # default-typedef ShadowNode).
13
+ set(LIB_LITERAL SheetViewSpec)
14
+ set(LIB_TARGET_NAME react_codegen_${LIB_LITERAL})
15
+
16
+ set(LIB_ANDROID_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
17
+ set(LIB_CUSTOM_CPP_DIR ${LIB_ANDROID_DIR}/src/main/cpp)
18
+ set(LIB_CUSTOM_COMPONENTS_DIR
19
+ ${LIB_CUSTOM_CPP_DIR}/react/renderer/components/${LIB_LITERAL})
20
+ set(LIB_ANDROID_GENERATED_JNI_DIR
21
+ ${LIB_ANDROID_DIR}/build/generated/source/codegen/jni)
22
+ set(LIB_ANDROID_GENERATED_COMPONENTS_DIR
23
+ ${LIB_ANDROID_GENERATED_JNI_DIR}/react/renderer/components/${LIB_LITERAL})
24
+
25
+ add_compile_options(
26
+ -fexceptions
27
+ -frtti
28
+ -std=c++20
29
+ -Wall
30
+ -Wpedantic
31
+ -Wno-gnu-zero-variadic-macro-arguments
32
+ )
33
+
34
+ file(GLOB LIB_CUSTOM_SRCS CONFIGURE_DEPENDS
35
+ ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp
36
+ ${LIB_CUSTOM_COMPONENTS_DIR}/*.cpp
37
+ )
38
+
39
+ file(GLOB LIB_CODEGEN_SRCS CONFIGURE_DEPENDS
40
+ ${LIB_ANDROID_GENERATED_JNI_DIR}/*.cpp
41
+ ${LIB_ANDROID_GENERATED_COMPONENTS_DIR}/*.cpp
42
+ )
43
+
44
+ add_library(
45
+ ${LIB_TARGET_NAME}
46
+ SHARED
47
+ ${LIB_CUSTOM_SRCS}
48
+ ${LIB_CODEGEN_SRCS}
49
+ )
50
+
51
+ # Order matters: our `jni` and `cpp` dirs must come BEFORE the codegen
52
+ # generated directory so our custom `SheetViewSpec.h` shadows the generated
53
+ # one and our custom component-descriptor include path wins.
54
+ target_include_directories(
55
+ ${LIB_TARGET_NAME}
56
+ PUBLIC
57
+ ${CMAKE_CURRENT_SOURCE_DIR}
58
+ ${LIB_CUSTOM_CPP_DIR}
59
+ ${LIB_ANDROID_GENERATED_JNI_DIR}
60
+ ${LIB_ANDROID_GENERATED_COMPONENTS_DIR}
61
+ )
62
+
63
+ target_link_libraries(
64
+ ${LIB_TARGET_NAME}
65
+ ReactAndroid::reactnative
66
+ ReactAndroid::jsi
67
+ fbjni::fbjni
68
+ )
69
+
70
+ if(COMMAND target_compile_reactnative_options)
71
+ target_compile_reactnative_options(${LIB_TARGET_NAME} PRIVATE)
72
+ endif()
@@ -0,0 +1,40 @@
1
+ #pragma once
2
+
3
+ #include <ReactCommon/JavaTurboModule.h>
4
+ #include <ReactCommon/TurboModule.h>
5
+ #include <jsi/jsi.h>
6
+
7
+ /**
8
+ * Custom autolinking header for the SheetViewSpec library.
9
+ *
10
+ * The React Native gradle plugin generates a default `SheetViewSpec.h` at
11
+ * `android/build/generated/source/codegen/jni/SheetViewSpec.h`. By configuring
12
+ * our own `CMakeLists.txt` with an include directory that comes BEFORE the
13
+ * generated one, `autolinking.cpp` finds this file first and therefore sees
14
+ * our custom `SheetViewComponentDescriptor` declaration — which is defined in
15
+ * the library's `common/cpp` area and subclasses the codegen-provided
16
+ * ViewShadowNode with a custom `getContentOriginOffset` override.
17
+ *
18
+ * See react-native-screens' `rnscreens.h` for the same pattern.
19
+ */
20
+ #include <react/renderer/components/SheetViewSpec/SheetViewComponentDescriptor.h>
21
+
22
+ namespace facebook::react {
23
+
24
+ /**
25
+ * TurboModule provider declaration — codegen generates the implementation at
26
+ * `build/generated/source/codegen/jni/SheetViewSpec-generated.cpp`; we only
27
+ * repeat the prototype here so that consumers of this header (autolinking.cpp)
28
+ * can resolve both our ComponentDescriptor include AND the TurboModule symbol.
29
+ */
30
+ JSI_EXPORT
31
+ std::shared_ptr<TurboModule> SheetViewSpec_ModuleProvider(
32
+ const std::string& moduleName,
33
+ const JavaTurboModule::InitParams& params);
34
+
35
+ class JSI_EXPORT NativeSheetSpecJSI : public JavaTurboModule {
36
+ public:
37
+ NativeSheetSpecJSI(const JavaTurboModule::InitParams& params);
38
+ };
39
+
40
+ } // namespace facebook::react
@@ -44,6 +44,11 @@ public struct SheetOptions {
44
44
  public var horizontalPadding: CGFloat = 0
45
45
  public var maxWidth: CGFloat?
46
46
 
47
+ /// Present the sheet centered on screen instead of pinned to the bottom.
48
+ public var centered: Bool = false
49
+ /// When `centered`, slide the card up into place instead of fade+scale.
50
+ public var centerSlide: Bool = false
51
+
47
52
  public var isRubberBandEnabled: Bool = false
48
53
 
49
54
  /// Experimental flag that attempts to shrink the nested presentations more each time a new sheet is presented. This must be set before any sheet is presented.
@@ -50,15 +50,77 @@ public class SheetTransition: NSObject, UIViewControllerAnimatedTransitioning {
50
50
  sheet.contentViewController.updatePreferredHeight()
51
51
  sheet.resize(to: sheet.currentSize, animated: false)
52
52
  let contentView = sheet.contentViewController.contentView
53
+
54
+ if self.options.centered && !self.options.centerSlide {
55
+ // Centered fade: the card is centered by constraint, so fade +
56
+ // scale it in (0.9 -> 1.0) and fade the overlay in.
57
+ contentView.transform = CGAffineTransform(scaleX: 0.9, y: 0.9)
58
+ contentView.alpha = 0
59
+ sheet.overlayView.alpha = 0
60
+
61
+ UIView.performWithoutAnimation {
62
+ sheet.view.layoutIfNeeded()
63
+ }
64
+
65
+ UIView.animate(
66
+ withDuration: self.options.transitionDuration,
67
+ delay: 0,
68
+ options: [.curveEaseOut],
69
+ animations: {
70
+ contentView.transform = .identity
71
+ contentView.alpha = 1
72
+ sheet.overlayView.alpha = 1
73
+ },
74
+ completion: { _ in
75
+ transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
76
+ }
77
+ )
78
+ return
79
+ }
80
+
81
+ if self.options.centered {
82
+ // Centered slide: start the card fully below the bottom edge and
83
+ // slide it up into its centered resting position — symmetric with
84
+ // the centered dismiss (which slides it back down off the bottom).
85
+ // The offset is measured AFTER layout so it never reads a stale or
86
+ // zero height; reading it before layout was making the slide
87
+ // collapse into a fade on some presentations ("every other time").
88
+ UIView.performWithoutAnimation {
89
+ sheet.view.layoutIfNeeded()
90
+ }
91
+ let cardTop = contentView.convert(contentView.bounds, to: sheet.view).minY
92
+ let startOffset = max(contentView.bounds.height, sheet.view.bounds.height - cardTop)
93
+ contentView.transform = CGAffineTransform(translationX: 0, y: startOffset)
94
+ sheet.overlayView.alpha = 0
95
+
96
+ UIView.animate(
97
+ withDuration: self.options.transitionDuration,
98
+ delay: 0,
99
+ usingSpringWithDamping: 0.9,
100
+ initialSpringVelocity: 0,
101
+ options: [.curveEaseOut],
102
+ animations: {
103
+ contentView.transform = .identity
104
+ sheet.overlayView.alpha = 1
105
+ },
106
+ completion: { _ in
107
+ transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
108
+ }
109
+ )
110
+ return
111
+ }
112
+
113
+ // Slide-up (bottom presentation). For centered mode the branch above
114
+ // handles the slide; this is the original bottom-sheet path.
53
115
  contentView.transform = CGAffineTransform(translationX: 0, y: contentView.bounds.height)
54
116
  sheet.overlayView.alpha = 0
55
-
117
+
56
118
  let heightPercent = contentView.bounds.height / UIScreen.main.bounds.height
57
-
119
+
58
120
  UIView.performWithoutAnimation {
59
121
  sheet.view.layoutIfNeeded()
60
122
  }
61
-
123
+
62
124
  // Use a normal animation to animate the shadown and background view
63
125
  UIView.animate(withDuration: self.options.transitionDuration * 0.6, delay: 0, options: [.curveEaseOut], animations: {
64
126
  if self.options.shrinkPresentingViewController {
@@ -91,10 +153,27 @@ public class SheetTransition: NSObject, UIViewControllerAnimatedTransitioning {
91
153
  containerView.addSubview(sheet.view)
92
154
  let contentView = sheet.contentViewController.contentView
93
155
 
156
+ let dismissTransform: CGAffineTransform
157
+ if self.options.centered {
158
+ // The card sits in the vertical center, so translating it down
159
+ // by only its own height leaves it stranded mid-screen while the
160
+ // overlay has already faded out. Instead slide it all the way
161
+ // off the bottom of the screen — exactly like the bottom sheet —
162
+ // so the dim and the card leave the screen together. The offset
163
+ // is measured from the card's CURRENT on-screen top (which
164
+ // already includes any swipe-drag transform), so a pan-initiated
165
+ // dismiss continues smoothly from the finger's position.
166
+ let cardTop = contentView.convert(contentView.bounds, to: sheet.view).minY
167
+ let offset = max(contentView.bounds.height, sheet.view.bounds.height - cardTop)
168
+ dismissTransform = CGAffineTransform(translationX: 0, y: offset)
169
+ } else {
170
+ dismissTransform = CGAffineTransform(translationX: 0, y: contentView.bounds.height)
171
+ }
172
+
94
173
  self.restorePresentor(
95
174
  presenter,
96
175
  animations: {
97
- contentView.transform = CGAffineTransform(translationX: 0, y: contentView.bounds.height)
176
+ contentView.transform = dismissTransform
98
177
  sheet.overlayView.alpha = 0
99
178
  }, completion: { _ in
100
179
  transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
@@ -146,7 +146,7 @@ public class SheetViewController: UIViewController {
146
146
  var overflowView = UIView()
147
147
  var overlayTapGesture: UITapGestureRecognizer?
148
148
  private var contentViewHeightConstraint: NSLayoutConstraint!
149
- private var contentViewWidthConstraint: NSLayoutConstraint!
149
+ private var contentViewWidthConstraint: NSLayoutConstraint?
150
150
 
151
151
  /// The child view controller's scroll view we are watching so we can override the pull down/up to work on the sheet when needed
152
152
  private weak var childScrollView: UIScrollView?
@@ -158,6 +158,13 @@ public class SheetViewController: UIViewController {
158
158
  private var prePanHeight: CGFloat = 0
159
159
  private var isPanning: Bool = false
160
160
 
161
+ private var scrollHandoffEnabled = false
162
+ private var scrollOffsetObservation: NSKeyValueObservation?
163
+ private var panStartedInScrollView = false
164
+ private var isSheetDrivingPan = false
165
+ private var pinsScrollToTop = false
166
+ private var lastPanPoint: CGPoint = .zero
167
+
161
168
  public var contentBackgroundColor: UIColor? {
162
169
  get { self.contentViewController.contentBackgroundColor }
163
170
  set { self.contentViewController.contentBackgroundColor = newValue }
@@ -232,15 +239,69 @@ public class SheetViewController: UIViewController {
232
239
  self.didDismiss?(self, self.dismissAll)
233
240
  })
234
241
  } else if !self.options.useInlineMode {
235
- debugPrint(parent, view, view.superview)
242
+ //debugPrint(parent, view, view.superview)
236
243
  self.didDismiss?(self, dismissAll)
237
244
  }
238
245
  }
239
246
 
240
247
  /// Handle a scroll view in the child view controller by watching for the offset for the scrollview and taking priority when at the top (so pulling up/down can grow/shrink the sheet instead of bouncing the child's scroll view)
241
248
  public func handleScrollView(_ scrollView: UIScrollView) {
242
- scrollView.panGestureRecognizer.require(toFail: panGestureRecognizer)
243
249
  self.childScrollView = scrollView
250
+ self.scrollOffsetObservation = nil
251
+ self.scrollHandoffEnabled = self.orderedSizes.count > 1 && !isScrollViewInverted(scrollView)
252
+ guard self.scrollHandoffEnabled else {
253
+ scrollView.panGestureRecognizer.require(toFail: panGestureRecognizer)
254
+ return
255
+ }
256
+ self.scrollOffsetObservation = scrollView.observe(\.contentOffset, options: [.new]) {
257
+ [weak self] scrollView, _ in
258
+ guard let self, self.pinsScrollToTop else { return }
259
+ let top = -scrollView.contentInset.top
260
+ if scrollView.contentOffset.y != top {
261
+ scrollView.contentOffset.y = top
262
+ }
263
+ }
264
+ }
265
+
266
+ private func pinChildScrollViewToTop() {
267
+ guard let scrollView = self.childScrollView else { return }
268
+ scrollView.setContentOffset(CGPoint(x: scrollView.contentOffset.x, y: -scrollView.contentInset.top), animated: false)
269
+ }
270
+
271
+ private func updateScrollHandoff(_ gesture: UIPanGestureRecognizer, point: CGPoint) -> Bool {
272
+ guard let scrollView = self.childScrollView else { return true }
273
+ let maxSheetHeight = self.height(for: self.orderedSizes.last)
274
+ let currentHeight = self.contentViewHeightConstraint.constant
275
+ let isAtMax = currentHeight >= maxSheetHeight - 0.5
276
+ let deltaY = point.y - self.lastPanPoint.y
277
+ let isMovingDown = deltaY != 0 ? deltaY > 0 : gesture.velocity(in: self.view).y > 0
278
+ self.lastPanPoint = point
279
+
280
+ let sheetShouldDrive = !isAtMax || (isMovingDown && isScrollViewAtVisualTop(scrollView))
281
+ if gesture.state == .began || sheetShouldDrive != self.isSheetDrivingPan {
282
+ self.isSheetDrivingPan = sheetShouldDrive
283
+ self.firstPanPoint = point
284
+ if sheetShouldDrive {
285
+ self.prePanHeight = currentHeight
286
+ self.pinChildScrollViewToTop()
287
+ } else {
288
+ self.contentViewHeightConstraint.constant = maxSheetHeight
289
+ self.contentViewController.view.transform = .identity
290
+ }
291
+ self.pinsScrollToTop = sheetShouldDrive
292
+ }
293
+ return sheetShouldDrive
294
+ }
295
+
296
+ private func finishScrollHandoffPan() {
297
+ guard let lastSize = self.orderedSizes.last else { return }
298
+ self.isPanning = false
299
+ self.pinsScrollToTop = false
300
+ let previousSize = self.currentSize
301
+ self.currentSize = lastSize
302
+ if previousSize != lastSize {
303
+ self.sizeChanged?(self, lastSize, self.height(for: lastSize))
304
+ }
244
305
  }
245
306
 
246
307
  /// Change the sizes the sheet should try to pin to
@@ -282,16 +343,23 @@ public class SheetViewController: UIViewController {
282
343
  overlayTapView.backgroundColor = .clear
283
344
  overlayTapView.isUserInteractionEnabled = !self.allowGestureThroughOverlay
284
345
  self.view.addSubview(overlayTapView)
285
- Constraints(for: overlayTapView, self.contentViewController.view) {
286
- $0.top.pinToSuperview()
287
- $0.left.pinToSuperview()
288
- $0.right.pinToSuperview()
289
- $0.bottom.align(with: $1.top)
346
+ // The whole screen (except the card, which sits in front in z-order) is a
347
+ // tap-to-dismiss surface — taps above, below AND to the sides of the card
348
+ // dismiss. Previously the non-centered surface stopped at the card's top,
349
+ // so when the card was narrower than the screen (maxWidth / landscape) the
350
+ // dim strips beside the card had no tap handler and didn't dismiss.
351
+ Constraints(for: overlayTapView) {
352
+ $0.edges(.top, .left, .right, .bottom).pinToSuperview()
290
353
  }
291
354
 
292
355
  let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(overlayTapped))
293
356
  self.overlayTapGesture = tapGestureRecognizer
294
357
  overlayTapView.addGestureRecognizer(tapGestureRecognizer)
358
+
359
+ // The tap surface covers the whole screen and is added after the card
360
+ // (addContentView runs first), so bring the card back to front — taps on
361
+ // the card reach its content and only taps on the surrounding dim dismiss.
362
+ self.view.bringSubviewToFront(self.contentViewController.view)
295
363
  }
296
364
 
297
365
  @objc func overlayTapped(_ gesture: UITapGestureRecognizer) {
@@ -300,7 +368,11 @@ public class SheetViewController: UIViewController {
300
368
  }
301
369
 
302
370
  func updateMaxWidth(value: CGFloat) {
303
- self.contentViewWidthConstraint.constant = value
371
+ // `contentViewWidthConstraint` is only created in `addContentView()` when
372
+ // `options.maxWidth` is non-nil (and note SheetOptions maps maxWidth == 0 -> nil).
373
+ // A Fabric prop update always calls this (sheetMaxWidthSize defaults to 0), so
374
+ // guard against the constraint being absent to avoid an unexpectedly-nil crash.
375
+ self.contentViewWidthConstraint?.constant = value
304
376
  }
305
377
 
306
378
  private func addContentView() {
@@ -319,14 +391,18 @@ public class SheetViewController: UIViewController {
319
391
  $0.centerX.alignWithSuperview()
320
392
  self.contentViewHeightConstraint = $0.height.set(self.height(for: self.currentSize))
321
393
 
322
- let top: CGFloat
323
- if (self.options.useFullScreenMode) {
324
- top = 0
394
+ if self.options.centered {
395
+ $0.centerY.alignWithSuperview()
325
396
  } else {
326
- top = max(12, UIApplication.shared.windows.first(where: { $0.isKeyWindow })?.compatibleSafeAreaInsets.top ?? 12)
397
+ let top: CGFloat
398
+ if (self.options.useFullScreenMode) {
399
+ top = 0
400
+ } else {
401
+ top = max(12, UIApplication.shared.windows.first(where: { $0.isKeyWindow })?.compatibleSafeAreaInsets.top ?? 12)
402
+ }
403
+ $0.bottom.pinToSuperview()
404
+ $0.top.pinToSuperview(inset: top, relation: .greaterThanOrEqual).priority = UILayoutPriority(999)
327
405
  }
328
- $0.bottom.pinToSuperview()
329
- $0.top.pinToSuperview(inset: top, relation: .greaterThanOrEqual).priority = UILayoutPriority(999)
330
406
  }
331
407
  }
332
408
 
@@ -339,10 +415,43 @@ public class SheetViewController: UIViewController {
339
415
 
340
416
  @objc func panned(_ gesture: UIPanGestureRecognizer) {
341
417
  let point = gesture.translation(in: gesture.view?.superview)
418
+ if self.options.centered {
419
+ self.pannedCentered(gesture, point: point)
420
+ return
421
+ }
342
422
  if gesture.state == .began {
343
423
  self.firstPanPoint = point
344
424
  self.prePanHeight = self.contentViewController.view.bounds.height
345
425
  self.isPanning = true
426
+ if self.options.useInlineMode {
427
+ // Inline containment: the sheet lives inside the host
428
+ // RCTSurfaceView, so the main surface's RCTSurfaceTouchHandler
429
+ // (a UIGestureRecognizer on an ancestor) is tracking the same
430
+ // touch in parallel. `cancelsTouchesInView` only cancels
431
+ // delivery to UIViews — sibling gesture recognizers continue
432
+ // tracking and would emit a press on touchesEnded. Bounce
433
+ // their `isEnabled` to force-cancel and dispatch a touchCancel
434
+ // to JS so a swipe-to-dismiss isn't mistaken for a tap.
435
+ self.cancelAncestorRNTouchHandlers()
436
+ }
437
+ self.panStartedInScrollView = self.scrollHandoffEnabled && self.isPanInChildScrollView(gesture)
438
+ self.lastPanPoint = point
439
+ }
440
+
441
+ if self.panStartedInScrollView {
442
+ switch gesture.state {
443
+ case .began, .changed:
444
+ if !self.updateScrollHandoff(gesture, point: point) { return }
445
+ case .ended, .cancelled, .failed:
446
+ if !self.isSheetDrivingPan {
447
+ self.finishScrollHandoffPan()
448
+ return
449
+ }
450
+ // cancels the scroll view's deceleration after its own pan ends
451
+ DispatchQueue.main.async { [weak self] in self?.pinChildScrollViewToTop() }
452
+ default:
453
+ break
454
+ }
346
455
  }
347
456
 
348
457
  let minHeight: CGFloat = self.height(for: self.orderedSizes.first)
@@ -378,6 +487,7 @@ public class SheetViewController: UIViewController {
378
487
  self.overlayView.alpha = 1
379
488
  }, completion: { _ in
380
489
  self.isPanning = false
490
+ self.pinsScrollToTop = false
381
491
  })
382
492
 
383
493
  case .began, .changed:
@@ -422,7 +532,7 @@ public class SheetViewController: UIViewController {
422
532
 
423
533
 
424
534
  var newSize = self.currentSize
425
- if point.y < 0 {
535
+ if point.y - self.firstPanPoint.y < 0 {
426
536
  // We need to move to the next larger one
427
537
  newSize = self.orderedSizes.last ?? self.currentSize
428
538
  for size in self.orderedSizes.reversed() {
@@ -461,6 +571,7 @@ public class SheetViewController: UIViewController {
461
571
  self.view.layoutIfNeeded()
462
572
  }, completion: { complete in
463
573
  self.isPanning = false
574
+ self.pinsScrollToTop = false
464
575
  if previousSize != newSize {
465
576
  self.sizeChanged?(self, newSize, newContentHeight)
466
577
  }
@@ -472,6 +583,56 @@ public class SheetViewController: UIViewController {
472
583
  }
473
584
  }
474
585
 
586
+ /// Pan handling for centered presentation: the card follows the finger
587
+ /// downward (a translation, not a resize), the overlay fades by drag
588
+ /// progress, and the sheet dismisses past ~1/3 of the card height or on a
589
+ /// fast flick — otherwise it springs back to center.
590
+ private func pannedCentered(_ gesture: UIPanGestureRecognizer, point: CGPoint) {
591
+ let card = self.contentViewController.view!
592
+ switch gesture.state {
593
+ case .began:
594
+ self.firstPanPoint = point
595
+ self.isPanning = true
596
+ case .changed:
597
+ // Translation is already relative to gesture start; only follow the
598
+ // finger downward and clamp upward drag to 0.
599
+ let ty = max(0, point.y)
600
+ card.transform = CGAffineTransform(translationX: 0, y: ty)
601
+ let progress = min(1, ty / max(1, card.bounds.height))
602
+ self.overlayView.alpha = 1 - progress
603
+ case .ended, .cancelled, .failed:
604
+ self.isPanning = false
605
+ let ty = card.transform.ty
606
+ let velocity = gesture.velocity(in: gesture.view).y
607
+ let shouldDismiss = self.dismissOnPull && (ty > card.bounds.height / 3 || velocity > 800)
608
+ if shouldDismiss {
609
+ self.attemptDismiss(animated: true)
610
+ } else {
611
+ UIView.animate(withDuration: 0.25) {
612
+ card.transform = .identity
613
+ self.overlayView.alpha = 1
614
+ }
615
+ }
616
+ default:
617
+ break
618
+ }
619
+ }
620
+
621
+ private func cancelAncestorRNTouchHandlers() {
622
+ var v: UIView? = self.view.superview
623
+ while let view = v {
624
+ if let recognizers = view.gestureRecognizers {
625
+ for r in recognizers where r is RCTSurfaceTouchHandler {
626
+ if r.isEnabled {
627
+ r.isEnabled = false
628
+ r.isEnabled = true
629
+ }
630
+ }
631
+ }
632
+ v = view.superview
633
+ }
634
+ }
635
+
475
636
  private func height(for size: SheetSize?) -> CGFloat {
476
637
  guard let size = size else { return 0 }
477
638
  let contentHeight: CGFloat
@@ -542,6 +703,7 @@ public class SheetViewController: UIViewController {
542
703
  }
543
704
 
544
705
  public func attemptDismiss(animated: Bool) {
706
+ self.view.endEditing(true)
545
707
  if self.options.useInlineMode {
546
708
  if animated {
547
709
  self.animateOut {
@@ -595,12 +757,9 @@ public class SheetViewController: UIViewController {
595
757
 
596
758
  extension SheetViewController: SheetViewDelegate {
597
759
  func sheetPoint(inside point: CGPoint, with event: UIEvent?) -> Bool {
598
- let isInOverlay = self.overlayTapView.bounds.contains(point)
599
- if self.allowGestureThroughOverlay, isInOverlay {
600
- return false
601
- } else {
602
- return true
603
- }
760
+ guard self.allowGestureThroughOverlay else { return true }
761
+ let cardView = self.contentViewController.view!
762
+ return cardView.bounds.contains(self.view.convert(point, to: cardView))
604
763
  }
605
764
  }
606
765
 
@@ -626,9 +785,12 @@ extension SheetViewController: UIGestureRecognizerDelegate {
626
785
  guard pointInChildScrollView > 0, pointInChildScrollView < childScrollView.bounds.height else {
627
786
  return true
628
787
  }
629
- let topInset = childScrollView.contentInset.top
630
788
 
631
- if !(abs(velocity.y) > abs(velocity.x) && childScrollView.contentOffset.y <= -topInset) {
789
+ if self.scrollHandoffEnabled {
790
+ return abs(velocity.y) > abs(velocity.x)
791
+ }
792
+
793
+ if !(abs(velocity.y) > abs(velocity.x) && isScrollViewAtVisualTop(childScrollView)) {
632
794
  return false
633
795
  }
634
796
 
@@ -639,6 +801,42 @@ extension SheetViewController: UIGestureRecognizerDelegate {
639
801
  return true
640
802
  }
641
803
  }
804
+
805
+ public func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
806
+ guard self.scrollHandoffEnabled,
807
+ gestureRecognizer === self.panGestureRecognizer,
808
+ let childScrollView = self.childScrollView else { return false }
809
+ return otherGestureRecognizer === childScrollView.panGestureRecognizer
810
+ }
811
+
812
+ private func isPanInChildScrollView(_ gesture: UIPanGestureRecognizer) -> Bool {
813
+ guard let childScrollView = self.childScrollView,
814
+ let point = (gesture as? InitialTouchPanGestureRecognizer)?.initialTouchLocation else { return false }
815
+ let pointInChildScrollView = self.view.convert(point, to: childScrollView).y - childScrollView.contentOffset.y
816
+ return pointInChildScrollView > 0 && pointInChildScrollView < childScrollView.bounds.height
817
+ }
818
+
819
+ private func isScrollViewInverted(_ scrollView: UIScrollView) -> Bool {
820
+ // Check the scroll view itself and its ancestors for scaleY = -1.
821
+ // React Native applies the inverted transform via layer.transform (CATransform3D)
822
+ // on a parent wrapper view (RCTScrollView), not on the inner UIScrollView (RCTEnhancedScrollView).
823
+ var view: UIView? = scrollView
824
+ while let current = view {
825
+ if current.transform.d < 0 { return true }
826
+ if current.layer.transform.m22 < 0 { return true }
827
+ view = current.superview
828
+ }
829
+ return false
830
+ }
831
+
832
+ private func isScrollViewAtVisualTop(_ scrollView: UIScrollView) -> Bool {
833
+ if isScrollViewInverted(scrollView) {
834
+ let maxOffsetY = scrollView.contentSize.height - scrollView.bounds.height + scrollView.contentInset.bottom
835
+ if maxOffsetY <= 0 { return true }
836
+ return scrollView.contentOffset.y >= maxOffsetY - 1
837
+ }
838
+ return scrollView.contentOffset.y <= -scrollView.contentInset.top
839
+ }
642
840
  }
643
841
 
644
842
  extension SheetViewController: SheetContentViewDelegate {