Skip to content

Commit dab5b21

Browse files
authored
fix: prevent freeze from unmounting native components (#3324)
## 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
1 parent 1443bd9 commit dab5b21

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/components/Screen.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ interface ViewConfig extends View {
5555
};
5656
};
5757
};
58+
__viewConfig: {
59+
validAttributes: {
60+
style: {
61+
display: boolean | null;
62+
};
63+
};
64+
};
5865
}
5966

6067
export const InnerScreen = React.forwardRef<View, ScreenProps>(
@@ -178,6 +185,11 @@ export const InnerScreen = React.forwardRef<View, ScreenProps>(
178185
...ref._viewConfig.validAttributes.style,
179186
display: null,
180187
};
188+
} else if (ref?.__viewConfig?.validAttributes?.style) {
189+
ref.__viewConfig.validAttributes.style = {
190+
...ref.__viewConfig.validAttributes.style,
191+
display: null,
192+
};
181193
}
182194
setRef(ref);
183195
};

0 commit comments

Comments
 (0)