react-native-sheet2 6.1.19 → 7.12.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +754 -80
- package/{Sheet.podspec → Sheet2.podspec} +2 -2
- package/android/build.gradle +2 -25
- package/android/check.jks +0 -0
- package/android/src/main/AndroidManifest.xml +1 -2
- package/android/src/main/cpp/react/renderer/components/SheetViewSpec/SheetViewComponentDescriptor.h +12 -0
- package/android/src/main/cpp/react/renderer/components/SheetViewSpec/SheetViewShadowNode.cpp +17 -0
- package/android/src/main/cpp/react/renderer/components/SheetViewSpec/SheetViewShadowNode.h +36 -0
- package/android/src/main/cpp/react/renderer/components/SheetViewSpec/SheetViewState.h +52 -0
- package/android/src/main/java/com/behavior/BottomSheetBehavior.java +84 -16
- package/android/src/main/java/com/sheet2/AppFittedSheet.kt +431 -0
- package/android/src/main/java/com/{sheet → sheet2}/BaseRNView.kt +38 -31
- package/android/src/main/java/com/sheet2/CenteredSheetDialog.kt +272 -0
- package/android/src/main/java/com/{sheet → sheet2}/CustomBottomSheetDialog.java +32 -4
- package/android/src/main/java/com/{sheet → sheet2}/DialogRootViewGroup.kt +54 -12
- package/android/src/main/java/com/sheet2/FragmentModalBottomSheet.kt +161 -0
- package/android/src/main/java/com/sheet2/InlineFooterPresenter.kt +74 -0
- package/android/src/main/java/com/sheet2/InlineSheetPresenter.kt +249 -0
- package/android/src/main/java/com/sheet2/PassThroughLayouts.kt +17 -0
- package/android/src/main/java/com/{sheet → sheet2}/SafeAreaUtils.kt +4 -5
- package/android/src/main/java/com/sheet2/Sheet2Package.kt +44 -0
- package/android/src/main/java/com/sheet2/Sheet2View.kt +5 -0
- package/android/src/main/java/com/sheet2/Sheet2ViewManager.kt +163 -0
- package/android/src/main/java/com/{sheet → sheet2}/SheetDismissEvent.kt +1 -1
- package/android/src/main/java/com/{sheet → sheet2}/SheetModule.kt +14 -3
- package/android/src/main/java/com/{sheet → sheet2}/SheetPackage.kt +2 -3
- package/android/src/main/java/com/sheet2/SheetTreeLog.kt +78 -0
- package/android/src/main/java/com/{sheet → sheet2}/utils.kt +1 -2
- package/android/src/main/jni/CMakeLists.txt +72 -0
- package/android/src/main/jni/SheetViewSpec.h +40 -0
- package/ios/FittedSheets/SheetOptions.swift +5 -0
- package/ios/FittedSheets/SheetTransition.swift +83 -4
- package/ios/FittedSheets/SheetViewController.swift +222 -24
- package/ios/HostFittedSheet.swift +440 -51
- package/ios/SheetModule.h +5 -4
- package/ios/SheetModule.mm +11 -1
- package/ios/SheetTreeLog.swift +52 -0
- package/ios/SheetView.mm +118 -31
- package/ios/SheetViewComponentDescriptor.h +24 -0
- package/ios/SheetViewShadowNode.cpp +17 -0
- package/ios/SheetViewShadowNode.h +37 -0
- package/ios/SheetViewState.h +54 -0
- package/package.json +44 -74
- package/react-native.config.js +6 -4
- package/src/FittedSheet.tsx +131 -71
- package/src/GlobalSheetView.tsx +209 -0
- package/src/NativeSheet.ts +4 -0
- package/src/PublicSheetView.tsx +2 -1
- package/src/SheetTreeLog.ts +39 -0
- package/src/SheetViewNativeComponent.ts +25 -4
- package/src/index.tsx +29 -4
- package/src/logger.ts +16 -0
- package/android/generated/java/com/facebook/react/viewmanagers/SheetViewManagerDelegate.java +0 -67
- package/android/generated/java/com/facebook/react/viewmanagers/SheetViewManagerInterface.java +0 -27
- package/android/generated/java/com/sheet/NativeSheetSpec.java +0 -78
- package/android/generated/jni/CMakeLists.txt +0 -36
- package/android/generated/jni/RNSheetViewSpec-generated.cpp +0 -50
- package/android/generated/jni/RNSheetViewSpec.h +0 -31
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/ComponentDescriptors.cpp +0 -22
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/ComponentDescriptors.h +0 -24
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/EventEmitters.cpp +0 -24
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/EventEmitters.h +0 -25
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/Props.cpp +0 -33
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/Props.h +0 -36
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/RNSheetViewSpecJSI-generated.cpp +0 -46
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/RNSheetViewSpecJSI.h +0 -98
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/ShadowNodes.cpp +0 -17
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/ShadowNodes.h +0 -32
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/States.cpp +0 -16
- package/android/generated/jni/react/renderer/components/RNSheetViewSpec/States.h +0 -29
- package/android/src/main/AndroidManifestNew.xml +0 -2
- package/android/src/main/java/com/sheet/AppFittedSheet.kt +0 -214
- package/android/src/main/java/com/sheet/FragmentModalBottomSheet.kt +0 -67
- package/android/src/main/java/com/sheet/SheetView.kt +0 -5
- package/android/src/main/java/com/sheet/SheetViewManager.kt +0 -106
- package/ios/generated/RNSheetViewSpec/ComponentDescriptors.cpp +0 -22
- package/ios/generated/RNSheetViewSpec/ComponentDescriptors.h +0 -24
- package/ios/generated/RNSheetViewSpec/EventEmitters.cpp +0 -24
- package/ios/generated/RNSheetViewSpec/EventEmitters.h +0 -25
- package/ios/generated/RNSheetViewSpec/Props.cpp +0 -33
- package/ios/generated/RNSheetViewSpec/Props.h +0 -36
- package/ios/generated/RNSheetViewSpec/RCTComponentViewHelpers.h +0 -44
- package/ios/generated/RNSheetViewSpec/RNSheetViewSpec-generated.mm +0 -60
- package/ios/generated/RNSheetViewSpec/RNSheetViewSpec.h +0 -100
- package/ios/generated/RNSheetViewSpec/ShadowNodes.cpp +0 -17
- package/ios/generated/RNSheetViewSpec/ShadowNodes.h +0 -32
- package/ios/generated/RNSheetViewSpec/States.cpp +0 -16
- package/ios/generated/RNSheetViewSpec/States.h +0 -29
- package/ios/generated/RNSheetViewSpecJSI-generated.cpp +0 -46
- package/ios/generated/RNSheetViewSpecJSI.h +0 -98
- package/lib/module/FittedSheet.js +0 -153
- package/lib/module/FittedSheet.js.map +0 -1
- package/lib/module/NativeSheet.ts +0 -17
- package/lib/module/PublicSheetView.js +0 -48
- package/lib/module/PublicSheetView.js.map +0 -1
- package/lib/module/SheetViewNativeComponent.ts +0 -31
- package/lib/module/index.js +0 -17
- package/lib/module/index.js.map +0 -1
- package/lib/module/package.json +0 -1
- package/lib/typescript/package.json +0 -1
- package/lib/typescript/src/FittedSheet.d.ts +0 -51
- package/lib/typescript/src/FittedSheet.d.ts.map +0 -1
- package/lib/typescript/src/NativeSheet.d.ts +0 -16
- package/lib/typescript/src/NativeSheet.d.ts.map +0 -1
- package/lib/typescript/src/PublicSheetView.d.ts +0 -12
- package/lib/typescript/src/PublicSheetView.d.ts.map +0 -1
- package/lib/typescript/src/SheetViewNativeComponent.d.ts +0 -22
- package/lib/typescript/src/SheetViewNativeComponent.d.ts.map +0 -1
- package/lib/typescript/src/index.d.ts +0 -12
- package/lib/typescript/src/index.d.ts.map +0 -1
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
package com.sheet2
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.graphics.Color
|
|
5
|
+
import android.view.View
|
|
6
|
+
import android.view.ViewGroup
|
|
7
|
+
import android.view.ViewStructure
|
|
8
|
+
import android.view.accessibility.AccessibilityEvent
|
|
9
|
+
import androidx.appcompat.app.AppCompatActivity
|
|
10
|
+
import androidx.fragment.app.Fragment
|
|
11
|
+
import androidx.fragment.app.FragmentManager
|
|
12
|
+
import com.facebook.react.bridge.Arguments
|
|
13
|
+
import com.facebook.react.bridge.LifecycleEventListener
|
|
14
|
+
import com.facebook.react.bridge.ReactContext
|
|
15
|
+
import com.facebook.react.bridge.UiThreadUtil
|
|
16
|
+
import com.facebook.react.uimanager.PixelUtil.pxToDp
|
|
17
|
+
import com.facebook.react.uimanager.PointerEvents
|
|
18
|
+
import com.facebook.react.uimanager.ReactPointerEventsView
|
|
19
|
+
import com.facebook.react.uimanager.StateWrapper
|
|
20
|
+
import com.facebook.react.uimanager.UIManagerHelper
|
|
21
|
+
import com.facebook.react.uimanager.events.EventDispatcher
|
|
22
|
+
|
|
23
|
+
fun Fragment.safeShow(
|
|
24
|
+
manager: FragmentManager,
|
|
25
|
+
tag: String?
|
|
26
|
+
) {
|
|
27
|
+
val ft = manager.beginTransaction()
|
|
28
|
+
ft.add(this, tag)
|
|
29
|
+
ft.commitNowAllowingStateLoss()
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
internal fun AppFittedSheet.onSheetDismiss() {
|
|
33
|
+
val reactEventDispatcher = UIManagerHelper.getEventDispatcherForReactTag(context as ReactContext, id)
|
|
34
|
+
val surfaceId = UIManagerHelper.getSurfaceId(context)
|
|
35
|
+
reactEventDispatcher?.dispatchEvent(SheetDismissEvent(surfaceId, id))
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
private var presentedSheets: MutableList<String> = mutableListOf()
|
|
39
|
+
|
|
40
|
+
open class AppFittedSheet(context: Context) :
|
|
41
|
+
ViewGroup(context),
|
|
42
|
+
LifecycleEventListener,
|
|
43
|
+
ReactPointerEventsView {
|
|
44
|
+
// The sheet content lives in its own window or overlay; this placeholder must never take touches.
|
|
45
|
+
override val pointerEvents: PointerEvents = PointerEvents.NONE
|
|
46
|
+
|
|
47
|
+
private var stacked = true
|
|
48
|
+
private val fragmentTag = "CCBottomSheet-${System.currentTimeMillis()}"
|
|
49
|
+
var mHostView = DialogRootViewGroup(context)
|
|
50
|
+
private var inlineOverlayView: View? = null
|
|
51
|
+
private var dialogOverlayView: View? = null
|
|
52
|
+
|
|
53
|
+
var dismissable = true
|
|
54
|
+
set(value) {
|
|
55
|
+
field = value
|
|
56
|
+
inlinePresenter.setDismissable(value)
|
|
57
|
+
}
|
|
58
|
+
var dismissOnOverlayTap = true
|
|
59
|
+
var overlayOpacity = -1F
|
|
60
|
+
var collapsedHeight = 0F
|
|
61
|
+
var topLeftRightCornerRadius: Float = 0F
|
|
62
|
+
var _backgroundColor: Int = Color.TRANSPARENT
|
|
63
|
+
var isSystemUILight: Boolean = false
|
|
64
|
+
var useInlinePresentation: Boolean = false
|
|
65
|
+
set(value) {
|
|
66
|
+
field = value
|
|
67
|
+
// When inline, mHostView sits inside the main ReactRootView; turn off its
|
|
68
|
+
// own JSTouchDispatcher so we don't double-dispatch touches.
|
|
69
|
+
mHostView.inlineMode = value
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
var presentationStyle: String = "bottom"
|
|
73
|
+
set(value) {
|
|
74
|
+
field = value
|
|
75
|
+
// In centered mode the FrameLayout centers the card; disable the RN
|
|
76
|
+
// view's own translationX centering so it isn't double-shifted (right
|
|
77
|
+
// side in landscape).
|
|
78
|
+
mHostView.centeredPresentation = value == "center"
|
|
79
|
+
}
|
|
80
|
+
var centerAnimation: String = "fade"
|
|
81
|
+
private var centeredDialog: CenteredSheetDialog? = null
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Fabric state wrapper for this SheetView. Set by [Sheet2ViewManager.updateState].
|
|
85
|
+
* Used to push `contentOriginOffset` values back to C++ so that
|
|
86
|
+
* `SheetViewShadowNode::getContentOriginOffset()` reflects the visual position
|
|
87
|
+
* of the sheet content — which keeps Pressability's responder-region check
|
|
88
|
+
* aligned with actual touch coordinates.
|
|
89
|
+
*/
|
|
90
|
+
internal var fabricStateWrapper: StateWrapper? = null
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Pushes a Fabric state update whose effect is to make `measure()` / Pressability
|
|
94
|
+
* region checks see the sheet content at its on-screen position.
|
|
95
|
+
*
|
|
96
|
+
* Two cases:
|
|
97
|
+
* - **Inline mode**: [mHostView] is re-parented into an overlay inside the same
|
|
98
|
+
* Activity Window, visually offset from this AppFittedSheet's Yoga position.
|
|
99
|
+
* The offset we need to add at the `<_FittedSheet>` shadow-node level is the
|
|
100
|
+
* visual delta between `mHostView`'s on-screen position and this view's.
|
|
101
|
+
* - **Dialog mode**: [mHostView] lives in a separate Dialog Window; touches
|
|
102
|
+
* inside it are dispatched by `mHostView`'s own `JSTouchDispatcher` in
|
|
103
|
+
* mHostView-local coordinates (top of sheet = 0). Meanwhile `measure()` on
|
|
104
|
+
* Fabric goes through the main-surface shadow tree and would return
|
|
105
|
+
* coordinates that include this AppFittedSheet's own Yoga-page position.
|
|
106
|
+
* Pushing `-anchor.getLocationInWindow` cancels that out so `measure()`
|
|
107
|
+
* reports mHostView-local coordinates that match the touch coords.
|
|
108
|
+
*/
|
|
109
|
+
internal fun pushContentOriginOffset() {
|
|
110
|
+
val wrapper = fabricStateWrapper ?: return
|
|
111
|
+
if (!isAttachedToWindow) return
|
|
112
|
+
val anchorLoc = IntArray(2).also { getLocationInWindow(it) }
|
|
113
|
+
|
|
114
|
+
val offsetXDp: Float
|
|
115
|
+
val offsetYDp: Float
|
|
116
|
+
if (useInlinePresentation) {
|
|
117
|
+
val hostLoc = IntArray(2).also { mHostView.getLocationInWindow(it) }
|
|
118
|
+
offsetXDp = (hostLoc[0] - anchorLoc[0]).toFloat().pxToDp()
|
|
119
|
+
offsetYDp = (hostLoc[1] - anchorLoc[1]).toFloat().pxToDp()
|
|
120
|
+
} else {
|
|
121
|
+
offsetXDp = (-anchorLoc[0]).toFloat().pxToDp()
|
|
122
|
+
offsetYDp = (-anchorLoc[1]).toFloat().pxToDp()
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
val map = Arguments.createMap()
|
|
126
|
+
map.putDouble("contentOriginOffsetX", offsetXDp.toDouble())
|
|
127
|
+
map.putDouble("contentOriginOffsetY", offsetYDp.toDouble())
|
|
128
|
+
runCatching { wrapper.updateState(map) }
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
private val inlinePresenter: InlineSheetPresenter by lazy {
|
|
132
|
+
InlineSheetPresenter(this, mHostView)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
private val footerPresenter: InlineFooterPresenter by lazy {
|
|
136
|
+
InlineFooterPresenter(this, mHostView)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
init {
|
|
140
|
+
mHostView.onSheetLayoutChanged = { pushContentOriginOffset() }
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
var maxWidth: Float = 0F
|
|
144
|
+
set(value) {
|
|
145
|
+
field = value
|
|
146
|
+
mHostView.sheetMaxWidthSize = value
|
|
147
|
+
if (this.sheet == null) return
|
|
148
|
+
mHostView.updateMaxWidth(mHostView.sheetMaxWidthSize)
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
var eventDispatcher: EventDispatcher?
|
|
152
|
+
get() = mHostView.eventDispatcher
|
|
153
|
+
set(eventDispatcher) {
|
|
154
|
+
mHostView.eventDispatcher = eventDispatcher
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
private fun getCurrentActivity(): AppCompatActivity? {
|
|
158
|
+
return (context as? ReactContext)?.currentActivity as? AppCompatActivity
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
private fun findSheet(name: String): FragmentModalBottomSheet? {
|
|
162
|
+
return getCurrentActivity()?.supportFragmentManager?.findFragmentByTag(name) as? FragmentModalBottomSheet
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
private val sheet: FragmentModalBottomSheet?
|
|
166
|
+
get() = findSheet(fragmentTag)
|
|
167
|
+
|
|
168
|
+
override fun setId(id: Int) {
|
|
169
|
+
super.setId(id)
|
|
170
|
+
// In inline mode mHostView is re-parented under our own overlay. Forwarding the
|
|
171
|
+
// RN tag to it would make two Android views share the same id, which confuses
|
|
172
|
+
// RN's responder/event routing. Keep the forwarding only for Dialog mode.
|
|
173
|
+
if (!useInlinePresentation) {
|
|
174
|
+
mHostView.id = id
|
|
175
|
+
} else {
|
|
176
|
+
mHostView.id = View.NO_ID
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
fun showOrUpdate() {
|
|
181
|
+
UiThreadUtil.assertOnUiThread()
|
|
182
|
+
|
|
183
|
+
mHostView.setCornerRadius(topLeftRightCornerRadius)
|
|
184
|
+
mHostView.setBackgroundColor(_backgroundColor)
|
|
185
|
+
|
|
186
|
+
if (presentationStyle == "center") {
|
|
187
|
+
if (centeredDialog == null || centeredDialog?.isShowing != true) {
|
|
188
|
+
// mHostView may still be attached to a previous parent; detach first.
|
|
189
|
+
(mHostView.parent as? ViewGroup)?.removeView(mHostView)
|
|
190
|
+
centeredDialog = CenteredSheetDialog(
|
|
191
|
+
context = getCurrentActivity() ?: context,
|
|
192
|
+
contentView = mHostView,
|
|
193
|
+
dismissable = dismissable,
|
|
194
|
+
slide = centerAnimation == "slide",
|
|
195
|
+
) {
|
|
196
|
+
(mHostView.parent as? ViewGroup)?.removeView(mHostView)
|
|
197
|
+
centeredDialog = null
|
|
198
|
+
onSheetDismiss()
|
|
199
|
+
}
|
|
200
|
+
centeredDialog?.show()
|
|
201
|
+
// Sync Fabric shadow tree with our Yoga-position once the centered Dialog
|
|
202
|
+
// is laid out (same reason as the bottom-sheet Dialog path below).
|
|
203
|
+
post { pushContentOriginOffset() }
|
|
204
|
+
}
|
|
205
|
+
return
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (presentationStyle == "footer") {
|
|
209
|
+
footerPresenter.show()
|
|
210
|
+
return
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (useInlinePresentation) {
|
|
214
|
+
if (!inlinePresenter.isShown) {
|
|
215
|
+
inlinePresenter.show(
|
|
216
|
+
dismissable = dismissable,
|
|
217
|
+
dismissOnOverlayTap = dismissOnOverlayTap,
|
|
218
|
+
overlayOpacity = overlayOpacity,
|
|
219
|
+
collapsedHeight = collapsedHeight.toInt(),
|
|
220
|
+
) { onSheetDismiss() }
|
|
221
|
+
}
|
|
222
|
+
return
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
val sheet = this.sheet
|
|
226
|
+
if (sheet == null) {
|
|
227
|
+
if (stacked) {
|
|
228
|
+
presentedSheets.lastOrNull()?.let {
|
|
229
|
+
findSheet(it)?.collapse()
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
val fragment = FragmentModalBottomSheet(
|
|
234
|
+
modalView = mHostView,
|
|
235
|
+
dismissable = dismissable,
|
|
236
|
+
dismissOnOverlayTap = dismissOnOverlayTap,
|
|
237
|
+
overlayOpacity = overlayOpacity,
|
|
238
|
+
isSystemUILight = isSystemUILight
|
|
239
|
+
) { dismissAll ->
|
|
240
|
+
val parent = mHostView.parent as? ViewGroup
|
|
241
|
+
SheetTreeLog.log(
|
|
242
|
+
context,
|
|
243
|
+
"sheet.detachHost",
|
|
244
|
+
"host=${SheetTreeLog.tag(mHostView)} parent=${SheetTreeLog.tag(parent)}" +
|
|
245
|
+
" parentChildren=${SheetTreeLog.childTags(parent)}",
|
|
246
|
+
)
|
|
247
|
+
parent?.removeViewAt(0)
|
|
248
|
+
onSheetDismiss()
|
|
249
|
+
if (dismissAll) {
|
|
250
|
+
if (stacked) {
|
|
251
|
+
var lastName = presentedSheets.removeLastOrNull()
|
|
252
|
+
if (lastName == fragmentTag) lastName = presentedSheets.lastOrNull()
|
|
253
|
+
if (lastName != null) {
|
|
254
|
+
findSheet(lastName)?.let {
|
|
255
|
+
it.dismissAll = true
|
|
256
|
+
it.dismissAllowingStateLoss()
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return@FragmentModalBottomSheet
|
|
261
|
+
}
|
|
262
|
+
if (stacked) {
|
|
263
|
+
var lastName = presentedSheets.removeLastOrNull()
|
|
264
|
+
if (lastName == fragmentTag) {
|
|
265
|
+
lastName = presentedSheets.lastOrNull()
|
|
266
|
+
}
|
|
267
|
+
lastName?.let { findSheet(it)?.expand() }
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
getCurrentActivity()?.supportFragmentManager?.let {
|
|
271
|
+
fragment.safeShow(it, fragmentTag)
|
|
272
|
+
fragment.setOverlayView(dialogOverlayView)
|
|
273
|
+
if (stacked) {
|
|
274
|
+
if (presentedSheets.contains(fragmentTag)) return
|
|
275
|
+
presentedSheets.add(fragmentTag)
|
|
276
|
+
}
|
|
277
|
+
// Sync Fabric shadow tree with our Yoga-position once Dialog is laid out —
|
|
278
|
+
// ensures Pressability's measure() returns coords matching the Dialog
|
|
279
|
+
// JSTouchDispatcher's touch coords (which are mHostView-local).
|
|
280
|
+
post { pushContentOriginOffset() }
|
|
281
|
+
}
|
|
282
|
+
} else {
|
|
283
|
+
// Sheet already showing; reapply offset in case window position changed.
|
|
284
|
+
post { pushContentOriginOffset() }
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
fun setNewNestedScrollView(view: View) {
|
|
289
|
+
sheet?.setNewNestedScrollView(view)
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
override fun dispatchProvideStructure(structure: ViewStructure) {
|
|
293
|
+
mHostView.dispatchProvideStructure(structure)
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
override fun addView(child: View, index: Int) {
|
|
297
|
+
UiThreadUtil.assertOnUiThread()
|
|
298
|
+
// An overlay child is kept out of mHostView while getChildCount keeps
|
|
299
|
+
// counting it, so from here on this view's children and React Native's idea
|
|
300
|
+
// of them are two different lists.
|
|
301
|
+
SheetTreeLog.log(
|
|
302
|
+
context,
|
|
303
|
+
"sheet.addView",
|
|
304
|
+
"child=${SheetTreeLog.tag(child)} index=$index self=${SheetTreeLog.tag(this)}" +
|
|
305
|
+
" hostChildren=${SheetTreeLog.childTags(mHostView)}" +
|
|
306
|
+
" inline=$useInlinePresentation",
|
|
307
|
+
)
|
|
308
|
+
if (useInlinePresentation && index > 0) {
|
|
309
|
+
inlineOverlayView = child
|
|
310
|
+
inlinePresenter.setOverlayView(child)
|
|
311
|
+
return
|
|
312
|
+
}
|
|
313
|
+
if (!useInlinePresentation && index > 0) {
|
|
314
|
+
dialogOverlayView = child
|
|
315
|
+
sheet?.setOverlayView(child)
|
|
316
|
+
return
|
|
317
|
+
}
|
|
318
|
+
mHostView.addView(child, index)
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
override fun getChildCount(): Int =
|
|
322
|
+
if (useInlinePresentation) 0 else reactChildCount()
|
|
323
|
+
|
|
324
|
+
override fun getChildAt(index: Int): View? =
|
|
325
|
+
if (useInlinePresentation) null else reactChildAt(index)
|
|
326
|
+
|
|
327
|
+
internal fun reactChildCount(): Int =
|
|
328
|
+
mHostView.childCount +
|
|
329
|
+
(if (inlineOverlayView != null) 1 else 0) +
|
|
330
|
+
(if (dialogOverlayView != null) 1 else 0)
|
|
331
|
+
|
|
332
|
+
internal fun reactChildAt(index: Int): View? {
|
|
333
|
+
if (index < mHostView.childCount) return mHostView.getChildAt(index)
|
|
334
|
+
val overlayIndex = index - mHostView.childCount
|
|
335
|
+
if (inlineOverlayView != null && overlayIndex == 0) return inlineOverlayView
|
|
336
|
+
return dialogOverlayView
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
override fun removeView(child: View) {
|
|
340
|
+
UiThreadUtil.assertOnUiThread()
|
|
341
|
+
SheetTreeLog.log(
|
|
342
|
+
context,
|
|
343
|
+
"sheet.removeView",
|
|
344
|
+
"child=${SheetTreeLog.tag(child)} self=${SheetTreeLog.tag(this)}" +
|
|
345
|
+
" hostChildren=${SheetTreeLog.childTags(mHostView)}",
|
|
346
|
+
)
|
|
347
|
+
if (child == inlineOverlayView) {
|
|
348
|
+
inlineOverlayView = null
|
|
349
|
+
inlinePresenter.setOverlayView(null)
|
|
350
|
+
return
|
|
351
|
+
}
|
|
352
|
+
if (child == dialogOverlayView) {
|
|
353
|
+
dialogOverlayView = null
|
|
354
|
+
sheet?.setOverlayView(null)
|
|
355
|
+
return
|
|
356
|
+
}
|
|
357
|
+
dismiss()
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
override fun removeViewAt(index: Int) {
|
|
361
|
+
UiThreadUtil.assertOnUiThread()
|
|
362
|
+
SheetTreeLog.log(
|
|
363
|
+
context,
|
|
364
|
+
"sheet.removeViewAt",
|
|
365
|
+
"index=$index self=${SheetTreeLog.tag(this)}" +
|
|
366
|
+
" hostChildren=${SheetTreeLog.childTags(mHostView)}",
|
|
367
|
+
)
|
|
368
|
+
if (useInlinePresentation && index >= mHostView.childCount && inlineOverlayView != null) {
|
|
369
|
+
inlineOverlayView = null
|
|
370
|
+
inlinePresenter.setOverlayView(null)
|
|
371
|
+
return
|
|
372
|
+
}
|
|
373
|
+
if (!useInlinePresentation && index >= mHostView.childCount && dialogOverlayView != null) {
|
|
374
|
+
dialogOverlayView = null
|
|
375
|
+
sheet?.setOverlayView(null)
|
|
376
|
+
return
|
|
377
|
+
}
|
|
378
|
+
dismiss()
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
internal fun onDropInstance() {
|
|
382
|
+
(context as ReactContext).removeLifecycleEventListener(this)
|
|
383
|
+
dismiss()
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
fun dismiss() {
|
|
387
|
+
UiThreadUtil.assertOnUiThread()
|
|
388
|
+
if (centeredDialog != null) {
|
|
389
|
+
centeredDialog?.dismiss()
|
|
390
|
+
centeredDialog = null
|
|
391
|
+
return
|
|
392
|
+
}
|
|
393
|
+
if (presentationStyle == "footer") {
|
|
394
|
+
footerPresenter.dismiss()
|
|
395
|
+
onSheetDismiss()
|
|
396
|
+
return
|
|
397
|
+
}
|
|
398
|
+
if (useInlinePresentation) {
|
|
399
|
+
inlinePresenter.dismiss()
|
|
400
|
+
return
|
|
401
|
+
}
|
|
402
|
+
this.sheet?.dismissAllowingStateLoss()
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
override fun addChildrenForAccessibility(outChildren: ArrayList<View?>?) {}
|
|
406
|
+
|
|
407
|
+
override fun dispatchPopulateAccessibilityEvent(event: AccessibilityEvent?) = false
|
|
408
|
+
override fun onHostResume() { showOrUpdate() }
|
|
409
|
+
override fun onHostPause() {}
|
|
410
|
+
override fun onHostDestroy() { onDropInstance() }
|
|
411
|
+
|
|
412
|
+
override fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int) {}
|
|
413
|
+
|
|
414
|
+
companion object {
|
|
415
|
+
// Other dialog fragments (an Alert still closing, for example) can sit above the sheet
|
|
416
|
+
// in the same fragment manager, so look for the topmost sheet, not the topmost fragment.
|
|
417
|
+
private fun presentedSheet(activity: AppCompatActivity): FragmentModalBottomSheet? =
|
|
418
|
+
activity.supportFragmentManager.fragments
|
|
419
|
+
.lastOrNull { it is FragmentModalBottomSheet && !it.isRemoving } as? FragmentModalBottomSheet
|
|
420
|
+
|
|
421
|
+
fun dismissAll(activity: AppCompatActivity) {
|
|
422
|
+
val fragment = presentedSheet(activity) ?: return
|
|
423
|
+
fragment.dismissAll = true
|
|
424
|
+
fragment.dismissAllowingStateLoss()
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
fun dismissPresented(activity: AppCompatActivity) {
|
|
428
|
+
presentedSheet(activity)?.dismissAllowingStateLoss()
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
package com.
|
|
1
|
+
package com.sheet2
|
|
2
2
|
|
|
3
3
|
import android.annotation.SuppressLint
|
|
4
4
|
import android.content.Context
|
|
@@ -6,7 +6,6 @@ import android.view.MotionEvent
|
|
|
6
6
|
import android.view.View
|
|
7
7
|
import android.view.accessibility.AccessibilityNodeInfo
|
|
8
8
|
import androidx.annotation.UiThread
|
|
9
|
-
import com.facebook.react.bridge.GuardedRunnable
|
|
10
9
|
import com.facebook.react.bridge.WritableMap
|
|
11
10
|
import com.facebook.react.bridge.WritableNativeMap
|
|
12
11
|
import com.facebook.react.config.ReactFeatureFlags
|
|
@@ -16,7 +15,6 @@ import com.facebook.react.uimanager.PixelUtil.pxToDp
|
|
|
16
15
|
import com.facebook.react.uimanager.RootView
|
|
17
16
|
import com.facebook.react.uimanager.StateWrapper
|
|
18
17
|
import com.facebook.react.uimanager.ThemedReactContext
|
|
19
|
-
import com.facebook.react.uimanager.UIManagerModule
|
|
20
18
|
import com.facebook.react.uimanager.events.EventDispatcher
|
|
21
19
|
import com.facebook.react.views.view.ReactViewGroup
|
|
22
20
|
|
|
@@ -24,6 +22,16 @@ open class BaseRNView(context: Context?) : ReactViewGroup(context), RootView {
|
|
|
24
22
|
internal var stateWrapper: StateWrapper? = null
|
|
25
23
|
internal var eventDispatcher: EventDispatcher? = null
|
|
26
24
|
|
|
25
|
+
/**
|
|
26
|
+
* When true, disables this view's own touch-dispatch pipeline (local
|
|
27
|
+
* `JSTouchDispatcher`, unconditional `onTouchEvent` consumption, no-op
|
|
28
|
+
* `requestDisallowInterceptTouchEvent`). Required in inline presentation —
|
|
29
|
+
* there the view lives inside the main `ReactRootView`, and having a second
|
|
30
|
+
* dispatcher fire for the same `MotionEvent` breaks RN's responder system.
|
|
31
|
+
* Default `false` for the Dialog mode, where this view is a real root.
|
|
32
|
+
*/
|
|
33
|
+
var inlineMode: Boolean = false
|
|
34
|
+
|
|
27
35
|
private var viewWidth = 0
|
|
28
36
|
private var viewHeight = 0
|
|
29
37
|
private val jSTouchDispatcher: JSTouchDispatcher = JSTouchDispatcher(this)
|
|
@@ -52,28 +60,13 @@ open class BaseRNView(context: Context?) : ReactViewGroup(context), RootView {
|
|
|
52
60
|
|
|
53
61
|
@UiThread
|
|
54
62
|
public fun updateState(width: Int, height: Int) {
|
|
63
|
+
val sw = stateWrapper ?: return
|
|
55
64
|
val realWidth: Float = width.toFloat().pxToDp()
|
|
56
65
|
val realHeight: Float = height.toFloat().pxToDp()
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
newStateData.putDouble("screenWidth", realWidth.toDouble())
|
|
62
|
-
newStateData.putDouble("screenHeight", realHeight.toDouble())
|
|
63
|
-
sw.updateState(newStateData)
|
|
64
|
-
}
|
|
65
|
-
?: run {
|
|
66
|
-
// old architecture
|
|
67
|
-
// TODO: T44725185 remove after full migration to Fabric
|
|
68
|
-
reactContext.runOnNativeModulesQueueThread(
|
|
69
|
-
object : GuardedRunnable(reactContext) {
|
|
70
|
-
override fun runGuarded() {
|
|
71
|
-
reactContext.reactApplicationContext
|
|
72
|
-
.getNativeModule(UIManagerModule::class.java)
|
|
73
|
-
?.updateNodeSize(id, viewWidth, viewHeight)
|
|
74
|
-
}
|
|
75
|
-
})
|
|
76
|
-
}
|
|
66
|
+
val newStateData: WritableMap = WritableNativeMap()
|
|
67
|
+
newStateData.putDouble("screenWidth", realWidth.toDouble())
|
|
68
|
+
newStateData.putDouble("screenHeight", realHeight.toDouble())
|
|
69
|
+
sw.updateState(newStateData)
|
|
77
70
|
}
|
|
78
71
|
|
|
79
72
|
override fun handleException(t: Throwable) {
|
|
@@ -81,19 +74,20 @@ open class BaseRNView(context: Context?) : ReactViewGroup(context), RootView {
|
|
|
81
74
|
}
|
|
82
75
|
|
|
83
76
|
override fun onInterceptTouchEvent(event: MotionEvent): Boolean {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
jSPointerDispatcher?.handleMotionEvent(event, eventDispatcher, true)
|
|
77
|
+
if (!inlineMode) {
|
|
78
|
+
dispatchTouchEventToJs(event, isCapture = true)
|
|
87
79
|
}
|
|
88
80
|
return super.onInterceptTouchEvent(event)
|
|
89
81
|
}
|
|
90
82
|
|
|
91
83
|
@SuppressLint("ClickableViewAccessibility")
|
|
92
84
|
override fun onTouchEvent(event: MotionEvent): Boolean {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
85
|
+
if (inlineMode) {
|
|
86
|
+
// Nested inside the main ReactRootView — do not dispatch our own JS
|
|
87
|
+
// touch events or eat the event; let normal target finding run.
|
|
88
|
+
return super.onTouchEvent(event)
|
|
96
89
|
}
|
|
90
|
+
dispatchTouchEventToJs(event, isCapture = false)
|
|
97
91
|
super.onTouchEvent(event)
|
|
98
92
|
// In case when there is no children interested in handling touch event, we return true from
|
|
99
93
|
// the root view in order to receive subsequent events related to that gesture
|
|
@@ -101,7 +95,7 @@ open class BaseRNView(context: Context?) : ReactViewGroup(context), RootView {
|
|
|
101
95
|
}
|
|
102
96
|
|
|
103
97
|
override fun onChildStartedNativeGesture(childView: View?, ev: MotionEvent) {
|
|
104
|
-
|
|
98
|
+
if (inlineMode) return
|
|
105
99
|
eventDispatcher?.let { eventDispatcher ->
|
|
106
100
|
jSTouchDispatcher.onChildStartedNativeGesture(ev, eventDispatcher)
|
|
107
101
|
jSPointerDispatcher?.onChildStartedNativeGesture(childView, ev, eventDispatcher)
|
|
@@ -109,13 +103,26 @@ open class BaseRNView(context: Context?) : ReactViewGroup(context), RootView {
|
|
|
109
103
|
}
|
|
110
104
|
|
|
111
105
|
override fun onChildEndedNativeGesture(childView: View, ev: MotionEvent) {
|
|
112
|
-
|
|
106
|
+
if (inlineMode) return
|
|
113
107
|
eventDispatcher?.let { jSTouchDispatcher.onChildEndedNativeGesture(ev, it) }
|
|
114
108
|
jSPointerDispatcher?.onChildEndedNativeGesture()
|
|
115
109
|
}
|
|
116
110
|
|
|
117
111
|
override fun requestDisallowInterceptTouchEvent(disallowIntercept: Boolean) {
|
|
112
|
+
if (inlineMode) {
|
|
113
|
+
// Nested inside the app's main ReactRootView — respect ancestors' intercept
|
|
114
|
+
// requests so normal gesture arbitration works.
|
|
115
|
+
super.requestDisallowInterceptTouchEvent(disallowIntercept)
|
|
116
|
+
return
|
|
117
|
+
}
|
|
118
118
|
// No-op - override in order to still receive events to onInterceptTouchEvent
|
|
119
119
|
// even when some other view disallow that
|
|
120
120
|
}
|
|
121
|
+
|
|
122
|
+
private fun dispatchTouchEventToJs(event: MotionEvent, isCapture: Boolean) {
|
|
123
|
+
eventDispatcher?.let { eventDispatcher ->
|
|
124
|
+
jSTouchDispatcher.handleTouchEvent(event, eventDispatcher, reactContext)
|
|
125
|
+
jSPointerDispatcher?.handleMotionEvent(event, eventDispatcher, isCapture)
|
|
126
|
+
}
|
|
127
|
+
}
|
|
121
128
|
}
|