Skip to content

Commit

Permalink
fix: header config missing ref (#2434)
Browse files Browse the repository at this point in the history
## Description

This PR changes `ScreenStackHeaderConfig` into a
[forwardRef](@alduzy/reanimated-patch).

This is needed if you want to attach `ref` to it, which
**react-native-reanimated** needs to do
[here](https://github.com/software-mansion/react-native-reanimated/blob/1d417a5c711d60822d25bd8b823f1f5968214bde/apps/common-app/src/examples/ScreenStackHeaderConfigBackgroundColorExample.tsx#L24)
in order to migrate to v4, since the header config is now a function
component and cannot be used directly anymore.

Without this change the app crashes with `Cannot read property
'getScrollableNode' of null`.

Related PR:
software-mansion/react-native-reanimated#6622

<!--
## Changes

Please describe things you've changed here, make a **high level**
overview, if change is simple you can omit this section.

For example:

- Updated `about.md` docs

-->

<!--

## Screenshots / GIFs

Here you can add screenshots / GIFs documenting your change.

You can add before / after section if you're changing some behavior.

### Before

### After

-->
<!--
## Test code and steps to reproduce

Please include code that can be used to test this change and short
description how this example should work.
This snippet should be as minimal as possible and ready to be pasted
into editor (don't exclude exports or remove "not important" parts of
reproduction example)
-->

## Checklist

- [x] Ensured that CI passes
  • Loading branch information
alduzy authored Oct 23, 2024
1 parent df26107 commit b74e0eb
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/components/ScreenStackHeaderConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
ScreenStackHeaderConfigProps,
SearchBarProps,
} from '../types';
import { Image, ImageProps, StyleSheet, ViewProps } from 'react-native';
import { Image, ImageProps, StyleSheet, View, ViewProps } from 'react-native';

// Native components
import ScreenStackHeaderConfigNativeComponent from '../fabric/ScreenStackHeaderConfigNativeComponent';
Expand All @@ -16,17 +16,19 @@ export const ScreenStackHeaderSubview: React.ComponentType<
React.PropsWithChildren<ViewProps & { type?: HeaderSubviewTypes }>
> = ScreenStackHeaderSubviewNativeComponent as any;

Check warning on line 17 in src/components/ScreenStackHeaderConfig.tsx

View workflow job for this annotation

GitHub Actions / install-and-lint

Unexpected any. Specify a different type

export function ScreenStackHeaderConfig(
props: ScreenStackHeaderConfigProps,
): React.JSX.Element {
return (
<ScreenStackHeaderConfigNativeComponent
{...props}
style={styles.headerConfig}
pointerEvents="box-none"
/>
);
}
export const ScreenStackHeaderConfig = React.forwardRef<
View,
ScreenStackHeaderConfigProps
>((props, ref) => (
<ScreenStackHeaderConfigNativeComponent
{...props}
ref={ref}
style={styles.headerConfig}
pointerEvents="box-none"
/>
));

ScreenStackHeaderConfig.displayName = 'ScreenStackHeaderConfig';

export const ScreenStackHeaderBackButtonImage = (
props: ImageProps,
Expand Down

0 comments on commit b74e0eb

Please sign in to comment.