@onekeyfe/react-native-device-utils 6.7.0-33 → 6.7.0-35
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/margelo/nitro/reactnativedeviceutils/ReactNativeDeviceUtils.kt
CHANGED
|
@@ -25,6 +25,7 @@ import androidx.window.layout.WindowLayoutInfo
|
|
|
25
25
|
import androidx.window.java.layout.WindowInfoTrackerCallbackAdapter
|
|
26
26
|
import androidx.appcompat.app.AppCompatDelegate
|
|
27
27
|
import com.facebook.proguard.annotations.DoNotStrip
|
|
28
|
+
import com.facebook.react.ReactRootView
|
|
28
29
|
import com.facebook.react.bridge.LifecycleEventListener
|
|
29
30
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
30
31
|
import com.margelo.nitro.NitroModules
|
|
@@ -965,9 +966,9 @@ class ReactNativeDeviceUtils : HybridReactNativeDeviceUtilsSpec(), LifecycleEven
|
|
|
965
966
|
// the platform bar transparent and draw the requested color only
|
|
966
967
|
// behind three-button navigation.
|
|
967
968
|
window.navigationBarColor = Color.TRANSPARENT
|
|
968
|
-
installNavigationBarProtection(
|
|
969
|
+
installNavigationBarProtection(activity, appearance.color)
|
|
969
970
|
} else {
|
|
970
|
-
removeNavigationBarProtection(
|
|
971
|
+
removeNavigationBarProtection(activity)
|
|
971
972
|
window.navigationBarColor = appearance.color
|
|
972
973
|
}
|
|
973
974
|
} catch (e: Exception) {
|
|
@@ -979,27 +980,40 @@ class ReactNativeDeviceUtils : HybridReactNativeDeviceUtilsSpec(), LifecycleEven
|
|
|
979
980
|
}
|
|
980
981
|
}
|
|
981
982
|
|
|
982
|
-
private fun installNavigationBarProtection(
|
|
983
|
-
val
|
|
984
|
-
val
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
983
|
+
private fun installNavigationBarProtection(activity: Activity, color: Int) {
|
|
984
|
+
val decorView = activity.window?.decorView as? ViewGroup ?: return
|
|
985
|
+
val contentView = activity.findViewById<ViewGroup>(android.R.id.content)
|
|
986
|
+
val reactRootIndex = contentView?.let(::findReactRootIndex)
|
|
987
|
+
// Overlay hosts are content-view children added after the React root, and a
|
|
988
|
+
// dimmed overlay must cover this bar together with the rest of the screen,
|
|
989
|
+
// so the protection belongs directly above the React root and below them.
|
|
990
|
+
// While the React root does not exist yet, fall back to the decor view; the
|
|
991
|
+
// next call moves it into place.
|
|
992
|
+
val container =
|
|
993
|
+
if (contentView != null && reactRootIndex != null) contentView else decorView
|
|
994
|
+
val targetIndex =
|
|
995
|
+
if (container === contentView && reactRootIndex != null) {
|
|
996
|
+
reactRootIndex + 1
|
|
997
|
+
} else {
|
|
998
|
+
container.childCount
|
|
999
|
+
}
|
|
1000
|
+
// A detached React root falls back to the decor view while an earlier
|
|
1001
|
+
// protection may still live in the content view. Reuse it (moving it to the
|
|
1002
|
+
// fallback container) and drop any duplicate, so one activity never ends up
|
|
1003
|
+
// with a second protection stacked above later overlays.
|
|
1004
|
+
val protectionView =
|
|
1005
|
+
findNavigationBarProtection(contentView ?: decorView)
|
|
1006
|
+
?: findNavigationBarProtection(decorView)
|
|
1007
|
+
?: View(container.context).also { view ->
|
|
1008
|
+
view.tag = NAVIGATION_BAR_PROTECTION_VIEW_TAG
|
|
1009
|
+
view.isClickable = false
|
|
1010
|
+
view.isFocusable = false
|
|
1011
|
+
view.importantForAccessibility = View.IMPORTANT_FOR_ACCESSIBILITY_NO
|
|
1012
|
+
}
|
|
1013
|
+
removeDuplicateNavigationBarProtections(contentView, decorView, protectionView)
|
|
1014
|
+
placeNavigationBarProtection(container, protectionView, targetIndex)
|
|
1000
1015
|
|
|
1001
1016
|
protectionView.visibility = View.VISIBLE
|
|
1002
|
-
protectionView.bringToFront()
|
|
1003
1017
|
ViewCompat.setOnApplyWindowInsetsListener(protectionView) { view, windowInsets ->
|
|
1004
1018
|
val navigationBarInsets = windowInsets.getInsets(
|
|
1005
1019
|
WindowInsetsCompat.Type.navigationBars()
|
|
@@ -1060,9 +1074,57 @@ class ReactNativeDeviceUtils : HybridReactNativeDeviceUtilsSpec(), LifecycleEven
|
|
|
1060
1074
|
ViewCompat.requestApplyInsets(protectionView)
|
|
1061
1075
|
}
|
|
1062
1076
|
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1077
|
+
/** Removes extra protection views left by an earlier fallback. */
|
|
1078
|
+
private fun removeDuplicateNavigationBarProtections(
|
|
1079
|
+
contentView: ViewGroup?,
|
|
1080
|
+
decorView: ViewGroup,
|
|
1081
|
+
keep: View,
|
|
1082
|
+
) {
|
|
1083
|
+
for (container in listOfNotNull(contentView, decorView)) {
|
|
1084
|
+
for (index in container.childCount - 1 downTo 0) {
|
|
1085
|
+
val child = container.getChildAt(index)
|
|
1086
|
+
if (child !== keep && child.tag == NAVIGATION_BAR_PROTECTION_VIEW_TAG) {
|
|
1087
|
+
ViewCompat.setOnApplyWindowInsetsListener(child, null)
|
|
1088
|
+
container.removeView(child)
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
/** Index of the React root child, or null before the root view exists. */
|
|
1095
|
+
private fun findReactRootIndex(container: ViewGroup): Int? {
|
|
1096
|
+
for (index in 0 until container.childCount) {
|
|
1097
|
+
if (container.getChildAt(index) is ReactRootView) {
|
|
1098
|
+
return index
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
return null
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
private fun placeNavigationBarProtection(
|
|
1105
|
+
container: ViewGroup,
|
|
1106
|
+
protectionView: View,
|
|
1107
|
+
index: Int,
|
|
1108
|
+
) {
|
|
1109
|
+
val parent = protectionView.parent as? ViewGroup
|
|
1110
|
+
if (parent === container && container.indexOfChild(protectionView) == index) {
|
|
1111
|
+
return
|
|
1112
|
+
}
|
|
1113
|
+
parent?.removeView(protectionView)
|
|
1114
|
+
container.addView(
|
|
1115
|
+
protectionView,
|
|
1116
|
+
index.coerceIn(0, container.childCount),
|
|
1117
|
+
FrameLayout.LayoutParams(
|
|
1118
|
+
ViewGroup.LayoutParams.MATCH_PARENT,
|
|
1119
|
+
0,
|
|
1120
|
+
Gravity.BOTTOM,
|
|
1121
|
+
),
|
|
1122
|
+
)
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
private fun findNavigationBarProtection(container: ViewGroup): View? {
|
|
1126
|
+
for (index in 0 until container.childCount) {
|
|
1127
|
+
val child = container.getChildAt(index)
|
|
1066
1128
|
if (child.tag == NAVIGATION_BAR_PROTECTION_VIEW_TAG) {
|
|
1067
1129
|
return child
|
|
1068
1130
|
}
|
|
@@ -1070,11 +1132,15 @@ class ReactNativeDeviceUtils : HybridReactNativeDeviceUtilsSpec(), LifecycleEven
|
|
|
1070
1132
|
return null
|
|
1071
1133
|
}
|
|
1072
1134
|
|
|
1073
|
-
private fun removeNavigationBarProtection(
|
|
1074
|
-
|
|
1075
|
-
val
|
|
1076
|
-
|
|
1077
|
-
|
|
1135
|
+
private fun removeNavigationBarProtection(activity: Activity?) {
|
|
1136
|
+
if (activity == null) return
|
|
1137
|
+
val decorView = activity.window?.decorView as? ViewGroup
|
|
1138
|
+
val contentView = activity.findViewById<ViewGroup>(android.R.id.content)
|
|
1139
|
+
for (container in listOfNotNull(contentView, decorView)) {
|
|
1140
|
+
val protectionView = findNavigationBarProtection(container) ?: continue
|
|
1141
|
+
ViewCompat.setOnApplyWindowInsetsListener(protectionView, null)
|
|
1142
|
+
container.removeView(protectionView)
|
|
1143
|
+
}
|
|
1078
1144
|
}
|
|
1079
1145
|
|
|
1080
1146
|
override fun onHostResume() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/react-native-device-utils",
|
|
3
|
-
"version": "6.7.0-
|
|
3
|
+
"version": "6.7.0-35",
|
|
4
4
|
"description": "Native device, launch, system appearance and boot recovery utilities for OneKey",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"types": "./lib/typescript/src/index.d.ts",
|