Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Android): Fix calculating header height when changing status/action bar visibility #1922

Merged
merged 2 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions android/src/main/java/com/swmansion/rnscreens/Screen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -246,21 +246,21 @@ 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 { resolvedActionBarSize }
?.let { PixelUtil.toDIPFromPixel(it.toFloat()).toDouble() } ?: 56.0
.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 { it > 0 && 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import com.swmansion.rnscreens.events.HeaderDetachedEvent
class ScreenStackHeaderConfig(context: Context) : ViewGroup(context) {
private val mConfigSubviews = ArrayList<ScreenStackHeaderSubview>(3)
val toolbar: CustomToolbar
var mIsHidden = false
private var headerTopInset: Int? = null
private var mTitle: String? = null
private var mTitleColor = 0
Expand All @@ -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
Expand Down
Loading