11import { KeyboardAwareScrollView , LandingHeader } from '@baca/components'
22import { BACA_APP_URL , BACA_DOCS_URL } from '@baca/constants'
3- import { Button , Center , Text , Box , ScrollView } from '@baca/design-system'
4- import { useCallback , useScreenOptions , useTranslation , useViewportDimensions } from '@baca/hooks'
3+ import { Button , Center , Text , Box } from '@baca/design-system'
4+ import { useCallback , useScreenOptions , useTranslation } from '@baca/hooks'
55import { draftImages } from '@baca/screens'
6- import { ImageSourcePropType , Linking , Image , StyleSheet } from 'react-native'
6+ import { useState , useEffect } from 'react'
7+ import { ImageSourcePropType , Linking , Image , Dimensions , StyleSheet } from 'react-native'
78
89export const LandingScreen = ( ) => {
910 const { t } = useTranslation ( )
10- const { viewportWidth, viewportHeight } = useViewportDimensions ( )
11+ const [ screenWidth , setScreenWidth ] = useState ( Dimensions . get ( 'window' ) . width )
12+
13+ useEffect ( ( ) => {
14+ const onChange = ( { window } : { window : { width : number } } ) => setScreenWidth ( window . width )
15+ const subscription = Dimensions . addEventListener ( 'change' , onChange )
16+ return ( ) => subscription ?. remove ( )
17+ } , [ ] )
18+
19+ let numColumns
20+ if ( screenWidth >= 1100 ) {
21+ numColumns = 4
22+ } else if ( screenWidth <= 767 ) {
23+ numColumns = 2
24+ } else {
25+ numColumns = 4
26+ }
27+
28+ const imageSize = screenWidth / numColumns - 16
1129
1230 const openLink = useCallback ( ( url : string ) => Linking . openURL ( url ) , [ ] )
1331
1432 const renderItem = ( item : ImageSourcePropType , index : number ) => (
15- < Box key = { index } height = { viewportHeight * 0.6 } width = { viewportWidth * 0.6 } >
33+ < Box key = { index } height = { imageSize } width = { imageSize } style = { styles . imagesContainer } >
1634 < Image source = { item } resizeMode = "contain" style = { styles . imageSize } />
1735 </ Box >
1836 )
@@ -51,17 +69,9 @@ export const LandingScreen = () => {
5169 </ Button . SecondaryColor >
5270 </ Box >
5371
54- < ScrollView
55- height = { viewportHeight * 0.6 }
56- horizontal
57- mt = { 8 }
58- pagingEnabled
59- scrollEventThrottle = { 16 }
60- showsHorizontalScrollIndicator = { false }
61- width = { viewportWidth * 0.6 }
62- >
72+ < Box flexDirection = "row" flexWrap = "wrap" justifyContent = "center" mt = { 4 } >
6373 { draftImages . map ( renderItem ) }
64- </ ScrollView >
74+ </ Box >
6575 </ Center >
6676 </ KeyboardAwareScrollView >
6777 )
@@ -72,4 +82,7 @@ const styles = StyleSheet.create({
7282 height : '100%' ,
7383 width : '100%' ,
7484 } ,
85+ imagesContainer : {
86+ padding : 6 ,
87+ } ,
7588} )
0 commit comments