Skip to content

Commit 715e559

Browse files
committed
split row and list into {ios,android} pairs
1 parent ae792a4 commit 715e559

File tree

4 files changed

+179
-10
lines changed

4 files changed

+179
-10
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// @flow
2+
3+
import React from 'react'
4+
import {Dimensions, StyleSheet} from 'react-native'
5+
6+
import {saveHomescreenOrder} from '../../../flux/parts/homescreen'
7+
import {connect} from 'react-redux'
8+
import * as c from '../../components/colors'
9+
import fromPairs from 'lodash/fromPairs'
10+
import sortBy from 'lodash/sortBy'
11+
12+
import type {ViewType} from '../../views'
13+
import {allViews} from '../../views'
14+
import {EditHomeRow} from './row'
15+
16+
const styles = StyleSheet.create({
17+
contentContainer: {
18+
backgroundColor: c.androidLightBackground,
19+
paddingTop: 10,
20+
paddingBottom: 20,
21+
},
22+
})
23+
24+
type Props = {
25+
onSaveOrder: (ViewType[]) => any,
26+
order: string[],
27+
}
28+
;[]
29+
30+
type State = {
31+
width: number,
32+
}
33+
;[]
34+
35+
class EditHomeView extends React.PureComponent<void, Props, State> {
36+
static navigationOptions = {
37+
title: 'Edit Home',
38+
}
39+
40+
renderRow = ({data, active}: {data: ViewType, active: boolean}) => (
41+
<EditHomeRow data={data} active={active} width={this.state.width} />
42+
)
43+
44+
onChangeOrder = (order: ViewType[]) => this.props.onSaveOrder(order)
45+
46+
keyExtractor = (item: ViewType) => view.view
47+
48+
render() {
49+
const data = sortBy(allViews, (item: ViewType) =>
50+
this.props.order.indexOf(item.view),
51+
)
52+
53+
return (
54+
<FlatList
55+
contentContainerStyle={styles.contentContainer}
56+
data={allViews}
57+
keyExtractor={this.keyExtractor}
58+
onChangeOrder={this.onChangeOrder}
59+
renderRow={this.renderRow}
60+
/>
61+
)
62+
}
63+
}
64+
65+
function mapState(state) {
66+
return {
67+
order: state.homescreen.order,
68+
}
69+
}
70+
71+
function mapDispatch(dispatch) {
72+
return {
73+
onSaveOrder: newOrder => dispatch(saveHomescreenOrder(newOrder)),
74+
}
75+
}
76+
77+
export const ConnectedEditHomeView = connect(mapState, mapDispatch)(
78+
EditHomeView,
79+
)

source/views/home/edit/list.js renamed to source/views/home/edit/list.ios.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ type Props = {
3030
onSaveOrder: (ViewType[]) => any,
3131
order: string[],
3232
}
33+
3334
type State = {
3435
width: number,
3536
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// @flow
2+
3+
import React from 'react'
4+
import {View, StyleSheet, Text} from 'react-native'
5+
6+
import * as c from '../../components/colors'
7+
8+
import EntypoIcon from 'react-native-vector-icons/Entypo'
9+
import IonIcon from 'react-native-vector-icons/Ionicons'
10+
11+
import {Touchable} from '../../components/touchable'
12+
import type {ViewType} from '../../views'
13+
14+
const ROW_HORIZONTAL_MARGIN = 15
15+
const styles = StyleSheet.create({
16+
row: {
17+
flex: 1,
18+
19+
flexDirection: 'row',
20+
alignItems: 'center',
21+
22+
backgroundColor: c.white,
23+
24+
marginVertical: 5,
25+
marginHorizontal: ROW_HORIZONTAL_MARGIN,
26+
paddingVertical: 12,
27+
paddingRight: 10,
28+
29+
borderRadius: 4,
30+
31+
elevation: 1,
32+
},
33+
icon: {
34+
paddingLeft: 10,
35+
paddingRight: 10,
36+
color: c.black,
37+
},
38+
viewIcon: {
39+
// marginRight: 20,
40+
},
41+
text: {
42+
flex: 1,
43+
flexShrink: 0,
44+
fontSize: 18,
45+
color: c.white,
46+
},
47+
})
48+
49+
const MenuIcon = ({icon, tint}: {icon: string, tint: string}) => (
50+
<EntypoIcon
51+
name={icon}
52+
size={32}
53+
style={[styles.icon, styles.viewIcon, {color: tint}]}
54+
/>
55+
)
56+
57+
type Props = {
58+
data: ViewType,
59+
width: number,
60+
onMoveUp: string => any,
61+
onMoveDown: string => any,
62+
}
63+
;[]
64+
65+
export class EditHomeRow extends React.PureComponent<void, Props, void> {
66+
onMoveUp = () => {
67+
this.props.onMoveUp(this.props.data.view)
68+
}
69+
70+
onMoveDown = () => {
71+
this.props.onMoveDown(this.props.data.view)
72+
}
73+
74+
render() {
75+
const width = this.props.width - ROW_HORIZONTAL_MARGIN * 2
76+
77+
return (
78+
<View style={[styles.row, {width}]}>
79+
<MenuIcon icon={this.props.data.icon} tint={this.props.data.tint} />
80+
81+
<Text style={[styles.text, {color: this.props.data.tint}]}>
82+
{this.props.data.title}
83+
</Text>
84+
85+
<Touchable onPress={this.onMoveUp}>
86+
<IonIcon name="md-arrow-up" size={32} style={styles.icon} />
87+
</Touchable>
88+
89+
<Touchable onPress={this.onMoveDown}>
90+
<IonIcon name="md-arrow-down" size={32} style={styles.icon} />
91+
</Touchable>
92+
</View>
93+
)
94+
}
95+
}

source/views/home/edit/row.js renamed to source/views/home/edit/row.ios.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @flow
22

33
import React from 'react'
4-
import {Animated, Easing, StyleSheet, Text, Platform} from 'react-native'
4+
import {Animated, Easing, StyleSheet, Text} from 'react-native'
55

66
import * as c from '../../components/colors'
77

@@ -46,14 +46,6 @@ const styles = StyleSheet.create({
4646
},
4747
})
4848

49-
const reorderIcon = (
50-
<IonIcon
51-
name={Platform.OS === 'ios' ? 'ios-reorder' : 'md-reorder'}
52-
size={32}
53-
style={[styles.icon]}
54-
/>
55-
)
56-
5749
const MenuIcon = ({icon, tint}: {icon: string, tint: string}) => (
5850
<EntypoIcon
5951
name={icon}
@@ -173,10 +165,12 @@ export class EditHomeRow extends React.Component<void, Props, State> {
173165
return (
174166
<Animated.View style={[styles.row, this.state.style, {width}]}>
175167
<MenuIcon icon={this.props.data.icon} tint={this.props.data.tint} />
168+
176169
<Text style={[styles.text, {color: this.props.data.tint}]}>
177170
{this.props.data.title}
178171
</Text>
179-
{reorderIcon}
172+
173+
<IonIcon name="ios-reorder" size={32} style={[styles.icon]} />
180174
</Animated.View>
181175
)
182176
}

0 commit comments

Comments
 (0)