Skip to content

Commit 66d3df8

Browse files
authored
chore(example): remove reanimated to fix a perf issue (#171)
* chore(example): get rid of reanimated because of a perf bug * chore(example): remove reanimated dependency
1 parent 3c53f44 commit 66d3df8

File tree

5 files changed

+32
-371
lines changed

5 files changed

+32
-371
lines changed

packages/example/babel.jest.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,5 @@ module.exports = {
2222
},
2323
],
2424
['@babel/plugin-proposal-class-properties', { loose: false }],
25-
'react-native-reanimated/plugin',
2625
],
2726
};

packages/example/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
"react": "18.2.0",
3131
"react-native": "npm:react-native-tvos@0.74.1-0",
3232
"react-native-keyevent": "^0.3.2",
33-
"react-native-reanimated": "~3.10.1",
3433
"react-native-safe-area-context": "4.10.1",
3534
"react-native-screens": "3.31.1",
3635
"react-native-svg": "15.2.0",

packages/example/src/modules/program/view/ProgramNode.tsx

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { ProgramInfo } from '../domain/programInfo';
44
import { Program } from './Program';
55
import { forwardRef } from 'react';
66
import { SpatialNavigationNodeRef } from '../../../../../lib/src/spatial-navigation/types/SpatialNavigationNodeRef';
7-
8-
import Animated, { useAnimatedStyle, useSharedValue, withTiming } from 'react-native-reanimated';
7+
import { useRotateAnimation } from './useRotateAnimation';
8+
import { Animated } from 'react-native';
99

1010
type Props = {
1111
programInfo: ProgramInfo;
@@ -17,17 +17,7 @@ type Props = {
1717

1818
export const ProgramNode = forwardRef<SpatialNavigationNodeRef, Props>(
1919
({ programInfo, onSelect, indexRange, label, variant }: Props, ref) => {
20-
const rotationZ = useSharedValue(0);
21-
22-
const rotate360 = () => {
23-
rotationZ.value = withTiming(rotationZ.value + 360);
24-
};
25-
26-
const animatedStyle = useAnimatedStyle(() => {
27-
return {
28-
transform: [{ rotateZ: `${rotationZ.value}deg` }],
29-
};
30-
});
20+
const { rotate360, animatedStyle } = useRotateAnimation();
3121

3222
return (
3323
<SpatialNavigationFocusableView
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { useRef } from 'react';
2+
import { Animated } from 'react-native';
3+
4+
export const useRotateAnimation = () => {
5+
const rotationZ = useRef(new Animated.Value(0)).current;
6+
7+
const rotate360 = () => {
8+
Animated.timing(rotationZ, {
9+
toValue: 360,
10+
duration: 1000, // Adjust duration as needed
11+
useNativeDriver: true,
12+
}).start(() => {
13+
rotationZ.setValue(0); // Reset to 0 after completing a full rotation
14+
});
15+
};
16+
17+
const animatedStyle = {
18+
transform: [
19+
{
20+
rotateZ: rotationZ.interpolate({
21+
inputRange: [0, 360],
22+
outputRange: ['0deg', '360deg'],
23+
}),
24+
},
25+
],
26+
};
27+
28+
return { rotate360, animatedStyle };
29+
};

0 commit comments

Comments
 (0)