Skip to content

Commit b52deae

Browse files
haswaltclaude
andauthored
fix: update components for react-native-reanimated 4 compatibility (#52)
- FadingView: pass useAnimatedProps result directly instead of spreading, which broke Reanimated 4's internal animated proxy tracking - ScrollView: use Animated.ScrollView from reanimated instead of createAnimatedComponent(ScrollView) for proper Reanimated 4 support - Header/LargeHeader: convert View to Animated.View to support animated styles passed by consumers, preventing the "animated style to non-animated component" error in Reanimated 4 https://claude.ai/code/session_01K8dw23CbhakgyCBmuwr5jP Co-authored-by: Claude <noreply@anthropic.com>
1 parent 20a9cee commit b52deae

File tree

4 files changed

+27
-22
lines changed

4 files changed

+27
-22
lines changed

src/components/containers/FadingView.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,14 @@ const FadingView = forwardRef<Animated.View, FadingViewProps>(
4545
children,
4646
style,
4747
opacity,
48-
animatedProps = {},
48+
// Remove animatedProps from rest to avoid passing stale/spread values
49+
animatedProps: _externalAnimatedProps,
4950
opacityThresholdToEnablePointerEvents = 1,
5051
...rest
5152
},
5253
ref
5354
) => {
54-
const _animatedProps = useAnimatedProps(() => {
55+
const animatedProps = useAnimatedProps(() => {
5556
const _pointerEvents: AnimatedViewPointerEvents =
5657
opacity.value >= opacityThresholdToEnablePointerEvents ? 'auto' : 'none';
5758
return { pointerEvents: _pointerEvents };
@@ -62,7 +63,7 @@ const FadingView = forwardRef<Animated.View, FadingViewProps>(
6263
<Animated.View
6364
ref={ref}
6465
style={[styles.container, style, fadeStyle]}
65-
animatedProps={{ ..._animatedProps, ...animatedProps }}
66+
animatedProps={animatedProps}
6667
{...rest}
6768
>
6869
{children}

src/components/containers/ScrollView.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import React, { useImperativeHandle } from 'react';
2-
import { View, StyleSheet, ScrollView } from 'react-native';
2+
import { View, StyleSheet } from 'react-native';
33
import { useSafeAreaInsets } from 'react-native-safe-area-context';
44
import Animated, { useAnimatedRef } from 'react-native-reanimated';
55

66
import FadingView from './FadingView';
77
import { useScrollContainerLogic } from './useScrollContainerLogic';
88
import type { SharedScrollContainerProps } from './types';
99

10-
const AnimatedScrollView = Animated.createAnimatedComponent(ScrollView);
11-
12-
type AnimatedScrollViewProps = React.ComponentProps<typeof AnimatedScrollView> & {
10+
type AnimatedScrollViewProps = React.ComponentProps<typeof Animated.ScrollView> & {
1311
children?: React.ReactNode;
1412
};
1513

@@ -91,7 +89,7 @@ const ScrollViewWithHeadersInputComp = (
9189
]}
9290
>
9391
{!absoluteHeader && HeaderComponent({ showNavBar, scrollY })}
94-
<AnimatedScrollView
92+
<Animated.ScrollView
9593
ref={scrollRef}
9694
scrollEventThrottle={16}
9795
overScrollMode="auto"
@@ -152,7 +150,7 @@ const ScrollViewWithHeadersInputComp = (
152150
{LargeHeaderSubtitleComponent && LargeHeaderSubtitleComponent({ showNavBar, scrollY })}
153151

154152
{children}
155-
</AnimatedScrollView>
153+
</Animated.ScrollView>
156154

157155
{absoluteHeader && (
158156
<View style={styles.absoluteHeader} onLayout={onAbsoluteHeaderLayout}>

src/components/headers/Header.tsx

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { useMemo } from 'react';
22
import { useWindowDimensions } from 'react-native';
3-
import { StyleSheet, View } from 'react-native';
3+
import { StyleSheet } from 'react-native';
4+
import Animated from 'react-native-reanimated';
45
import { useSafeAreaInsets } from 'react-native-safe-area-context';
56
import { FadingView } from '../containers';
67
import { HeaderBottomBorder } from '../line';
@@ -41,10 +42,12 @@ const Header: React.FC<HeaderProps> = ({
4142
const noHeaderLeftRight = !headerLeft && !headerRight;
4243

4344
return (
44-
<View>
45+
<Animated.View>
4546
{SurfaceComponent && SurfaceComponent({ showNavBar })}
4647

47-
<View style={[styles.container, !ignoreTopSafeArea && { paddingTop: top }, headerStyle]}>
48+
<Animated.View
49+
style={[styles.container, !ignoreTopSafeArea && { paddingTop: top }, headerStyle]}
50+
>
4851
{headerLeftFadesIn ? (
4952
<FadingView
5053
opacity={showNavBar}
@@ -58,7 +61,7 @@ const Header: React.FC<HeaderProps> = ({
5861
{headerLeft}
5962
</FadingView>
6063
) : (
61-
<View
64+
<Animated.View
6265
style={[
6366
styles.leftContainer,
6467
noHeaderLeftRight && styles.noFlex,
@@ -67,7 +70,7 @@ const Header: React.FC<HeaderProps> = ({
6770
]}
6871
>
6972
{headerLeft}
70-
</View>
73+
</Animated.View>
7174
)}
7275

7376
{headerCenter &&
@@ -79,9 +82,11 @@ const Header: React.FC<HeaderProps> = ({
7982
{headerCenter}
8083
</FadingView>
8184
) : (
82-
<View style={[styles.centerContainer, { width: centerWidth }, headerCenterStyle]}>
85+
<Animated.View
86+
style={[styles.centerContainer, { width: centerWidth }, headerCenterStyle]}
87+
>
8388
{headerCenter}
84-
</View>
89+
</Animated.View>
8590
))}
8691

8792
{headerRightFadesIn ? (
@@ -97,7 +102,7 @@ const Header: React.FC<HeaderProps> = ({
97102
{headerRight}
98103
</FadingView>
99104
) : (
100-
<View
105+
<Animated.View
101106
style={[
102107
styles.rightContainer,
103108
noHeaderLeftRight && styles.noFlex,
@@ -106,9 +111,9 @@ const Header: React.FC<HeaderProps> = ({
106111
]}
107112
>
108113
{headerRight}
109-
</View>
114+
</Animated.View>
110115
)}
111-
</View>
116+
</Animated.View>
112117

113118
{!noBottomBorder && (
114119
<HeaderBottomBorder
@@ -118,7 +123,7 @@ const Header: React.FC<HeaderProps> = ({
118123
borderWidth={borderWidth}
119124
/>
120125
)}
121-
</View>
126+
</Animated.View>
122127
);
123128
};
124129

src/components/headers/LargeHeader.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
2-
import { StyleSheet, View } from 'react-native';
2+
import { StyleSheet } from 'react-native';
3+
import Animated from 'react-native-reanimated';
34
import type { LargeHeaderProps } from './types';
45

56
const LH_VERTICAL_PADDING = 6;
@@ -13,7 +14,7 @@ const LH_HORIZONTAL_PADDING = 12;
1314
const LargeHeader: React.FC<React.PropsWithChildren<LargeHeaderProps>> = ({
1415
headerStyle,
1516
children,
16-
}) => <View style={[styles.headerContainer, headerStyle]}>{children}</View>;
17+
}) => <Animated.View style={[styles.headerContainer, headerStyle]}>{children}</Animated.View>;
1718

1819
export default LargeHeader;
1920

0 commit comments

Comments
 (0)