react-native-sheet2 6.1.19 → 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.
- package/README.md +754 -80
- package/{Sheet.podspec → Sheet2.podspec} +2 -2
- package/android/build.gradle +2 -25
- package/android/check.jks +0 -0
- package/android/src/main/AndroidManifest.xml +1 -2
- package/android/src/main/cpp/react/renderer/components/SheetViewSpec/SheetViewComponentDescriptor.h +12 -0
- package/android/src/main/cpp/react/renderer/components/SheetViewSpec/SheetViewShadowNode.cpp +17 -0
- package/android/src/main/cpp/react/renderer/components/SheetViewSpec/SheetViewShadowNode.h +36 -0
- package/android/src/main/cpp/react/renderer/components/SheetViewSpec/SheetViewState.h +52 -0
- package/android/src/main/java/com/behavior/BottomSheetBehavior.java +84 -16
- package/android/src/main/java/com/sheet2/AppFittedSheet.kt +431 -0
- package/android/src/main/java/com/{sheet → sheet2}/BaseRNView.kt +38 -31
- package/android/src/main/java/com/sheet2/CenteredSheetDialog.kt +272 -0
- package/android/src/main/java/com/{sheet → sheet2}/CustomBottomSheetDialog.java +32 -4
- package/android/src/main/java/com/{sheet → sheet2}/DialogRootViewGroup.kt +54 -12
- package/android/src/main/java/com/sheet2/FragmentModalBottomSheet.kt +161 -0
- package/android/src/main/java/com/sheet2/InlineFooterPresenter.kt +74 -0
- package/android/src/main/java/com/sheet2/InlineSheetPresenter.kt +249 -0
- package/android/src/main/java/com/sheet2/PassThroughLayouts.kt +17 -0
- package/android/src/main/java/com/{sheet → sheet2}/SafeAreaUtils.kt +4 -5
- package/android/src/main/java/com/sheet2/Sheet2Package.kt +44 -0
- package/android/src/main/java/com/sheet2/Sheet2View.kt +5 -0
- package/android/src/main/java/com/sheet2/Sheet2ViewManager.kt +163 -0
- package/android/src/main/java/com/{sheet → sheet2}/SheetDismissEvent.kt +1 -1
- package/android/src/main/java/com/{sheet → sheet2}/SheetModule.kt +14 -3
- package/android/src/main/java/com/{sheet → sheet2}/SheetPackage.kt +2 -3
- package/android/src/main/java/com/sheet2/SheetTreeLog.kt +78 -0
- package/android/src/main/java/com/{sheet → sheet2}/utils.kt +1 -2
- package/android/src/main/jni/CMakeLists.txt +72 -0
- package/android/src/main/jni/SheetViewSpec.h +40 -0
- package/ios/FittedSheets/SheetOptions.swift +5 -0
- package/ios/FittedSheets/SheetTransition.swift +83 -4
- package/ios/FittedSheets/SheetViewController.swift +222 -24
- package/ios/HostFittedSheet.swift +440 -51
- package/ios/SheetModule.h +5 -4
- package/ios/SheetModule.mm +11 -1
- package/ios/SheetTreeLog.swift +52 -0
- package/ios/SheetView.mm +118 -31
- package/ios/SheetViewComponentDescriptor.h +24 -0
- package/ios/SheetViewShadowNode.cpp +17 -0
- package/ios/SheetViewShadowNode.h +37 -0
- package/ios/SheetViewState.h +54 -0
- package/package.json +44 -74
- package/react-native.config.js +6 -4
- package/src/FittedSheet.tsx +131 -71
- package/src/GlobalSheetView.tsx +209 -0
- package/src/NativeSheet.ts +4 -0
- package/src/PublicSheetView.tsx +2 -1
- package/src/SheetTreeLog.ts +39 -0
- package/src/SheetViewNativeComponent.ts +25 -4
- package/src/index.tsx +29 -4
- package/src/logger.ts +16 -0
- package/android/generated/java/com/facebook/react/viewmanagers/SheetViewManagerDelegate.java +0 -67
- package/android/generated/java/com/facebook/react/viewmanagers/SheetViewManagerInterface.java +0 -27
- package/android/generated/java/com/sheet/NativeSheetSpec.java +0 -78
- package/android/generated/jni/CMakeLists.txt +0 -36
- package/android/generated/jni/RNSheetViewSpec-generated.cpp +0 -50
- package/android/generated/jni/RNSheetViewSpec.h +0 -31
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/ComponentDescriptors.cpp +0 -22
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/ComponentDescriptors.h +0 -24
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/EventEmitters.cpp +0 -24
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/EventEmitters.h +0 -25
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/Props.cpp +0 -33
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/Props.h +0 -36
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/RNSheetViewSpecJSI-generated.cpp +0 -46
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/RNSheetViewSpecJSI.h +0 -98
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/ShadowNodes.cpp +0 -17
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/ShadowNodes.h +0 -32
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/States.cpp +0 -16
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/States.h +0 -29
- package/android/src/main/AndroidManifestNew.xml +0 -2
- package/android/src/main/java/com/sheet/AppFittedSheet.kt +0 -214
- package/android/src/main/java/com/sheet/FragmentModalBottomSheet.kt +0 -67
- package/android/src/main/java/com/sheet/SheetView.kt +0 -5
- package/android/src/main/java/com/sheet/SheetViewManager.kt +0 -106
- package/ios/generated/RNSheetViewSpec/ComponentDescriptors.cpp +0 -22
- package/ios/generated/RNSheetViewSpec/ComponentDescriptors.h +0 -24
- package/ios/generated/RNSheetViewSpec/EventEmitters.cpp +0 -24
- package/ios/generated/RNSheetViewSpec/EventEmitters.h +0 -25
- package/ios/generated/RNSheetViewSpec/Props.cpp +0 -33
- package/ios/generated/RNSheetViewSpec/Props.h +0 -36
- package/ios/generated/RNSheetViewSpec/RCTComponentViewHelpers.h +0 -44
- package/ios/generated/RNSheetViewSpec/RNSheetViewSpec-generated.mm +0 -60
- package/ios/generated/RNSheetViewSpec/RNSheetViewSpec.h +0 -100
- package/ios/generated/RNSheetViewSpec/ShadowNodes.cpp +0 -17
- package/ios/generated/RNSheetViewSpec/ShadowNodes.h +0 -32
- package/ios/generated/RNSheetViewSpec/States.cpp +0 -16
- package/ios/generated/RNSheetViewSpec/States.h +0 -29
- package/ios/generated/RNSheetViewSpecJSI-generated.cpp +0 -46
- package/ios/generated/RNSheetViewSpecJSI.h +0 -98
- package/lib/module/FittedSheet.js +0 -153
- package/lib/module/FittedSheet.js.map +0 -1
- package/lib/module/NativeSheet.ts +0 -17
- package/lib/module/PublicSheetView.js +0 -48
- package/lib/module/PublicSheetView.js.map +0 -1
- package/lib/module/SheetViewNativeComponent.ts +0 -31
- package/lib/module/index.js +0 -17
- package/lib/module/index.js.map +0 -1
- package/lib/module/package.json +0 -1
- package/lib/typescript/package.json +0 -1
- package/lib/typescript/src/FittedSheet.d.ts +0 -51
- package/lib/typescript/src/FittedSheet.d.ts.map +0 -1
- package/lib/typescript/src/NativeSheet.d.ts +0 -16
- package/lib/typescript/src/NativeSheet.d.ts.map +0 -1
- package/lib/typescript/src/PublicSheetView.d.ts +0 -12
- package/lib/typescript/src/PublicSheetView.d.ts.map +0 -1
- package/lib/typescript/src/SheetViewNativeComponent.d.ts +0 -22
- package/lib/typescript/src/SheetViewNativeComponent.d.ts.map +0 -1
- package/lib/typescript/src/index.d.ts +0 -12
- package/lib/typescript/src/index.d.ts.map +0 -1
|
@@ -10,45 +10,123 @@ func viewPort() -> CGSize {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
var presentedSheets: [SheetViewController] = []
|
|
13
|
+
var footers: [UIView] = []
|
|
13
14
|
var lastPresentedSheetSizes: [[SheetSize]] = []
|
|
14
15
|
|
|
15
16
|
public final class HostFittedSheet: UIView {
|
|
16
17
|
private(set) var _modalViewController: SheetViewController?
|
|
17
18
|
private let viewController = UIViewController()
|
|
18
19
|
private var _touchHandler: RCTSurfaceTouchHandler?
|
|
20
|
+
private weak var _touchHandlerAttachedView: UIView?
|
|
19
21
|
@objc
|
|
20
22
|
public var onSheetDismiss: (() -> Void)?
|
|
21
23
|
private var _reactSubview: UIView?
|
|
24
|
+
private var _reactSubviewBoundsObservation: NSKeyValueObservation?
|
|
25
|
+
private var _overlaySubview: UIView?
|
|
22
26
|
private var _isPresented = false
|
|
23
27
|
private var _sheetSize: CGFloat?
|
|
24
28
|
public var sheetMaxWidthSize: CGFloat?
|
|
25
29
|
private var dismissable = true
|
|
30
|
+
private var dismissOnOverlayTap = true
|
|
31
|
+
private var overlayOpacity: CGFloat = -1
|
|
32
|
+
private var collapsedHeight: CGFloat = 0
|
|
33
|
+
private var _footer = false
|
|
34
|
+
// Inline sheets mounted outside any RN surface (e.g. at the app root) get no touches from the surface handler.
|
|
35
|
+
private var _ownsTouches = false
|
|
26
36
|
private var topLeftRightCornerRadius: CGFloat?
|
|
27
37
|
private var stacked = false
|
|
28
38
|
private var _backgroundColor: UIColor = .clear
|
|
39
|
+
private var _windowLevel: UIWindow.Level = .alert
|
|
40
|
+
private var _useInlinePresentation = false
|
|
41
|
+
private var _centered: Bool = false
|
|
42
|
+
private var _centerSlide: Bool = false
|
|
43
|
+
@objc
|
|
44
|
+
public var uniqueId: String = ""
|
|
45
|
+
|
|
46
|
+
// Wired by SheetView.mm to push a contentOriginOffset through Fabric state.
|
|
47
|
+
// Used only in inline containment — in dialog mode the sheet lives in its
|
|
48
|
+
// own UIWindow so the Yoga-computed position already matches the physical
|
|
49
|
+
// one and no delta is needed.
|
|
50
|
+
@objc
|
|
51
|
+
public var stateUpdater: ((Float, Float) -> Void)?
|
|
29
52
|
|
|
30
53
|
private var sheetMaxWidth: CGFloat {
|
|
31
54
|
return sheetMaxWidthSize ?? viewPort().width
|
|
32
55
|
}
|
|
33
56
|
|
|
34
57
|
private var _alertWindow: UIWindow?
|
|
58
|
+
private weak var _previousKeyWindow: UIWindow?
|
|
35
59
|
private func createVC() -> UIViewController {
|
|
36
|
-
|
|
60
|
+
let previousKeyWindow = RCTKeyWindow()
|
|
61
|
+
_previousKeyWindow = previousKeyWindow
|
|
62
|
+
if let scene = previousKeyWindow?.windowScene {
|
|
63
|
+
_alertWindow = UIWindow(windowScene: scene)
|
|
64
|
+
} else {
|
|
65
|
+
_alertWindow = UIWindow(frame: .init(origin: .zero, size: viewPort()))
|
|
66
|
+
}
|
|
67
|
+
|
|
37
68
|
let controller = UIViewController()
|
|
38
69
|
_alertWindow?.rootViewController = controller
|
|
39
|
-
_alertWindow?.windowLevel =
|
|
70
|
+
_alertWindow?.windowLevel = _windowLevel
|
|
40
71
|
_alertWindow?.isHidden = false
|
|
41
72
|
_alertWindow?.makeKeyAndVisible()
|
|
42
73
|
return controller
|
|
43
74
|
}
|
|
75
|
+
private func releaseWindow() {
|
|
76
|
+
guard let alertWindow = _alertWindow else { return }
|
|
77
|
+
_alertWindow = nil
|
|
78
|
+
let scene = alertWindow.windowScene
|
|
79
|
+
alertWindow.isHidden = true
|
|
80
|
+
alertWindow.windowScene = nil
|
|
81
|
+
alertWindow.rootViewController = nil
|
|
82
|
+
let previous = _previousKeyWindow
|
|
83
|
+
_previousKeyWindow = nil
|
|
84
|
+
if let previous, previous !== alertWindow, !previous.isHidden {
|
|
85
|
+
previous.makeKey()
|
|
86
|
+
} else {
|
|
87
|
+
scene?.windows.first { $0 !== alertWindow && $0.windowLevel == .normal }?.makeKey()
|
|
88
|
+
}
|
|
89
|
+
}
|
|
44
90
|
private var presentViewController: UIViewController?
|
|
45
91
|
|
|
92
|
+
@objc
|
|
93
|
+
public func setWindowLevel(_ level: NSString) {
|
|
94
|
+
let str = level as String
|
|
95
|
+
switch str {
|
|
96
|
+
case "normal":
|
|
97
|
+
_windowLevel = .normal
|
|
98
|
+
case "statusBar":
|
|
99
|
+
_windowLevel = .statusBar
|
|
100
|
+
default:
|
|
101
|
+
_windowLevel = .alert
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
@objc
|
|
106
|
+
public func setUseInlinePresentation(_ value: Bool) {
|
|
107
|
+
_useInlinePresentation = value
|
|
108
|
+
// Re-place the overlay for the current mode. Safe to call in either mode:
|
|
109
|
+
// attachOverlaySubview no-ops until both the overlay subview and the
|
|
110
|
+
// sheet VC's view exist (the sheet isn't initialized yet at this point).
|
|
111
|
+
attachOverlaySubview()
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
@objc
|
|
115
|
+
public func setPresentationStyle(_ value: NSString) {
|
|
116
|
+
_centered = (value as String) == "center"
|
|
117
|
+
_footer = (value as String) == "footer"
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
@objc
|
|
121
|
+
public func setCenterAnimation(_ value: NSString) {
|
|
122
|
+
_centerSlide = (value as String) == "slide"
|
|
123
|
+
}
|
|
124
|
+
|
|
46
125
|
@objc
|
|
47
126
|
public func setPassScrollViewReactTag() {
|
|
48
|
-
debugPrint("😀 setPassScrollViewReactTag")
|
|
49
127
|
tryAttachScrollView()
|
|
50
128
|
}
|
|
51
|
-
|
|
129
|
+
|
|
52
130
|
@objc
|
|
53
131
|
public func setSheetBackgroundColor(_ color: UIColor?) {
|
|
54
132
|
_backgroundColor = color ?? .clear
|
|
@@ -57,9 +135,11 @@ public final class HostFittedSheet: UIView {
|
|
|
57
135
|
|
|
58
136
|
@objc
|
|
59
137
|
public func setFittedSheetParams(_ params: NSDictionary) {
|
|
60
|
-
debugPrint("😀 setFittedSheetParams", params)
|
|
61
138
|
sheetMaxWidthSize = RCTConvert.cgFloat(params["maxWidth"])
|
|
62
139
|
dismissable = params["dismissable"] as? Bool ?? true
|
|
140
|
+
dismissOnOverlayTap = params["dismissOnOverlayTap"] as? Bool ?? true
|
|
141
|
+
overlayOpacity = RCTConvert.cgFloat(params["overlayOpacity"])
|
|
142
|
+
collapsedHeight = RCTConvert.cgFloat(params["collapsedHeight"])
|
|
63
143
|
topLeftRightCornerRadius = RCTConvert.cgFloat(params["topLeftRightCornerRadius"])
|
|
64
144
|
|
|
65
145
|
if let value = sheetMaxWidthSize {
|
|
@@ -75,35 +155,101 @@ public final class HostFittedSheet: UIView {
|
|
|
75
155
|
fatalError("init(coder:) has not been implemented")
|
|
76
156
|
}
|
|
77
157
|
|
|
158
|
+
public override func removeFromSuperview() {
|
|
159
|
+
super.removeFromSuperview()
|
|
160
|
+
if _isPresented {
|
|
161
|
+
destroy()
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
78
165
|
public override func insertReactSubview(_ subview: UIView!, at atIndex: Int) {
|
|
79
|
-
|
|
80
|
-
|
|
166
|
+
SheetTreeLog.log(
|
|
167
|
+
"sheet.insertReactSubview",
|
|
168
|
+
details: "child=\(SheetTreeLog.name(subview)) index=\(atIndex) self=\(SheetTreeLog.name(self))"
|
|
169
|
+
+ " presented=\(_isPresented)"
|
|
170
|
+
)
|
|
171
|
+
if atIndex > 0 {
|
|
172
|
+
// The overlay never becomes a subview of the content view React Native
|
|
173
|
+
// mounted it into.
|
|
174
|
+
_overlaySubview = subview
|
|
175
|
+
subview.isUserInteractionEnabled = false
|
|
176
|
+
attachOverlaySubview()
|
|
177
|
+
return
|
|
178
|
+
}
|
|
179
|
+
|
|
81
180
|
_touchHandler = RCTSurfaceTouchHandler()
|
|
82
181
|
_touchHandler?.attach(to: subview)
|
|
182
|
+
_touchHandlerAttachedView = subview
|
|
83
183
|
viewController.view.insertSubview(subview, at: 0)
|
|
84
184
|
_reactSubview = subview
|
|
185
|
+
_reactSubviewBoundsObservation = subview.observe(\.bounds, options: [.old, .new]) {
|
|
186
|
+
[weak self] _, change in
|
|
187
|
+
guard let self, self._footer, self._isPresented,
|
|
188
|
+
let old = change.oldValue, let new = change.newValue,
|
|
189
|
+
old.height != new.height, new.height > 0 else { return }
|
|
190
|
+
self.layoutFooter()
|
|
191
|
+
}
|
|
85
192
|
}
|
|
86
193
|
|
|
87
194
|
public override func removeReactSubview(_ subview: UIView!) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
195
|
+
SheetTreeLog.log(
|
|
196
|
+
"sheet.removeReactSubview",
|
|
197
|
+
details: "child=\(SheetTreeLog.name(subview)) self=\(SheetTreeLog.name(self))"
|
|
198
|
+
+ " presented=\(_isPresented)"
|
|
199
|
+
)
|
|
200
|
+
if let overlaySubview = _overlaySubview, subview === overlaySubview {
|
|
201
|
+
_overlaySubview?.removeFromSuperview()
|
|
202
|
+
_overlaySubview = nil
|
|
203
|
+
return
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
detachTouchHandler()
|
|
207
|
+
_reactSubviewBoundsObservation?.invalidate()
|
|
208
|
+
_reactSubviewBoundsObservation = nil
|
|
91
209
|
_reactSubview?.removeFromSuperview()
|
|
92
210
|
_reactSubview = nil
|
|
93
211
|
}
|
|
94
212
|
|
|
213
|
+
private func attachOverlaySubview() {
|
|
214
|
+
// Works in both inline containment and modal presentation: in both cases
|
|
215
|
+
// the sheet's root view is `_modalViewController?.view`, so the visual,
|
|
216
|
+
// non-interactive overlay is placed on top of it the same way.
|
|
217
|
+
guard let overlaySubview = _overlaySubview,
|
|
218
|
+
let sheetView = _modalViewController?.view else { return }
|
|
219
|
+
|
|
220
|
+
SheetTreeLog.log(
|
|
221
|
+
"sheet.attachOverlay",
|
|
222
|
+
details: "overlay=\(SheetTreeLog.name(overlaySubview))"
|
|
223
|
+
+ " from=\(SheetTreeLog.name(overlaySubview.superview))"
|
|
224
|
+
+ " to=\(SheetTreeLog.name(sheetView))"
|
|
225
|
+
)
|
|
226
|
+
overlaySubview.removeFromSuperview()
|
|
227
|
+
overlaySubview.frame = sheetView.bounds
|
|
228
|
+
overlaySubview.autoresizingMask = [.flexibleWidth, .flexibleHeight]
|
|
229
|
+
overlaySubview.isUserInteractionEnabled = false
|
|
230
|
+
sheetView.addSubview(overlaySubview)
|
|
231
|
+
sheetView.bringSubviewToFront(overlaySubview)
|
|
232
|
+
overlaySubview.setNeedsLayout()
|
|
233
|
+
overlaySubview.layoutIfNeeded()
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
private func detachTouchHandler() {
|
|
237
|
+
if let v = _touchHandlerAttachedView {
|
|
238
|
+
_touchHandler?.detach(from: v)
|
|
239
|
+
}
|
|
240
|
+
_touchHandlerAttachedView = nil
|
|
241
|
+
}
|
|
242
|
+
|
|
95
243
|
// need to leave it empty
|
|
96
244
|
public override func didUpdateReactSubviews() {}
|
|
97
245
|
|
|
98
246
|
public override func didMoveToWindow() {
|
|
99
247
|
super.didMoveToWindow()
|
|
100
|
-
//tryToPresent()
|
|
101
248
|
}
|
|
102
249
|
|
|
103
250
|
|
|
104
251
|
@objc
|
|
105
252
|
public func finalizeUpdates() {
|
|
106
|
-
debugPrint("😀 finalizeUpdates _isPresented: \(_isPresented), superviewNil: \(superview == nil)")
|
|
107
253
|
if _isPresented && superview == nil {
|
|
108
254
|
destroy()
|
|
109
255
|
} else {
|
|
@@ -114,52 +260,160 @@ public final class HostFittedSheet: UIView {
|
|
|
114
260
|
// MARK: calculatedSize
|
|
115
261
|
@objc
|
|
116
262
|
public func setCalculatedHeight(_ height: CGFloat) {
|
|
117
|
-
debugPrint("😀 setCalculatedHeight", height)
|
|
118
263
|
// prevent show on change orientation for stack
|
|
119
264
|
if let m = _modalViewController, presentedSheets.contains(m) {
|
|
120
265
|
return
|
|
121
266
|
}
|
|
122
267
|
_sheetSize = RCTConvert.cgFloat(height)
|
|
123
|
-
|
|
268
|
+
if _footer {
|
|
269
|
+
layoutFooter()
|
|
270
|
+
} else {
|
|
271
|
+
_modalViewController?.setSizes(sheetSizes(_sheetSize ?? 0))
|
|
272
|
+
}
|
|
273
|
+
// Inline-containment mode: tryToPresent early-returned while height was
|
|
274
|
+
// still 0 — now that we have a real size, try again.
|
|
275
|
+
if _useInlinePresentation && !_isPresented && (_sheetSize ?? 0) > 0 {
|
|
276
|
+
tryToPresent()
|
|
277
|
+
}
|
|
124
278
|
}
|
|
125
279
|
|
|
126
280
|
private func initializeSheet(_ size: CGSize) {
|
|
127
|
-
|
|
281
|
+
var opts = SheetOptions(
|
|
282
|
+
pullBarHeight: 0,
|
|
283
|
+
shouldExtendBackground: false,
|
|
284
|
+
shrinkPresentingViewController: false,
|
|
285
|
+
useInlineMode: _useInlinePresentation && !_centered,
|
|
286
|
+
maxWidth: self.sheetMaxWidth
|
|
287
|
+
)
|
|
288
|
+
opts.centered = _centered
|
|
289
|
+
opts.centerSlide = _centerSlide
|
|
128
290
|
self._modalViewController = SheetViewController(
|
|
129
291
|
controller: self.viewController,
|
|
130
|
-
sizes:
|
|
131
|
-
options:
|
|
132
|
-
pullBarHeight: 0,
|
|
133
|
-
shouldExtendBackground: false,
|
|
134
|
-
shrinkPresentingViewController: false,
|
|
135
|
-
maxWidth: self.sheetMaxWidth
|
|
136
|
-
)
|
|
292
|
+
sizes: sheetSizes(size.height),
|
|
293
|
+
options: opts
|
|
137
294
|
)
|
|
138
295
|
|
|
139
296
|
self._modalViewController?.allowPullingPastMaxHeight = false
|
|
140
|
-
self._modalViewController?.dismissOnOverlayTap = self.dismissable
|
|
297
|
+
self._modalViewController?.dismissOnOverlayTap = self.dismissable && self.dismissOnOverlayTap
|
|
298
|
+
if overlayOpacity >= 0 {
|
|
299
|
+
self._modalViewController?.overlayColor = UIColor(white: 0, alpha: overlayOpacity)
|
|
300
|
+
}
|
|
301
|
+
self._modalViewController?.allowGestureThroughOverlay = overlayOpacity == 0
|
|
141
302
|
self._modalViewController?.dismissOnPull = self.dismissable
|
|
142
303
|
self._modalViewController?.cornerRadius = self.topLeftRightCornerRadius ?? 12
|
|
143
304
|
self._modalViewController?.contentBackgroundColor = _backgroundColor
|
|
144
305
|
}
|
|
145
306
|
|
|
307
|
+
private func hasSurfaceTouchHandler(_ view: UIView?) -> Bool {
|
|
308
|
+
var current = view
|
|
309
|
+
while let v = current {
|
|
310
|
+
if v.gestureRecognizers?.contains(where: { $0 is RCTSurfaceTouchHandler }) == true { return true }
|
|
311
|
+
current = v.superview
|
|
312
|
+
}
|
|
313
|
+
return false
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
private func sheetSizes(_ height: CGFloat) -> [SheetSize] {
|
|
317
|
+
guard _useInlinePresentation, collapsedHeight > 0, collapsedHeight < height else {
|
|
318
|
+
return [.fixed(height)]
|
|
319
|
+
}
|
|
320
|
+
return [.fixed(collapsedHeight), .fixed(height)]
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
private func presentFooter() {
|
|
324
|
+
guard let hostVC = presentViewController else { return }
|
|
325
|
+
hostVC.view.addSubview(viewController.view)
|
|
326
|
+
_ownsTouches = !hasSurfaceTouchHandler(hostVC.view)
|
|
327
|
+
if !_ownsTouches { detachTouchHandler() }
|
|
328
|
+
footers.append(viewController.view)
|
|
329
|
+
layoutFooter()
|
|
330
|
+
DispatchQueue.main.async { [weak self] in
|
|
331
|
+
self?.pushContentOriginOffset()
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
private func layoutFooter() {
|
|
336
|
+
guard _footer, let host = viewController.view.superview else { return }
|
|
337
|
+
let contentHeight = _reactSubview?.bounds.height ?? 0
|
|
338
|
+
let height = contentHeight > 0 ? contentHeight : (_sheetSize ?? 0)
|
|
339
|
+
viewController.view.frame = CGRect(
|
|
340
|
+
x: 0,
|
|
341
|
+
y: host.bounds.height - height,
|
|
342
|
+
width: host.bounds.width,
|
|
343
|
+
height: height
|
|
344
|
+
)
|
|
345
|
+
viewController.view.autoresizingMask = [.flexibleWidth, .flexibleTopMargin]
|
|
346
|
+
_reactSubview?.frame = viewController.view.bounds
|
|
347
|
+
host.bringSubviewToFront(viewController.view)
|
|
348
|
+
DispatchQueue.main.async { [weak self] in
|
|
349
|
+
self?.pushContentOriginOffset()
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
146
353
|
private func tryAttachScrollView() {
|
|
147
354
|
guard let controller = _modalViewController else { return }
|
|
148
|
-
debugPrint("😀 tryAttachScrollView")
|
|
149
355
|
let scrollView = self._reactSubview?.find(deepIndex: 0)
|
|
150
356
|
if let v = scrollView {
|
|
151
|
-
debugPrint("😀 tryAttachScrollView.found")
|
|
152
357
|
controller.handleScrollView(v)
|
|
153
358
|
}
|
|
154
359
|
}
|
|
155
360
|
|
|
361
|
+
/// Pushes the delta between this view's Yoga position (where the Fabric
|
|
362
|
+
/// shadow tree thinks the sheet content lives) and the physical
|
|
363
|
+
/// on-screen position of the RN subview after child-VC containment.
|
|
364
|
+
/// Consumed by `SheetViewShadowNode::getContentOriginOffset` so that
|
|
365
|
+
/// `measure()` / Pressability region checks report window-relative coords
|
|
366
|
+
/// matching the real touch positions. Only meaningful in inline
|
|
367
|
+
/// containment — dialog mode has matching coords and needs no offset.
|
|
368
|
+
private func pushContentOriginOffset() {
|
|
369
|
+
guard _useInlinePresentation, !_ownsTouches else { return }
|
|
370
|
+
guard self.window != nil else { return }
|
|
371
|
+
guard let reactSubview = _reactSubview, reactSubview.window != nil else { return }
|
|
372
|
+
let yogaPos = self.convert(CGPoint.zero, to: nil)
|
|
373
|
+
let physicalPos = reactSubview.convert(CGPoint.zero, to: nil)
|
|
374
|
+
let offsetX = Float(physicalPos.x - yogaPos.x)
|
|
375
|
+
let offsetY = Float(physicalPos.y - yogaPos.y)
|
|
376
|
+
stateUpdater?(offsetX, offsetY)
|
|
377
|
+
}
|
|
378
|
+
|
|
156
379
|
private func tryToPresent() {
|
|
157
380
|
if (!self.isUserInteractionEnabled && self.superview?.reactSubviews().contains(self) != nil) {
|
|
158
381
|
return;
|
|
159
382
|
}
|
|
160
383
|
|
|
384
|
+
// Inline-containment mode needs a real height on first present: the
|
|
385
|
+
// contentVC.view height constraint is set to `_sheetSize` at init time,
|
|
386
|
+
// and changes to sheet sizes go through `setSizes` (which expects a
|
|
387
|
+
// presented sheet). If we present at height 0, contentVC.view has 0
|
|
388
|
+
// height, its hit-testable bounds are 0, and touches on RN content never
|
|
389
|
+
// reach the RN view. Wait for the JS-side onLayout to push a non-zero
|
|
390
|
+
// height first.
|
|
391
|
+
if (_useInlinePresentation && !_isPresented && (_sheetSize ?? 0) <= 0) {
|
|
392
|
+
return
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
if !_isPresented && _footer {
|
|
396
|
+
if (_sheetSize ?? 0) <= 0 { return }
|
|
397
|
+
presentViewController = self.findEnclosingViewController() ?? RCTPresentedViewController()
|
|
398
|
+
_isPresented = true
|
|
399
|
+
RCTExecuteOnMainQueue { [weak self] in
|
|
400
|
+
self?.presentFooter()
|
|
401
|
+
}
|
|
402
|
+
return
|
|
403
|
+
}
|
|
404
|
+
|
|
161
405
|
if (!_isPresented) {
|
|
162
|
-
|
|
406
|
+
if _useInlinePresentation {
|
|
407
|
+
// Present on the current react-navigation Screen's VC (found via
|
|
408
|
+
// UIResponder chain), so the sheet lives inside the same nav
|
|
409
|
+
// subtree and react-native-screens `fullScreenModal` push covers
|
|
410
|
+
// the sheet naturally. `RCTPresentedViewController()` would return
|
|
411
|
+
// the app's ROOT VC — fallback only.
|
|
412
|
+
presentViewController = self.findEnclosingViewController()
|
|
413
|
+
?? RCTPresentedViewController()
|
|
414
|
+
} else {
|
|
415
|
+
presentViewController = createVC()
|
|
416
|
+
}
|
|
163
417
|
// sheet already presented
|
|
164
418
|
if stacked {
|
|
165
419
|
if let controller = presentViewController as? SheetViewController {
|
|
@@ -174,18 +428,93 @@ public final class HostFittedSheet: UIView {
|
|
|
174
428
|
|
|
175
429
|
_isPresented = true
|
|
176
430
|
let size: CGSize = .init(width: self.sheetMaxWidth, height: _sheetSize ?? 0)
|
|
177
|
-
debugPrint("😀 HostFittedSheet.tryToPresent", self.presentViewController)
|
|
178
431
|
RCTExecuteOnMainQueue { [weak self] in
|
|
179
432
|
guard let self else { return }
|
|
180
433
|
|
|
181
434
|
self.initializeSheet(size)
|
|
182
|
-
self.
|
|
183
|
-
|
|
435
|
+
guard let sheetVC = self._modalViewController,
|
|
436
|
+
let hostVC = self.presentViewController else { return }
|
|
437
|
+
|
|
438
|
+
if self._useInlinePresentation {
|
|
439
|
+
// Child-VC containment: sheet is a child of host VC, NOT a modal.
|
|
440
|
+
// This prevents react-native-screens from auto-dismissing the
|
|
441
|
+
// sheet when it pushes a new fullScreenModal (rn-screens calls
|
|
442
|
+
// dismiss on the current presentedViewController before
|
|
443
|
+
// presenting a new modal; as a child VC we don't appear as
|
|
444
|
+
// presentedViewController).
|
|
445
|
+
sheetVC.willMove(toParent: hostVC)
|
|
446
|
+
hostVC.addChild(sheetVC)
|
|
447
|
+
sheetVC.view.frame = hostVC.view.bounds
|
|
448
|
+
sheetVC.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
|
|
449
|
+
hostVC.view.addSubview(sheetVC.view)
|
|
450
|
+
sheetVC.didMove(toParent: hostVC)
|
|
451
|
+
footers.forEach { footer in
|
|
452
|
+
if footer.superview === hostVC.view { hostVC.view.bringSubviewToFront(footer) }
|
|
453
|
+
}
|
|
454
|
+
self.attachOverlaySubview()
|
|
455
|
+
sheetVC.view.setNeedsLayout()
|
|
456
|
+
sheetVC.view.layoutIfNeeded()
|
|
457
|
+
|
|
458
|
+
// Don't attach our own RCTSurfaceTouchHandler in inline
|
|
459
|
+
// containment: the sheet's subtree stays within the main Fabric
|
|
460
|
+
// surface (RNSScreenStackView/RNSScreen are Fabric views), so
|
|
461
|
+
// the main surface's touch handler already receives touches via
|
|
462
|
+
// UIKit hit-test and dispatches them through Fabric's normal
|
|
463
|
+
// pipeline. Keeping our own handler duplicates every touch event
|
|
464
|
+
// and breaks Pressability state after the first tap.
|
|
465
|
+
self._ownsTouches = !self.hasSurfaceTouchHandler(hostVC.view)
|
|
466
|
+
if !self._ownsTouches { self.detachTouchHandler() }
|
|
467
|
+
|
|
468
|
+
// Push the visual delta (Yoga-position → physical on-screen
|
|
469
|
+
// position) into the Fabric state so that descendants' measure()
|
|
470
|
+
// / Pressability region checks report the real window-relative
|
|
471
|
+
// coords. Without this, containment breaks taps on any button
|
|
472
|
+
// inside the sheet (same root cause as the Android fix). Run on
|
|
473
|
+
// the next layout tick so hostVC.view and self have settled
|
|
474
|
+
// window positions.
|
|
475
|
+
DispatchQueue.main.async { [weak self] in
|
|
476
|
+
self?.pushContentOriginOffset()
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
// Slide-in animation — UIKit's modal transition isn't used in
|
|
480
|
+
// containment, so do it manually (mirror of animateOut: translate
|
|
481
|
+
// content down, fade overlay, then animate back to resting).
|
|
482
|
+
sheetVC.view.layoutIfNeeded()
|
|
483
|
+
let contentView = sheetVC.contentViewController.view!
|
|
484
|
+
let startY = max(contentView.bounds.height, 1)
|
|
485
|
+
contentView.transform = CGAffineTransform(translationX: 0, y: startY)
|
|
486
|
+
sheetVC.overlayView.alpha = 0
|
|
487
|
+
UIView.animate(
|
|
488
|
+
withDuration: 0.3,
|
|
489
|
+
delay: 0,
|
|
490
|
+
usingSpringWithDamping: 1,
|
|
491
|
+
initialSpringVelocity: 0,
|
|
492
|
+
options: [.curveEaseOut],
|
|
493
|
+
animations: {
|
|
494
|
+
contentView.transform = .identity
|
|
495
|
+
sheetVC.overlayView.alpha = 1
|
|
496
|
+
},
|
|
497
|
+
completion: { [weak self] _ in
|
|
498
|
+
self?.pushContentOriginOffset()
|
|
499
|
+
}
|
|
500
|
+
)
|
|
501
|
+
sheetVC.sizeChanged = { [weak self] _, _, _ in
|
|
502
|
+
DispatchQueue.main.async {
|
|
503
|
+
self?.pushContentOriginOffset()
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
} else {
|
|
507
|
+
hostVC.present(sheetVC, animated: true) { [weak self] in
|
|
508
|
+
// Modal presentation: attach the overlay once the sheet VC's view
|
|
509
|
+
// is on screen (mirrors the inline-containment attach above).
|
|
510
|
+
self?.attachOverlaySubview()
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
sheetVC.didDismiss = { [weak self] old, silent in
|
|
184
514
|
guard let self else { return }
|
|
185
|
-
|
|
515
|
+
releaseWindow()
|
|
186
516
|
onSheetDismiss?()
|
|
187
517
|
if old.dismissAll == true {
|
|
188
|
-
debugPrint("😀 _modalViewController.dismissingSilently")
|
|
189
518
|
if stacked, let popped = presentedSheets.popLast() {
|
|
190
519
|
popped.dismissAll = true
|
|
191
520
|
popped.dismiss(animated: false)
|
|
@@ -195,7 +524,6 @@ public final class HostFittedSheet: UIView {
|
|
|
195
524
|
if stacked, let popped = presentedSheets.popLast() {
|
|
196
525
|
popped.setSizes(lastPresentedSheetSizes.popLast() ?? [])
|
|
197
526
|
}
|
|
198
|
-
debugPrint("______", presentedSheets)
|
|
199
527
|
}
|
|
200
528
|
|
|
201
529
|
// some delay to wait rn render
|
|
@@ -210,45 +538,92 @@ public final class HostFittedSheet: UIView {
|
|
|
210
538
|
|
|
211
539
|
@objc
|
|
212
540
|
public func dismiss() {
|
|
213
|
-
|
|
541
|
+
_reactSubview?.endEditing(true)
|
|
542
|
+
if _footer {
|
|
543
|
+
destroy()
|
|
544
|
+
onSheetDismiss?()
|
|
545
|
+
return
|
|
546
|
+
}
|
|
547
|
+
if _useInlinePresentation {
|
|
548
|
+
// attemptDismiss handles both inline (removeFromSuperview +
|
|
549
|
+
// removeFromParent) and modal paths internally.
|
|
550
|
+
_modalViewController?.attemptDismiss(animated: true)
|
|
551
|
+
} else {
|
|
552
|
+
_modalViewController?.dismiss(animated: true)
|
|
553
|
+
}
|
|
214
554
|
}
|
|
215
555
|
|
|
216
556
|
@objc
|
|
217
557
|
public func destroy() {
|
|
218
|
-
|
|
558
|
+
SheetTreeLog.log(
|
|
559
|
+
"sheet.destroy",
|
|
560
|
+
details: "self=\(SheetTreeLog.name(self)) content=\(SheetTreeLog.name(_reactSubview))"
|
|
561
|
+
+ " overlay=\(SheetTreeLog.name(_overlaySubview)) presented=\(_isPresented)"
|
|
562
|
+
)
|
|
563
|
+
_reactSubview?.endEditing(true)
|
|
564
|
+
if _footer {
|
|
565
|
+
_isPresented = false
|
|
566
|
+
footers.removeAll { $0 === viewController.view }
|
|
567
|
+
viewController.view.removeFromSuperview()
|
|
568
|
+
presentViewController = nil
|
|
569
|
+
return
|
|
570
|
+
}
|
|
571
|
+
if !_isPresented && _modalViewController == nil {
|
|
572
|
+
return
|
|
573
|
+
}
|
|
574
|
+
|
|
219
575
|
_isPresented = false
|
|
220
576
|
|
|
577
|
+
// Remove from global array if present
|
|
578
|
+
if let modalVC = _modalViewController, let index = presentedSheets.firstIndex(of: modalVC) {
|
|
579
|
+
presentedSheets.remove(at: index)
|
|
580
|
+
if lastPresentedSheetSizes.count > index {
|
|
581
|
+
lastPresentedSheetSizes.remove(at: index)
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
|
|
221
585
|
let cleanup = { [weak self] in
|
|
222
|
-
guard let self else {
|
|
223
|
-
|
|
224
|
-
self.viewController.removeFromParent()
|
|
225
|
-
self.viewController.view.removeFromSuperview()
|
|
226
|
-
self._reactSubview?.removeFromSuperview()
|
|
227
|
-
if let v = self._reactSubview {
|
|
228
|
-
self._touchHandler?.detach(from: v)
|
|
586
|
+
guard let self else {
|
|
587
|
+
return
|
|
229
588
|
}
|
|
589
|
+
|
|
590
|
+
// Clear dismiss callback first to prevent retain cycles
|
|
591
|
+
self._modalViewController?.didDismiss = nil
|
|
592
|
+
self.onSheetDismiss = nil
|
|
593
|
+
|
|
594
|
+
// Remove view hierarchy
|
|
595
|
+
self._overlaySubview?.removeFromSuperview()
|
|
596
|
+
self._reactSubview?.removeFromSuperview()
|
|
597
|
+
self.detachTouchHandler()
|
|
598
|
+
self.viewController.view.removeFromSuperview()
|
|
599
|
+
self.viewController.removeFromParent()
|
|
600
|
+
|
|
601
|
+
self.releaseWindow()
|
|
602
|
+
|
|
603
|
+
// Nil out all references
|
|
230
604
|
self.presentViewController = nil
|
|
231
605
|
self._modalViewController = nil
|
|
232
606
|
self._touchHandler = nil
|
|
233
607
|
self._sheetSize = nil
|
|
234
608
|
self.sheetMaxWidthSize = nil
|
|
609
|
+
self._overlaySubview = nil
|
|
235
610
|
self._reactSubview = nil
|
|
236
|
-
self._alertWindow = nil
|
|
237
611
|
}
|
|
238
612
|
|
|
239
|
-
if self._modalViewController
|
|
240
|
-
|
|
241
|
-
|
|
613
|
+
if let modalVC = self._modalViewController, modalVC.isBeingDismissed != true && modalVC.isBeingPresented != true {
|
|
614
|
+
if _useInlinePresentation {
|
|
615
|
+
// Containment path — no modal presenter, run animateOut then cleanup.
|
|
616
|
+
modalVC.attemptDismiss(animated: true)
|
|
617
|
+
cleanup()
|
|
618
|
+
} else {
|
|
619
|
+
modalVC.dismiss(animated: true, completion: cleanup)
|
|
620
|
+
}
|
|
242
621
|
} else {
|
|
243
|
-
debugPrint("😀 _modalViewController.cleanup")
|
|
244
622
|
cleanup()
|
|
245
623
|
}
|
|
246
|
-
|
|
247
624
|
}
|
|
248
625
|
|
|
249
|
-
deinit {
|
|
250
|
-
debugPrint("😀 HostFittedSheet.deinit")
|
|
251
|
-
}
|
|
626
|
+
deinit {}
|
|
252
627
|
|
|
253
628
|
}
|
|
254
629
|
|
|
@@ -267,5 +642,19 @@ extension UIView {
|
|
|
267
642
|
|
|
268
643
|
return nil
|
|
269
644
|
}
|
|
270
|
-
}
|
|
271
645
|
|
|
646
|
+
/// Walks the UIResponder chain to find the nearest enclosing
|
|
647
|
+
/// `UIViewController` (standard RN pattern — see
|
|
648
|
+
/// `node_modules/react-native/React/Views/UIView+React.m`).
|
|
649
|
+
/// Used for inline sheet presentation so the sheet is attached to the
|
|
650
|
+
/// current react-navigation Screen's VC (not app root), allowing
|
|
651
|
+
/// react-native-screens `fullScreenModal` to cover the sheet.
|
|
652
|
+
fileprivate func findEnclosingViewController() -> UIViewController? {
|
|
653
|
+
var responder: UIResponder? = self.next
|
|
654
|
+
while let r = responder {
|
|
655
|
+
if let vc = r as? UIViewController { return vc }
|
|
656
|
+
responder = r.next
|
|
657
|
+
}
|
|
658
|
+
return nil
|
|
659
|
+
}
|
|
660
|
+
}
|
package/ios/SheetModule.h
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
#
|
|
3
|
-
#
|
|
1
|
+
|
|
2
|
+
#import <ReactCodegen/SheetViewSpec/SheetViewSpec.h>
|
|
3
|
+
#if __has_include("Sheet2-Swift.h")
|
|
4
|
+
#import "Sheet2-Swift.h"
|
|
4
5
|
#else
|
|
5
|
-
#import <
|
|
6
|
+
#import <Sheet2/Sheet2-Swift.h>
|
|
6
7
|
#endif
|
|
7
8
|
|
|
8
9
|
@interface SheetModule : NSObject <NativeSheetSpec>
|
package/ios/SheetModule.mm
CHANGED
|
@@ -37,8 +37,18 @@ RCT_EXPORT_MODULE(Sheet)
|
|
|
37
37
|
return dict;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
- (NSArray<NSString *> *)getTreeLog {
|
|
41
|
+
return [SheetTreeLog snapshot];
|
|
42
|
+
}
|
|
43
|
+
|
|
40
44
|
- (void)dismiss:(NSInteger)tag {
|
|
41
|
-
|
|
45
|
+
if (SheetTreeLog.logsEnabled) {
|
|
46
|
+
NSLog(@"dismissModule %d", (int)tag);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
- (void)setLogsEnabled:(BOOL)enabled {
|
|
51
|
+
SheetTreeLog.logsEnabled = enabled;
|
|
42
52
|
}
|
|
43
53
|
|
|
44
54
|
- (void)dismissAll {
|