react-native-unistyles 2.8.0-beta.3 → 2.8.0-beta.5
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.
@@ -10,13 +10,13 @@ import kotlin.math.max
|
|
10
10
|
|
11
11
|
class Platform(private val reactApplicationContext: ReactApplicationContext) {
|
12
12
|
private val displayMetrics: DisplayMetrics = reactApplicationContext.resources.displayMetrics
|
13
|
-
private val density: Float = reactApplicationContext.resources.displayMetrics.density
|
14
13
|
private var insetsCompat: InsetsCompat = InsetsCompat.getDefaults()
|
15
14
|
|
16
15
|
var defaultNavigationBarColor: Int? = null
|
17
16
|
var defaultStatusBarColor: Int? = null
|
18
17
|
|
19
18
|
fun getScreenDimensions(): Dimensions {
|
19
|
+
val density = reactApplicationContext.resources.displayMetrics.density
|
20
20
|
val screenWidth = (displayMetrics.widthPixels / density).toInt()
|
21
21
|
val screenHeight = (displayMetrics.heightPixels / density).toInt()
|
22
22
|
|
@@ -36,12 +36,14 @@ class Platform(private val reactApplicationContext: ReactApplicationContext) {
|
|
36
36
|
}
|
37
37
|
|
38
38
|
fun getStatusBarDimensions(): Dimensions {
|
39
|
+
val density = reactApplicationContext.resources.displayMetrics.density
|
39
40
|
val screenWidth = (displayMetrics.widthPixels / density).toInt()
|
40
41
|
|
41
42
|
return Dimensions(screenWidth, getStatusBarHeight())
|
42
43
|
}
|
43
44
|
|
44
45
|
fun getNavigationBarDimensions(): Dimensions {
|
46
|
+
val density = reactApplicationContext.resources.displayMetrics.density
|
45
47
|
val screenWidth = (displayMetrics.widthPixels / density).toInt()
|
46
48
|
|
47
49
|
return Dimensions(screenWidth, getNavigationBarHeight())
|
@@ -84,6 +86,7 @@ class Platform(private val reactApplicationContext: ReactApplicationContext) {
|
|
84
86
|
}
|
85
87
|
|
86
88
|
fun getInsets(): Insets {
|
89
|
+
val density = reactApplicationContext.resources.displayMetrics.density
|
87
90
|
val top = max(this.insetsCompat.cutout.top, this.insetsCompat.statusBar.top)
|
88
91
|
val bottom = this.insetsCompat.navigationBar.bottom
|
89
92
|
val left = this.insetsCompat.statusBar.left
|
@@ -98,10 +101,14 @@ class Platform(private val reactApplicationContext: ReactApplicationContext) {
|
|
98
101
|
}
|
99
102
|
|
100
103
|
private fun getStatusBarHeight(): Int {
|
104
|
+
val density = reactApplicationContext.resources.displayMetrics.density
|
105
|
+
|
101
106
|
return (this.insetsCompat.statusBar.top / density).toInt()
|
102
107
|
}
|
103
108
|
|
104
109
|
private fun getNavigationBarHeight(): Int {
|
110
|
+
val density = reactApplicationContext.resources.displayMetrics.density
|
111
|
+
|
105
112
|
return (this.insetsCompat.navigationBar.bottom / density).toInt()
|
106
113
|
}
|
107
114
|
}
|
@@ -164,7 +164,13 @@ class UnistylesModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
|
|
164
164
|
|
165
165
|
try {
|
166
166
|
activity.runOnUiThread {
|
167
|
-
|
167
|
+
val nextColor = when {
|
168
|
+
color == "" -> platform.defaultNavigationBarColor!!
|
169
|
+
color == "transparent" -> Color.TRANSPARENT
|
170
|
+
else -> Color.parseColor(color)
|
171
|
+
}
|
172
|
+
|
173
|
+
activity.window.navigationBarColor = nextColor
|
168
174
|
}
|
169
175
|
} catch (_: Exception) {
|
170
176
|
Log.d("Unistyles", "Failed to set navigation bar color: $color")
|