-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
133 lines (121 loc) · 2.74 KB
/
Copy pathApp.js
File metadata and controls
133 lines (121 loc) · 2.74 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import React, { Component } from "react";
import {
Text,
View,
StyleSheet,
FlatList,
UIManager,
LayoutAnimation,
TouchableOpacity
} from 'react-native';
import Card from "./Card";
UIManager.setLayoutAnimationEnabledExperimental &&
UIManager.setLayoutAnimationEnabledExperimental(true);
const imageUrl =
"https://kenh14cdn.com/2019/2/24/3561716420480213454575853861059020806684672n-15510057259571546306615.jpg";
const cards = [
{
key: 0,
uri: imageUrl,
title: "Pretty girl",
description: "blah blah..."
}
];
export default class App extends Component {
constructor(props) {
super(props);
this.state = {
cards
};
}
setAnimation = () => {
LayoutAnimation.configureNext({
duration: 250,
update: {
type: LayoutAnimation.Types.easeIn,
springDamping: 0.7
}
});
LayoutAnimation.configureNext({
duration: 500,
create: {
type: LayoutAnimation.Types.easeIn,
property: LayoutAnimation.Properties.scaleXY,
springDamping: 0.7
}
});
};
addItem = (() => {
let key = cards.length;
return () => {
const { cards } = this.state;
cards.unshift({
key,
uri: imageUrl,
title: "Pretty girl",
description: "blah blah...",
animated: true
});
this.setAnimation();
this.setState({
cards: cards.slice(0)
});
key++;
};
})();
removeItem = key => {
const { cards } = this.state;
this.setAnimation();
this.setState({
cards: cards.slice().filter(card => card.key !== key)
});
};
renderItem = ({ item }) => <Card item={item} removeItem={this.removeItem} />;
render() {
return (
<View style={styles.container}>
<FlatList
contentContainerStyle={styles.paragraph}
data={this.state.cards}
renderItem={this.renderItem}
ItemSeparatorComponent={() => <View style={{ marginTop: 10 }} />}
keyExtractor={item => item.key.toString()}
/>
<TouchableOpacity style={styles.addButton} onPress={this.addItem}>
<Text style={styles.addIcon}>+</Text>
</TouchableOpacity>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
paddingTop: 30,
backgroundColor: "#FFF"
},
paragraph: {
fontSize: 18,
fontWeight: "bold",
textAlign: "center",
color: "#34495e",
paddingBottom: 10
},
addButton: {
height: 60,
width: 60,
elevation: 3,
borderColor: "#00F",
borderRadius: 30,
alignItems: "center",
justifyContent: "center",
position: "absolute",
bottom: 25,
right: 25
},
addIcon: {
fontSize: 35,
color: "gray",
textAlign: "center"
}
});