@lodev09/react-native-true-sheet 3.7.0-beta.4 → 3.7.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.
|
@@ -39,10 +39,6 @@ class TrueSheetView(private val reactContext: ThemedReactContext) :
|
|
|
39
39
|
// ==================== Properties ====================
|
|
40
40
|
|
|
41
41
|
internal val viewController: TrueSheetViewController = TrueSheetViewController(reactContext)
|
|
42
|
-
|
|
43
|
-
private val containerView: TrueSheetContainerView?
|
|
44
|
-
get() = viewController.getChildAt(0) as? TrueSheetContainerView
|
|
45
|
-
|
|
46
42
|
override var eventDispatcher: EventDispatcher? = null
|
|
47
43
|
|
|
48
44
|
// Initial present configuration (set by ViewManager before mount)
|
|
@@ -81,10 +77,6 @@ class TrueSheetView(private val reactContext: ThemedReactContext) :
|
|
|
81
77
|
|
|
82
78
|
// ==================== ReactViewGroup Overrides ====================
|
|
83
79
|
|
|
84
|
-
override fun dispatchProvideStructure(structure: ViewStructure) {
|
|
85
|
-
super.dispatchProvideStructure(structure)
|
|
86
|
-
}
|
|
87
|
-
|
|
88
80
|
override fun onLayout(
|
|
89
81
|
changed: Boolean,
|
|
90
82
|
left: Int,
|
|
@@ -277,10 +269,12 @@ class TrueSheetView(private val reactContext: ThemedReactContext) :
|
|
|
277
269
|
@UiThread
|
|
278
270
|
fun present(detentIndex: Int, animated: Boolean = true, promiseCallback: () -> Unit) {
|
|
279
271
|
if (!viewController.isPresented) {
|
|
280
|
-
//
|
|
272
|
+
// Dismiss keyboard if focused view is within a sheet or if target detent will be dimmed
|
|
281
273
|
val parentSheet = TrueSheetStackManager.getTopmostSheet()
|
|
282
|
-
|
|
283
|
-
|
|
274
|
+
val isFocusedViewWithinSheet = parentSheet?.viewController?.isFocusedViewWithinSheet() == true
|
|
275
|
+
val shouldDismissKeyboard = isFocusedViewWithinSheet || viewController.isDimmedAtDetentIndex(detentIndex)
|
|
276
|
+
if (KeyboardUtils.isKeyboardVisible(reactContext) && shouldDismissKeyboard) {
|
|
277
|
+
viewController.saveFocusedView()
|
|
284
278
|
KeyboardUtils.dismiss(this) {
|
|
285
279
|
post { present(detentIndex, animated, promiseCallback) }
|
|
286
280
|
}
|
|
@@ -205,9 +205,6 @@ class TrueSheetViewController(private val reactContext: ThemedReactContext) :
|
|
|
205
205
|
if (isPresented) sheetView?.setupGrabber()
|
|
206
206
|
}
|
|
207
207
|
|
|
208
|
-
val isDimmedAtCurrentDetent: Boolean
|
|
209
|
-
get() = dimmed && currentDetentIndex >= dimmedDetentIndex
|
|
210
|
-
|
|
211
208
|
// =============================================================================
|
|
212
209
|
// MARK: - Computed Properties
|
|
213
210
|
// =============================================================================
|
|
@@ -288,6 +285,11 @@ class TrueSheetViewController(private val reactContext: ThemedReactContext) :
|
|
|
288
285
|
private val dimViews: List<TrueSheetDimView>
|
|
289
286
|
get() = listOfNotNull(dimView, parentDimView)
|
|
290
287
|
|
|
288
|
+
val isDimmedAtCurrentDetent: Boolean
|
|
289
|
+
get() = isDimmedAtDetentIndex(currentDetentIndex)
|
|
290
|
+
|
|
291
|
+
fun isDimmedAtDetentIndex(index: Int): Boolean = dimmed && index >= dimmedDetentIndex
|
|
292
|
+
|
|
291
293
|
// =============================================================================
|
|
292
294
|
// MARK: - Sheet Creation & Cleanup
|
|
293
295
|
// =============================================================================
|
|
@@ -713,7 +715,7 @@ class TrueSheetViewController(private val reactContext: ThemedReactContext) :
|
|
|
713
715
|
}
|
|
714
716
|
|
|
715
717
|
private fun finishDismiss() {
|
|
716
|
-
|
|
718
|
+
restoreFocusedView()
|
|
717
719
|
emitDidDismissEvents()
|
|
718
720
|
cleanupSheet()
|
|
719
721
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
package com.lodev09.truesheet.core
|
|
2
2
|
|
|
3
|
+
import android.view.ViewGroup
|
|
3
4
|
import com.lodev09.truesheet.TrueSheetView
|
|
4
5
|
|
|
5
6
|
/**
|
|
@@ -10,6 +11,25 @@ object TrueSheetStackManager {
|
|
|
10
11
|
|
|
11
12
|
private val presentedSheetStack = mutableListOf<TrueSheetView>()
|
|
12
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Gets the parent sheet at the given index, if any.
|
|
16
|
+
* Only returns a parent if it's in the same container.
|
|
17
|
+
* Must be called within synchronized block.
|
|
18
|
+
*/
|
|
19
|
+
private fun getParentSheetAt(index: Int, rootContainer: ViewGroup?): TrueSheetView? {
|
|
20
|
+
if (index <= 0) return null
|
|
21
|
+
return presentedSheetStack[index - 1].takeIf { it.rootContainerView == rootContainer }
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Returns the topmost presented and visible sheet.
|
|
26
|
+
* Must be called within synchronized block.
|
|
27
|
+
*/
|
|
28
|
+
private fun findTopmostSheet(): TrueSheetView? =
|
|
29
|
+
presentedSheetStack.lastOrNull {
|
|
30
|
+
it.viewController.isPresented && it.viewController.isSheetVisible
|
|
31
|
+
}
|
|
32
|
+
|
|
13
33
|
/**
|
|
14
34
|
* Called when a sheet is about to be presented.
|
|
15
35
|
* Returns the visible parent sheet to stack on, or null if none.
|
|
@@ -18,13 +38,7 @@ object TrueSheetStackManager {
|
|
|
18
38
|
@JvmStatic
|
|
19
39
|
fun onSheetWillPresent(sheetView: TrueSheetView, detentIndex: Int): TrueSheetView? {
|
|
20
40
|
synchronized(presentedSheetStack) {
|
|
21
|
-
val
|
|
22
|
-
val parentSheet = presentedSheetStack.lastOrNull()
|
|
23
|
-
?.takeIf {
|
|
24
|
-
it.viewController.isPresented &&
|
|
25
|
-
it.viewController.isSheetVisible &&
|
|
26
|
-
it.rootContainerView == rootContainer
|
|
27
|
-
}
|
|
41
|
+
val parentSheet = findTopmostSheet()?.takeIf { it.rootContainerView == sheetView.rootContainerView }
|
|
28
42
|
|
|
29
43
|
val childSheetTop = sheetView.viewController.detentCalculator.getSheetTopForDetentIndex(detentIndex)
|
|
30
44
|
parentSheet?.updateTranslationForChild(childSheetTop)
|
|
@@ -60,11 +74,7 @@ object TrueSheetStackManager {
|
|
|
60
74
|
fun onSheetSizeChanged(sheetView: TrueSheetView) {
|
|
61
75
|
synchronized(presentedSheetStack) {
|
|
62
76
|
val index = presentedSheetStack.indexOf(sheetView)
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
val rootContainer = sheetView.rootContainerView
|
|
66
|
-
val parentSheet = presentedSheetStack[index - 1]
|
|
67
|
-
.takeIf { it.rootContainerView == rootContainer } ?: return
|
|
77
|
+
val parentSheet = getParentSheetAt(index, sheetView.rootContainerView) ?: return
|
|
68
78
|
|
|
69
79
|
// Post to ensure layout is complete before reading position
|
|
70
80
|
sheetView.viewController.post {
|
|
@@ -117,9 +127,7 @@ object TrueSheetStackManager {
|
|
|
117
127
|
fun getParentSheet(sheetView: TrueSheetView): TrueSheetView? {
|
|
118
128
|
synchronized(presentedSheetStack) {
|
|
119
129
|
val index = presentedSheetStack.indexOf(sheetView)
|
|
120
|
-
|
|
121
|
-
val rootContainer = sheetView.rootContainerView
|
|
122
|
-
return presentedSheetStack[index - 1].takeIf { it.rootContainerView == rootContainer }
|
|
130
|
+
return getParentSheetAt(index, sheetView.rootContainerView)
|
|
123
131
|
}
|
|
124
132
|
}
|
|
125
133
|
|
|
@@ -140,7 +148,7 @@ object TrueSheetStackManager {
|
|
|
140
148
|
@JvmStatic
|
|
141
149
|
fun getTopmostSheet(): TrueSheetView? {
|
|
142
150
|
synchronized(presentedSheetStack) {
|
|
143
|
-
return
|
|
151
|
+
return findTopmostSheet()
|
|
144
152
|
}
|
|
145
153
|
}
|
|
146
154
|
}
|
package/package.json
CHANGED