-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSampleComponents.tsx
125 lines (107 loc) · 2.58 KB
/
SampleComponents.tsx
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
import { useState, useEffect } from 'react'
import {
StyleSheet,
Text as _Text,
Image,
View,
Pressable,
ActivityIndicator,
ScrollView,
TextProps
} from 'react-native';
const Text = (props: TextProps) => <_Text style={[styles.text, props.style]}>{props.children}</_Text>;
interface CatProps {name: string};
function Cat() {
return (
<View>
<Image
source={{ uri: 'https://rb.gy/5zq7ne', height: 100, width: 100 }}
/>
<Text>Hello, I'm a cat!</Text>
</View>
);
}
function MoviePosterShowcase() {
const [isLoading, setIsLoading] = useState(true);
const [movies, setMovies] = useState([]);
useEffect(() => {
async function fetchMovies() {
const URL = 'https://api.sampleapis.com/movies/animation';
const response = await fetch(URL);
const data = await response.json();
setMovies(data);
setIsLoading(false);
}
fetchMovies();
}, []);
if (isLoading) return <ActivityIndicator/>;
return (
<ScrollView contentContainerStyle={styles.posterContainer}>
{movies.map((movie: {id: string, posterURL: string}) => (
<Image
key={movie.id}
source={{ uri: movie.posterURL }}
style={styles.poster}
/>
))}
</ScrollView>
);
}
export function Doge() {
const [numPets, setNumPets] = useState(0);
return (
<>
<Pressable onPress={() => setNumPets(numPets + 1)}>
<Image source={{ uri: 'https://rb.gy/weptcb', height: 200, width: 300}} />
</Pressable>
<Text>You pet me {numPets} times!</Text>
</>
);
}
// Usage: <Elephant name="Ella" size={75} />
function Elephant(props: ElephantProps) {
return (
<View style={styles.elephant}>
<Text style={{fontSize: props.size}}>🐘</Text>
<Text>Hi, I'm {props.name} the elephant</Text>
</View>
);
}
interface ElephantProps {
name: string,
size: number
};
const styles = StyleSheet.create({
dog: {
backgroundColor: 'red'
},
button: {
backgroundColor: 'green',
borderRadius: 5,
padding: 5
},
text: {
fontSize: 32
},
elephant: {
backgroundColor: 'orange',
borderRadius: 5,
width: 200,
alignItems: 'center',
margin: 10,
padding: 10
},
posterContainer: {
flexWrap: 'wrap',
padding: 20,
flexDirection: 'row',
justifyContent: 'center',
alignContent: 'center',
alignSelf: 'stretch'
},
poster: {
margin: 5,
height: 250,
width: 150
}
});