diff --git a/android/src/main/java/com/swmansion/rnscreens/Screen.kt b/android/src/main/java/com/swmansion/rnscreens/Screen.kt index 3495957a88..46cfad7767 100644 --- a/android/src/main/java/com/swmansion/rnscreens/Screen.kt +++ b/android/src/main/java/com/swmansion/rnscreens/Screen.kt @@ -65,12 +65,15 @@ class Screen(context: ReactContext?) : FabricEnabledViewGroup(context) { val width = r - l val height = b - t - val headerHeight = calculateHeaderHeight().first + val headerHeight = calculateHeaderHeight() + val totalHeight = headerHeight.first + headerHeight.second // action bar height + status bar height if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) { - updateScreenSizeFabric(width, height, headerHeight) + updateScreenSizeFabric(width, height, totalHeight) } else { updateScreenSizePaper(width, height) } + + notifyHeaderHeightChange(totalHeight) } } @@ -236,11 +239,12 @@ class Screen(context: ReactContext?) : FabricEnabledViewGroup(context) { // Check if it's possible to get an attribute from theme context and assign a value from it. // Otherwise, the default value will be returned. val actionBarHeight = TypedValue.complexToDimensionPixelSize(actionBarTv.data, resources.displayMetrics) - .takeIf { resolvedActionBarSize && headerConfig?.isHeaderHidden != true } + .takeIf { resolvedActionBarSize && headerConfig?.isHeaderHidden != true && headerConfig?.isHeaderTranslucent != true } ?.let { PixelUtil.toDIPFromPixel(it.toFloat()).toDouble() } ?: 0.0 val statusBarHeight = context.resources.getIdentifier("status_bar_height", "dimen", "android") - .takeIf { it > 0 && isStatusBarHidden != true } + // Count only status bar when action bar is visible and status bar is not hidden + .takeIf { it > 0 && isStatusBarHidden != true && actionBarHeight > 0 } ?.let { (context.resources::getDimensionPixelSize)(it) } ?.let { PixelUtil.toDIPFromPixel(it.toFloat()).toDouble() } ?: 0.0 @@ -248,6 +252,11 @@ class Screen(context: ReactContext?) : FabricEnabledViewGroup(context) { return actionBarHeight to statusBarHeight } + private fun notifyHeaderHeightChange(headerHeight: Double) { + UIManagerHelper.getEventDispatcherForReactTag(context as ReactContext, id) + ?.dispatchEvent(HeaderHeightChangeEvent(id, headerHeight)) + } + enum class StackPresentation { PUSH, MODAL, TRANSPARENT_MODAL } diff --git a/android/src/main/java/com/swmansion/rnscreens/ScreenStackHeaderConfig.kt b/android/src/main/java/com/swmansion/rnscreens/ScreenStackHeaderConfig.kt index 458cd9ba3f..7358e22938 100644 --- a/android/src/main/java/com/swmansion/rnscreens/ScreenStackHeaderConfig.kt +++ b/android/src/main/java/com/swmansion/rnscreens/ScreenStackHeaderConfig.kt @@ -25,6 +25,7 @@ class ScreenStackHeaderConfig(context: Context) : ViewGroup(context) { private val configSubviews = ArrayList(3) val toolbar: CustomToolbar var isHeaderHidden = false // named this way to avoid conflict with platform's isHidden + var isHeaderTranslucent = false // named this way to avoid conflict with platform's isTranslucent private var headerTopInset: Int? = null private var title: String? = null private var titleColor = 0 @@ -38,7 +39,6 @@ class ScreenStackHeaderConfig(context: Context) : ViewGroup(context) { private var isDestroyed = false private var backButtonInCustomView = false private var isTopInsetEnabled = true - private var isTranslucent = false private var tintColor = 0 private var isAttachedToWindow = false private val defaultStartInset: Int @@ -195,7 +195,7 @@ class ScreenStackHeaderConfig(context: Context) : ViewGroup(context) { screenFragment?.setToolbarShadowHidden(isShadowHidden) // translucent - screenFragment?.setToolbarTranslucent(isTranslucent) + screenFragment?.setToolbarTranslucent(isHeaderTranslucent) // title actionBar.title = title @@ -363,7 +363,7 @@ class ScreenStackHeaderConfig(context: Context) : ViewGroup(context) { } fun setTranslucent(translucent: Boolean) { - isTranslucent = translucent + isHeaderTranslucent = translucent } fun setBackButtonInCustomView(backButtonInCustomView: Boolean) {