@lodev09/react-native-true-sheet 2.0.5 → 4.0.0-beta.0
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 +36 -8
- package/RNTrueSheet.podspec +20 -0
- package/android/build.gradle +26 -14
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetContainerView.kt +108 -0
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetContainerViewManager.kt +21 -0
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetContentView.kt +46 -0
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetContentViewManager.kt +21 -0
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetFooterView.kt +47 -0
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetFooterViewManager.kt +21 -0
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetModule.kt +165 -0
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetPackage.kt +36 -4
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetView.kt +257 -299
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetViewController.kt +855 -0
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetViewManager.kt +104 -82
- package/android/src/main/java/com/lodev09/truesheet/events/DetentChangeEvent.kt +26 -0
- package/android/src/main/java/com/lodev09/truesheet/events/DidDismissEvent.kt +20 -0
- package/android/src/main/java/com/lodev09/truesheet/events/DidPresentEvent.kt +26 -0
- package/android/src/main/java/com/lodev09/truesheet/events/DragBeginEvent.kt +26 -0
- package/android/src/main/java/com/lodev09/truesheet/events/DragChangeEvent.kt +26 -0
- package/android/src/main/java/com/lodev09/truesheet/events/DragEndEvent.kt +26 -0
- package/android/src/main/java/com/lodev09/truesheet/events/MountEvent.kt +20 -0
- package/android/src/main/java/com/lodev09/truesheet/events/PositionChangeEvent.kt +32 -0
- package/android/src/main/java/com/lodev09/truesheet/events/SizeChangeEvent.kt +27 -0
- package/android/src/main/java/com/lodev09/truesheet/events/WillDismissEvent.kt +20 -0
- package/android/src/main/java/com/lodev09/truesheet/events/WillPresentEvent.kt +26 -0
- package/android/src/main/java/com/lodev09/truesheet/{core/Utils.kt → utils/ScreenUtils.kt} +47 -17
- package/android/src/main/res/values/styles.xml +8 -0
- package/ios/TrueSheetComponentDescriptor.h +24 -0
- package/ios/TrueSheetContainerView.h +47 -0
- package/ios/TrueSheetContainerView.mm +117 -0
- package/ios/TrueSheetContentView.h +37 -0
- package/ios/TrueSheetContentView.mm +114 -0
- package/ios/TrueSheetFooterView.h +27 -0
- package/ios/TrueSheetFooterView.mm +101 -0
- package/ios/TrueSheetModule.h +44 -0
- package/ios/TrueSheetModule.mm +133 -0
- package/ios/TrueSheetView.h +53 -0
- package/ios/TrueSheetView.mm +433 -0
- package/ios/TrueSheetViewController.h +53 -0
- package/ios/TrueSheetViewController.mm +649 -0
- package/ios/events/OnDetentChangeEvent.h +28 -0
- package/ios/events/OnDetentChangeEvent.mm +30 -0
- package/ios/events/OnDidDismissEvent.h +26 -0
- package/ios/events/OnDidDismissEvent.mm +25 -0
- package/ios/events/OnDidPresentEvent.h +28 -0
- package/ios/events/OnDidPresentEvent.mm +30 -0
- package/ios/events/OnDragBeginEvent.h +28 -0
- package/ios/events/OnDragBeginEvent.mm +30 -0
- package/ios/events/OnDragChangeEvent.h +28 -0
- package/ios/events/OnDragChangeEvent.mm +30 -0
- package/ios/events/OnDragEndEvent.h +28 -0
- package/ios/events/OnDragEndEvent.mm +30 -0
- package/ios/events/OnMountEvent.h +26 -0
- package/ios/events/OnMountEvent.mm +25 -0
- package/ios/events/OnPositionChangeEvent.h +29 -0
- package/ios/events/OnPositionChangeEvent.mm +32 -0
- package/ios/events/OnSizeChangeEvent.h +28 -0
- package/ios/events/OnSizeChangeEvent.mm +30 -0
- package/ios/events/OnWillDismissEvent.h +26 -0
- package/ios/events/OnWillDismissEvent.mm +25 -0
- package/ios/events/OnWillPresentEvent.h +28 -0
- package/ios/events/OnWillPresentEvent.mm +30 -0
- package/ios/utils/GestureUtil.h +25 -0
- package/ios/utils/GestureUtil.mm +26 -0
- package/ios/utils/LayoutUtil.h +44 -0
- package/ios/utils/LayoutUtil.mm +50 -0
- package/ios/utils/WindowUtil.h +27 -0
- package/ios/utils/WindowUtil.mm +42 -0
- package/lib/module/TrueSheet.js +231 -135
- package/lib/module/TrueSheet.js.map +1 -1
- package/lib/module/TrueSheetGrabber.js +16 -14
- package/lib/module/TrueSheetGrabber.js.map +1 -1
- package/lib/module/fabric/TrueSheetContainerViewNativeComponent.ts +8 -0
- package/lib/module/fabric/TrueSheetContentViewNativeComponent.ts +8 -0
- package/lib/module/fabric/TrueSheetFooterViewNativeComponent.ts +8 -0
- package/lib/module/fabric/TrueSheetViewNativeComponent.ts +63 -0
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/reanimated/ReanimatedTrueSheet.js +87 -0
- package/lib/module/reanimated/ReanimatedTrueSheet.js.map +1 -0
- package/lib/module/reanimated/ReanimatedTrueSheetProvider.js +72 -0
- package/lib/module/reanimated/ReanimatedTrueSheetProvider.js.map +1 -0
- package/lib/module/reanimated/index.js +6 -0
- package/lib/module/reanimated/index.js.map +1 -0
- package/lib/module/reanimated/useReanimatedPositionChangeHandler.js +19 -0
- package/lib/module/reanimated/useReanimatedPositionChangeHandler.js.map +1 -0
- package/lib/module/specs/NativeTrueSheetModule.js +12 -0
- package/lib/module/specs/NativeTrueSheetModule.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/TrueSheet.d.ts +79 -0
- package/lib/typescript/src/TrueSheet.d.ts.map +1 -0
- package/lib/typescript/src/TrueSheet.types.d.ts +260 -0
- package/lib/typescript/src/TrueSheet.types.d.ts.map +1 -0
- package/lib/typescript/{commonjs/src → src}/TrueSheetGrabber.d.ts +1 -1
- package/lib/typescript/src/TrueSheetGrabber.d.ts.map +1 -0
- package/lib/typescript/src/fabric/TrueSheetContainerViewNativeComponent.d.ts +6 -0
- package/lib/typescript/src/fabric/TrueSheetContainerViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/fabric/TrueSheetContentViewNativeComponent.d.ts +6 -0
- package/lib/typescript/src/fabric/TrueSheetContentViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/fabric/TrueSheetFooterViewNativeComponent.d.ts +6 -0
- package/lib/typescript/src/fabric/TrueSheetFooterViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/fabric/TrueSheetViewNativeComponent.d.ts +44 -0
- package/lib/typescript/src/fabric/TrueSheetViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/{commonjs/src → src}/index.d.ts +1 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/reanimated/ReanimatedTrueSheet.d.ts +43 -0
- package/lib/typescript/src/reanimated/ReanimatedTrueSheet.d.ts.map +1 -0
- package/lib/typescript/src/reanimated/ReanimatedTrueSheetProvider.d.ts +57 -0
- package/lib/typescript/src/reanimated/ReanimatedTrueSheetProvider.d.ts.map +1 -0
- package/lib/typescript/src/reanimated/index.d.ts +4 -0
- package/lib/typescript/src/reanimated/index.d.ts.map +1 -0
- package/lib/typescript/src/reanimated/useReanimatedPositionChangeHandler.d.ts +6 -0
- package/lib/typescript/src/reanimated/useReanimatedPositionChangeHandler.d.ts.map +1 -0
- package/lib/typescript/src/specs/NativeTrueSheetModule.d.ts +34 -0
- package/lib/typescript/src/specs/NativeTrueSheetModule.d.ts.map +1 -0
- package/package.json +104 -75
- package/react-native.config.js +17 -0
- package/src/TrueSheet.tsx +285 -188
- package/src/TrueSheet.types.ts +119 -106
- package/src/TrueSheetGrabber.tsx +29 -28
- package/src/__mocks__/index.js +60 -12
- package/src/fabric/TrueSheetContainerViewNativeComponent.ts +8 -0
- package/src/fabric/TrueSheetContentViewNativeComponent.ts +8 -0
- package/src/fabric/TrueSheetFooterViewNativeComponent.ts +8 -0
- package/src/fabric/TrueSheetViewNativeComponent.ts +63 -0
- package/src/index.ts +4 -3
- package/src/reanimated/ReanimatedTrueSheet.tsx +95 -0
- package/src/reanimated/ReanimatedTrueSheetProvider.tsx +92 -0
- package/src/reanimated/index.ts +3 -0
- package/src/reanimated/useReanimatedPositionChangeHandler.ts +26 -0
- package/src/specs/NativeTrueSheetModule.ts +38 -0
- package/TrueSheet.podspec +0 -49
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetDialog.kt +0 -400
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetEvent.kt +0 -22
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetViewModule.kt +0 -63
- package/android/src/main/java/com/lodev09/truesheet/core/KeyboardManager.kt +0 -58
- package/android/src/main/java/com/lodev09/truesheet/core/RootSheetView.kt +0 -102
- package/ios/Extensions/UIBlurEffect+withTint.swift +0 -62
- package/ios/Extensions/UIView+pinTo.swift +0 -74
- package/ios/Extensions/UIViewController+detentForSize.swift +0 -134
- package/ios/TrueSheet-Bridging-Header.h +0 -14
- package/ios/TrueSheetEvent.swift +0 -48
- package/ios/TrueSheetView.swift +0 -461
- package/ios/TrueSheetViewController.swift +0 -275
- package/ios/TrueSheetViewManager.m +0 -53
- package/ios/TrueSheetViewManager.swift +0 -48
- package/ios/Utils/Logger.swift +0 -39
- package/ios/Utils/Promise.swift +0 -25
- package/lib/commonjs/TrueSheet.js +0 -258
- package/lib/commonjs/TrueSheet.js.map +0 -1
- package/lib/commonjs/TrueSheet.types.js +0 -6
- package/lib/commonjs/TrueSheet.types.js.map +0 -1
- package/lib/commonjs/TrueSheetFooter.js +0 -19
- package/lib/commonjs/TrueSheetFooter.js.map +0 -1
- package/lib/commonjs/TrueSheetGrabber.js +0 -54
- package/lib/commonjs/TrueSheetGrabber.js.map +0 -1
- package/lib/commonjs/TrueSheetModule.js +0 -19
- package/lib/commonjs/TrueSheetModule.js.map +0 -1
- package/lib/commonjs/__mocks__/index.js +0 -52
- package/lib/commonjs/__mocks__/index.js.map +0 -1
- package/lib/commonjs/index.js +0 -39
- package/lib/commonjs/index.js.map +0 -1
- package/lib/module/TrueSheetFooter.js +0 -14
- package/lib/module/TrueSheetFooter.js.map +0 -1
- package/lib/module/TrueSheetModule.js +0 -15
- package/lib/module/TrueSheetModule.js.map +0 -1
- package/lib/module/__mocks__/index.js +0 -21
- package/lib/module/__mocks__/index.js.map +0 -1
- package/lib/typescript/commonjs/package.json +0 -1
- package/lib/typescript/commonjs/src/TrueSheet.d.ts +0 -70
- package/lib/typescript/commonjs/src/TrueSheet.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/TrueSheet.types.d.ts +0 -241
- package/lib/typescript/commonjs/src/TrueSheet.types.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/TrueSheetFooter.d.ts +0 -7
- package/lib/typescript/commonjs/src/TrueSheetFooter.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/TrueSheetGrabber.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/TrueSheetModule.d.ts +0 -2
- package/lib/typescript/commonjs/src/TrueSheetModule.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/index.d.ts.map +0 -1
- package/lib/typescript/module/src/TrueSheet.d.ts +0 -70
- package/lib/typescript/module/src/TrueSheet.d.ts.map +0 -1
- package/lib/typescript/module/src/TrueSheet.types.d.ts +0 -241
- package/lib/typescript/module/src/TrueSheet.types.d.ts.map +0 -1
- package/lib/typescript/module/src/TrueSheetFooter.d.ts +0 -7
- package/lib/typescript/module/src/TrueSheetFooter.d.ts.map +0 -1
- package/lib/typescript/module/src/TrueSheetGrabber.d.ts +0 -39
- package/lib/typescript/module/src/TrueSheetGrabber.d.ts.map +0 -1
- package/lib/typescript/module/src/TrueSheetModule.d.ts +0 -2
- package/lib/typescript/module/src/TrueSheetModule.d.ts.map +0 -1
- package/lib/typescript/module/src/index.d.ts +0 -4
- package/lib/typescript/module/src/index.d.ts.map +0 -1
- package/src/TrueSheetFooter.tsx +0 -17
- package/src/TrueSheetModule.ts +0 -19
- /package/lib/{typescript/module → module}/package.json +0 -0
package/ios/TrueSheetView.swift
DELETED
|
@@ -1,461 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Created by Jovanni Lo (@lodev09)
|
|
3
|
-
// Copyright (c) 2024-present. All rights reserved.
|
|
4
|
-
//
|
|
5
|
-
// This source code is licensed under the MIT license found in the
|
|
6
|
-
// LICENSE file in the root directory of this source tree.
|
|
7
|
-
//
|
|
8
|
-
|
|
9
|
-
@objc(TrueSheetView)
|
|
10
|
-
class TrueSheetView: UIView, RCTInvalidating, TrueSheetViewControllerDelegate {
|
|
11
|
-
// MARK: - React properties
|
|
12
|
-
|
|
13
|
-
// MARK: - Events
|
|
14
|
-
|
|
15
|
-
@objc var onMount: RCTDirectEventBlock?
|
|
16
|
-
@objc var onDismiss: RCTDirectEventBlock?
|
|
17
|
-
@objc var onPresent: RCTDirectEventBlock?
|
|
18
|
-
@objc var onSizeChange: RCTDirectEventBlock?
|
|
19
|
-
@objc var onContainerSizeChange: RCTDirectEventBlock?
|
|
20
|
-
@objc var onDragBegin: RCTDirectEventBlock?
|
|
21
|
-
@objc var onDragChange: RCTDirectEventBlock?
|
|
22
|
-
@objc var onDragEnd: RCTDirectEventBlock?
|
|
23
|
-
|
|
24
|
-
// MARK: - React Properties
|
|
25
|
-
|
|
26
|
-
@objc var initialIndex: NSNumber = -1
|
|
27
|
-
@objc var initialIndexAnimated = true
|
|
28
|
-
|
|
29
|
-
// MARK: - Private properties
|
|
30
|
-
|
|
31
|
-
private var isPresented = false
|
|
32
|
-
private var activeIndex: Int?
|
|
33
|
-
private var bridge: RCTBridge?
|
|
34
|
-
private var eventDispatcher: (any RCTEventDispatcherProtocol)?
|
|
35
|
-
private var viewController: TrueSheetViewController
|
|
36
|
-
|
|
37
|
-
private var touchHandler: RCTTouchHandler
|
|
38
|
-
// New Arch
|
|
39
|
-
private var surfaceTouchHandler: RCTSurfaceTouchHandler
|
|
40
|
-
|
|
41
|
-
// MARK: - Content properties
|
|
42
|
-
|
|
43
|
-
private var containerView: UIView?
|
|
44
|
-
private var contentView: UIView?
|
|
45
|
-
private var footerView: UIView?
|
|
46
|
-
private var scrollView: UIView?
|
|
47
|
-
|
|
48
|
-
// Bottom: Reference the bottom constraint to adjust during keyboard event
|
|
49
|
-
// Height: Reference height constraint during content updates
|
|
50
|
-
private var footerConstraints: Constraints?
|
|
51
|
-
|
|
52
|
-
private var uiManager: RCTUIManager? {
|
|
53
|
-
guard let uiManager = bridge?.uiManager else { return nil }
|
|
54
|
-
return uiManager
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// MARK: - Setup
|
|
58
|
-
|
|
59
|
-
init(with bridge: RCTBridge) {
|
|
60
|
-
self.bridge = bridge
|
|
61
|
-
eventDispatcher = bridge.eventDispatcher()
|
|
62
|
-
|
|
63
|
-
viewController = TrueSheetViewController()
|
|
64
|
-
touchHandler = RCTTouchHandler(bridge: bridge)
|
|
65
|
-
surfaceTouchHandler = RCTSurfaceTouchHandler()
|
|
66
|
-
|
|
67
|
-
super.init(frame: .zero)
|
|
68
|
-
|
|
69
|
-
viewController.delegate = self
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
@available(*, unavailable)
|
|
73
|
-
required init?(coder _: NSCoder) {
|
|
74
|
-
fatalError("init(coder:) has not been implemented")
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
override func insertReactSubview(_ subview: UIView!, at index: Int) {
|
|
78
|
-
super.insertReactSubview(subview, at: index)
|
|
79
|
-
|
|
80
|
-
guard containerView == nil else {
|
|
81
|
-
Logger.error("Sheet can only have one content view.")
|
|
82
|
-
return
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
containerView = subview
|
|
86
|
-
|
|
87
|
-
viewController.view.addSubview(subview)
|
|
88
|
-
touchHandler.attach(to: subview)
|
|
89
|
-
surfaceTouchHandler.attach(to: subview)
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
override func removeReactSubview(_ subview: UIView!) {
|
|
93
|
-
guard subview == containerView else {
|
|
94
|
-
Logger.error("Cannot remove view other than sheet view")
|
|
95
|
-
return
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
super.removeReactSubview(subview)
|
|
99
|
-
|
|
100
|
-
// Touch handler for Old Arch
|
|
101
|
-
touchHandler.detach(from: subview)
|
|
102
|
-
|
|
103
|
-
// Touch handler that works in New Arch
|
|
104
|
-
surfaceTouchHandler.detach(from: subview)
|
|
105
|
-
|
|
106
|
-
// Remove all constraints
|
|
107
|
-
// Fixes New Arch weird layout issue :/
|
|
108
|
-
containerView?.unpin()
|
|
109
|
-
footerView?.unpin()
|
|
110
|
-
contentView?.unpin()
|
|
111
|
-
scrollView?.unpin()
|
|
112
|
-
|
|
113
|
-
containerView = nil
|
|
114
|
-
contentView = nil
|
|
115
|
-
footerView = nil
|
|
116
|
-
scrollView = nil
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
override func didUpdateReactSubviews() {
|
|
120
|
-
// Do nothing, as subviews are managed by `insertReactSubview`
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
override func layoutSubviews() {
|
|
124
|
-
super.layoutSubviews()
|
|
125
|
-
|
|
126
|
-
if let containerView, contentView == nil {
|
|
127
|
-
contentView = containerView.subviews[0]
|
|
128
|
-
footerView = containerView.subviews[1]
|
|
129
|
-
|
|
130
|
-
containerView.pinTo(view: viewController.view, constraints: nil)
|
|
131
|
-
|
|
132
|
-
if let contentView {
|
|
133
|
-
// Set initial content height
|
|
134
|
-
let contentHeight = contentView.bounds.height
|
|
135
|
-
setContentHeight(NSNumber(value: contentHeight))
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// Set footer constraints
|
|
139
|
-
if let footerView {
|
|
140
|
-
footerView.pinTo(view: viewController.view, from: [.left, .right, .bottom], with: 0) { constraints in
|
|
141
|
-
self.footerConstraints = constraints
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
// Set initial footer height
|
|
145
|
-
let footerHeight = footerView.bounds.height
|
|
146
|
-
setFooterHeight(NSNumber(value: footerHeight))
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// Present sheet at initial index
|
|
150
|
-
let initialIndex = self.initialIndex.intValue
|
|
151
|
-
if initialIndex >= 0 {
|
|
152
|
-
present(at: initialIndex, promise: nil, animated: initialIndexAnimated)
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
dispatchEvent(name: "onMount", block: onMount, data: nil)
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// MARK: - ViewController delegate
|
|
160
|
-
|
|
161
|
-
func viewControllerKeyboardWillHide() {
|
|
162
|
-
footerConstraints?.bottom?.constant = 0
|
|
163
|
-
|
|
164
|
-
UIView.animate(withDuration: 0.3) {
|
|
165
|
-
self.viewController.view.layoutIfNeeded()
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
func viewControllerKeyboardWillShow(_ keyboardHeight: CGFloat) {
|
|
170
|
-
footerConstraints?.bottom?.constant = -keyboardHeight
|
|
171
|
-
|
|
172
|
-
UIView.animate(withDuration: 0.3) {
|
|
173
|
-
self.viewController.view.layoutIfNeeded()
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
func viewControllerDidChangeWidth(_ width: CGFloat) {
|
|
178
|
-
// We only pass width to JS since height is handled by the constraints
|
|
179
|
-
dispatchEvent(name: "onContainerSizeChange", block: onContainerSizeChange, data: ["width": width])
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
func viewControllerDidDrag(_ state: UIGestureRecognizer.State, _ height: CGFloat) {
|
|
183
|
-
let sizeInfo = SizeInfo(index: activeIndex ?? 0, value: height)
|
|
184
|
-
|
|
185
|
-
switch state {
|
|
186
|
-
case .began:
|
|
187
|
-
dispatchEvent(name: "onDragBegin", block: onDragBegin, data: sizeInfoData(from: sizeInfo))
|
|
188
|
-
case .changed:
|
|
189
|
-
dispatchEvent(name: "onDragChange", block: onDragChange, data: sizeInfoData(from: sizeInfo))
|
|
190
|
-
case .ended, .cancelled:
|
|
191
|
-
dispatchEvent(name: "onDragEnd", block: onDragEnd, data: sizeInfoData(from: sizeInfo))
|
|
192
|
-
default:
|
|
193
|
-
Logger.info("Drag state is not supported")
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
func viewControllerWillAppear() {
|
|
198
|
-
guard let contentView, let scrollView, let containerView else {
|
|
199
|
-
return
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
// Add constraints to fix weirdness and support ScrollView
|
|
203
|
-
contentView.pinTo(view: containerView, constraints: nil)
|
|
204
|
-
scrollView.pinTo(view: contentView, constraints: nil)
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
func viewControllerDidDismiss() {
|
|
208
|
-
isPresented = false
|
|
209
|
-
activeIndex = nil
|
|
210
|
-
dispatchEvent(name: "onDismiss", block: onDismiss, data: nil)
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
func viewControllerDidChangeSize(_ sizeInfo: SizeInfo?) {
|
|
214
|
-
guard let sizeInfo else { return }
|
|
215
|
-
|
|
216
|
-
if sizeInfo.index != activeIndex {
|
|
217
|
-
activeIndex = sizeInfo.index
|
|
218
|
-
dispatchEvent(name: "onSizeChange", block: onSizeChange, data: sizeInfoData(from: sizeInfo))
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
func invalidate() {
|
|
223
|
-
viewController.dismiss(animated: true)
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
// MARK: - Prop setters
|
|
227
|
-
|
|
228
|
-
@objc
|
|
229
|
-
func setDismissible(_ dismissible: Bool) {
|
|
230
|
-
viewController.isModalInPresentation = !dismissible
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
@objc
|
|
234
|
-
func setMaxHeight(_ height: NSNumber) {
|
|
235
|
-
let maxHeight = CGFloat(height.floatValue)
|
|
236
|
-
guard viewController.maxHeight != maxHeight else {
|
|
237
|
-
return
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
viewController.maxHeight = maxHeight
|
|
241
|
-
|
|
242
|
-
if #available(iOS 15.0, *) {
|
|
243
|
-
withPresentedSheet { _ in
|
|
244
|
-
viewController.setupSizes()
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
@objc
|
|
250
|
-
func setContentHeight(_ height: NSNumber) {
|
|
251
|
-
let contentHeight = CGFloat(height.floatValue)
|
|
252
|
-
guard viewController.contentHeight != contentHeight else {
|
|
253
|
-
return
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
viewController.contentHeight = contentHeight
|
|
257
|
-
|
|
258
|
-
if #available(iOS 15.0, *) {
|
|
259
|
-
withPresentedSheet { _ in
|
|
260
|
-
viewController.setupSizes()
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
@objc
|
|
266
|
-
func setFooterHeight(_ height: NSNumber) {
|
|
267
|
-
let footerHeight = CGFloat(height.floatValue)
|
|
268
|
-
guard let footerView, viewController.footerHeight != footerHeight else {
|
|
269
|
-
return
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
viewController.footerHeight = footerHeight
|
|
273
|
-
|
|
274
|
-
if footerView.subviews.first != nil {
|
|
275
|
-
containerView?.bringSubviewToFront(footerView)
|
|
276
|
-
footerConstraints?.height?.constant = viewController.footerHeight
|
|
277
|
-
} else {
|
|
278
|
-
containerView?.sendSubviewToBack(footerView)
|
|
279
|
-
footerConstraints?.height?.constant = 0
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
if #available(iOS 15.0, *) {
|
|
283
|
-
withPresentedSheet { _ in
|
|
284
|
-
viewController.setupSizes()
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
@objc
|
|
290
|
-
func setSizes(_ sizes: [Any]) {
|
|
291
|
-
viewController.sizes = Array(sizes.prefix(3))
|
|
292
|
-
|
|
293
|
-
if #available(iOS 15.0, *) {
|
|
294
|
-
withPresentedSheet { _ in
|
|
295
|
-
viewController.setupSizes()
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
@objc
|
|
301
|
-
func setBackground(_ color: NSNumber?) {
|
|
302
|
-
viewController.backgroundColor = RCTConvert.uiColor(color)
|
|
303
|
-
viewController.setupBackground()
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
@objc
|
|
307
|
-
func setBlurTint(_ tint: NSString?) {
|
|
308
|
-
if let tint {
|
|
309
|
-
viewController.blurEffect = UIBlurEffect(with: tint as String)
|
|
310
|
-
} else {
|
|
311
|
-
viewController.blurEffect = nil
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
viewController.setupBackground()
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
@objc
|
|
318
|
-
func setCornerRadius(_ radius: NSNumber?) {
|
|
319
|
-
var cornerRadius: CGFloat?
|
|
320
|
-
|
|
321
|
-
if let radius {
|
|
322
|
-
cornerRadius = CGFloat(radius.floatValue)
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
viewController.cornerRadius = cornerRadius
|
|
326
|
-
if #available(iOS 15.0, *) {
|
|
327
|
-
withPresentedSheet { sheet in
|
|
328
|
-
sheet.preferredCornerRadius = viewController.cornerRadius
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
@objc
|
|
334
|
-
func setGrabber(_ visible: Bool) {
|
|
335
|
-
viewController.grabber = visible
|
|
336
|
-
|
|
337
|
-
if #available(iOS 15.0, *) {
|
|
338
|
-
withPresentedSheet { sheet in
|
|
339
|
-
sheet.prefersGrabberVisible = visible
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
@objc
|
|
345
|
-
func setDimmed(_ dimmed: Bool) {
|
|
346
|
-
guard viewController.dimmed != dimmed else {
|
|
347
|
-
return
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
viewController.dimmed = dimmed
|
|
351
|
-
|
|
352
|
-
if #available(iOS 15.0, *) {
|
|
353
|
-
withPresentedSheet { _ in
|
|
354
|
-
viewController.setupDimmedBackground()
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
@objc
|
|
360
|
-
func setDimmedIndex(_ index: NSNumber) {
|
|
361
|
-
guard viewController.dimmedIndex != index.intValue else {
|
|
362
|
-
return
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
viewController.dimmedIndex = index.intValue
|
|
366
|
-
|
|
367
|
-
if #available(iOS 15.0, *) {
|
|
368
|
-
withPresentedSheet { _ in
|
|
369
|
-
viewController.setupDimmedBackground()
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
@objc
|
|
375
|
-
func setScrollableHandle(_ tag: NSNumber?) {
|
|
376
|
-
scrollView = uiManager?.view(forReactTag: tag)
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
// MARK: - Methods
|
|
380
|
-
|
|
381
|
-
private func sizeInfoData(from sizeInfo: SizeInfo?) -> [String: Any]? {
|
|
382
|
-
guard let sizeInfo else {
|
|
383
|
-
return nil
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
return ["index": sizeInfo.index, "value": sizeInfo.value]
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
/// Use to customize some properties of the Sheet without fully reconfiguring.
|
|
390
|
-
@available(iOS 15.0, *)
|
|
391
|
-
func withPresentedSheet(completion: (UISheetPresentationController) -> Void) {
|
|
392
|
-
guard isPresented, let sheet = viewController.sheetPresentationController else {
|
|
393
|
-
return
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
sheet.animateChanges {
|
|
397
|
-
completion(sheet)
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
func dispatchEvent(name: String, block: RCTDirectEventBlock?, data: [String: Any]?) {
|
|
402
|
-
// eventDispatcher doesn't work in New Arch so we need to call it directly :/
|
|
403
|
-
// we needed eventDispatcher for Reanimated to work on old arch.
|
|
404
|
-
#if RCT_NEW_ARCH_ENABLED
|
|
405
|
-
block?(data)
|
|
406
|
-
#else
|
|
407
|
-
eventDispatcher?.send(TrueSheetEvent(viewTag: reactTag, name: name, data: data))
|
|
408
|
-
#endif
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
func dismiss(promise: Promise) {
|
|
412
|
-
guard isPresented else {
|
|
413
|
-
promise.resolve(nil)
|
|
414
|
-
return
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
viewController.dismiss(animated: true) {
|
|
418
|
-
promise.resolve(nil)
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
func present(at index: Int, promise: Promise?, animated: Bool = true) {
|
|
423
|
-
let rvc = reactViewController()
|
|
424
|
-
|
|
425
|
-
guard let rvc else {
|
|
426
|
-
promise?.reject(message: "No react view controller present.")
|
|
427
|
-
return
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
guard viewController.sizes.indices.contains(index) else {
|
|
431
|
-
promise?.reject(message: "Size at \(index) is not configured.")
|
|
432
|
-
return
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
if isPresented {
|
|
436
|
-
withPresentedSheet { sheet in
|
|
437
|
-
sheet.selectedDetentIdentifier = viewController.detentIdentifierForIndex(index)
|
|
438
|
-
|
|
439
|
-
// Trigger onSizeChange event when size is changed while presenting
|
|
440
|
-
viewControllerDidChangeSize(self.viewController.currentSizeInfo)
|
|
441
|
-
promise?.resolve(nil)
|
|
442
|
-
}
|
|
443
|
-
} else {
|
|
444
|
-
viewController.prepareForPresentation(at: index) {
|
|
445
|
-
// Keep track of the active index
|
|
446
|
-
self.activeIndex = index
|
|
447
|
-
self.isPresented = true
|
|
448
|
-
|
|
449
|
-
rvc.present(self.viewController, animated: animated) {
|
|
450
|
-
if #available(iOS 15.0, *) {
|
|
451
|
-
self.viewController.observeDrag()
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
let data = self.sizeInfoData(from: self.viewController.currentSizeInfo)
|
|
455
|
-
self.dispatchEvent(name: "onPresent", block: self.onPresent, data: data)
|
|
456
|
-
promise?.resolve(nil)
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
}
|