@@ -13,17 +13,31 @@ import sortBy from 'lodash/sortBy'
1313import type { TopLevelViewPropsType } from '../types'
1414import type { ViewType } from '../views'
1515import { allViews } from '../views'
16+ import { Column } from '../components/layout'
1617import { HomeScreenButton , CELL_MARGIN } from './button'
1718import { trackedOpenUrl } from '../components/open-url'
1819import { EditHomeButton , OpenSettingsButton } from '../components/nav-buttons'
1920
21+ function partitionByIndex < T > (arr: T[]): [T[], T[]] {
22+ return arr . reduce (
23+ ( acc , val , idx ) => {
24+ return idx % 2 === 0
25+ ? [ acc [ 0 ] . concat ( val ) , acc [ 1 ] ]
26+ : [ acc [ 0 ] , acc [ 1 ] . concat ( val ) ]
27+ } ,
28+ [ [ ] , [ ] ] ,
29+ )
30+ }
31+
2032function HomePage({
2133 navigation ,
2234 order ,
2335 views = allViews ,
2436} : { order : string [ ] , views : ViewType [ ] } & TopLevelViewPropsType ) {
2537 const sortedViews = sortBy ( views , view => order . indexOf ( view . view ) )
2638
39+ const columns = partitionByIndex ( sortedViews )
40+
2741 return (
2842 < ScrollView
2943 overflow = "hidden"
@@ -34,18 +48,22 @@ function HomePage({
3448 >
3549 < StatusBar barStyle = "light-content" backgroundColor = { c . gold } />
3650
37- { sortedViews . map ( view =>
38- < HomeScreenButton
39- key = { view . view }
40- view = { view }
41- onPress = { ( ) => {
42- if ( view . type === 'url' ) {
43- return trackedOpenUrl ( { url : view . url , id : view . view } )
44- } else {
45- return navigation . navigate ( view . view )
46- }
47- } }
48- /> ,
51+ { columns . map ( ( contents , i ) =>
52+ < Column key = { i } flex = { 1 } >
53+ { contents . map ( view =>
54+ < HomeScreenButton
55+ key = { view . view }
56+ view = { view }
57+ onPress = { ( ) => {
58+ if ( view . type === 'url' ) {
59+ return trackedOpenUrl ( { url : view . url , id : view . view } )
60+ } else {
61+ return navigation . navigate ( view . view )
62+ }
63+ } }
64+ /> ,
65+ ) }
66+ </ Column > ,
4967 ) }
5068 </ ScrollView >
5169 )
@@ -72,9 +90,6 @@ const styles = StyleSheet.create({
7290 marginTop : CELL_MARGIN / 2 ,
7391 paddingBottom : CELL_MARGIN / 2 ,
7492
75- alignItems : 'flex-start' ,
76- justifyContent : 'center' ,
7793 flexDirection : 'row' ,
78- flexWrap : 'wrap' ,
7994 } ,
8095} )
0 commit comments