diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/utils/SystemUiUtils.kt b/lib/android/app/src/main/java/com/reactnativenavigation/utils/SystemUiUtils.kt index d1133e13386..89665d16b7a 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/utils/SystemUiUtils.kt +++ b/lib/android/app/src/main/java/com/reactnativenavigation/utils/SystemUiUtils.kt @@ -17,7 +17,7 @@ import kotlin.math.ceil object SystemUiUtils { private const val STATUS_BAR_HEIGHT_M = 24 private const val STATUS_BAR_HEIGHT_L = 25 - private const val STATUS_BAR_HEIGHT_TRANSLUCENCY = 0.65f + internal const val STATUS_BAR_HEIGHT_TRANSLUCENCY = 0.65f private var statusBarHeight = -1 var navigationBarDefaultColor = -1 private set @@ -124,7 +124,8 @@ object SystemUiUtils { val opaqueColor = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { Color.BLACK }else{ - val alpha = if (translucent) STATUS_BAR_HEIGHT_TRANSLUCENCY else 1f + val colorAlpha = Color.alpha(color) + val alpha = if (translucent && colorAlpha == 255) STATUS_BAR_HEIGHT_TRANSLUCENCY else colorAlpha/255.0f val red: Int = Color.red(color) val green: Int = Color.green(color) val blue: Int = Color.blue(color) diff --git a/lib/android/app/src/test/java/com/reactnativenavigation/utils/SystemUiUtilsTest.kt b/lib/android/app/src/test/java/com/reactnativenavigation/utils/SystemUiUtilsTest.kt new file mode 100644 index 00000000000..de710103622 --- /dev/null +++ b/lib/android/app/src/test/java/com/reactnativenavigation/utils/SystemUiUtilsTest.kt @@ -0,0 +1,27 @@ +package com.reactnativenavigation.utils + +import android.graphics.Color +import android.view.Window +import com.reactnativenavigation.BaseTest +import com.reactnativenavigation.utils.SystemUiUtils.STATUS_BAR_HEIGHT_TRANSLUCENCY +import org.junit.Test +import org.mockito.Mockito +import org.mockito.kotlin.verify +import kotlin.math.ceil + +class SystemUiUtilsTest : BaseTest() { + + @Test + fun `setStatusBarColor - should change color considering alpha`() { + val window = Mockito.mock(Window::class.java) + val alphaColor = Color.argb(44, 22, 255, 255) + val color = Color.argb(255, 22, 255, 255) + SystemUiUtils.setStatusBarColor(window, alphaColor, false) + + verify(window).statusBarColor = alphaColor + + SystemUiUtils.setStatusBarColor(window, color, true) + + verify(window).statusBarColor = Color.argb(ceil(STATUS_BAR_HEIGHT_TRANSLUCENCY*255).toInt(), 22, 255, 255) + } +} \ No newline at end of file diff --git a/playground/src/screens/SystemUiOptions.tsx b/playground/src/screens/SystemUiOptions.tsx index bd9a34acf90..9c217b89ad6 100644 --- a/playground/src/screens/SystemUiOptions.tsx +++ b/playground/src/screens/SystemUiOptions.tsx @@ -18,6 +18,7 @@ interface State { } const colors = [ '#000000', + '#00AAAF00', '#20303C', '#3182C8', '#00AAAF',