Skip to content

Commit c912f83

Browse files
committed
Move animations to reanimated
These work on web
1 parent 32b71df commit c912f83

File tree

6 files changed

+85
-53
lines changed

6 files changed

+85
-53
lines changed

.editorconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
dotnet_diagnostic.CA1860.severity = none
33

44

5-
[*.{ts,tsx}]
5+
[*.{ts,tsx,js,jsx}]
66
indent_style = space
77
indent_size = 2

liftlog-react/bable.config.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
presets: [],
3+
plugins: [
4+
'@babel/plugin-proposal-export-namespace-from',
5+
'react-native-reanimated/plugin',
6+
],
7+
};

liftlog-react/components/presentation/potential-set-counter.tsx

+37-45
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
import { PotentialSet } from '@/models/session-models';
22
import BigNumber from 'bignumber.js';
33
import { useEffect, useState } from 'react';
4-
import { TouchableRipple, useTheme } from 'react-native-paper';
5-
import {
6-
Animated,
7-
Easing,
8-
Text,
9-
Touchable,
10-
useAnimatedValue,
11-
View,
12-
} from 'react-native';
4+
import { TouchableRipple } from 'react-native-paper';
5+
import { Text, Touchable } from 'react-native';
136
import WeightFormat from '@/components/presentation/weight-format';
147
import WeightDialog from '@/components/presentation/weight-dialog';
158
import { useAppTheme } from '@/hooks/useAppTheme';
169
import { PressableProps } from 'react-native-paper/lib/typescript/components/TouchableRipple/Pressable';
10+
import Animated, { useSharedValue, withTiming } from 'react-native-reanimated';
1711

1812
interface PotentialSetCounterProps {
1913
set: PotentialSet;
@@ -30,33 +24,40 @@ interface PotentialSetCounterProps {
3024

3125
export default function PotentialSetCounter(props: PotentialSetCounterProps) {
3226
const { colors, spacing } = useAppTheme();
33-
const holdingScale = useAnimatedValue(1);
34-
const weightScale = useAnimatedValue(props.showWeight ? 1 : 0);
27+
const holdingScale = useSharedValue(1);
28+
const weightHeight = useSharedValue(0);
29+
const weightWidth = useSharedValue(0);
30+
const weightPadding = useSharedValue(0);
31+
const bottomBorderRadius = useSharedValue(10);
3532
const [isHolding, setIsHolding] = useState(false);
3633
const [isWeightDialogOpen, setIsWeightDialogOpen] = useState(false);
3734
const repCountValue = props.set?.set?.repsCompleted;
38-
const bottomRadiusValue = weightScale.interpolate({
39-
inputRange: [0, 1],
40-
outputRange: [10, 0],
41-
});
4235

4336
useEffect(() => {
44-
Animated.timing(holdingScale, {
45-
toValue: isHolding ? 1.1 : 1,
46-
duration: 200,
47-
easing: Easing.cubic,
48-
useNativeDriver: true,
49-
}).start();
50-
}, [isHolding, holdingScale]);
37+
bottomBorderRadius.value = withTiming(props.showWeight ? 0 : 10, {
38+
duration: 150,
39+
});
40+
weightHeight.value = withTiming(props.showWeight ? spacing[9] : 0, {
41+
duration: 150,
42+
});
43+
weightWidth.value = withTiming(props.showWeight ? spacing[14] : 0, {
44+
duration: 150,
45+
});
46+
weightPadding.value = withTiming(props.showWeight ? spacing[2] : 0, {
47+
duration: 150,
48+
});
49+
}, [
50+
props.showWeight,
51+
bottomBorderRadius,
52+
weightHeight,
53+
weightWidth,
54+
weightPadding,
55+
spacing,
56+
]);
5157

5258
useEffect(() => {
53-
Animated.timing(weightScale, {
54-
toValue: props.showWeight ? 1 : 0,
55-
duration: 150,
56-
easing: Easing.cubic,
57-
useNativeDriver: false,
58-
}).start();
59-
}, [props.showWeight, weightScale]);
59+
holdingScale.value = withTiming(isHolding ? 1.1 : 1, { duration: 400 });
60+
}, [isHolding, holdingScale]);
6061

6162
const callbacks = props.isReadonly
6263
? {}
@@ -85,10 +86,10 @@ export default function PotentialSetCounter(props: PotentialSetCounterProps) {
8586
>
8687
<Animated.View
8788
style={{
89+
borderBottomLeftRadius: bottomBorderRadius,
90+
borderBottomRightRadius: bottomBorderRadius,
8891
borderTopLeftRadius: 10,
8992
borderTopRightRadius: 10,
90-
borderBottomRightRadius: bottomRadiusValue,
91-
borderBottomLeftRadius: bottomRadiusValue,
9293
overflow: 'hidden',
9394
}}
9495
>
@@ -126,19 +127,10 @@ export default function PotentialSetCounter(props: PotentialSetCounterProps) {
126127
</Animated.View>
127128
<Animated.View
128129
style={{
129-
height: weightScale.interpolate({
130-
inputRange: [0, 1],
131-
outputRange: [0, spacing[9]],
132-
}),
133-
paddingBlock: weightScale.interpolate({
134-
inputRange: [0, 1],
135-
outputRange: [0, spacing[2]],
136-
}),
137-
width: weightScale.interpolate({
138-
inputRange: [0, 1],
139-
outputRange: [0, spacing[14]],
140-
}),
141-
borderTopWidth: weightScale,
130+
height: weightHeight,
131+
width: weightWidth,
132+
padding: weightPadding,
133+
borderTopWidth: 1,
142134
borderColor: colors.outline,
143135
backgroundColor: colors.surfaceContainerHigh,
144136
borderBottomLeftRadius: 10,
@@ -149,7 +141,7 @@ export default function PotentialSetCounter(props: PotentialSetCounterProps) {
149141
<TouchableRipple
150142
style={{
151143
alignItems: 'center',
152-
marginBlock: -spacing[2],
144+
margin: -spacing[2],
153145
padding: spacing[2],
154146
}}
155147
onPress={

liftlog-react/metro.config.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
const { getDefaultConfig } = require("expo/metro-config");
1+
const { getDefaultConfig } = require('expo/metro-config');
2+
const {
3+
wrapWithReanimatedMetroConfig,
4+
} = require('react-native-reanimated/metro-config');
25

36
const config = getDefaultConfig(__dirname);
47

5-
module.exports = config
8+
module.exports = wrapWithReanimatedMetroConfig(config);

liftlog-react/package-lock.json

+32-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

liftlog-react/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"lint": "eslint ."
1111
},
1212
"dependencies": {
13+
"@babel/plugin-proposal-export-namespace-from": "^7.18.9",
1314
"@js-joda/core": "^5.6.4",
1415
"@pchmn/expo-material3-theme": "^1.3.2",
1516
"@tolgee/react": "^6.2.2",
@@ -27,9 +28,10 @@
2728
"react-dom": "18.3.1",
2829
"react-native": "0.76.7",
2930
"react-native-paper": "^5.13.1",
31+
"react-native-reanimated": "~3.16.1",
3032
"react-native-safe-area-context": "^5.3.0",
3133
"react-native-screens": "~4.4.0",
32-
"react-native-web": "~0.19.6"
34+
"react-native-web": "~0.19.13"
3335
},
3436
"devDependencies": {
3537
"@babel/core": "^7.20.0",

0 commit comments

Comments
 (0)