I am attempting to arrange squares just like how they look in the image, but I can’t really figure out the whole flex and positioning stuff: squares
This is probably really simple but I just can’t figure it out.
Advertisement
Answer
Well, here is a quick and dirty version of your picture.
JavaScript
x
37
37
1
import React from "react"
2
import { StyleSheet, View } from "react-native"
3
4
export const Test = () => {
5
return (
6
<View style={styles.container}>
7
<View style={styles.row}>
8
<View style={[styles.square]} />
9
<View style={[styles.square]} />
10
<View style={[styles.square, { backgroundColor: "yellow" }]} />
11
<View style={[styles.square, { backgroundColor: "turquoise" }]} />
12
</View>
13
<View style={styles.row}>
14
<View style={[styles.square, { backgroundColor: "red" }]} />
15
<View style={[styles.square, { backgroundColor: "blue" }]} />
16
<View style={[styles.square, { backgroundColor: "green" }]} />
17
<View style={[styles.square, { backgroundColor: "violet" }]} />
18
<View style={[styles.square, { backgroundColor: "yellow" }]} />
19
</View>
20
<View style={[styles.square, { backgroundColor: "lightgrey", height: 25, width: 300 }]} />
21
</View>
22
)
23
}
24
25
const styles = StyleSheet.create({
26
container: {
27
display: "flex",
28
},
29
row: {
30
flexDirection: "row",
31
},
32
square: {
33
width: 60,
34
height: 60,
35
},
36
})
37
which yields to the following view.