From 95d89ff5fd6c7123b3c3a29015b56663f165b1bd Mon Sep 17 00:00:00 2001 From: tboba Date: Tue, 17 Oct 2023 18:00:40 +0200 Subject: [PATCH 1/2] Fix calculating dynamic header height on changing status bar / action bar visibility --- android/src/main/java/com/swmansion/rnscreens/Screen.kt | 6 ++++-- .../java/com/swmansion/rnscreens/ScreenStackHeaderConfig.kt | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/android/src/main/java/com/swmansion/rnscreens/Screen.kt b/android/src/main/java/com/swmansion/rnscreens/Screen.kt index 1bc265d1a6..658d6b4186 100644 --- a/android/src/main/java/com/swmansion/rnscreens/Screen.kt +++ b/android/src/main/java/com/swmansion/rnscreens/Screen.kt @@ -253,14 +253,16 @@ class Screen constructor(context: ReactContext?) : FabricEnabledViewGroup(contex // 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 { headerConfig?.mIsHidden != true } .takeIf { resolvedActionBarSize } - ?.let { PixelUtil.toDIPFromPixel(it.toFloat()).toDouble() } ?: 56.0 + ?.let { PixelUtil.toDIPFromPixel(it.toFloat()).toDouble() } ?: 0.0 val statusBarHeight = context.resources.getIdentifier("status_bar_height", "dimen", "android") .takeIf { it > 0 } + .takeIf { isStatusBarHidden != true } ?.let { (context.resources::getDimensionPixelSize)(it) } ?.let { PixelUtil.toDIPFromPixel(it.toFloat()).toDouble() } - ?: 24.0 + ?: 0.0 val totalHeight = actionBarHeight + statusBarHeight UIManagerHelper.getEventDispatcherForReactTag(context as ReactContext, id) diff --git a/android/src/main/java/com/swmansion/rnscreens/ScreenStackHeaderConfig.kt b/android/src/main/java/com/swmansion/rnscreens/ScreenStackHeaderConfig.kt index ed1fd58196..c0c9726e8d 100644 --- a/android/src/main/java/com/swmansion/rnscreens/ScreenStackHeaderConfig.kt +++ b/android/src/main/java/com/swmansion/rnscreens/ScreenStackHeaderConfig.kt @@ -24,6 +24,7 @@ import com.swmansion.rnscreens.events.HeaderDetachedEvent class ScreenStackHeaderConfig(context: Context) : ViewGroup(context) { private val mConfigSubviews = ArrayList(3) val toolbar: CustomToolbar + var mIsHidden = false private var headerTopInset: Int? = null private var mTitle: String? = null private var mTitleColor = 0 @@ -32,7 +33,6 @@ class ScreenStackHeaderConfig(context: Context) : ViewGroup(context) { private var mTitleFontSize = 0f private var mTitleFontWeight = 0 private var mBackgroundColor: Int? = null - private var mIsHidden = false private var mIsBackButtonHidden = false private var mIsShadowHidden = false private var mDestroyed = false From 496d56b2d8baf30f4537c4e4f555b3df47edfc40 Mon Sep 17 00:00:00 2001 From: tboba Date: Tue, 17 Oct 2023 18:12:08 +0200 Subject: [PATCH 2/2] Merge takeIfs, make fun private --- android/src/main/java/com/swmansion/rnscreens/Screen.kt | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/android/src/main/java/com/swmansion/rnscreens/Screen.kt b/android/src/main/java/com/swmansion/rnscreens/Screen.kt index 658d6b4186..b9acc11e90 100644 --- a/android/src/main/java/com/swmansion/rnscreens/Screen.kt +++ b/android/src/main/java/com/swmansion/rnscreens/Screen.kt @@ -246,20 +246,18 @@ class Screen constructor(context: ReactContext?) : FabricEnabledViewGroup(contex mNativeBackButtonDismissalEnabled = enableNativeBackButtonDismissal } - fun calculateHeaderHeight() { + private fun calculateHeaderHeight() { val actionBarTv = TypedValue() val resolvedActionBarSize = context.theme.resolveAttribute(android.R.attr.actionBarSize, actionBarTv, true) // 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 { headerConfig?.mIsHidden != true } - .takeIf { resolvedActionBarSize } + .takeIf { resolvedActionBarSize && headerConfig?.mIsHidden != true } ?.let { PixelUtil.toDIPFromPixel(it.toFloat()).toDouble() } ?: 0.0 val statusBarHeight = context.resources.getIdentifier("status_bar_height", "dimen", "android") - .takeIf { it > 0 } - .takeIf { isStatusBarHidden != true } + .takeIf { it > 0 && isStatusBarHidden != true } ?.let { (context.resources::getDimensionPixelSize)(it) } ?.let { PixelUtil.toDIPFromPixel(it.toFloat()).toDouble() } ?: 0.0