forked from software-mansion-labs/reanimated-3-playground
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Screen.js
44 lines (40 loc) · 894 Bytes
/
Screen.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import Animated, {
useSharedValue,
withTiming,
useAnimatedStyle,
Easing,
} from 'react-native-reanimated';
import {View, Button} from 'react-native';
import React from 'react';
export default function AnimatedStyleUpdateExample(props) {
const randomWidth = useSharedValue(10);
const config = {
duration: 500,
easing: Easing.bezier(0.5, 0.01, 0, 1),
};
const style = useAnimatedStyle(() => {
return {
width: withTiming(randomWidth.value, config),
};
});
return (
<View
style={{
flex: 1,
flexDirection: 'column',
}}>
<Animated.View
style={[
{width: 100, height: 80, backgroundColor: 'black', margin: 30},
style,
]}
/>
<Button
title="toggle"
onPress={() => {
randomWidth.value = Math.random() * 350;
}}
/>
</View>
);
}