-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
49 lines (45 loc) · 1.19 KB
/
App.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
45
46
47
48
49
import React, {useState, useCallback} from 'react';
import {SafeAreaView, StyleSheet} from 'react-native';
import SwipeableCard from './SwipeableCard';
const App = () => {
const [array, updateArray] = useState([1, 2, 3, 4]);
const popItem = useCallback(
() =>
updateArray((pa) => {
pa.pop();
if (pa.length <= 0) {
// Added Math.random form Manitaning uniqe key values, other wise refs are not refreshed
setTimeout(
() =>
updateArray([
1 + parseInt(Math.random() * 100, 10),
2 + parseInt(Math.random() * 100, 10),
3 + parseInt(Math.random() * 100, 10),
4 + parseInt(Math.random() * 100, 10),
]),
2000,
);
}
return pa;
}),
[],
);
return (
<SafeAreaView style={styles.root}>
{array.map((i) => (
<SwipeableCard action={popItem} key={i} />
))}
</SafeAreaView>
);
};
const styles = StyleSheet.create({
root: {
flex: 1,
position: 'relative',
justifyContent: 'center',
alignItems: 'stretch',
backgroundColor: '#ff0000a0',
padding: 20,
},
});
export default App;