1
1
import { PotentialSet } from '@/models/session-models' ;
2
2
import BigNumber from 'bignumber.js' ;
3
3
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' ;
13
6
import WeightFormat from '@/components/presentation/weight-format' ;
14
7
import WeightDialog from '@/components/presentation/weight-dialog' ;
15
8
import { useAppTheme } from '@/hooks/useAppTheme' ;
16
9
import { PressableProps } from 'react-native-paper/lib/typescript/components/TouchableRipple/Pressable' ;
10
+ import Animated , { useSharedValue , withTiming } from 'react-native-reanimated' ;
17
11
18
12
interface PotentialSetCounterProps {
19
13
set : PotentialSet ;
@@ -30,33 +24,40 @@ interface PotentialSetCounterProps {
30
24
31
25
export default function PotentialSetCounter ( props : PotentialSetCounterProps ) {
32
26
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 ) ;
35
32
const [ isHolding , setIsHolding ] = useState ( false ) ;
36
33
const [ isWeightDialogOpen , setIsWeightDialogOpen ] = useState ( false ) ;
37
34
const repCountValue = props . set ?. set ?. repsCompleted ;
38
- const bottomRadiusValue = weightScale . interpolate ( {
39
- inputRange : [ 0 , 1 ] ,
40
- outputRange : [ 10 , 0 ] ,
41
- } ) ;
42
35
43
36
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
+ ] ) ;
51
57
52
58
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 ] ) ;
60
61
61
62
const callbacks = props . isReadonly
62
63
? { }
@@ -85,10 +86,10 @@ export default function PotentialSetCounter(props: PotentialSetCounterProps) {
85
86
>
86
87
< Animated . View
87
88
style = { {
89
+ borderBottomLeftRadius : bottomBorderRadius ,
90
+ borderBottomRightRadius : bottomBorderRadius ,
88
91
borderTopLeftRadius : 10 ,
89
92
borderTopRightRadius : 10 ,
90
- borderBottomRightRadius : bottomRadiusValue ,
91
- borderBottomLeftRadius : bottomRadiusValue ,
92
93
overflow : 'hidden' ,
93
94
} }
94
95
>
@@ -126,19 +127,10 @@ export default function PotentialSetCounter(props: PotentialSetCounterProps) {
126
127
</ Animated . View >
127
128
< Animated . View
128
129
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 ,
142
134
borderColor : colors . outline ,
143
135
backgroundColor : colors . surfaceContainerHigh ,
144
136
borderBottomLeftRadius : 10 ,
@@ -149,7 +141,7 @@ export default function PotentialSetCounter(props: PotentialSetCounterProps) {
149
141
< TouchableRipple
150
142
style = { {
151
143
alignItems : 'center' ,
152
- marginBlock : - spacing [ 2 ] ,
144
+ margin : - spacing [ 2 ] ,
153
145
padding : spacing [ 2 ] ,
154
146
} }
155
147
onPress = {
0 commit comments