Skip to content

Commit

Permalink
fix(Android): add notifying for header height change, fix header heig…
Browse files Browse the repository at this point in the history
…ht values (software-mansion#2075)

## Description

This PR reverts the change from another PR software-mansion#2028 that removed notifying
about header height change event. Also, here I've also included changes
that are fixing incorrect values being returned from
`calculateHeaderHeight()` function, which causes to move the target of
the touchables 🚀

## Changes

- Fixed incorrect values, returned from `calculateHeaderHeight` method
- Reverted notifying about header height change

## Test code and steps to reproduce

You can check `Test556.tsx` and `Test1072.tsx` to check if touchables
are working correctly.

## Checklist

- [ ] Ensured that CI passes
  • Loading branch information
tboba authored and ja1ns committed Oct 9, 2024
1 parent 6822b4c commit 16288f7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
17 changes: 13 additions & 4 deletions android/src/main/java/com/swmansion/rnscreens/Screen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -236,18 +239,24 @@ 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

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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class ScreenStackHeaderConfig(context: Context) : ViewGroup(context) {
private val configSubviews = ArrayList<ScreenStackHeaderSubview>(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
Expand All @@ -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
Expand Down Expand Up @@ -195,7 +195,7 @@ class ScreenStackHeaderConfig(context: Context) : ViewGroup(context) {
screenFragment?.setToolbarShadowHidden(isShadowHidden)

// translucent
screenFragment?.setToolbarTranslucent(isTranslucent)
screenFragment?.setToolbarTranslucent(isHeaderTranslucent)

// title
actionBar.title = title
Expand Down Expand Up @@ -363,7 +363,7 @@ class ScreenStackHeaderConfig(context: Context) : ViewGroup(context) {
}

fun setTranslucent(translucent: Boolean) {
isTranslucent = translucent
isHeaderTranslucent = translucent
}

fun setBackButtonInCustomView(backButtonInCustomView: Boolean) {
Expand Down

0 comments on commit 16288f7

Please sign in to comment.