Skip to content

Commit 4325c0c

Browse files
committed
添加动画
1 parent 3f4be36 commit 4325c0c

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

app/page/Discover.js

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { View, Text, StyleSheet, Button, TouchableOpacity} from 'react-native';
2+
import { View, Text, StyleSheet, Button, TouchableOpacity, Animated, Easing} from 'react-native';
33
import Icon from "react-native-vector-icons/Ionicons";
44
import { getLabelPrinter } from 'jest-matcher-utils';
55

@@ -32,7 +32,8 @@ class MyScreen extends React.Component {
3232
super(props)
3333
this.state = {
3434
isOn: false,
35-
count: 1
35+
animatedRightValue: new Animated.Value(-140),
36+
animatedValue: new Animated.Value(0),
3637
}
3738
}
3839

@@ -42,15 +43,34 @@ class MyScreen extends React.Component {
4243

4344
toggleHandle = () => {
4445
this.modelComponent()
45-
this.setState({
46+
this.setState({
4647
isOn: !this.state.isOn
47-
});
48+
},
49+
() => {
50+
Animated.timing(
51+
this.state.animatedRightValue,
52+
{
53+
toValue: this.state.isOn ? 7 : -140,
54+
// easing: Easing.ease,
55+
duration: 100,
56+
}
57+
).start()
58+
}
59+
);
4860
}
4961

5062
modelComponent = () => {
51-
if(this.state.isOn) {
5263
return (
53-
<View style={styles.model}>
64+
<Animated.View style={{
65+
position: 'absolute',
66+
top: 10,
67+
right: this.state.animatedRightValue,
68+
width: 140,
69+
height: 240,
70+
backgroundColor: '#555',
71+
borderRadius: 5,
72+
zIndex:999,
73+
}}>
5474
<Text style={styles.modelArrow}></Text>
5575
<View style={styles.modelContainer}>
5676
<View style={{height: 35, marginBottom: 10}}>
@@ -104,11 +124,9 @@ class MyScreen extends React.Component {
104124
</TouchableOpacity>
105125
</View>
106126
</View>
107-
</View>
127+
</Animated.View>
108128
)
109-
} else {
110-
return <View></View>
111-
}
129+
// return <Animated.View style={{width: 0}}></Animated.View>
112130
}
113131

114132
toFriendCicle = () => {

0 commit comments

Comments
 (0)