@lodev09/react-native-true-sheet 3.6.11 → 3.7.0-beta.1
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/android/src/main/java/com/lodev09/truesheet/TrueSheetView.kt +1 -1
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetViewController.kt +29 -28
- package/android/src/main/java/com/lodev09/truesheet/core/TrueSheetCoordinatorLayout.kt +7 -0
- package/android/src/main/java/com/lodev09/truesheet/core/TrueSheetStackManager.kt +22 -7
- package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetViewShadowNode.h +6 -0
- package/package.json +1 -1
|
@@ -66,7 +66,7 @@ class TrueSheetView(private val reactContext: ThemedReactContext) :
|
|
|
66
66
|
private var isSheetUpdatePending: Boolean = false
|
|
67
67
|
|
|
68
68
|
// Root container for the coordinator layout (activity or Modal dialog content view)
|
|
69
|
-
|
|
69
|
+
internal var rootContainerView: ViewGroup? = null
|
|
70
70
|
|
|
71
71
|
// ==================== Initialization ====================
|
|
72
72
|
|
|
@@ -367,6 +367,13 @@ class TrueSheetViewController(private val reactContext: ThemedReactContext) :
|
|
|
367
367
|
}
|
|
368
368
|
}
|
|
369
369
|
|
|
370
|
+
override fun coordinatorLayoutDidChangeConfiguration() {
|
|
371
|
+
if (!isPresented) return
|
|
372
|
+
|
|
373
|
+
updateStateDimensions()
|
|
374
|
+
sheetView?.let { emitChangePositionDelegate(it.top, realtime = false) }
|
|
375
|
+
}
|
|
376
|
+
|
|
370
377
|
// =============================================================================
|
|
371
378
|
// MARK: - TrueSheetDimViewDelegate
|
|
372
379
|
// =============================================================================
|
|
@@ -749,15 +756,7 @@ class TrueSheetViewController(private val reactContext: ThemedReactContext) :
|
|
|
749
756
|
animate = isPresented
|
|
750
757
|
)
|
|
751
758
|
|
|
752
|
-
|
|
753
|
-
val newHeight = realScreenHeight - expandedOffset - offset
|
|
754
|
-
val newWidth = minOf(screenWidth, DEFAULT_MAX_WIDTH.dpToPx().toInt())
|
|
755
|
-
|
|
756
|
-
if (lastStateWidth != newWidth || lastStateHeight != newHeight) {
|
|
757
|
-
lastStateWidth = newWidth
|
|
758
|
-
lastStateHeight = newHeight
|
|
759
|
-
delegate?.viewControllerDidChangeSize(newWidth, newHeight)
|
|
760
|
-
}
|
|
759
|
+
updateStateDimensions(expandedOffset)
|
|
761
760
|
|
|
762
761
|
if (isPresented) {
|
|
763
762
|
setStateForDetentIndex(currentDetentIndex)
|
|
@@ -907,14 +906,19 @@ class TrueSheetViewController(private val reactContext: ThemedReactContext) :
|
|
|
907
906
|
setupSheetDetents()
|
|
908
907
|
if (!isDismissing && detentIndexBeforeKeyboard >= 0) {
|
|
909
908
|
setStateForDetentIndex(detentIndexBeforeKeyboard)
|
|
910
|
-
detentIndexBeforeKeyboard = -1
|
|
911
909
|
}
|
|
912
910
|
}
|
|
913
911
|
|
|
914
|
-
override fun keyboardDidHide() {
|
|
912
|
+
override fun keyboardDidHide() {
|
|
913
|
+
if (!shouldHandleKeyboard(checkFocus = false)) return
|
|
914
|
+
detentIndexBeforeKeyboard = -1
|
|
915
|
+
positionFooter()
|
|
916
|
+
}
|
|
915
917
|
|
|
916
918
|
override fun keyboardDidChangeHeight(height: Int) {
|
|
917
|
-
if (
|
|
919
|
+
// Skip focus check if already handling keyboard (focus may be lost during hide)
|
|
920
|
+
val isHandlingKeyboard = detentIndexBeforeKeyboard >= 0
|
|
921
|
+
if (!shouldHandleKeyboard(checkFocus = !isHandlingKeyboard)) return
|
|
918
922
|
positionFooter()
|
|
919
923
|
}
|
|
920
924
|
}
|
|
@@ -1003,6 +1007,19 @@ class TrueSheetViewController(private val reactContext: ThemedReactContext) :
|
|
|
1003
1007
|
// MARK: - Detent Helpers
|
|
1004
1008
|
// =============================================================================
|
|
1005
1009
|
|
|
1010
|
+
private fun updateStateDimensions(expandedOffset: Int? = null) {
|
|
1011
|
+
val offset = expandedOffset ?: (realScreenHeight - detentCalculator.getDetentHeight(detents.last()))
|
|
1012
|
+
val topOffset = if (offset == 0) topInset else 0
|
|
1013
|
+
val newHeight = realScreenHeight - offset - topOffset
|
|
1014
|
+
val newWidth = minOf(screenWidth, DEFAULT_MAX_WIDTH.dpToPx().toInt())
|
|
1015
|
+
|
|
1016
|
+
if (lastStateWidth != newWidth || lastStateHeight != newHeight) {
|
|
1017
|
+
lastStateWidth = newWidth
|
|
1018
|
+
lastStateHeight = newHeight
|
|
1019
|
+
delegate?.viewControllerDidChangeSize(newWidth, newHeight)
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1006
1023
|
fun translateSheet(translationY: Int) {
|
|
1007
1024
|
val sheet = sheetView ?: return
|
|
1008
1025
|
|
|
@@ -1047,22 +1064,6 @@ class TrueSheetViewController(private val reactContext: ThemedReactContext) :
|
|
|
1047
1064
|
(getTag(R.id.react_test_id) as? String)?.let { info.viewIdResourceName = it }
|
|
1048
1065
|
}
|
|
1049
1066
|
|
|
1050
|
-
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
|
|
1051
|
-
super.onSizeChanged(w, h, oldw, oldh)
|
|
1052
|
-
|
|
1053
|
-
if (w == oldw && h == oldh) return
|
|
1054
|
-
if (!isPresented) return
|
|
1055
|
-
|
|
1056
|
-
// Skip reconfiguration if expanded and only height changed (e.g., keyboard)
|
|
1057
|
-
if (h + topInset >= screenHeight && isExpanded && oldw == w) return
|
|
1058
|
-
|
|
1059
|
-
post {
|
|
1060
|
-
setupSheetDetents()
|
|
1061
|
-
positionFooter()
|
|
1062
|
-
sheetView?.let { emitChangePositionDelegate(it.top, realtime = false) }
|
|
1063
|
-
}
|
|
1064
|
-
}
|
|
1065
|
-
|
|
1066
1067
|
// =============================================================================
|
|
1067
1068
|
// MARK: - RootView Touch Handling
|
|
1068
1069
|
// =============================================================================
|
|
@@ -2,6 +2,7 @@ package com.lodev09.truesheet.core
|
|
|
2
2
|
|
|
3
3
|
import android.annotation.SuppressLint
|
|
4
4
|
import android.content.Context
|
|
5
|
+
import android.content.res.Configuration
|
|
5
6
|
import android.view.MotionEvent
|
|
6
7
|
import android.view.ViewConfiguration
|
|
7
8
|
import android.view.ViewGroup
|
|
@@ -12,6 +13,7 @@ import com.facebook.react.uimanager.ReactPointerEventsView
|
|
|
12
13
|
|
|
13
14
|
interface TrueSheetCoordinatorLayoutDelegate {
|
|
14
15
|
fun coordinatorLayoutDidLayout(changed: Boolean)
|
|
16
|
+
fun coordinatorLayoutDidChangeConfiguration()
|
|
15
17
|
}
|
|
16
18
|
|
|
17
19
|
/**
|
|
@@ -53,6 +55,11 @@ class TrueSheetCoordinatorLayout(context: Context) :
|
|
|
53
55
|
delegate?.coordinatorLayoutDidLayout(changed)
|
|
54
56
|
}
|
|
55
57
|
|
|
58
|
+
override fun onConfigurationChanged(newConfig: Configuration?) {
|
|
59
|
+
super.onConfigurationChanged(newConfig)
|
|
60
|
+
delegate?.coordinatorLayoutDidChangeConfiguration()
|
|
61
|
+
}
|
|
62
|
+
|
|
56
63
|
override val pointerEvents: PointerEvents
|
|
57
64
|
get() = PointerEvents.BOX_NONE
|
|
58
65
|
|
|
@@ -13,12 +13,18 @@ object TrueSheetStackManager {
|
|
|
13
13
|
/**
|
|
14
14
|
* Called when a sheet is about to be presented.
|
|
15
15
|
* Returns the visible parent sheet to stack on, or null if none.
|
|
16
|
+
* Only returns a parent if it's in the same container (e.g., same Screen).
|
|
16
17
|
*/
|
|
17
18
|
@JvmStatic
|
|
18
19
|
fun onSheetWillPresent(sheetView: TrueSheetView, detentIndex: Int): TrueSheetView? {
|
|
19
20
|
synchronized(presentedSheetStack) {
|
|
21
|
+
val rootContainer = sheetView.rootContainerView
|
|
20
22
|
val parentSheet = presentedSheetStack.lastOrNull()
|
|
21
|
-
?.takeIf {
|
|
23
|
+
?.takeIf {
|
|
24
|
+
it.viewController.isPresented &&
|
|
25
|
+
it.viewController.isSheetVisible &&
|
|
26
|
+
it.rootContainerView == rootContainer
|
|
27
|
+
}
|
|
22
28
|
|
|
23
29
|
val childSheetTop = sheetView.viewController.detentCalculator.getSheetTopForDetentIndex(detentIndex)
|
|
24
30
|
parentSheet?.updateTranslationForChild(childSheetTop)
|
|
@@ -48,6 +54,7 @@ object TrueSheetStackManager {
|
|
|
48
54
|
/**
|
|
49
55
|
* Called when a presented sheet's size changes (e.g., after setupSheetDetents).
|
|
50
56
|
* Updates parent sheet translations to match the new sheet position.
|
|
57
|
+
* Only affects parent sheets in the same container.
|
|
51
58
|
*/
|
|
52
59
|
@JvmStatic
|
|
53
60
|
fun onSheetSizeChanged(sheetView: TrueSheetView) {
|
|
@@ -55,7 +62,9 @@ object TrueSheetStackManager {
|
|
|
55
62
|
val index = presentedSheetStack.indexOf(sheetView)
|
|
56
63
|
if (index <= 0) return
|
|
57
64
|
|
|
65
|
+
val rootContainer = sheetView.rootContainerView
|
|
58
66
|
val parentSheet = presentedSheetStack[index - 1]
|
|
67
|
+
.takeIf { it.rootContainerView == rootContainer } ?: return
|
|
59
68
|
|
|
60
69
|
// Post to ensure layout is complete before reading position
|
|
61
70
|
sheetView.viewController.post {
|
|
@@ -71,15 +80,18 @@ object TrueSheetStackManager {
|
|
|
71
80
|
}
|
|
72
81
|
|
|
73
82
|
/**
|
|
74
|
-
* Returns all sheets presented on top of the given sheet (children/descendants)
|
|
75
|
-
* Returns them in reverse order (top-most first) for proper dismissal.
|
|
83
|
+
* Returns all sheets presented on top of the given sheet (children/descendants)
|
|
84
|
+
* that are in the same container. Returns them in reverse order (top-most first) for proper dismissal.
|
|
76
85
|
*/
|
|
77
86
|
@JvmStatic
|
|
78
87
|
fun getSheetsAbove(sheetView: TrueSheetView): List<TrueSheetView> {
|
|
79
88
|
synchronized(presentedSheetStack) {
|
|
80
89
|
val index = presentedSheetStack.indexOf(sheetView)
|
|
81
90
|
if (index < 0 || index >= presentedSheetStack.size - 1) return emptyList()
|
|
82
|
-
|
|
91
|
+
val rootContainer = sheetView.rootContainerView
|
|
92
|
+
return presentedSheetStack.subList(index + 1, presentedSheetStack.size)
|
|
93
|
+
.filter { it.rootContainerView == rootContainer }
|
|
94
|
+
.reversed()
|
|
83
95
|
}
|
|
84
96
|
}
|
|
85
97
|
|
|
@@ -99,23 +111,26 @@ object TrueSheetStackManager {
|
|
|
99
111
|
|
|
100
112
|
/**
|
|
101
113
|
* Gets the parent sheet of the given sheet, if any.
|
|
114
|
+
* Only returns a parent if it's in the same container.
|
|
102
115
|
*/
|
|
103
116
|
@JvmStatic
|
|
104
117
|
fun getParentSheet(sheetView: TrueSheetView): TrueSheetView? {
|
|
105
118
|
synchronized(presentedSheetStack) {
|
|
106
119
|
val index = presentedSheetStack.indexOf(sheetView)
|
|
107
120
|
if (index <= 0) return null
|
|
108
|
-
|
|
121
|
+
val rootContainer = sheetView.rootContainerView
|
|
122
|
+
return presentedSheetStack[index - 1].takeIf { it.rootContainerView == rootContainer }
|
|
109
123
|
}
|
|
110
124
|
}
|
|
111
125
|
|
|
112
126
|
/**
|
|
113
|
-
* Returns true if the given sheet is the topmost presented sheet.
|
|
127
|
+
* Returns true if the given sheet is the topmost presented sheet in its container.
|
|
114
128
|
*/
|
|
115
129
|
@JvmStatic
|
|
116
130
|
fun isTopmostSheet(sheetView: TrueSheetView): Boolean {
|
|
117
131
|
synchronized(presentedSheetStack) {
|
|
118
|
-
|
|
132
|
+
val rootContainer = sheetView.rootContainerView
|
|
133
|
+
return presentedSheetStack.lastOrNull { it.rootContainerView == rootContainer } == sheetView
|
|
119
134
|
}
|
|
120
135
|
}
|
|
121
136
|
}
|
|
@@ -22,6 +22,12 @@ class JSI_EXPORT TrueSheetViewShadowNode final
|
|
|
22
22
|
using ConcreteViewShadowNode::ConcreteViewShadowNode;
|
|
23
23
|
|
|
24
24
|
public:
|
|
25
|
+
static ShadowNodeTraits BaseTraits() {
|
|
26
|
+
auto traits = ConcreteViewShadowNode::BaseTraits();
|
|
27
|
+
traits.set(ShadowNodeTraits::Trait::RootNodeKind);
|
|
28
|
+
return traits;
|
|
29
|
+
}
|
|
30
|
+
|
|
25
31
|
void adjustLayoutWithState();
|
|
26
32
|
};
|
|
27
33
|
|
package/package.json
CHANGED