react-native-sheet2 1.2.6 → 6.1.18
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/LICENSE +1 -1
- package/README.md +51 -32
- package/{react-native-sheet.podspec → Sheet.podspec} +7 -6
- package/android/build.gradle +43 -25
- package/android/generated/java/com/facebook/react/viewmanagers/SheetViewManagerDelegate.java +67 -0
- package/android/generated/java/com/facebook/react/viewmanagers/SheetViewManagerInterface.java +27 -0
- package/android/generated/java/com/sheet/NativeSheetSpec.java +78 -0
- package/android/generated/jni/CMakeLists.txt +36 -0
- package/android/generated/jni/RNSheetViewSpec-generated.cpp +50 -0
- package/android/generated/jni/RNSheetViewSpec.h +31 -0
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/ComponentDescriptors.cpp +22 -0
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/ComponentDescriptors.h +24 -0
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/EventEmitters.cpp +24 -0
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/EventEmitters.h +25 -0
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/Props.cpp +33 -0
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/Props.h +36 -0
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/RNSheetViewSpecJSI-generated.cpp +46 -0
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/RNSheetViewSpecJSI.h +98 -0
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/ShadowNodes.cpp +17 -0
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/ShadowNodes.h +32 -0
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/States.cpp +16 -0
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/States.h +29 -0
- package/android/gradle.properties +4 -5
- package/android/src/main/AndroidManifest.xml +0 -9
- package/android/src/main/AndroidManifestNew.xml +2 -0
- package/android/src/main/java/com/behavior/BottomSheetBehavior.java +10 -17
- package/android/src/main/java/com/sheet/AppFittedSheet.kt +107 -39
- package/android/src/main/java/com/sheet/BaseRNView.kt +81 -33
- package/android/src/main/java/com/sheet/CustomBottomSheetDialog.java +8 -0
- package/android/src/main/java/com/sheet/DialogRootViewGroup.kt +44 -33
- package/android/src/main/java/com/sheet/FragmentModalBottomSheet.kt +12 -2
- package/android/src/main/java/com/sheet/SafeAreaUtils.kt +90 -0
- package/android/src/main/java/com/sheet/SheetDismissEvent.kt +20 -0
- package/android/src/main/java/com/sheet/SheetModule.kt +37 -0
- package/android/src/main/java/com/sheet/SheetPackage.kt +32 -6
- package/android/src/main/java/com/sheet/SheetView.kt +5 -0
- package/android/src/main/java/com/sheet/SheetViewManager.kt +77 -56
- package/android/src/main/java/com/sheet/utils.kt +2 -10
- package/android/src/main/res/layout/dialog_bottom_sheet.xml +2 -2
- package/android/src/main/res/values/styles.xml +9 -0
- package/ios/FittedSheets/SheetContentViewController.swift +4 -4
- package/ios/FittedSheets/SheetViewController.swift +29 -100
- package/ios/HostFittedSheet.swift +271 -0
- package/ios/Sheet-Bridging-Header.h +1 -0
- package/ios/SheetModule.h +10 -0
- package/ios/SheetModule.mm +67 -0
- package/ios/SheetView.h +14 -0
- package/ios/SheetView.mm +129 -0
- package/ios/generated/RNSheetViewSpec/ComponentDescriptors.cpp +22 -0
- package/ios/generated/RNSheetViewSpec/ComponentDescriptors.h +24 -0
- package/ios/generated/RNSheetViewSpec/EventEmitters.cpp +24 -0
- package/ios/generated/RNSheetViewSpec/EventEmitters.h +25 -0
- package/ios/generated/RNSheetViewSpec/Props.cpp +33 -0
- package/ios/generated/RNSheetViewSpec/Props.h +36 -0
- package/ios/generated/RNSheetViewSpec/RCTComponentViewHelpers.h +44 -0
- package/ios/generated/RNSheetViewSpec/RNSheetViewSpec-generated.mm +60 -0
- package/ios/generated/RNSheetViewSpec/RNSheetViewSpec.h +100 -0
- package/ios/generated/RNSheetViewSpec/ShadowNodes.cpp +17 -0
- package/ios/generated/RNSheetViewSpec/ShadowNodes.h +32 -0
- package/ios/generated/RNSheetViewSpec/States.cpp +16 -0
- package/ios/generated/RNSheetViewSpec/States.h +29 -0
- package/ios/generated/RNSheetViewSpecJSI-generated.cpp +46 -0
- package/ios/generated/RNSheetViewSpecJSI.h +98 -0
- package/lib/module/FittedSheet.js +153 -0
- package/lib/module/FittedSheet.js.map +1 -0
- package/lib/module/NativeSheet.ts +17 -0
- package/lib/module/PublicSheetView.js +48 -0
- package/lib/module/PublicSheetView.js.map +1 -0
- package/lib/module/SheetViewNativeComponent.ts +31 -0
- package/lib/module/index.js +13 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/FittedSheet.d.ts +51 -0
- package/lib/typescript/src/FittedSheet.d.ts.map +1 -0
- package/lib/typescript/src/NativeSheet.d.ts +16 -0
- package/lib/typescript/src/NativeSheet.d.ts.map +1 -0
- package/lib/typescript/src/PublicSheetView.d.ts +12 -0
- package/lib/typescript/src/PublicSheetView.d.ts.map +1 -0
- package/lib/typescript/src/SheetViewNativeComponent.d.ts +22 -0
- package/lib/typescript/src/SheetViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +8 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/package.json +109 -42
- package/react-native.config.js +12 -0
- package/src/FittedSheet.tsx +118 -95
- package/src/NativeSheet.ts +17 -0
- package/src/PublicSheetView.tsx +66 -0
- package/src/SheetViewNativeComponent.ts +31 -0
- package/src/index.tsx +26 -8
- package/android/src/main/java/com/modal/FullScreenDialog.kt +0 -100
- package/android/src/main/java/com/modal/TopModalView.kt +0 -77
- package/android/src/main/java/com/modal/TopModalViewManager.kt +0 -83
- package/android/src/main/java/com/modal/TopModalViewModule.kt +0 -40
- package/android/src/main/java/com/sheet/SheetViewModule.kt +0 -41
- package/ios/LBBottomSheet/BottomSheetConstant.swift +0 -48
- package/ios/LBBottomSheet/Model/BottomSheetController+Behavior.swift +0 -262
- package/ios/LBBottomSheet/Model/BottomSheetController+Theme.swift +0 -156
- package/ios/LBBottomSheet/Protocols/BottomSheetInteractionDelegate.swift +0 -29
- package/ios/LBBottomSheet/Protocols/BottomSheetPositionDelegate.swift +0 -31
- package/ios/LBBottomSheet/UI/BottomSheet.storyboard +0 -105
- package/ios/LBBottomSheet/UI/BottomSheetController.swift +0 -601
- package/ios/LBBottomSheet/Utils/Components/ForwardingEventsView.swift +0 -60
- package/ios/LBBottomSheet/Utils/Extensions/CACornerMask+Extension.swift +0 -33
- package/ios/LBBottomSheet/Utils/Extensions/Mirror+Extension.swift +0 -47
- package/ios/LBBottomSheet/Utils/Extensions/UIApplication+Extension.swift +0 -35
- package/ios/LBBottomSheet/Utils/Extensions/UIColor+Extension.swift +0 -61
- package/ios/LBBottomSheet/Utils/Extensions/UIGestureRecognizer+Extensions.swift +0 -28
- package/ios/LBBottomSheet/Utils/Extensions/UIScreen+Extension.swift +0 -28
- package/ios/LBBottomSheet/Utils/Extensions/UIScrollView+Extension.swift +0 -25
- package/ios/LBBottomSheet/Utils/Extensions/UIView+Extension.swift +0 -52
- package/ios/LBBottomSheet/Utils/Extensions/UIViewController+Extension.swift +0 -104
- package/ios/Sheet.xcodeproj/project.pbxproj +0 -377
- package/ios/SheetViewManager.m +0 -25
- package/ios/SheetViewManager.swift +0 -324
- package/ios/TopModalViewManager.swift +0 -196
- package/src/TopModal.tsx +0 -94
|
@@ -1,324 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// AppFittedSheet.swift
|
|
3
|
-
// PopupMenu
|
|
4
|
-
//
|
|
5
|
-
// Created by Sergei Golishnikov on 14/02/2022.
|
|
6
|
-
// Copyright © 2022 Facebook. All rights reserved.
|
|
7
|
-
//
|
|
8
|
-
|
|
9
|
-
import Foundation
|
|
10
|
-
import UIKit
|
|
11
|
-
import React
|
|
12
|
-
|
|
13
|
-
class ModalHostShadowView: RCTShadowView {
|
|
14
|
-
static var attachedViews: [Int: HostFittedSheet] = [:]
|
|
15
|
-
override func insertReactSubview(_ subview: RCTShadowView!, at atIndex: Int) {
|
|
16
|
-
super.insertReactSubview(subview, at: atIndex)
|
|
17
|
-
if subview != nil {
|
|
18
|
-
let s = RCTScreenSize()
|
|
19
|
-
let orientation = UIDevice.current.orientation
|
|
20
|
-
var width = s.width
|
|
21
|
-
if orientation == .landscapeLeft || orientation == .landscapeRight {
|
|
22
|
-
width = s.height
|
|
23
|
-
}
|
|
24
|
-
(subview as RCTShadowView).width = YGValue.init(value: Float(width), unit: .point)
|
|
25
|
-
subview.position = .absolute
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
func renderSizes(subviews: [RCTShadowView]?) {
|
|
30
|
-
guard let subviews else { return }
|
|
31
|
-
for v in subviews {
|
|
32
|
-
debugPrint(v)
|
|
33
|
-
renderSizes(subviews: v.reactSubviews())
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
override func layoutSubviews(with layoutContext: RCTLayoutContext) {
|
|
38
|
-
super.layoutSubviews(with: layoutContext)
|
|
39
|
-
|
|
40
|
-
RCTExecuteOnMainQueue { [weak self] in
|
|
41
|
-
guard let self else { return }
|
|
42
|
-
let view = RCTBridge.current().uiManager.view(
|
|
43
|
-
forReactTag: self.reactTag) as? HostFittedSheet
|
|
44
|
-
let v = self.reactSubviews()[0]
|
|
45
|
-
let size = v.contentFrame.size
|
|
46
|
-
debugPrint("😀 ModalHostShadowView.layoutSubviews", size)
|
|
47
|
-
view?._modalViewController?.setSizes([.fixed(size.height)])
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
let FITTED_SHEET_SCROLL_VIEW = "fittedSheetScrollView"
|
|
53
|
-
|
|
54
|
-
@objc(SheetViewManager)
|
|
55
|
-
class SheetViewManager: RCTViewManager {
|
|
56
|
-
override static func requiresMainQueueSetup() -> Bool {
|
|
57
|
-
return true
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
override func view() -> UIView! {
|
|
61
|
-
let v = HostFittedSheet(bridge: bridge)
|
|
62
|
-
return v
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
private func getSheetView(withTag tag: NSNumber) -> HostFittedSheet {
|
|
66
|
-
// swiftlint:disable force_cast
|
|
67
|
-
return bridge.uiManager.view(forReactTag: tag) as! HostFittedSheet
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
@objc
|
|
71
|
-
final func dismiss(_ node: NSNumber) {
|
|
72
|
-
DispatchQueue.main.async {
|
|
73
|
-
let component = self.getSheetView(withTag: node)
|
|
74
|
-
component._modalViewController?.dismiss(animated: true)
|
|
75
|
-
debugPrint("😀dismiss")
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
override func shadowView() -> RCTShadowView! {
|
|
80
|
-
return ModalHostShadowView()
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
deinit {
|
|
84
|
-
debugPrint("😀 deinit view manager")
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
class HostFittedSheet: UIView {
|
|
90
|
-
var _modalViewController: SheetViewController?
|
|
91
|
-
let viewController = UIViewController()
|
|
92
|
-
var _touchHandler: RCTTouchHandler?
|
|
93
|
-
var _reactSubview: UIView?
|
|
94
|
-
var _bridge: RCTBridge?
|
|
95
|
-
var _isPresented = false
|
|
96
|
-
var _sheetSize: NSNumber?
|
|
97
|
-
var _scrollViewTag: NSNumber?
|
|
98
|
-
|
|
99
|
-
private var _alertWindow: UIWindow?
|
|
100
|
-
private lazy var presentViewController: UIViewController = {
|
|
101
|
-
_alertWindow = UIWindow(frame: .init(origin: .zero, size: RCTScreenSize()))
|
|
102
|
-
let controller = UIViewController()
|
|
103
|
-
_alertWindow?.rootViewController = controller
|
|
104
|
-
_alertWindow?.windowLevel = UIWindow.Level.alert
|
|
105
|
-
_alertWindow?.isHidden = false
|
|
106
|
-
_alertWindow?.makeKeyAndVisible()
|
|
107
|
-
return controller
|
|
108
|
-
}()
|
|
109
|
-
|
|
110
|
-
@objc
|
|
111
|
-
private var onSheetDismiss: RCTDirectEventBlock?
|
|
112
|
-
|
|
113
|
-
var sheetMaxWidthSize: NSNumber?
|
|
114
|
-
private var dismissable = true
|
|
115
|
-
var sheetMaxHeightSize: NSNumber?
|
|
116
|
-
var sheetMinHeightSize: NSNumber?
|
|
117
|
-
private var topLeftRightCornerRadius: NSNumber?
|
|
118
|
-
private var sheetBackgroundColor: UIColor?
|
|
119
|
-
|
|
120
|
-
@objc
|
|
121
|
-
func setPassScrollViewReactTag(_ tag: NSNumber) {
|
|
122
|
-
debugPrint("😀 setPassScrollViewReactTag", tag)
|
|
123
|
-
guard let scrollView = self._bridge?.uiManager.view(forReactTag: tag) as? RCTScrollView else {
|
|
124
|
-
return
|
|
125
|
-
}
|
|
126
|
-
if self._modalViewController == nil {
|
|
127
|
-
self._scrollViewTag = tag
|
|
128
|
-
}
|
|
129
|
-
debugPrint("😀 setPassScrollViewReactTag found", scrollView, self._modalViewController)
|
|
130
|
-
self._modalViewController?.handleScrollView(scrollView.scrollView)
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
@objc
|
|
134
|
-
var fittedSheetParams: NSDictionary? {
|
|
135
|
-
didSet {
|
|
136
|
-
debugPrint("😀 ", fittedSheetParams ?? "nil")
|
|
137
|
-
sheetMaxWidthSize = (fittedSheetParams?["maxWidth"] as? NSNumber)
|
|
138
|
-
sheetMaxHeightSize = (fittedSheetParams?["maxHeight"] as? NSNumber)
|
|
139
|
-
sheetMinHeightSize = (fittedSheetParams?["minHeight"] as? NSNumber)
|
|
140
|
-
dismissable = (fittedSheetParams?["dismissable"] as? Bool) ?? true
|
|
141
|
-
topLeftRightCornerRadius = (fittedSheetParams?["topLeftRightCornerRadius"] as? NSNumber)
|
|
142
|
-
sheetBackgroundColor = RCTConvert.uiColor(fittedSheetParams?["backgroundColor"])
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
var sheetWidth: CGFloat {
|
|
147
|
-
return CGFloat(sheetMaxWidthSize?.floatValue ?? Float(UIScreen.main.bounds.width))
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
init(bridge: RCTBridge) {
|
|
151
|
-
self._bridge = bridge
|
|
152
|
-
super.init(frame: .zero)
|
|
153
|
-
_touchHandler = RCTTouchHandler(bridge: bridge)
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
required init?(coder: NSCoder) {
|
|
157
|
-
fatalError("init(coder:) has not been implemented")
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
override func insertReactSubview(_ subview: UIView!, at atIndex: Int) {
|
|
161
|
-
debugPrint("😀insertReactSubview")
|
|
162
|
-
super.insertReactSubview(subview, at: atIndex)
|
|
163
|
-
_touchHandler?.attach(to: subview)
|
|
164
|
-
viewController.view.insertSubview(subview, at: 0)
|
|
165
|
-
_reactSubview = subview
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
override func removeReactSubview(_ subview: UIView!) {
|
|
169
|
-
debugPrint("😀removeReactSubview")
|
|
170
|
-
super.removeReactSubview(subview)
|
|
171
|
-
_touchHandler?.detach(from: subview)
|
|
172
|
-
_reactSubview = nil
|
|
173
|
-
//destroy()
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
// need to leave it empty
|
|
177
|
-
override func didUpdateReactSubviews() {}
|
|
178
|
-
|
|
179
|
-
override func didMoveToWindow() {
|
|
180
|
-
super.didMoveToWindow()
|
|
181
|
-
|
|
182
|
-
// In the case where there is a LayoutAnimation, we will be reinserted into the view hierarchy but only for aesthetic
|
|
183
|
-
// purposes. In such a case, we should NOT represent the <Modal>.
|
|
184
|
-
|
|
185
|
-
if (!self.isUserInteractionEnabled && self.superview?.reactSubviews().contains(self) != nil) {
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
if (!_isPresented && self.window != nil) {
|
|
190
|
-
_isPresented = true
|
|
191
|
-
var size: CGSize = .zero
|
|
192
|
-
DispatchQueue.main.async { [weak self] in
|
|
193
|
-
guard let self = self else { return }
|
|
194
|
-
if self._sheetSize?.floatValue == nil {
|
|
195
|
-
self._reactSubview?.setNeedsLayout()
|
|
196
|
-
self._reactSubview?.layoutIfNeeded()
|
|
197
|
-
self._reactSubview?.sizeToFit()
|
|
198
|
-
size = self._reactSubview?.frame.size ?? .zero
|
|
199
|
-
debugPrint("😀 self._sheetSize?.floatValue == nil", size)
|
|
200
|
-
} else {
|
|
201
|
-
size = .init(width: self.sheetWidth, height: CGFloat(self._sheetSize!.floatValue))
|
|
202
|
-
debugPrint("😀 else", size)
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
if size.width > self.sheetWidth {
|
|
206
|
-
size.width = self.sheetWidth
|
|
207
|
-
}
|
|
208
|
-
// if maxSize is present notify react native view
|
|
209
|
-
if self.sheetMaxHeightSize != nil && size.height > self.sheetMaxHeightSize!.doubleValue {
|
|
210
|
-
size.height = self.sheetMaxHeightSize!.doubleValue
|
|
211
|
-
}
|
|
212
|
-
// if maxSize is present notify react native view
|
|
213
|
-
if self.sheetMinHeightSize != nil && size.height < self.sheetMinHeightSize!.doubleValue {
|
|
214
|
-
size.height = self.sheetMinHeightSize!.doubleValue
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
self._modalViewController = SheetViewController(
|
|
218
|
-
controller: self.viewController,
|
|
219
|
-
sizes: [.fixed(size.height)],
|
|
220
|
-
options: .init(
|
|
221
|
-
pullBarHeight: 0,
|
|
222
|
-
shouldExtendBackground: false,
|
|
223
|
-
shrinkPresentingViewController: false,
|
|
224
|
-
maxWidth: self.sheetWidth
|
|
225
|
-
)
|
|
226
|
-
)
|
|
227
|
-
self._modalViewController?.allowPullingPastMaxHeight = false
|
|
228
|
-
self._modalViewController?.dismissOnOverlayTap = self.dismissable
|
|
229
|
-
self._modalViewController?.autoAdjustToKeyboard = false
|
|
230
|
-
self._modalViewController?.dismissOnPull = self.dismissable
|
|
231
|
-
self._modalViewController?.cornerRadius = self.topLeftRightCornerRadius?.doubleValue ?? 12
|
|
232
|
-
self._modalViewController?.contentBackgroundColor = self.sheetBackgroundColor ?? .clear
|
|
233
|
-
debugPrint("😀 attachedViews \(self.reactTag.intValue)")
|
|
234
|
-
ModalHostShadowView.attachedViews[self.reactTag.intValue] = self
|
|
235
|
-
|
|
236
|
-
if let tag = self._scrollViewTag {
|
|
237
|
-
self.setPassScrollViewReactTag(tag)
|
|
238
|
-
} else {
|
|
239
|
-
let scrollView = self._reactSubview?.find(FITTED_SHEET_SCROLL_VIEW, deepIndex: 0) as? RCTScrollView
|
|
240
|
-
if scrollView != nil {
|
|
241
|
-
self._modalViewController?.handleScrollView(scrollView!.scrollView)
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
self.presentViewController.present(self._modalViewController!, animated: true)
|
|
246
|
-
//self.reactViewController().present(self._modalViewController!, animated: true)
|
|
247
|
-
|
|
248
|
-
self._modalViewController?.didDismiss = { [weak self] _ in
|
|
249
|
-
debugPrint("😀didDismiss \(self?.onSheetDismiss)")
|
|
250
|
-
self?.onSheetDismiss?([:])
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
override func removeFromSuperview() {
|
|
257
|
-
super.removeFromSuperview()
|
|
258
|
-
debugPrint("😀removeFromSuperview")
|
|
259
|
-
//destroy()
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
override func didMoveToSuperview() {
|
|
263
|
-
super.didMoveToSuperview()
|
|
264
|
-
if _isPresented && superview == nil {
|
|
265
|
-
debugPrint("😀didMoveToSuperview")
|
|
266
|
-
destroy()
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
func destroy() {
|
|
271
|
-
debugPrint("😀destroy")
|
|
272
|
-
_isPresented = false
|
|
273
|
-
|
|
274
|
-
let cleanup = { [weak self] in
|
|
275
|
-
guard let self = self else { return }
|
|
276
|
-
debugPrint("😀 cleanup")
|
|
277
|
-
ModalHostShadowView.attachedViews.removeValue(forKey: self.reactTag.intValue)
|
|
278
|
-
self._modalViewController = nil
|
|
279
|
-
self._reactSubview?.removeFromSuperview()
|
|
280
|
-
if let v = self._reactSubview {
|
|
281
|
-
self._touchHandler?.detach(from: self._reactSubview)
|
|
282
|
-
}
|
|
283
|
-
self._touchHandler = nil
|
|
284
|
-
self._bridge = nil
|
|
285
|
-
self.onSheetDismiss = nil
|
|
286
|
-
self._sheetSize = nil
|
|
287
|
-
self.sheetMaxWidthSize = nil
|
|
288
|
-
self._reactSubview = nil
|
|
289
|
-
self._alertWindow = nil
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
if self._modalViewController?.isBeingDismissed != true {
|
|
293
|
-
debugPrint("😀dismissViewController")
|
|
294
|
-
self._modalViewController?.dismiss(animated: true, completion: cleanup)
|
|
295
|
-
} else {
|
|
296
|
-
cleanup()
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
deinit {
|
|
302
|
-
debugPrint("😀deinit")
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
extension UIView {
|
|
309
|
-
func find(_ nId: String, deepIndex: Int) -> UIView? {
|
|
310
|
-
if deepIndex >= 10 { return nil }
|
|
311
|
-
if self.nativeID?.contains(nId) == true || self.accessibilityIdentifier?.contains(nId) == true {
|
|
312
|
-
return self
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
let index = deepIndex + 1
|
|
316
|
-
for subview in subviews {
|
|
317
|
-
if let v = subview.find(nId, deepIndex: index) {
|
|
318
|
-
return v
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
return nil
|
|
323
|
-
}
|
|
324
|
-
}
|
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// TopModalViewManager.swift
|
|
3
|
-
// Sheet
|
|
4
|
-
//
|
|
5
|
-
// Created by Sergei Golishnikov on 10/03/2023.
|
|
6
|
-
// Copyright © 2023 Facebook. All rights reserved.
|
|
7
|
-
//
|
|
8
|
-
|
|
9
|
-
import Foundation
|
|
10
|
-
import UIKit
|
|
11
|
-
import React
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
class TopModalShadowView: RCTShadowView {
|
|
15
|
-
static var attachedViews: [Int: HostFittedSheet] = [:]
|
|
16
|
-
override func insertReactSubview(_ subview: RCTShadowView!, at atIndex: Int) {
|
|
17
|
-
super.insertReactSubview(subview, at: atIndex)
|
|
18
|
-
if subview != nil {
|
|
19
|
-
let size = RCTScreenSize()
|
|
20
|
-
subview.width = .init(value: Float(size.width), unit: .point)
|
|
21
|
-
subview.height = .init(value: Float(size.height), unit: .point)
|
|
22
|
-
subview.position = .absolute
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
@objc(TopModalViewManager)
|
|
28
|
-
class TopModalViewManager: RCTViewManager {
|
|
29
|
-
override static func requiresMainQueueSetup() -> Bool {
|
|
30
|
-
return true
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
override func view() -> UIView! {
|
|
34
|
-
let v = TopModalView(bridge: bridge)
|
|
35
|
-
return v
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
private func getSheetView(withTag tag: NSNumber) -> TopModalView {
|
|
39
|
-
// swiftlint:disable force_cast
|
|
40
|
-
return bridge.uiManager.view(forReactTag: tag) as! TopModalView
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
@objc
|
|
44
|
-
final func dismiss(_ node: NSNumber) {
|
|
45
|
-
DispatchQueue.main.async {
|
|
46
|
-
let component = self.getSheetView(withTag: node)
|
|
47
|
-
component.dismissVC()
|
|
48
|
-
debugPrint("😀dismiss")
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
override func shadowView() -> RCTShadowView! {
|
|
53
|
-
return TopModalShadowView()
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
deinit {
|
|
57
|
-
debugPrint("😀 deinit view manager")
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
class TopModalView: RCTView {
|
|
63
|
-
let viewController = UIViewController()
|
|
64
|
-
var _touchHandler: RCTTouchHandler?
|
|
65
|
-
var _reactSubview: UIView?
|
|
66
|
-
var _bridge: RCTBridge?
|
|
67
|
-
weak var manager: SheetViewManager?
|
|
68
|
-
var _isPresented = false
|
|
69
|
-
var _scrollViewTag: NSNumber?
|
|
70
|
-
|
|
71
|
-
private var _alertWindow: UIWindow?
|
|
72
|
-
private lazy var presentViewController: UIViewController = {
|
|
73
|
-
_alertWindow = UIWindow(frame: .init(origin: .zero, size: RCTScreenSize()))
|
|
74
|
-
let controller = UIViewController()
|
|
75
|
-
_alertWindow?.rootViewController = controller
|
|
76
|
-
_alertWindow?.windowLevel = UIWindow.Level.alert
|
|
77
|
-
_alertWindow?.isHidden = false
|
|
78
|
-
viewController.modalPresentationStyle = .fullScreen
|
|
79
|
-
|
|
80
|
-
if (animationType == "fade") {
|
|
81
|
-
viewController.modalTransitionStyle = .crossDissolve
|
|
82
|
-
} else if (animationType == "slide") {
|
|
83
|
-
viewController.modalTransitionStyle = .coverVertical
|
|
84
|
-
} else if animationType == "none" {
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
viewController.view.backgroundColor = .clear
|
|
89
|
-
return controller
|
|
90
|
-
}()
|
|
91
|
-
|
|
92
|
-
@objc
|
|
93
|
-
private var onModalDismiss: RCTDirectEventBlock?
|
|
94
|
-
@objc
|
|
95
|
-
private var animated: Bool = true
|
|
96
|
-
/// objc doesn't support String Enums
|
|
97
|
-
@objc
|
|
98
|
-
private var animationType = "slide"
|
|
99
|
-
|
|
100
|
-
init(bridge: RCTBridge) {
|
|
101
|
-
self._bridge = bridge
|
|
102
|
-
super.init(frame: .zero)
|
|
103
|
-
_touchHandler = RCTTouchHandler(bridge: bridge)
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
required init?(coder: NSCoder) {
|
|
107
|
-
fatalError("init(coder:) has not been implemented")
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
override func insertReactSubview(_ subview: UIView!, at atIndex: Int) {
|
|
111
|
-
debugPrint("😀insertReactSubview")
|
|
112
|
-
super.insertReactSubview(subview, at: atIndex)
|
|
113
|
-
_touchHandler?.attach(to: subview)
|
|
114
|
-
viewController.view.insertSubview(subview, at: 0)
|
|
115
|
-
_reactSubview = subview
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
override func removeReactSubview(_ subview: UIView!) {
|
|
119
|
-
debugPrint("😀removeReactSubview")
|
|
120
|
-
super.removeReactSubview(subview)
|
|
121
|
-
_touchHandler?.detach(from: subview)
|
|
122
|
-
_reactSubview = nil
|
|
123
|
-
//destroy()
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// need to leave it empty
|
|
127
|
-
override func didUpdateReactSubviews() {}
|
|
128
|
-
|
|
129
|
-
override func didMoveToWindow() {
|
|
130
|
-
super.didMoveToWindow()
|
|
131
|
-
if (!self.isUserInteractionEnabled && self.superview?.reactSubviews().contains(self) != nil) {
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
if (!_isPresented && self.window != nil) {
|
|
136
|
-
_isPresented = true
|
|
137
|
-
DispatchQueue.main.async { [weak self] in
|
|
138
|
-
guard let self = self else {return}
|
|
139
|
-
guard let rv = self._reactSubview else {return}
|
|
140
|
-
self.viewController.view.addSubview(rv)
|
|
141
|
-
self.presentViewController.present(self.viewController, animated: self.animated)
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
override func removeFromSuperview() {
|
|
147
|
-
super.removeFromSuperview()
|
|
148
|
-
debugPrint("😀removeFromSuperview")
|
|
149
|
-
//destroy()
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
override func didMoveToSuperview() {
|
|
153
|
-
super.didMoveToSuperview()
|
|
154
|
-
if _isPresented && superview == nil {
|
|
155
|
-
debugPrint("😀didMoveToSuperview")
|
|
156
|
-
destroy()
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
func dismissVC() {
|
|
161
|
-
self.viewController.dismiss(animated: self.animated) {
|
|
162
|
-
debugPrint("😀 dismissVC \(self.onModalDismiss)")
|
|
163
|
-
self.onModalDismiss?([:])
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
func destroy() {
|
|
168
|
-
debugPrint("😀destroy")
|
|
169
|
-
_isPresented = false
|
|
170
|
-
|
|
171
|
-
let cleanup = { [weak self] in
|
|
172
|
-
guard let self = self else { return }
|
|
173
|
-
debugPrint("😀 cleanup")
|
|
174
|
-
self._reactSubview?.removeFromSuperview()
|
|
175
|
-
self._touchHandler?.detach(from: self._reactSubview)
|
|
176
|
-
self._touchHandler = nil
|
|
177
|
-
self._bridge = nil
|
|
178
|
-
self.onModalDismiss = nil
|
|
179
|
-
self._reactSubview = nil
|
|
180
|
-
self._alertWindow = nil
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
if self.viewController.isBeingDismissed != true {
|
|
185
|
-
debugPrint("😀dismissViewController")
|
|
186
|
-
self.viewController.dismiss(animated: self.animated, completion: cleanup)
|
|
187
|
-
} else {
|
|
188
|
-
cleanup()
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
deinit {
|
|
194
|
-
debugPrint("😀deinit")
|
|
195
|
-
}
|
|
196
|
-
}
|
package/src/TopModal.tsx
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
findNodeHandle,
|
|
3
|
-
NativeModules,
|
|
4
|
-
requireNativeComponent,
|
|
5
|
-
StyleSheet,
|
|
6
|
-
View,
|
|
7
|
-
} from 'react-native';
|
|
8
|
-
import React from 'react';
|
|
9
|
-
|
|
10
|
-
const TopModalView = requireNativeComponent<any>('TopModalView');
|
|
11
|
-
|
|
12
|
-
interface Props {
|
|
13
|
-
onModalDismiss?: () => void;
|
|
14
|
-
children: React.ReactNode;
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @default false
|
|
18
|
-
* @platform Android
|
|
19
|
-
*/
|
|
20
|
-
isEdgeToEdge?: boolean;
|
|
21
|
-
/**
|
|
22
|
-
* @default false
|
|
23
|
-
* @platform Android
|
|
24
|
-
*/
|
|
25
|
-
isSystemUILight?: boolean;
|
|
26
|
-
|
|
27
|
-
animated?: boolean;
|
|
28
|
-
/** @default "slide" */
|
|
29
|
-
animationType?: 'slide' | 'fade' | 'none';
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
interface State {
|
|
33
|
-
show: boolean;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export class TopModal extends React.PureComponent<Props, State> {
|
|
37
|
-
private sheetRef = React.createRef<any>();
|
|
38
|
-
|
|
39
|
-
constructor(props: Props) {
|
|
40
|
-
super(props);
|
|
41
|
-
this.state = {
|
|
42
|
-
show: false,
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
show = () => {
|
|
47
|
-
if (this.state.show) return;
|
|
48
|
-
this.setState({ show: true });
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
hide = () => {
|
|
52
|
-
if (!this.state.show) return;
|
|
53
|
-
const tag = findNodeHandle(this.sheetRef.current);
|
|
54
|
-
if (!tag) return;
|
|
55
|
-
console.log('[TopModal.hide]', tag);
|
|
56
|
-
NativeModules.TopModalView.dismiss(tag);
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
private onDismiss = () => {
|
|
60
|
-
console.log('[FittedSheet.onDismiss]');
|
|
61
|
-
this.setState({ show: false });
|
|
62
|
-
this.props.onModalDismiss?.();
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
componentWillUnmount() {
|
|
66
|
-
this.hide();
|
|
67
|
-
console.log('[TopModal.componentWillUnmount]');
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
render() {
|
|
71
|
-
if (!this.state.show) {
|
|
72
|
-
this.hide();
|
|
73
|
-
console.log('[TopModal.render.remove]');
|
|
74
|
-
return null;
|
|
75
|
-
}
|
|
76
|
-
return (
|
|
77
|
-
<TopModalView
|
|
78
|
-
ref={this.sheetRef}
|
|
79
|
-
onModalDismiss={this.onDismiss}
|
|
80
|
-
animated={this.props.animated ?? true}
|
|
81
|
-
animationType={this.props.animationType ?? 'slide'}
|
|
82
|
-
isEdgeToEdge={this.props.isEdgeToEdge ?? false}
|
|
83
|
-
isStatusBarBgLight={this.props.isSystemUILight ?? false}
|
|
84
|
-
>
|
|
85
|
-
<View
|
|
86
|
-
accessibilityLabel={'top-modal-root-view'}
|
|
87
|
-
nativeID={'top-modal-root-view'}
|
|
88
|
-
style={StyleSheet.absoluteFill}
|
|
89
|
-
children={this.props.children}
|
|
90
|
-
/>
|
|
91
|
-
</TopModalView>
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
}
|