Skip to content

fix(Android,Fabric): prevent header subview disappearance when using setOptions #2812

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

Merged
merged 2 commits into from
Mar 27, 2025
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ class ScreenStackHeaderSubview(
) : FabricEnabledHeaderSubviewViewGroup(context) {
private var reactWidth = 0
private var reactHeight = 0

/**
* Semantics: true iff we **believe** that SurfaceMountingManager has measured this view during mount item
* execution. We recognize this case by checking measure mode in `onMeasure`. If Androidx
* happens to use `EXACTLY` for both dimensions this property might convey invalid information.
*/
private var isReactSizeSet = false

var type = Type.RIGHT

val config: ScreenStackHeaderConfig?
Expand All @@ -22,9 +30,10 @@ class ScreenStackHeaderSubview(
if (MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.EXACTLY &&
MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.EXACTLY
) {
// dimensions provided by react
// dimensions provided by react (with high probability)
reactWidth = MeasureSpec.getSize(widthMeasureSpec)
reactHeight = MeasureSpec.getSize(heightMeasureSpec)
isReactSizeSet = true
val parent = parent
if (parent != null) {
forceLayout()
Expand All @@ -44,7 +53,15 @@ class ScreenStackHeaderSubview(
if (changed && BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
val width = r - l
val height = b - t
updateSubviewFrameState(width, height, l, t)

// When setting subviews via `setOptions` from `useEffect` hook in a component, the first
// frame received might be computed by native layout & completely invalid (zero height).
// RN layout is the source of subview **size** (not origin) & we need to avoid sending
// this native size to ST. Doing otherwise might lead to problems.
// See: https://github.com/software-mansion/react-native-screens/pull/2812
if (isReactSizeSet) {
updateSubviewFrameState(width, height, l, t)
}
}
}

Expand Down
Loading