Skip to content

Commit da70214

Browse files
committed
make the homescreen resize correctly in landscape
1 parent b7d1063 commit da70214

File tree

2 files changed

+39
-19
lines changed

2 files changed

+39
-19
lines changed

source/views/home/button.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ export function HomeScreenButton({
1414
view: ViewType,
1515
onPress: () => any,
1616
}) {
17-
const screenWidth = Dimensions.get('window').width
17+
// const screenWidth = Dimensions.get('window').width
1818
const style = {
19-
width: screenWidth / 2 - CELL_MARGIN * 1.5,
19+
// width: screenWidth / 2 - CELL_MARGIN * 1.5,
20+
// flex: 1,
2021
backgroundColor: view.tint,
2122
}
2223

@@ -41,12 +42,16 @@ const cellHorizontalPadding = 4
4142
const styles = StyleSheet.create({
4243
// Main buttons for actions on home screen
4344
rectangle: {
45+
flex: 1,
46+
4447
alignItems: 'center',
4548
justifyContent: 'center',
49+
4650
paddingTop: cellVerticalPadding,
4751
paddingBottom: cellVerticalPadding / 2,
4852
paddingHorizontal: cellHorizontalPadding,
4953
borderRadius: Platform.OS === 'ios' ? 6 : 3,
54+
5055
elevation: 2,
5156

5257
marginTop: CELL_MARGIN / 2,
@@ -61,9 +66,9 @@ const styles = StyleSheet.create({
6166
},
6267
rectangleButtonText: {
6368
color: c.white,
64-
marginTop: cellVerticalPadding / 2,
69+
// marginTop: cellVerticalPadding / 2,
6570
fontFamily: Platform.OS === 'ios' ? 'System' : 'sans-serif-condensed',
66-
textAlign: 'center',
71+
// textAlign: 'center',
6772
fontSize: 14,
6873
},
6974
})

source/views/home/home.js

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,31 @@ import sortBy from 'lodash/sortBy'
1313
import type {TopLevelViewPropsType} from '../types'
1414
import type {ViewType} from '../views'
1515
import {allViews} from '../views'
16+
import {Column} from '../components/layout'
1617
import {HomeScreenButton, CELL_MARGIN} from './button'
1718
import {trackedOpenUrl} from '../components/open-url'
1819
import {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+
2032
function 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

Comments
 (0)