@@ -13,18 +13,18 @@ import Animated, {
13
13
const avatar = require ( "../assets/avatar.png" ) ;
14
14
15
15
const MIN_SCALE = 1 ;
16
- const MAX_SCALE = 1.5 ;
16
+ const MAX_SCALE = 2 ;
17
17
18
18
/**
19
19
* This is an example component that uses the `volumechange` event to animate the volume metering of a user's voice.
20
20
*/
21
21
export function VolumeMeteringAvatar ( ) {
22
- const haloScale = useSharedValue ( MIN_SCALE ) ;
22
+ const volumeScale = useSharedValue ( MIN_SCALE ) ;
23
23
const pulseScale = useSharedValue ( MIN_SCALE ) ;
24
24
const pulseOpacity = useSharedValue ( 0 ) ;
25
25
26
26
const reset = ( ) => {
27
- haloScale . value = MIN_SCALE ;
27
+ volumeScale . value = MIN_SCALE ;
28
28
pulseScale . value = MIN_SCALE ;
29
29
pulseOpacity . value = 0 ;
30
30
} ;
@@ -45,16 +45,14 @@ export function VolumeMeteringAvatar() {
45
45
Extrapolation . CLAMP ,
46
46
) ;
47
47
48
- // Animate the halo scaling
49
- haloScale . value = withSequence (
48
+ // Animate the volume scaling
49
+ volumeScale . value = withSequence (
50
50
withSpring ( newScale , {
51
- damping : 15 ,
51
+ damping : 10 ,
52
52
stiffness : 150 ,
53
53
} ) ,
54
- withTiming ( MIN_SCALE , {
55
- duration : 500 ,
56
- easing : Easing . linear ,
57
- } ) ,
54
+ // Scale back down, unless the volume changes again
55
+ withTiming ( MIN_SCALE , { duration : 500 } ) ,
58
56
) ;
59
57
60
58
// Animate the pulse (scale and fade out)
@@ -69,22 +67,22 @@ export function VolumeMeteringAvatar() {
69
67
}
70
68
} ) ;
71
69
72
- const haloAnimatedStyle = useAnimatedStyle ( ( ) => ( {
73
- transform : [ { scale : haloScale . value } ] ,
70
+ const volumeScaleStyle = useAnimatedStyle ( ( ) => ( {
71
+ transform : [ { scale : volumeScale . value } ] ,
74
72
} ) ) ;
75
73
76
- const pulseAnimatedStyle = useAnimatedStyle ( ( ) => ( {
74
+ const pulseStyle = useAnimatedStyle ( ( ) => ( {
77
75
opacity : pulseOpacity . value ,
78
76
transform : [ { scale : pulseScale . value } ] ,
79
77
} ) ) ;
80
78
81
79
return (
82
80
< View style = { styles . container } >
83
- < View style = { styles . pulseContainer } >
84
- < Animated . View style = { [ styles . halo , haloAnimatedStyle ] } />
81
+ < View style = { styles . absoluteCenteredContainer } >
82
+ < Animated . View style = { [ styles . circularBorder , volumeScaleStyle ] } />
85
83
</ View >
86
- < View style = { styles . pulseContainer } >
87
- < Animated . View style = { [ styles . pulse , pulseAnimatedStyle ] } />
84
+ < View style = { styles . absoluteCenteredContainer } >
85
+ < Animated . View style = { [ styles . pulse , pulseStyle ] } />
88
86
</ View >
89
87
< View style = { [ styles . centered ] } >
90
88
< Image source = { avatar } style = { styles . avatar } />
@@ -98,7 +96,7 @@ const styles = StyleSheet.create({
98
96
position : "relative" ,
99
97
marginVertical : 20 ,
100
98
} ,
101
- pulseContainer : {
99
+ absoluteCenteredContainer : {
102
100
position : "absolute" ,
103
101
top : 0 ,
104
102
bottom : 0 ,
@@ -114,7 +112,7 @@ const styles = StyleSheet.create({
114
112
height : 96 ,
115
113
borderRadius : 96 ,
116
114
} ,
117
- halo : {
115
+ circularBorder : {
118
116
backgroundColor : "#6b7280" ,
119
117
width : 96 ,
120
118
height : 96 ,
0 commit comments