Skip to content
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
13 changes: 8 additions & 5 deletions android/src/main/java/com/swmansion/rnscreens/Screen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,6 @@ class Screen(
val height = b - t

dispatchShadowStateUpdate(width, height, t)

// FormSheet has no header in current model.
notifyHeaderHeightChange(t)
}
}

Expand Down Expand Up @@ -456,12 +453,18 @@ class Screen(
super.onTouchEvent(event)
}

private fun notifyHeaderHeightChange(headerHeight: Int) {
internal fun notifyHeaderHeightChange(headerHeight: Int) {
val screenContext = context as ReactContext
val surfaceId = UIManagerHelper.getSurfaceId(screenContext)
UIManagerHelper
.getEventDispatcherForReactTag(screenContext, id)
?.dispatchEvent(HeaderHeightChangeEvent(surfaceId, id, headerHeight))
?.dispatchEvent(
HeaderHeightChangeEvent(
surfaceId,
id,
PixelUtil.toDIPFromPixel(headerHeight.toFloat()).toDouble(),
),
)
}

internal fun onSheetDetentChanged(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ class ScreenStackHeaderConfig(
defaultStartInsetWithNavigation
}

val headerHeightUpdateProxy = ScreenStackHeaderHeightUpdateProxy()

fun destroy() {
isDestroyed = true
}
Expand Down Expand Up @@ -126,6 +128,8 @@ class ScreenStackHeaderConfig(

val contentInsetEnd = toolbar.currentContentInsetEnd + toolbar.paddingEnd

headerHeightUpdateProxy.updateHeaderHeightIfNeeded(this, screen)

// Note that implementation of the callee differs between architectures.
updateHeaderConfigState(
toolbar.width,
Expand Down Expand Up @@ -216,6 +220,7 @@ class ScreenStackHeaderConfig(
if (toolbar.parent != null) {
screenFragment?.removeToolbar()
}
headerHeightUpdateProxy.updateHeaderHeightIfNeeded(this, screen)
return
}

Expand Down Expand Up @@ -336,6 +341,8 @@ class ScreenStackHeaderConfig(
toolbar.addView(view)
i++
}

headerHeightUpdateProxy.updateHeaderHeightIfNeeded(this, screen)
}

private fun maybeUpdate() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.swmansion.rnscreens

class ScreenStackHeaderHeightUpdateProxy {
var previousHeaderHeightInPx: Int? = null

fun updateHeaderHeightIfNeeded(
config: ScreenStackHeaderConfig,
screen: Screen?,
) {
val currentHeaderHeightInPx = if (config.isHeaderHidden) 0 else config.toolbar.height

if (currentHeaderHeightInPx != previousHeaderHeightInPx) {
previousHeaderHeightInPx = currentHeaderHeightInPx
screen?.notifyHeaderHeightChange(currentHeaderHeightInPx)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ import com.facebook.react.uimanager.events.Event
class HeaderHeightChangeEvent(
surfaceId: Int,
viewId: Int,
private val headerHeight: Int,
private val headerHeightInDp: Double,
) : Event<HeaderHeightChangeEvent>(surfaceId, viewId) {
override fun getEventName() = EVENT_NAME

// As the same header height could appear twice, use header height as a coalescing key.
override fun getCoalescingKey(): Short = headerHeight.toShort()
override fun getCoalescingKey(): Short = headerHeightInDp.toInt().toShort()

override fun getEventData(): WritableMap? =
Arguments.createMap().apply {
putDouble("headerHeight", headerHeight.toDouble())
putDouble("headerHeight", headerHeightInDp)
}

companion object {
Expand Down
Loading
Loading