Skip to content

Commit b39a86c

Browse files
authored
fix(Android): add notifying for header height change, fix header height values (#2075)
## Description This PR reverts the change from another PR #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
1 parent 181fa8c commit b39a86c

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

android/src/main/java/com/swmansion/rnscreens/Screen.kt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,15 @@ class Screen(context: ReactContext?) : FabricEnabledViewGroup(context) {
6565
val width = r - l
6666
val height = b - t
6767

68-
val headerHeight = calculateHeaderHeight().first
68+
val headerHeight = calculateHeaderHeight()
69+
val totalHeight = headerHeight.first + headerHeight.second // action bar height + status bar height
6970
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
70-
updateScreenSizeFabric(width, height, headerHeight)
71+
updateScreenSizeFabric(width, height, totalHeight)
7172
} else {
7273
updateScreenSizePaper(width, height)
7374
}
75+
76+
notifyHeaderHeightChange(totalHeight)
7477
}
7578
}
7679

@@ -236,18 +239,24 @@ class Screen(context: ReactContext?) : FabricEnabledViewGroup(context) {
236239
// Check if it's possible to get an attribute from theme context and assign a value from it.
237240
// Otherwise, the default value will be returned.
238241
val actionBarHeight = TypedValue.complexToDimensionPixelSize(actionBarTv.data, resources.displayMetrics)
239-
.takeIf { resolvedActionBarSize && headerConfig?.isHeaderHidden != true }
242+
.takeIf { resolvedActionBarSize && headerConfig?.isHeaderHidden != true && headerConfig?.isHeaderTranslucent != true }
240243
?.let { PixelUtil.toDIPFromPixel(it.toFloat()).toDouble() } ?: 0.0
241244

242245
val statusBarHeight = context.resources.getIdentifier("status_bar_height", "dimen", "android")
243-
.takeIf { it > 0 && isStatusBarHidden != true }
246+
// Count only status bar when action bar is visible and status bar is not hidden
247+
.takeIf { it > 0 && isStatusBarHidden != true && actionBarHeight > 0 }
244248
?.let { (context.resources::getDimensionPixelSize)(it) }
245249
?.let { PixelUtil.toDIPFromPixel(it.toFloat()).toDouble() }
246250
?: 0.0
247251

248252
return actionBarHeight to statusBarHeight
249253
}
250254

255+
private fun notifyHeaderHeightChange(headerHeight: Double) {
256+
UIManagerHelper.getEventDispatcherForReactTag(context as ReactContext, id)
257+
?.dispatchEvent(HeaderHeightChangeEvent(id, headerHeight))
258+
}
259+
251260
enum class StackPresentation {
252261
PUSH, MODAL, TRANSPARENT_MODAL
253262
}

android/src/main/java/com/swmansion/rnscreens/ScreenStackHeaderConfig.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class ScreenStackHeaderConfig(context: Context) : ViewGroup(context) {
2525
private val configSubviews = ArrayList<ScreenStackHeaderSubview>(3)
2626
val toolbar: CustomToolbar
2727
var isHeaderHidden = false // named this way to avoid conflict with platform's isHidden
28+
var isHeaderTranslucent = false // named this way to avoid conflict with platform's isTranslucent
2829
private var headerTopInset: Int? = null
2930
private var title: String? = null
3031
private var titleColor = 0
@@ -38,7 +39,6 @@ class ScreenStackHeaderConfig(context: Context) : ViewGroup(context) {
3839
private var isDestroyed = false
3940
private var backButtonInCustomView = false
4041
private var isTopInsetEnabled = true
41-
private var isTranslucent = false
4242
private var tintColor = 0
4343
private var isAttachedToWindow = false
4444
private val defaultStartInset: Int
@@ -195,7 +195,7 @@ class ScreenStackHeaderConfig(context: Context) : ViewGroup(context) {
195195
screenFragment?.setToolbarShadowHidden(isShadowHidden)
196196

197197
// translucent
198-
screenFragment?.setToolbarTranslucent(isTranslucent)
198+
screenFragment?.setToolbarTranslucent(isHeaderTranslucent)
199199

200200
// title
201201
actionBar.title = title
@@ -363,7 +363,7 @@ class ScreenStackHeaderConfig(context: Context) : ViewGroup(context) {
363363
}
364364

365365
fun setTranslucent(translucent: Boolean) {
366-
isTranslucent = translucent
366+
isHeaderTranslucent = translucent
367367
}
368368

369369
fun setBackButtonInCustomView(backButtonInCustomView: Boolean) {

0 commit comments

Comments
 (0)