I'm trying to create a very simple 2D grid using a 2D array in react-native.
The size of the grid is controlled by a parameter called size. For some of the values of size (e.g 31 but not for 40) there appears to be gaps in the grid.
Following is the 30 line code to generate the 9x9 grid:
import { View } from 'react-native'
const size = 31
const Box = () => {
let grid = Array.from(Array(9), _ => Array(9).fill(0)) // 9x9 array
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
{grid.map((row, i) => (
<View key={i} style={{ height: size, flexDirection: 'row', backgroundColor: 'red' }}>
{row.map((cell, j) =>
<View key={j} style={{ width: size, height: size, backgroundColor: 'white' }}></View>
)}
</View>
))}
</View>
)
}
export default function App() {
return (
<View style={{ flex: 1, position: 'absolute', top: 0, left: 0, bottom: 0, right: 0, backgroundColor: 'gray' }}>
<Box />
</View>
)
}
There is also a snack available to edit and see the changes online here: https://snack.expo.dev/@diby3ndu/test
I'm attaching a screenshot of the grid running on Expo from my android device.
As you can see there are unwanted lines in the picture. The lines are not there in the online version though.
Can anyone help me figuring out what may be causing these unwanted lines?
