@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
|
@@ -1,176 +1,80 @@
|
|
|
1
1
|
package com.lodev09.truesheet
|
|
2
2
|
|
|
3
|
-
import android.
|
|
3
|
+
import android.annotation.SuppressLint
|
|
4
4
|
import android.view.View
|
|
5
|
-
import android.view.ViewGroup
|
|
6
5
|
import android.view.ViewStructure
|
|
7
6
|
import android.view.accessibility.AccessibilityEvent
|
|
8
|
-
import
|
|
7
|
+
import androidx.annotation.UiThread
|
|
9
8
|
import com.facebook.react.bridge.LifecycleEventListener
|
|
10
|
-
import com.facebook.react.bridge.UiThreadUtil
|
|
11
|
-
import com.facebook.react.bridge.WritableMap
|
|
12
9
|
import com.facebook.react.uimanager.ThemedReactContext
|
|
13
10
|
import com.facebook.react.uimanager.UIManagerHelper
|
|
14
11
|
import com.facebook.react.uimanager.events.EventDispatcher
|
|
15
|
-
import com.
|
|
16
|
-
import com.lodev09.truesheet.
|
|
17
|
-
import com.lodev09.truesheet.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
12
|
+
import com.facebook.react.views.view.ReactViewGroup
|
|
13
|
+
import com.lodev09.truesheet.events.DetentChangeEvent
|
|
14
|
+
import com.lodev09.truesheet.events.DidDismissEvent
|
|
15
|
+
import com.lodev09.truesheet.events.DidPresentEvent
|
|
16
|
+
import com.lodev09.truesheet.events.DragBeginEvent
|
|
17
|
+
import com.lodev09.truesheet.events.DragChangeEvent
|
|
18
|
+
import com.lodev09.truesheet.events.DragEndEvent
|
|
19
|
+
import com.lodev09.truesheet.events.MountEvent
|
|
20
|
+
import com.lodev09.truesheet.events.PositionChangeEvent
|
|
21
|
+
import com.lodev09.truesheet.events.SizeChangeEvent
|
|
22
|
+
import com.lodev09.truesheet.events.WillDismissEvent
|
|
23
|
+
import com.lodev09.truesheet.events.WillPresentEvent
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Main TrueSheet host view.
|
|
27
|
+
* Manages the sheet dialog and container, and dispatches events to JavaScript.
|
|
28
|
+
*/
|
|
29
|
+
@SuppressLint("ViewConstructor")
|
|
30
|
+
class TrueSheetView(private val reactContext: ThemedReactContext) :
|
|
31
|
+
ReactViewGroup(reactContext),
|
|
32
|
+
LifecycleEventListener,
|
|
33
|
+
TrueSheetViewControllerDelegate,
|
|
34
|
+
TrueSheetContainerViewDelegate {
|
|
37
35
|
|
|
38
36
|
/**
|
|
39
|
-
*
|
|
37
|
+
* The TrueSheetViewController instance that acts as both root view and controller
|
|
40
38
|
*/
|
|
41
|
-
private
|
|
39
|
+
private val viewController: TrueSheetViewController = TrueSheetViewController(reactContext)
|
|
42
40
|
|
|
43
41
|
/**
|
|
44
|
-
*
|
|
42
|
+
* Gets the container view (first child of view controller)
|
|
45
43
|
*/
|
|
46
|
-
private
|
|
44
|
+
private val containerView: TrueSheetContainerView?
|
|
45
|
+
get() = viewController.getChildAt(0) as? TrueSheetContainerView
|
|
47
46
|
|
|
48
|
-
|
|
49
|
-
* Promise callback to be invoked after `present` is called.
|
|
50
|
-
*/
|
|
51
|
-
private var presentPromise: (() -> Unit)? = null
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Promise callback to be invoked after `dismiss` is called.
|
|
55
|
-
*/
|
|
56
|
-
private var dismissPromise: (() -> Unit)? = null
|
|
47
|
+
var eventDispatcher: EventDispatcher? = null
|
|
57
48
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
*/
|
|
61
|
-
private val sheetDialog: TrueSheetDialog
|
|
49
|
+
var initialDetentIndex: Int = -1
|
|
50
|
+
var initialDetentAnimated: Boolean = true
|
|
62
51
|
|
|
63
52
|
/**
|
|
64
|
-
*
|
|
53
|
+
* Tracks if initial presentation has been handled
|
|
65
54
|
*/
|
|
66
|
-
private
|
|
55
|
+
private var hasHandledInitialPresentation = false
|
|
67
56
|
|
|
68
57
|
init {
|
|
69
58
|
reactContext.addLifecycleEventListener(this)
|
|
70
59
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
// Configure Sheet Dialog
|
|
75
|
-
sheetDialog.apply {
|
|
76
|
-
setOnSizeChangeListener { w, h ->
|
|
77
|
-
val data = Arguments.createMap()
|
|
78
|
-
data.putDouble("width", Utils.toDIP(w.toFloat()).toDouble())
|
|
79
|
-
data.putDouble("height", Utils.toDIP(h.toFloat()).toDouble())
|
|
80
|
-
|
|
81
|
-
dispatchEvent(TrueSheetEvent.CONTAINER_SIZE_CHANGE, data)
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// Setup listener when the dialog has been presented.
|
|
85
|
-
setOnShowListener {
|
|
86
|
-
registerKeyboardManager()
|
|
87
|
-
|
|
88
|
-
// Initialize footer y
|
|
89
|
-
UiThreadUtil.runOnUiThread {
|
|
90
|
-
positionFooter()
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// Re-enable animation
|
|
94
|
-
resetAnimation()
|
|
95
|
-
|
|
96
|
-
// Resolve the present promise
|
|
97
|
-
presentPromise?.let { promise ->
|
|
98
|
-
promise()
|
|
99
|
-
presentPromise = null
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// Dispatch onPresent event
|
|
103
|
-
dispatchEvent(TrueSheetEvent.PRESENT, sizeInfoData(getSizeInfoForIndex(currentSizeIndex)))
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// Setup listener when the dialog has been dismissed.
|
|
107
|
-
setOnDismissListener {
|
|
108
|
-
unregisterKeyboardManager()
|
|
109
|
-
|
|
110
|
-
// Resolve the dismiss promise
|
|
111
|
-
dismissPromise?.let { promise ->
|
|
112
|
-
promise()
|
|
113
|
-
dismissPromise = null
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// Dispatch onDismiss event
|
|
117
|
-
dispatchEvent(TrueSheetEvent.DISMISS)
|
|
118
|
-
}
|
|
60
|
+
// Set delegates
|
|
61
|
+
viewController.delegate = this
|
|
119
62
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
override fun onSlide(sheetView: View, slideOffset: Float) {
|
|
124
|
-
when (behavior.state) {
|
|
125
|
-
// For consistency with IOS, we consider SETTLING as dragging change.
|
|
126
|
-
BottomSheetBehavior.STATE_DRAGGING,
|
|
127
|
-
BottomSheetBehavior.STATE_SETTLING -> handleDragChange(sheetView)
|
|
128
|
-
|
|
129
|
-
else -> { }
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
footerView?.let {
|
|
133
|
-
val y = (maxScreenHeight - sheetView.top - footerHeight).toFloat()
|
|
134
|
-
if (slideOffset >= 0) {
|
|
135
|
-
// Sheet is expanding
|
|
136
|
-
it.y = y
|
|
137
|
-
} else {
|
|
138
|
-
// Sheet is collapsing
|
|
139
|
-
it.y = y - footerHeight * slideOffset
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
override fun onStateChanged(sheetView: View, newState: Int) {
|
|
145
|
-
if (!isShowing) return
|
|
146
|
-
|
|
147
|
-
when (newState) {
|
|
148
|
-
// When changed to dragging, we know that the drag has started
|
|
149
|
-
BottomSheetBehavior.STATE_DRAGGING -> handleDragBegin(sheetView)
|
|
150
|
-
|
|
151
|
-
// Either of the following state determines drag end
|
|
152
|
-
BottomSheetBehavior.STATE_EXPANDED,
|
|
153
|
-
BottomSheetBehavior.STATE_COLLAPSED,
|
|
154
|
-
BottomSheetBehavior.STATE_HALF_EXPANDED -> handleDragEnd(newState)
|
|
155
|
-
|
|
156
|
-
else -> { }
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
)
|
|
161
|
-
}
|
|
63
|
+
// Hide the host view from layout and touch handling
|
|
64
|
+
// The actual content is shown in a dialog window
|
|
65
|
+
visibility = GONE
|
|
162
66
|
}
|
|
163
67
|
|
|
164
68
|
override fun dispatchProvideStructure(structure: ViewStructure) {
|
|
165
|
-
|
|
69
|
+
super.dispatchProvideStructure(structure)
|
|
166
70
|
}
|
|
167
71
|
|
|
168
72
|
override fun onLayout(
|
|
169
73
|
changed: Boolean,
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
74
|
+
left: Int,
|
|
75
|
+
top: Int,
|
|
76
|
+
right: Int,
|
|
77
|
+
bottom: Int
|
|
174
78
|
) {
|
|
175
79
|
// Do nothing as we are laid out by UIManager
|
|
176
80
|
}
|
|
@@ -178,257 +82,311 @@ class TrueSheetView(context: Context) :
|
|
|
178
82
|
override fun setId(id: Int) {
|
|
179
83
|
super.setId(id)
|
|
180
84
|
|
|
181
|
-
|
|
182
|
-
|
|
85
|
+
viewController.id = id
|
|
86
|
+
TrueSheetModule.registerView(this, id)
|
|
183
87
|
}
|
|
184
88
|
|
|
185
89
|
override fun onAttachedToWindow() {
|
|
186
90
|
super.onAttachedToWindow()
|
|
187
|
-
|
|
188
|
-
// Initialize content
|
|
189
|
-
UiThreadUtil.runOnUiThread {
|
|
190
|
-
sheetDialog.contentView?.height?.let { setContentHeight(it) }
|
|
191
|
-
sheetDialog.footerView?.height?.let { setFooterHeight(it) }
|
|
192
|
-
|
|
193
|
-
if (initialIndex >= 0) {
|
|
194
|
-
currentSizeIndex = initialIndex
|
|
195
|
-
sheetDialog.present(initialIndex, initialIndexAnimated)
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
// Dispatch onMount event
|
|
199
|
-
dispatchEvent(TrueSheetEvent.MOUNT)
|
|
200
|
-
}
|
|
201
91
|
}
|
|
202
92
|
|
|
203
93
|
override fun onDetachedFromWindow() {
|
|
204
94
|
super.onDetachedFromWindow()
|
|
205
95
|
onDropInstance()
|
|
96
|
+
|
|
97
|
+
TrueSheetModule.unregisterView(id)
|
|
206
98
|
}
|
|
207
99
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
100
|
+
/**
|
|
101
|
+
* showOrUpdate will display the Dialog. It is called by the manager once all properties are set
|
|
102
|
+
* because we need to know all of them before creating the Dialog. It is also smart during updates
|
|
103
|
+
* if the changed properties can be applied directly to the Dialog or require the recreation of a
|
|
104
|
+
* new Dialog.
|
|
105
|
+
*/
|
|
106
|
+
fun showOrUpdate() {
|
|
107
|
+
// Only handle initial presentation once on mount
|
|
108
|
+
if (!hasHandledInitialPresentation && initialDetentIndex >= 0) {
|
|
109
|
+
hasHandledInitialPresentation = true
|
|
110
|
+
|
|
111
|
+
// Create dialog if not created yet
|
|
112
|
+
if (!viewController.isPresented) {
|
|
113
|
+
viewController.createDialog()
|
|
114
|
+
}
|
|
211
115
|
|
|
212
|
-
|
|
213
|
-
|
|
116
|
+
post {
|
|
117
|
+
present(initialDetentIndex, initialDetentAnimated) { }
|
|
118
|
+
}
|
|
119
|
+
} else if (viewController.isPresented) {
|
|
120
|
+
viewController.setupSheetDetents()
|
|
121
|
+
viewController.setStateForDetentIndex(viewController.currentDetentIndex)
|
|
122
|
+
viewController.positionFooter()
|
|
123
|
+
}
|
|
214
124
|
}
|
|
215
125
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
126
|
+
// ==================== View Management ====================
|
|
127
|
+
|
|
128
|
+
override fun addView(child: View?, index: Int) {
|
|
129
|
+
// Add the child to our ViewController
|
|
130
|
+
// This is the TrueSheetContainerView
|
|
131
|
+
viewController.addView(child, index)
|
|
132
|
+
|
|
133
|
+
// Create dialog and dispatch mount event when TrueSheetContainerView is added
|
|
134
|
+
if (child is TrueSheetContainerView) {
|
|
135
|
+
// Set up container delegate to listen for content size changes
|
|
136
|
+
child.delegate = this
|
|
137
|
+
|
|
138
|
+
// Get initial content height from container
|
|
139
|
+
val contentHeight = child.contentHeight
|
|
140
|
+
if (contentHeight > 0) {
|
|
141
|
+
viewController.contentHeight = contentHeight
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Create the dialog now that the container is mounted
|
|
145
|
+
viewController.createDialog()
|
|
146
|
+
|
|
147
|
+
val surfaceId = UIManagerHelper.getSurfaceId(this)
|
|
148
|
+
eventDispatcher?.dispatchEvent(
|
|
149
|
+
MountEvent(surfaceId, id)
|
|
150
|
+
)
|
|
151
|
+
}
|
|
220
152
|
}
|
|
221
153
|
|
|
222
|
-
override fun
|
|
154
|
+
override fun getChildCount(): Int = viewController.childCount
|
|
155
|
+
override fun getChildAt(index: Int): View? = viewController.getChildAt(index)
|
|
223
156
|
|
|
224
|
-
override fun removeView(child: View) {
|
|
225
|
-
|
|
226
|
-
|
|
157
|
+
override fun removeView(child: View?) {
|
|
158
|
+
if (child != null) {
|
|
159
|
+
// Clean up container delegate
|
|
160
|
+
if (child is TrueSheetContainerView) {
|
|
161
|
+
child.delegate = null
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
viewController.removeView(child)
|
|
165
|
+
}
|
|
227
166
|
}
|
|
228
167
|
|
|
229
168
|
override fun removeViewAt(index: Int) {
|
|
230
|
-
UiThreadUtil.assertOnUiThread()
|
|
231
169
|
val child = getChildAt(index)
|
|
232
|
-
|
|
170
|
+
viewController.removeView(child)
|
|
233
171
|
}
|
|
234
172
|
|
|
235
173
|
override fun addChildrenForAccessibility(outChildren: ArrayList<View>) {
|
|
236
174
|
// Explicitly override this to prevent accessibility events being passed down to children
|
|
237
|
-
// Those will be handled by the
|
|
175
|
+
// Those will be handled by the mHostView which lives in the dialog
|
|
238
176
|
}
|
|
239
177
|
|
|
240
178
|
// Explicitly override this to prevent accessibility events being passed down to children
|
|
241
179
|
// Those will be handled by the mHostView which lives in the dialog
|
|
242
|
-
|
|
180
|
+
override fun dispatchPopulateAccessibilityEvent(event: AccessibilityEvent): Boolean = false
|
|
181
|
+
|
|
182
|
+
fun onDropInstance() {
|
|
183
|
+
reactContext.removeLifecycleEventListener(this)
|
|
184
|
+
TrueSheetModule.unregisterView(id)
|
|
185
|
+
|
|
186
|
+
if (viewController.isPresented) {
|
|
187
|
+
viewController.dismiss()
|
|
188
|
+
}
|
|
189
|
+
viewController.delegate = null
|
|
190
|
+
}
|
|
243
191
|
|
|
244
192
|
override fun onHostResume() {
|
|
245
|
-
|
|
193
|
+
showOrUpdate()
|
|
246
194
|
}
|
|
247
195
|
|
|
248
196
|
override fun onHostPause() {
|
|
249
|
-
// do nothing
|
|
250
197
|
}
|
|
251
198
|
|
|
252
199
|
override fun onHostDestroy() {
|
|
253
|
-
// Drop the instance if the host is destroyed which will dismiss the dialog
|
|
254
200
|
onDropInstance()
|
|
255
201
|
}
|
|
256
202
|
|
|
257
|
-
|
|
258
|
-
reactContext.removeLifecycleEventListener(this)
|
|
259
|
-
sheetDialog.dismiss()
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
private fun sizeInfoData(sizeInfo: SizeInfo): WritableMap {
|
|
263
|
-
val data = Arguments.createMap()
|
|
264
|
-
data.putInt("index", sizeInfo.index)
|
|
265
|
-
data.putDouble("value", sizeInfo.value.toDouble())
|
|
203
|
+
// ==================== TrueSheetViewControllerDelegate Implementation ====================
|
|
266
204
|
|
|
267
|
-
|
|
205
|
+
override fun viewControllerWillPresent(index: Int, position: Float) {
|
|
206
|
+
val surfaceId = UIManagerHelper.getSurfaceId(this)
|
|
207
|
+
eventDispatcher?.dispatchEvent(
|
|
208
|
+
WillPresentEvent(surfaceId, id, index, position)
|
|
209
|
+
)
|
|
268
210
|
}
|
|
269
211
|
|
|
270
|
-
|
|
271
|
-
val
|
|
272
|
-
|
|
212
|
+
override fun viewControllerDidPresent(index: Int, position: Float) {
|
|
213
|
+
val surfaceId = UIManagerHelper.getSurfaceId(this)
|
|
214
|
+
eventDispatcher?.dispatchEvent(
|
|
215
|
+
DidPresentEvent(surfaceId, id, index, position)
|
|
216
|
+
)
|
|
273
217
|
|
|
274
|
-
|
|
218
|
+
// Set our touch event dispatcher on the view controller
|
|
219
|
+
viewController.eventDispatcher = eventDispatcher
|
|
275
220
|
}
|
|
276
221
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
dispatchEvent(
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
private fun handleDragChange(sheetView: View) {
|
|
285
|
-
if (!isDragging) return
|
|
222
|
+
override fun viewControllerWillDismiss() {
|
|
223
|
+
val surfaceId = UIManagerHelper.getSurfaceId(this)
|
|
224
|
+
eventDispatcher?.dispatchEvent(
|
|
225
|
+
WillDismissEvent(surfaceId, id)
|
|
226
|
+
)
|
|
286
227
|
|
|
287
|
-
//
|
|
288
|
-
|
|
228
|
+
// Clear our touch event dispatcher on the view controller
|
|
229
|
+
viewController.eventDispatcher = null
|
|
289
230
|
}
|
|
290
231
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
//
|
|
297
|
-
// Changing size programmatically is handled via the present method.
|
|
298
|
-
val sizeInfo = sheetDialog.getSizeInfoForState(state)
|
|
299
|
-
sizeInfo?.let {
|
|
300
|
-
// Dispatch drag ended after dragging
|
|
301
|
-
dispatchEvent(TrueSheetEvent.DRAG_END, sizeInfoData(it))
|
|
302
|
-
if (it.index != currentSizeIndex) {
|
|
303
|
-
// Invoke promise when sheet resized programmatically
|
|
304
|
-
presentPromise?.let { promise ->
|
|
305
|
-
promise()
|
|
306
|
-
presentPromise = null
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
currentSizeIndex = it.index
|
|
310
|
-
sheetDialog.setupDimmedBackground(it.index)
|
|
311
|
-
|
|
312
|
-
// Dispatch onSizeChange event
|
|
313
|
-
dispatchEvent(TrueSheetEvent.SIZE_CHANGE, sizeInfoData(it))
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
isDragging = false
|
|
232
|
+
override fun viewControllerDidDismiss() {
|
|
233
|
+
val surfaceId = UIManagerHelper.getSurfaceId(this)
|
|
234
|
+
eventDispatcher?.dispatchEvent(
|
|
235
|
+
DidDismissEvent(surfaceId, id)
|
|
236
|
+
)
|
|
318
237
|
}
|
|
319
238
|
|
|
320
|
-
|
|
321
|
-
|
|
239
|
+
override fun viewControllerDidChangeDetent(index: Int, position: Float) {
|
|
240
|
+
val surfaceId = UIManagerHelper.getSurfaceId(this)
|
|
241
|
+
eventDispatcher?.dispatchEvent(
|
|
242
|
+
DetentChangeEvent(surfaceId, id, index, position)
|
|
243
|
+
)
|
|
322
244
|
}
|
|
323
245
|
|
|
324
|
-
fun
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
246
|
+
override fun viewControllerDidDragBegin(index: Int, position: Float) {
|
|
247
|
+
val surfaceId = UIManagerHelper.getSurfaceId(this)
|
|
248
|
+
eventDispatcher?.dispatchEvent(
|
|
249
|
+
DragBeginEvent(surfaceId, id, index, position)
|
|
250
|
+
)
|
|
329
251
|
}
|
|
330
252
|
|
|
331
|
-
fun
|
|
332
|
-
|
|
253
|
+
override fun viewControllerDidDragChange(index: Int, position: Float) {
|
|
254
|
+
val surfaceId = UIManagerHelper.getSurfaceId(this)
|
|
255
|
+
eventDispatcher?.dispatchEvent(
|
|
256
|
+
DragChangeEvent(surfaceId, id, index, position)
|
|
257
|
+
)
|
|
333
258
|
}
|
|
334
259
|
|
|
335
|
-
fun
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
260
|
+
override fun viewControllerDidDragEnd(index: Int, position: Float) {
|
|
261
|
+
val surfaceId = UIManagerHelper.getSurfaceId(this)
|
|
262
|
+
eventDispatcher?.dispatchEvent(
|
|
263
|
+
DragEndEvent(surfaceId, id, index, position)
|
|
264
|
+
)
|
|
340
265
|
}
|
|
341
266
|
|
|
342
|
-
fun
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
267
|
+
override fun viewControllerDidChangePosition(index: Int, position: Float, transitioning: Boolean) {
|
|
268
|
+
val surfaceId = UIManagerHelper.getSurfaceId(this)
|
|
269
|
+
eventDispatcher?.dispatchEvent(
|
|
270
|
+
PositionChangeEvent(surfaceId, id, index, position, transitioning)
|
|
271
|
+
)
|
|
347
272
|
}
|
|
348
273
|
|
|
349
|
-
|
|
350
|
-
if (sheetDialog.footerHeight == height) return
|
|
274
|
+
// ==================== Property Setters (forward to controller) ====================
|
|
351
275
|
|
|
352
|
-
|
|
353
|
-
|
|
276
|
+
fun setMaxHeight(height: Int) {
|
|
277
|
+
if (viewController.maxSheetHeight == height) return
|
|
278
|
+
viewController.maxSheetHeight = height
|
|
354
279
|
}
|
|
355
280
|
|
|
356
281
|
fun setDimmed(dimmed: Boolean) {
|
|
357
|
-
if (
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
sheetDialog.setupDimmedBackground(currentSizeIndex)
|
|
282
|
+
if (viewController.dimmed == dimmed) return
|
|
283
|
+
viewController.dimmed = dimmed
|
|
284
|
+
if (viewController.isPresented) {
|
|
285
|
+
viewController.setupDimmedBackground(viewController.currentDetentIndex)
|
|
362
286
|
}
|
|
363
287
|
}
|
|
364
288
|
|
|
365
289
|
fun setDimmedIndex(index: Int) {
|
|
366
|
-
if (
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
sheetDialog.setupDimmedBackground(currentSizeIndex)
|
|
290
|
+
if (viewController.dimmedIndex == index) return
|
|
291
|
+
viewController.dimmedIndex = index
|
|
292
|
+
if (viewController.isPresented) {
|
|
293
|
+
viewController.setupDimmedBackground(viewController.currentDetentIndex)
|
|
371
294
|
}
|
|
372
295
|
}
|
|
373
296
|
|
|
374
297
|
fun setCornerRadius(radius: Float) {
|
|
375
|
-
if (
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
sheetDialog.setupBackground()
|
|
298
|
+
if (viewController.cornerRadius == radius) return
|
|
299
|
+
viewController.cornerRadius = radius
|
|
300
|
+
viewController.setupBackground()
|
|
379
301
|
}
|
|
380
302
|
|
|
381
|
-
fun
|
|
382
|
-
if (
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
sheetDialog.setupBackground()
|
|
303
|
+
fun setSheetBackgroundColor(color: Int) {
|
|
304
|
+
if (viewController.sheetBackgroundColor == color) return
|
|
305
|
+
viewController.sheetBackgroundColor = color
|
|
306
|
+
viewController.setupBackground()
|
|
386
307
|
}
|
|
387
308
|
|
|
388
309
|
fun setSoftInputMode(mode: Int) {
|
|
389
|
-
|
|
390
|
-
this.setSoftInputMode(mode)
|
|
391
|
-
}
|
|
310
|
+
viewController.setSoftInputMode(mode)
|
|
392
311
|
}
|
|
393
312
|
|
|
394
313
|
fun setDismissible(dismissible: Boolean) {
|
|
395
|
-
|
|
314
|
+
viewController.dismissible = dismissible
|
|
396
315
|
}
|
|
397
316
|
|
|
398
|
-
fun
|
|
399
|
-
sheetDialog.sizes = newSizes
|
|
400
|
-
configureIfShowing()
|
|
401
|
-
}
|
|
317
|
+
fun setGrabber(grabber: Boolean) {}
|
|
402
318
|
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
fun present(sizeIndex: Int, promiseCallback: () -> Unit) {
|
|
407
|
-
UiThreadUtil.assertOnUiThread()
|
|
408
|
-
|
|
409
|
-
currentSizeIndex = sizeIndex
|
|
319
|
+
fun setDetents(newDetents: MutableList<Double>) {
|
|
320
|
+
viewController.detents = newDetents
|
|
321
|
+
}
|
|
410
322
|
|
|
411
|
-
|
|
412
|
-
// For consistency with IOS, we are not waiting
|
|
413
|
-
// for the state to change before dispatching onSizeChange event.
|
|
414
|
-
val sizeInfo = sheetDialog.getSizeInfoForIndex(sizeIndex)
|
|
415
|
-
dispatchEvent(TrueSheetEvent.SIZE_CHANGE, sizeInfoData(sizeInfo))
|
|
323
|
+
fun setBlurTint(tint: String?) {}
|
|
416
324
|
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
}
|
|
325
|
+
fun setEdgeToEdgeFullScreen(edgeToEdgeFullScreen: Boolean) {
|
|
326
|
+
viewController.edgeToEdgeFullScreen = edgeToEdgeFullScreen
|
|
327
|
+
}
|
|
421
328
|
|
|
422
|
-
|
|
329
|
+
/**
|
|
330
|
+
* Presents the sheet at the given detent index.
|
|
331
|
+
*
|
|
332
|
+
* @param detentIndex The detent index to present at
|
|
333
|
+
* @param animated Whether to animate the presentation
|
|
334
|
+
* @param promiseCallback Callback invoked when presentation completes
|
|
335
|
+
*/
|
|
336
|
+
@UiThread
|
|
337
|
+
fun present(detentIndex: Int, animated: Boolean = true, promiseCallback: () -> Unit) {
|
|
338
|
+
viewController.presentPromise = promiseCallback
|
|
339
|
+
viewController.present(detentIndex, animated)
|
|
423
340
|
}
|
|
424
341
|
|
|
425
342
|
/**
|
|
426
343
|
* Dismisses the sheet.
|
|
344
|
+
*
|
|
345
|
+
* @param promiseCallback Callback invoked when dismissal completes
|
|
427
346
|
*/
|
|
347
|
+
@UiThread
|
|
428
348
|
fun dismiss(promiseCallback: () -> Unit) {
|
|
429
|
-
|
|
349
|
+
viewController.dismissPromise = promiseCallback
|
|
350
|
+
viewController.dismiss()
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
override fun viewControllerDidChangeSize(width: Int, height: Int) {
|
|
354
|
+
// Dispatch size change event to JS
|
|
355
|
+
val surfaceId = UIManagerHelper.getSurfaceId(this)
|
|
356
|
+
eventDispatcher?.dispatchEvent(
|
|
357
|
+
SizeChangeEvent(surfaceId, id, width, height)
|
|
358
|
+
)
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
// ==================== TrueSheetContainerViewDelegate Implementation ====================
|
|
362
|
+
|
|
363
|
+
override fun containerViewContentDidChangeSize(width: Int, height: Int) {
|
|
364
|
+
// Clamp content height to container height to prevent unbounded growth with scrollable content
|
|
365
|
+
val containerHeight = viewController.maxScreenHeight
|
|
366
|
+
val contentHeight = if (containerHeight > 0) minOf(height, containerHeight) else height
|
|
367
|
+
|
|
368
|
+
viewController.contentHeight = contentHeight
|
|
369
|
+
|
|
370
|
+
// Update detents if sheet is already presented
|
|
371
|
+
if (viewController.isPresented) {
|
|
372
|
+
// Reconfigure sheet detents with new content height
|
|
373
|
+
viewController.setupSheetDetents()
|
|
374
|
+
|
|
375
|
+
// Use post to ensure layout is complete before positioning footer
|
|
376
|
+
viewController.post {
|
|
377
|
+
viewController.positionFooter()
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
override fun containerViewFooterDidChangeSize(width: Int, height: Int) {
|
|
383
|
+
// Reposition footer when its size changes
|
|
384
|
+
if (viewController.isPresented) {
|
|
385
|
+
viewController.positionFooter()
|
|
386
|
+
}
|
|
387
|
+
}
|
|
430
388
|
|
|
431
|
-
|
|
432
|
-
|
|
389
|
+
companion object {
|
|
390
|
+
const val TAG_NAME = "TrueSheet"
|
|
433
391
|
}
|
|
434
392
|
}
|