Skip to content

Conversation

@kligarski
Copy link
Contributor

@kligarski kligarski commented Mar 13, 2025

Description

React Native sets display: 'none' for frozen screens - this behavior can become an issue, if you for example press back button twice very fast on iOS - frozen screen might still be invisible. The problem and its workaround suggested by @grahammendick can be seen in issue #1207. The workaround was introduced in PR #1208.

Recently, React Native 0.78 has changed the way of diffing props and the workaround stopped working. The details and a new workaround has been suggested by @grahammendick once again in issue #2753 and PR grahammendick/navigation#860.

This PR introduces the suggested workaround.

A big thank you to @grahammendick for figuring it out and suggesting the solution once again, appreciate it!

Furthermore, the new workaround fixes a bug with back button on the screen stack header on iOS. The bug was probably introduced with the update to 0.78. The back button would disappear and then reappear after a short delay with generic "Back" label instead of the screen name.

before_2778.mp4
after_2778.mp4

Fixes #2753.

Changes

  • change display: false to display: null,
  • change ViewConfig interface to allow null value.

Tests

Run TestFreeze example, click Go to Details twice and then click the back button in the header. The button behaves as expected, which was not the case before - the button would disappear and then reappear with a generic "Back" title.

Checklist

  • Updated TS types
  • Ensured that CI passes

@grahammendick
Copy link
Contributor

Nice. You're welcome 👍

@kligarski kligarski marked this pull request as ready for review March 13, 2025 14:19
@kligarski kligarski requested a review from kkafar March 13, 2025 14:19
Copy link
Member

@kkafar kkafar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks!

@kligarski kligarski merged commit 5e2416a into main Mar 13, 2025
1 of 3 checks passed
@kligarski kligarski deleted the @kligarski/prevent-rn-from-hiding-frozen-screens branch March 13, 2025 15:05
kkafar added a commit that referenced this pull request Oct 22, 2025
## Description

~~No idea why the freeze worked up to 0.81, maybe there was something on
native side that prevented children from being unmounted and it is no
longer there. Our fix did not work, however. This commit fixes it.~~

~~Name of the filed has been changed here:~~

~~facebook/react-native@a36dbae48657965027e63c5bf90e4982af554581~~

@kligarski:

Starting from RN 0.82, our workaround that prevented unmounting frozen
views has stopped working - the bug is very similar to one described
[here](#2778).
The details of the workaround are available
[here](grahammendick/navigation#860).

Due to introduction of DOM APIs, `react-native` replaced
`ReactFabricHostComponent` with `ReactNativeElement`. This was hidden
behind a feature flag until [this
PR](facebook/react-native#53360) to RN 0.82. The
default value for `enableAccessToHostTreeInFabric` flag has been
switched to `true`.

In the workaround, we relied on internal value of `_viewConfig` which
has been renamed to `__viewConfig` in `ReactNativeElement`
implementation.

In this PR, we handle all names of this property.

| before | after |
| --- | --- |
| <video
src="https://github.com/user-attachments/assets/3cf7b785-a91a-4f13-beb3-b71aaabc17ca"
/> | <video
src="https://github.com/user-attachments/assets/a2bbdf01-d2a9-4808-9401-8ad12839a190"
/> |

Fixes
software-mansion/react-native-screens-labs#502.

## Changes

- add check for `__viewConfig` prop name in workaround

## Test code and steps to reproduce

Run `Test1726`. Go to screen 3 and go back via native back button.
Customization of back button on the second screen should be still
visible.

## Checklist

- [x] Included code example that can be used to test this change
- [ ] Ensured that CI passes
grahammendick added a commit to grahammendick/navigation that referenced this pull request Oct 24, 2025
Doing this again after React Native 0.82 has broken it again again. Found out [from react native screens](software-mansion/react-native-screens#3324) - they didn't me about it (even though I told [them about the last break](software-mansion/react-native-screens#2778).
Couldn't recreate the problem with tabs - with scenes swipe back recreates. Maybe it's there for completeness or if there's special tabs scenario that can't remember?!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prevent React Native hiding frozen screens

4 participants