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,249 @@
|
|
|
1
|
+
package com.sheet2
|
|
2
|
+
|
|
3
|
+
import android.animation.ValueAnimator
|
|
4
|
+
import android.content.Context
|
|
5
|
+
import android.view.inputmethod.InputMethodManager
|
|
6
|
+
import android.graphics.Color
|
|
7
|
+
import android.os.SystemClock
|
|
8
|
+
import android.view.Gravity
|
|
9
|
+
import android.view.MotionEvent
|
|
10
|
+
import android.view.View
|
|
11
|
+
import android.view.ViewGroup
|
|
12
|
+
import android.view.ViewParent
|
|
13
|
+
import android.widget.FrameLayout
|
|
14
|
+
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
|
15
|
+
import com.behavior.BottomSheetBehavior
|
|
16
|
+
import com.facebook.react.uimanager.RootView
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Presents the sheet inline — as a child of the current react-native-screens
|
|
20
|
+
* Screen's container (ScreenStack / ScreensCoordinatorLayout) — instead of in a
|
|
21
|
+
* separate Dialog Window. When a new Screen (e.g. fullScreenModal) is pushed on
|
|
22
|
+
* top via react-native-screens, the new Screen is added as a later sibling in the
|
|
23
|
+
* same container and naturally covers our overlay.
|
|
24
|
+
*
|
|
25
|
+
* Known limitation on Fabric: `measure()` on RN refs inside the sheet returns
|
|
26
|
+
* Yoga-tree coords, not the native visual position. Pressability's responder
|
|
27
|
+
* region check therefore fails unless the RN consumer either provides large
|
|
28
|
+
* `hitSlop`, or until a custom Fabric ShadowNode with an
|
|
29
|
+
* `getContentOriginOffset` override is wired up (see plan v4, Шаг 2).
|
|
30
|
+
*/
|
|
31
|
+
internal class InlineSheetPresenter(
|
|
32
|
+
private val anchor: AppFittedSheet,
|
|
33
|
+
private val hostView: View,
|
|
34
|
+
) {
|
|
35
|
+
|
|
36
|
+
private var overlay: FrameLayout? = null
|
|
37
|
+
private var overlayHost: FrameLayout? = null
|
|
38
|
+
private var overlayView: View? = null
|
|
39
|
+
private var behavior: BottomSheetBehavior<FrameLayout>? = null
|
|
40
|
+
private var scrimAnimator: ValueAnimator? = null
|
|
41
|
+
private var onDismiss: (() -> Unit)? = null
|
|
42
|
+
private var snaps = false
|
|
43
|
+
|
|
44
|
+
val isShown: Boolean get() = overlay != null
|
|
45
|
+
|
|
46
|
+
fun show(
|
|
47
|
+
dismissable: Boolean,
|
|
48
|
+
dismissOnOverlayTap: Boolean,
|
|
49
|
+
overlayOpacity: Float,
|
|
50
|
+
collapsedHeight: Int,
|
|
51
|
+
onDismiss: () -> Unit,
|
|
52
|
+
) {
|
|
53
|
+
if (isShown) return
|
|
54
|
+
val root = findInlineRoot(anchor) ?: return
|
|
55
|
+
this.onDismiss = onDismiss
|
|
56
|
+
snaps = collapsedHeight > 0
|
|
57
|
+
val scrimAlpha = if (overlayOpacity >= 0) overlayOpacity else SCRIM_ALPHA
|
|
58
|
+
|
|
59
|
+
val ctx = anchor.context
|
|
60
|
+
|
|
61
|
+
val overlayRoot = PassThroughFrameLayout(ctx).apply {
|
|
62
|
+
layoutParams = ViewGroup.LayoutParams(
|
|
63
|
+
ViewGroup.LayoutParams.MATCH_PARENT,
|
|
64
|
+
ViewGroup.LayoutParams.MATCH_PARENT,
|
|
65
|
+
)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
val coordinator = PassThroughCoordinatorLayout(ctx).apply {
|
|
69
|
+
layoutParams = FrameLayout.LayoutParams(
|
|
70
|
+
FrameLayout.LayoutParams.MATCH_PARENT,
|
|
71
|
+
FrameLayout.LayoutParams.MATCH_PARENT,
|
|
72
|
+
)
|
|
73
|
+
setBackgroundColor(Color.TRANSPARENT)
|
|
74
|
+
}
|
|
75
|
+
overlayRoot.addView(coordinator)
|
|
76
|
+
|
|
77
|
+
val touchOutside = View(ctx).apply {
|
|
78
|
+
layoutParams = CoordinatorLayout.LayoutParams(
|
|
79
|
+
CoordinatorLayout.LayoutParams.MATCH_PARENT,
|
|
80
|
+
CoordinatorLayout.LayoutParams.MATCH_PARENT,
|
|
81
|
+
)
|
|
82
|
+
}
|
|
83
|
+
// Without a scrim touches outside the sheet must reach the screen behind.
|
|
84
|
+
if (scrimAlpha > 0) coordinator.addView(touchOutside)
|
|
85
|
+
|
|
86
|
+
val designBottomSheet = PassThroughFrameLayout(ctx).apply {
|
|
87
|
+
layoutParams = CoordinatorLayout.LayoutParams(
|
|
88
|
+
CoordinatorLayout.LayoutParams.MATCH_PARENT,
|
|
89
|
+
CoordinatorLayout.LayoutParams.WRAP_CONTENT,
|
|
90
|
+
).apply {
|
|
91
|
+
gravity = Gravity.TOP or Gravity.CENTER_HORIZONTAL
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
(hostView.parent as? ViewGroup)?.removeView(hostView)
|
|
96
|
+
designBottomSheet.addView(hostView)
|
|
97
|
+
coordinator.addView(designBottomSheet)
|
|
98
|
+
|
|
99
|
+
val behavior = BottomSheetBehavior<FrameLayout>().apply {
|
|
100
|
+
setHideable(true)
|
|
101
|
+
setSkipCollapsed(!snaps)
|
|
102
|
+
setDraggable(dismissable || snaps)
|
|
103
|
+
setPeekHeight(if (snaps) collapsedHeight else 10, false)
|
|
104
|
+
setState(BottomSheetBehavior.STATE_HIDDEN)
|
|
105
|
+
addBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() {
|
|
106
|
+
override fun onStateChanged(bottomSheet: View, newState: Int) {
|
|
107
|
+
if (newState == BottomSheetBehavior.STATE_DRAGGING) {
|
|
108
|
+
// BottomSheetBehavior took over the gesture natively. In inline
|
|
109
|
+
// mode JS touches are dispatched by the ancestor ReactRootView's
|
|
110
|
+
// JSTouchDispatcher, which doesn't see the native intercept and
|
|
111
|
+
// would still fire a press on ACTION_UP. Notify it to cancel the
|
|
112
|
+
// active responder so a swipe-to-dismiss isn't mistaken for a tap.
|
|
113
|
+
cancelAncestorJsTouches(bottomSheet)
|
|
114
|
+
} else if (newState == BottomSheetBehavior.STATE_HIDDEN) {
|
|
115
|
+
dismiss(animated = false, invokeCallback = true)
|
|
116
|
+
} else if (newState == BottomSheetBehavior.STATE_EXPANDED ||
|
|
117
|
+
newState == BottomSheetBehavior.STATE_COLLAPSED ||
|
|
118
|
+
newState == BottomSheetBehavior.STATE_HALF_EXPANDED
|
|
119
|
+
) {
|
|
120
|
+
if (snaps) behavior?.setHideable(dismissable)
|
|
121
|
+
// Sheet settled — sync Fabric shadow tree with our new visual
|
|
122
|
+
// position so Pressability measures correctly.
|
|
123
|
+
bottomSheet.post { anchor.pushContentOriginOffset() }
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
override fun onSlide(bottomSheet: View, slideOffset: Float) {
|
|
128
|
+
// While dragging, update offset each frame so the user can still tap
|
|
129
|
+
// elements after the sheet settles at a non-expanded position.
|
|
130
|
+
anchor.pushContentOriginOffset()
|
|
131
|
+
}
|
|
132
|
+
})
|
|
133
|
+
}
|
|
134
|
+
(designBottomSheet.layoutParams as CoordinatorLayout.LayoutParams).behavior = behavior
|
|
135
|
+
this.behavior = behavior
|
|
136
|
+
|
|
137
|
+
touchOutside.setOnClickListener {
|
|
138
|
+
if (dismissable && dismissOnOverlayTap) behavior.setState(BottomSheetBehavior.STATE_HIDDEN)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (scrimAlpha > 0) animateScrim(coordinator, fromAlpha = 0f, toAlpha = scrimAlpha)
|
|
142
|
+
|
|
143
|
+
root.addView(overlayRoot)
|
|
144
|
+
InlineFooterPresenter.bringFootersToFront(root)
|
|
145
|
+
overlay = overlayRoot
|
|
146
|
+
|
|
147
|
+
designBottomSheet.post {
|
|
148
|
+
behavior.setState(
|
|
149
|
+
if (snaps) BottomSheetBehavior.STATE_COLLAPSED else BottomSheetBehavior.STATE_EXPANDED
|
|
150
|
+
)
|
|
151
|
+
// Post once more so Fabric state sync runs after the expand-layout pass.
|
|
152
|
+
designBottomSheet.post { anchor.pushContentOriginOffset() }
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
fun dismiss(animated: Boolean = true, invokeCallback: Boolean = true) {
|
|
157
|
+
val layout = overlay ?: return
|
|
158
|
+
hideKeyboard()
|
|
159
|
+
val behavior = this.behavior
|
|
160
|
+
if (animated && behavior != null && behavior.getState() != BottomSheetBehavior.STATE_HIDDEN) {
|
|
161
|
+
behavior.setHideable(true)
|
|
162
|
+
behavior.setState(BottomSheetBehavior.STATE_HIDDEN)
|
|
163
|
+
return
|
|
164
|
+
}
|
|
165
|
+
scrimAnimator?.cancel()
|
|
166
|
+
scrimAnimator = null
|
|
167
|
+
this.behavior = null
|
|
168
|
+
this.overlayHost = null
|
|
169
|
+
overlay = null
|
|
170
|
+
(layout.parent as? ViewGroup)?.removeView(layout)
|
|
171
|
+
(hostView.parent as? ViewGroup)?.removeView(hostView)
|
|
172
|
+
if (invokeCallback) onDismiss?.invoke()
|
|
173
|
+
onDismiss = null
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
fun setDismissable(dismissable: Boolean) {
|
|
177
|
+
behavior?.setDraggable(dismissable || snaps)
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
fun setOverlayView(view: View?) {
|
|
181
|
+
if (overlayView == view) return
|
|
182
|
+
(overlayView?.parent as? ViewGroup)?.removeView(overlayView)
|
|
183
|
+
overlayView = view
|
|
184
|
+
attachOverlayView()
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
private fun attachOverlayView() {
|
|
188
|
+
val host = overlayHost ?: return
|
|
189
|
+
val view = overlayView ?: return
|
|
190
|
+
// Re-parenting a view React Native mounted somewhere else: its old parent
|
|
191
|
+
// loses a child without React Native being told.
|
|
192
|
+
val previousParent = view.parent as? ViewGroup
|
|
193
|
+
SheetTreeLog.log(
|
|
194
|
+
view.context,
|
|
195
|
+
"inline.attachOverlay",
|
|
196
|
+
"overlay=${SheetTreeLog.tag(view)} from=${SheetTreeLog.tag(previousParent)}" +
|
|
197
|
+
" fromChildren=${SheetTreeLog.childTags(previousParent)} to=${SheetTreeLog.tag(host)}",
|
|
198
|
+
)
|
|
199
|
+
previousParent?.removeView(view)
|
|
200
|
+
view.layoutParams = FrameLayout.LayoutParams(
|
|
201
|
+
FrameLayout.LayoutParams.MATCH_PARENT,
|
|
202
|
+
FrameLayout.LayoutParams.MATCH_PARENT,
|
|
203
|
+
)
|
|
204
|
+
host.addView(view)
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
private fun hideKeyboard() {
|
|
208
|
+
val focused = hostView.findFocus() ?: return
|
|
209
|
+
val imm = hostView.context.getSystemService(Context.INPUT_METHOD_SERVICE) as? InputMethodManager
|
|
210
|
+
imm?.hideSoftInputFromWindow(focused.windowToken, 0)
|
|
211
|
+
focused.clearFocus()
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
private fun cancelAncestorJsTouches(child: View) {
|
|
215
|
+
var p: ViewParent? = child.parent
|
|
216
|
+
while (p != null) {
|
|
217
|
+
if (p is RootView) {
|
|
218
|
+
val now = SystemClock.uptimeMillis()
|
|
219
|
+
val ev = MotionEvent.obtain(now, now, MotionEvent.ACTION_CANCEL, 0f, 0f, 0)
|
|
220
|
+
try {
|
|
221
|
+
(p as RootView).onChildStartedNativeGesture(child, ev)
|
|
222
|
+
} finally {
|
|
223
|
+
ev.recycle()
|
|
224
|
+
}
|
|
225
|
+
return
|
|
226
|
+
}
|
|
227
|
+
p = p.parent
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
private fun animateScrim(target: View, fromAlpha: Float, toAlpha: Float) {
|
|
232
|
+
scrimAnimator?.cancel()
|
|
233
|
+
val animator = ValueAnimator.ofFloat(fromAlpha, toAlpha).apply {
|
|
234
|
+
duration = SCRIM_DURATION_MS
|
|
235
|
+
addUpdateListener { animation ->
|
|
236
|
+
val alpha = animation.animatedValue as Float
|
|
237
|
+
val alphaByte = (alpha * 255).toInt().coerceIn(0, 255)
|
|
238
|
+
target.setBackgroundColor(Color.argb(alphaByte, 0, 0, 0))
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
scrimAnimator = animator
|
|
242
|
+
animator.start()
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
companion object {
|
|
246
|
+
private const val SCRIM_ALPHA = 0.5f
|
|
247
|
+
private const val SCRIM_DURATION_MS = 250L
|
|
248
|
+
}
|
|
249
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
package com.sheet2
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.widget.FrameLayout
|
|
5
|
+
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
|
6
|
+
import com.facebook.react.uimanager.PointerEvents
|
|
7
|
+
import com.facebook.react.uimanager.ReactPointerEventsView
|
|
8
|
+
|
|
9
|
+
internal class PassThroughFrameLayout(context: Context) : FrameLayout(context), ReactPointerEventsView {
|
|
10
|
+
override val pointerEvents: PointerEvents = PointerEvents.BOX_NONE
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
internal class PassThroughCoordinatorLayout(context: Context) :
|
|
14
|
+
CoordinatorLayout(context),
|
|
15
|
+
ReactPointerEventsView {
|
|
16
|
+
override val pointerEvents: PointerEvents = PointerEvents.BOX_NONE
|
|
17
|
+
}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
package com.
|
|
1
|
+
package com.sheet2
|
|
2
2
|
|
|
3
|
+
import android.graphics.Rect
|
|
3
4
|
import android.os.Build
|
|
4
5
|
import android.view.View
|
|
5
|
-
import android.view.ViewGroup
|
|
6
6
|
import android.view.WindowInsets
|
|
7
7
|
import androidx.annotation.RequiresApi
|
|
8
8
|
import com.facebook.react.uimanager.PixelUtil.pxToDp
|
|
9
|
-
import java.lang.IllegalArgumentException
|
|
10
9
|
import kotlin.math.max
|
|
11
10
|
import kotlin.math.min
|
|
12
11
|
|
|
@@ -44,7 +43,7 @@ private fun getRootWindowInsetsCompatM(rootView: View): EdgeInsets? {
|
|
|
44
43
|
}
|
|
45
44
|
|
|
46
45
|
private fun getRootWindowInsetsCompatBase(rootView: View): EdgeInsets? {
|
|
47
|
-
val visibleRect =
|
|
46
|
+
val visibleRect = Rect()
|
|
48
47
|
rootView.getWindowVisibleDisplayFrame(visibleRect)
|
|
49
48
|
return EdgeInsets(
|
|
50
49
|
top = visibleRect.top.toFloat(),
|
|
@@ -72,7 +71,7 @@ internal fun getSafeAreaInsets(view: View): EdgeInsets? {
|
|
|
72
71
|
// Calculate the part of the view that overlaps with window insets.
|
|
73
72
|
val windowWidth = rootView.width.toFloat()
|
|
74
73
|
val windowHeight = rootView.height.toFloat()
|
|
75
|
-
val visibleRect =
|
|
74
|
+
val visibleRect = Rect()
|
|
76
75
|
view.getGlobalVisibleRect(visibleRect)
|
|
77
76
|
return EdgeInsets(
|
|
78
77
|
top = max(windowInsets.top - visibleRect.top, 0f),
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
package com.sheet2
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.BaseReactPackage
|
|
4
|
+
import com.facebook.react.ReactPackage
|
|
5
|
+
import com.facebook.react.bridge.NativeModule
|
|
6
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
7
|
+
import com.facebook.react.module.model.ReactModuleInfo
|
|
8
|
+
import com.facebook.react.module.model.ReactModuleInfoProvider
|
|
9
|
+
import com.facebook.react.uimanager.ViewManager
|
|
10
|
+
import java.util.ArrayList
|
|
11
|
+
|
|
12
|
+
class Sheet2ViewPackage : BaseReactPackage() {
|
|
13
|
+
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
|
|
14
|
+
val viewManagers: MutableList<ViewManager<*, *>> = ArrayList()
|
|
15
|
+
viewManagers.add(Sheet2ViewManager(reactContext))
|
|
16
|
+
return viewManagers
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
|
|
20
|
+
return emptyList()
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
|
|
24
|
+
if (name == NativeSheetSpec.NAME) {
|
|
25
|
+
return SheetModule(reactContext)
|
|
26
|
+
}
|
|
27
|
+
return null
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
|
|
31
|
+
return ReactModuleInfoProvider {
|
|
32
|
+
val moduleInfos: MutableMap<String, ReactModuleInfo> = HashMap()
|
|
33
|
+
moduleInfos[NativeSheetSpec.NAME] = ReactModuleInfo(
|
|
34
|
+
NativeSheetSpec.NAME,
|
|
35
|
+
NativeSheetSpec.NAME,
|
|
36
|
+
false, // canOverrideExistingModule
|
|
37
|
+
false, // needsEagerInit
|
|
38
|
+
false, // isCxxModule
|
|
39
|
+
true // isTurboModule
|
|
40
|
+
)
|
|
41
|
+
moduleInfos
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
package com.sheet2
|
|
2
|
+
|
|
3
|
+
import android.graphics.Color
|
|
4
|
+
import android.view.View
|
|
5
|
+
import com.behavior.BottomSheetBehavior
|
|
6
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
7
|
+
import com.facebook.react.module.annotations.ReactModule
|
|
8
|
+
import com.facebook.react.uimanager.PixelUtil.dpToPx
|
|
9
|
+
import com.facebook.react.uimanager.ThemedReactContext
|
|
10
|
+
import com.facebook.react.uimanager.ReactStylesDiffMap
|
|
11
|
+
import com.facebook.react.uimanager.StateWrapper
|
|
12
|
+
import com.facebook.react.uimanager.UIManagerHelper
|
|
13
|
+
import com.facebook.react.uimanager.ViewGroupManager
|
|
14
|
+
import com.facebook.react.uimanager.ViewManagerDelegate
|
|
15
|
+
import com.facebook.react.viewmanagers.SheetViewManagerDelegate
|
|
16
|
+
import com.facebook.react.viewmanagers.SheetViewManagerInterface
|
|
17
|
+
|
|
18
|
+
@ReactModule(name = Sheet2ViewManager.NAME)
|
|
19
|
+
class Sheet2ViewManager(reactContext: ReactApplicationContext) : ViewGroupManager<Sheet2View>(reactContext),
|
|
20
|
+
SheetViewManagerInterface<Sheet2View> {
|
|
21
|
+
private val mDelegate: ViewManagerDelegate<Sheet2View>
|
|
22
|
+
|
|
23
|
+
init {
|
|
24
|
+
mDelegate = SheetViewManagerDelegate(this)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
override fun getDelegate(): ViewManagerDelegate<Sheet2View> {
|
|
28
|
+
return mDelegate
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
override fun getName(): String {
|
|
32
|
+
return NAME
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public override fun createViewInstance(context: ThemedReactContext): Sheet2View {
|
|
36
|
+
return Sheet2View(context)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
override fun dismissSheet(view: Sheet2View) {
|
|
40
|
+
SheetTreeLog.debug("dismissSheet")
|
|
41
|
+
view.dismiss()
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
override fun setUniqueId(view: Sheet2View, value: String?) {
|
|
45
|
+
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
override fun setDismissable(view: Sheet2View, value: Boolean) {
|
|
49
|
+
SheetTreeLog.debug("setDismissable $value")
|
|
50
|
+
view.dismissable = value
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
override fun setMaxWidth(view: Sheet2View, value: Double) {
|
|
54
|
+
SheetTreeLog.debug("setMaxWidth $value")
|
|
55
|
+
view.maxWidth = value.dpToPx()
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
override fun setMaxHeight(view: Sheet2View, value: Double) {
|
|
59
|
+
SheetTreeLog.debug("setMaxHeight $value")
|
|
60
|
+
view.mHostView.sheetMaxHeightSize = value.dpToPx()
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
override fun setMinHeight(view: Sheet2View, value: Double) {
|
|
64
|
+
SheetTreeLog.debug("setMinHeight $value")
|
|
65
|
+
view.mHostView.sheetMinHeightSize = value.dpToPx()
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
override fun setTopLeftRightCornerRadius(view: Sheet2View, value: Double) {
|
|
69
|
+
SheetTreeLog.debug("setTopLeftRightCornerRadius $value")
|
|
70
|
+
view.topLeftRightCornerRadius = value.dpToPx()
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
override fun setIsSystemUILight(view: Sheet2View, value: Boolean) {
|
|
74
|
+
SheetTreeLog.debug("setIsSystemUILight $value")
|
|
75
|
+
view.isSystemUILight = value
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
override fun setPassScrollViewReactTag(view: Sheet2View, value: String?) {
|
|
79
|
+
SheetTreeLog.debug("setPassScrollViewReactTag $value")
|
|
80
|
+
value ?: return
|
|
81
|
+
val v = BottomSheetBehavior.findView(view.mHostView) ?: return
|
|
82
|
+
view.setNewNestedScrollView(v)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
override fun setSheetBackgroundColor(view: Sheet2View, value: Int?) {
|
|
86
|
+
view._backgroundColor = value ?: Color.TRANSPARENT
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
override fun setWindowLevel(view: Sheet2View, value: String?) {
|
|
90
|
+
// iOS only
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
override fun setUseInlinePresentation(view: Sheet2View, value: Boolean) {
|
|
94
|
+
view.useInlinePresentation = value
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
override fun setPresentationStyle(view: Sheet2View, value: String?) {
|
|
98
|
+
view.presentationStyle = value ?: "bottom"
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
override fun setCenterAnimation(view: Sheet2View, value: String?) {
|
|
102
|
+
view.centerAnimation = value ?: "fade"
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
override fun setDismissOnOverlayTap(view: Sheet2View, value: Boolean) {
|
|
106
|
+
view.dismissOnOverlayTap = value
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
override fun setOverlayOpacity(view: Sheet2View, value: Double) {
|
|
110
|
+
view.overlayOpacity = value.toFloat()
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
override fun setCollapsedHeight(view: Sheet2View, value: Double) {
|
|
114
|
+
view.collapsedHeight = value.dpToPx()
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
override fun setCalculatedHeight(view: Sheet2View, value: Double) {
|
|
118
|
+
SheetTreeLog.debug("setCalculatedHeight $value")
|
|
119
|
+
view.mHostView.setVirtualHeight(value.dpToPx())
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
override fun getChildCount(parent: Sheet2View): Int {
|
|
123
|
+
return parent.reactChildCount()
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
override fun getChildAt(parent: Sheet2View, index: Int): View? {
|
|
127
|
+
return parent.reactChildAt(index)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
override fun onDropViewInstance(view: Sheet2View) {
|
|
131
|
+
super.onDropViewInstance(view)
|
|
132
|
+
view.onDropInstance()
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
override fun onAfterUpdateTransaction(view: Sheet2View) {
|
|
136
|
+
super.onAfterUpdateTransaction(view)
|
|
137
|
+
SheetTreeLog.debug("onAfterUpdateTransaction")
|
|
138
|
+
view.showOrUpdate()
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
override fun updateState(
|
|
142
|
+
view: Sheet2View,
|
|
143
|
+
props: ReactStylesDiffMap?,
|
|
144
|
+
stateWrapper: StateWrapper?
|
|
145
|
+
): Any? {
|
|
146
|
+
view.fabricStateWrapper = stateWrapper
|
|
147
|
+
return super.updateState(view, props, stateWrapper)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
protected override fun addEventEmitters(
|
|
151
|
+
reactContext: ThemedReactContext,
|
|
152
|
+
view: Sheet2View
|
|
153
|
+
) {
|
|
154
|
+
val dispatcher = UIManagerHelper.getEventDispatcherForReactTag(reactContext, view.id)
|
|
155
|
+
if (dispatcher != null) {
|
|
156
|
+
view.eventDispatcher = dispatcher
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
companion object {
|
|
161
|
+
const val NAME = "SheetView"
|
|
162
|
+
}
|
|
163
|
+
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
package com.
|
|
1
|
+
package com.sheet2
|
|
2
2
|
|
|
3
3
|
import android.view.ViewGroup
|
|
4
4
|
import androidx.appcompat.app.AppCompatActivity
|
|
5
5
|
import com.facebook.react.bridge.Arguments
|
|
6
6
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
7
|
+
import com.facebook.react.bridge.WritableArray
|
|
7
8
|
import com.facebook.react.bridge.WritableMap
|
|
8
9
|
|
|
9
10
|
class SheetModule(reactContext: ReactApplicationContext) : NativeSheetSpec(reactContext) {
|
|
@@ -23,15 +24,25 @@ class SheetModule(reactContext: ReactApplicationContext) : NativeSheetSpec(react
|
|
|
23
24
|
return Arguments.createMap()
|
|
24
25
|
}
|
|
25
26
|
|
|
27
|
+
override fun getTreeLog(): WritableArray {
|
|
28
|
+
val entries = Arguments.createArray()
|
|
29
|
+
SheetTreeLog.snapshot().forEach { entries.pushString(it) }
|
|
30
|
+
return entries
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
override fun setLogsEnabled(enabled: Boolean) {
|
|
34
|
+
SheetTreeLog.logsEnabled = enabled
|
|
35
|
+
}
|
|
36
|
+
|
|
26
37
|
override fun dismissAll() {
|
|
27
38
|
reactApplicationContext.runOnUiQueueThread {
|
|
28
|
-
reactApplicationContext.currentActivity?.let { AppFittedSheet.dismissAll(it as AppCompatActivity) }
|
|
39
|
+
reactApplicationContext.currentActivity?.let { AppFittedSheet.Companion.dismissAll(it as AppCompatActivity) }
|
|
29
40
|
}
|
|
30
41
|
}
|
|
31
42
|
|
|
32
43
|
override fun dismissPresented() {
|
|
33
44
|
reactApplicationContext.runOnUiQueueThread {
|
|
34
|
-
reactApplicationContext.currentActivity?.let { AppFittedSheet.dismissPresented(it as AppCompatActivity) }
|
|
45
|
+
reactApplicationContext.currentActivity?.let { AppFittedSheet.Companion.dismissPresented(it as AppCompatActivity) }
|
|
35
46
|
}
|
|
36
47
|
}
|
|
37
48
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
package com.
|
|
1
|
+
package com.sheet2
|
|
2
2
|
|
|
3
3
|
import com.facebook.react.BaseReactPackage
|
|
4
|
-
import com.facebook.react.ReactPackage
|
|
5
4
|
import com.facebook.react.bridge.NativeModule
|
|
6
5
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
7
6
|
import com.facebook.react.module.model.ReactModuleInfo
|
|
@@ -12,7 +11,7 @@ import java.util.ArrayList
|
|
|
12
11
|
class SheetViewPackage : BaseReactPackage() {
|
|
13
12
|
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
|
|
14
13
|
val viewManagers: MutableList<ViewManager<*, *>> = ArrayList()
|
|
15
|
-
viewManagers.add(
|
|
14
|
+
viewManagers.add(Sheet2ViewManager(reactContext))
|
|
16
15
|
return viewManagers
|
|
17
16
|
}
|
|
18
17
|
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
package com.sheet2
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.util.Log
|
|
5
|
+
import android.view.View
|
|
6
|
+
import android.view.ViewGroup
|
|
7
|
+
import com.facebook.react.bridge.ReactContext
|
|
8
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Every place where this library moves a view React Native believes it owns.
|
|
12
|
+
*
|
|
13
|
+
* The mounting crashes worth chasing carry no frame of ours: on Android the
|
|
14
|
+
* stack between `ViewGroupManager.addView` and `ViewGroup.addInArray` is React
|
|
15
|
+
* Native and the framework only ("addViewAt: failed to insert view [child] into
|
|
16
|
+
* parent [parent] at index N", caused by "IndexOutOfBoundsException: index=N
|
|
17
|
+
* count=0"). So the only way to tell afterwards whether a sheet was involved is
|
|
18
|
+
* to say so ourselves, naming the views by the id React Native uses as the tag —
|
|
19
|
+
* which is exactly what that message carries.
|
|
20
|
+
*
|
|
21
|
+
* Entries go to logcat, to a small in-memory ring for a local session, and — when
|
|
22
|
+
* a listener is registered from JS — to the app, which is expected to turn them
|
|
23
|
+
* into breadcrumbs. Breadcrumbs are what survives into a native crash report.
|
|
24
|
+
*/
|
|
25
|
+
object SheetTreeLog {
|
|
26
|
+
private const val TAG = "Sheet2Tree"
|
|
27
|
+
private const val EVENT = "sheet2:tree"
|
|
28
|
+
private const val CAPACITY = 32
|
|
29
|
+
|
|
30
|
+
private val entries = ArrayDeque<String>()
|
|
31
|
+
|
|
32
|
+
@Volatile
|
|
33
|
+
var logsEnabled = false
|
|
34
|
+
|
|
35
|
+
fun debug(message: String) {
|
|
36
|
+
if (logsEnabled) Log.d(TAG, message)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
fun log(context: Context?, op: String, details: String) {
|
|
40
|
+
val entry = "$op $details"
|
|
41
|
+
|
|
42
|
+
synchronized(entries) {
|
|
43
|
+
if (entries.size == CAPACITY) entries.removeFirst()
|
|
44
|
+
entries.addLast(entry)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
debug(entry)
|
|
48
|
+
emit(context, entry)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** The tag React Native knows the view by, or "-" when there is no view. */
|
|
52
|
+
fun tag(view: View?): String = view?.let { "${it.id}" } ?: "-"
|
|
53
|
+
|
|
54
|
+
fun childTags(parent: ViewGroup?): String {
|
|
55
|
+
if (parent == null) return "-"
|
|
56
|
+
val count = parent.childCount
|
|
57
|
+
if (count == 0) return "none"
|
|
58
|
+
|
|
59
|
+
return (0 until count).joinToString(",") { "${parent.getChildAt(it).id}" }
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
fun snapshot(): List<String> = synchronized(entries) { entries.toList() }
|
|
63
|
+
|
|
64
|
+
private fun emit(context: Context?, entry: String) {
|
|
65
|
+
val reactContext = context as? ReactContext ?: return
|
|
66
|
+
if (!reactContext.hasActiveReactInstance()) return
|
|
67
|
+
|
|
68
|
+
try {
|
|
69
|
+
reactContext
|
|
70
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
71
|
+
.emit(EVENT, entry)
|
|
72
|
+
} catch (error: Throwable) {
|
|
73
|
+
// A sheet can be torn down while the instance is going away; diagnostics
|
|
74
|
+
// must never be the reason something crashes.
|
|
75
|
+
debug("emit failed: ${error.message}")
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
package com.
|
|
1
|
+
package com.sheet2
|
|
2
2
|
|
|
3
3
|
import android.content.Context
|
|
4
4
|
import android.graphics.Color
|
|
@@ -8,7 +8,6 @@ import android.view.Window
|
|
|
8
8
|
import android.view.WindowInsetsController
|
|
9
9
|
import androidx.core.graphics.toColorInt
|
|
10
10
|
import com.facebook.react.bridge.ReadableMap
|
|
11
|
-
import com.facebook.react.uimanager.PixelUtil
|
|
12
11
|
|
|
13
12
|
|
|
14
13
|
fun ReadableMap?.bool(value: String, default: Boolean): Boolean {
|