Skip to content

Commit cd460ce

Browse files
committed
split EditHomeView into multiple files
1 parent 236fc08 commit cd460ce

File tree

4 files changed

+118
-98
lines changed

4 files changed

+118
-98
lines changed

source/views/home/edit/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// @flow
2+
3+
export {ConnectedEditHomeView} from './list'

source/views/home/edit/list.js

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 {
5+
Dimensions,
6+
StyleSheet,
7+
} from 'react-native'
8+
9+
import {saveHomescreenOrder} from '../../../flux/parts/homescreen'
10+
import {connect} from 'react-redux'
11+
import * as c from '../../components/colors'
12+
import fromPairs from 'lodash/fromPairs'
13+
14+
import SortableList from 'react-native-sortable-list'
15+
16+
import type {ViewType} from '../../views'
17+
import {allViews} from '../../views'
18+
import {EditHomeRow} from './row'
19+
20+
const objViews = fromPairs(allViews.map(v => [v.view, v]))
21+
22+
const styles = StyleSheet.create({
23+
contentContainer: {
24+
backgroundColor: c.iosLightBackground,
25+
paddingTop: 10,
26+
paddingBottom: 20,
27+
flexDirection: 'column',
28+
alignItems: 'stretch',
29+
},
30+
})
31+
32+
type Props = {
33+
onSaveOrder: (ViewType[]) => any,
34+
order: string[],
35+
}
36+
type State = {
37+
width: number,
38+
}
39+
40+
class EditHomeView extends React.PureComponent<void, Props, State> {
41+
static navigationOptions = {
42+
title: 'Edit Home',
43+
}
44+
45+
state = {
46+
width: Dimensions.get('window').width,
47+
}
48+
49+
componentWillMount() {
50+
Dimensions.addEventListener('change', this.handleResizeEvent)
51+
}
52+
53+
componentWillUnmount() {
54+
Dimensions.removeEventListener('change', this.handleResizeEvent)
55+
}
56+
57+
handleResizeEvent = event => {
58+
this.setState(() => ({width: event.window.width}))
59+
}
60+
61+
renderRow = ({data, active}: {data: ViewType, active: boolean}) => (
62+
<EditHomeRow data={data} active={active} width={this.state.width} />
63+
)
64+
65+
onChangeOrder = (order: ViewType[]) => this.props.onSaveOrder(order)
66+
67+
render() {
68+
return (
69+
<SortableList
70+
contentContainerStyle={[
71+
styles.contentContainer,
72+
{width: this.state.width},
73+
]}
74+
data={objViews}
75+
order={this.props.order}
76+
onChangeOrder={this.onChangeOrder}
77+
renderRow={this.renderRow}
78+
/>
79+
)
80+
}
81+
}
82+
83+
function mapStateToProps(state) {
84+
return {
85+
order: state.homescreen.order,
86+
}
87+
}
88+
89+
function mapDispatchToProps(dispatch) {
90+
return {
91+
onSaveOrder: newOrder => dispatch(saveHomescreenOrder(newOrder)),
92+
}
93+
}
94+
95+
export const ConnectedEditHomeView = connect(mapStateToProps, mapDispatchToProps)(EditHomeView)
Lines changed: 19 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,23 @@
1-
/**
2-
* @flow
3-
* All About Olaf
4-
* Edit Home page
5-
*/
1+
// @flow
62

73
import React from 'react'
84
import {
95
Animated,
10-
Dimensions,
116
Easing,
127
StyleSheet,
138
Text,
149
Platform,
1510
} from 'react-native'
1611

17-
import {saveHomescreenOrder} from '../../flux/parts/homescreen'
18-
import {connect} from 'react-redux'
19-
import * as c from '../components/colors'
20-
import fromPairs from 'lodash/fromPairs'
12+
import * as c from '../../components/colors'
2113

2214
import EntypoIcon from 'react-native-vector-icons/Entypo'
2315
import IonIcon from 'react-native-vector-icons/Ionicons'
24-
import SortableList from 'react-native-sortable-list'
2516

26-
import type {ViewType} from '../views'
27-
import {allViews} from '../views'
28-
29-
const objViews = fromPairs(allViews.map(v => [v.view, v]))
17+
import type {ViewType} from '../../views'
3018

3119
const ROW_HORIZONTAL_MARGIN = 15
3220
const styles = StyleSheet.create({
33-
contentContainer: {
34-
backgroundColor: c.iosLightBackground,
35-
paddingTop: 10,
36-
paddingBottom: 20,
37-
flexDirection: 'column',
38-
alignItems: 'stretch',
39-
},
4021
row: {
4122
flex: 1,
4223

@@ -87,13 +68,13 @@ const MenuIcon = ({icon, tint}: {icon: string, tint: string}) => (
8768
/>
8869
)
8970

90-
type RowProps = {
71+
type Props = {
9172
data: ViewType,
9273
active: boolean,
9374
width: number,
9475
}
9576

96-
type RowState = {
77+
type State = {
9778
style: {
9879
shadowRadius: Animated.Value,
9980
transform: Array<{[key: string]: Animated.Value}>,
@@ -102,7 +83,7 @@ type RowState = {
10283
},
10384
}
10485

105-
class Row extends React.Component<void, RowProps, RowState> {
86+
export class EditHomeRow extends React.Component<void, Props, State> {
10687
static startStyle = {
10788
shadowRadius: 2,
10889
transform: [{scale: 1}],
@@ -119,16 +100,16 @@ class Row extends React.Component<void, RowProps, RowState> {
119100

120101
state = {
121102
style: {
122-
shadowRadius: new Animated.Value(Row.startStyle.shadowRadius),
103+
shadowRadius: new Animated.Value(EditHomeRow.startStyle.shadowRadius),
123104
transform: [
124-
{scale: new Animated.Value(Row.startStyle.transform[0].scale)},
105+
{scale: new Animated.Value(EditHomeRow.startStyle.transform[0].scale)},
125106
],
126-
opacity: new Animated.Value(Row.startStyle.opacity),
127-
elevation: new Animated.Value(Row.startStyle.elevation),
107+
opacity: new Animated.Value(EditHomeRow.startStyle.opacity),
108+
elevation: new Animated.Value(EditHomeRow.startStyle.elevation),
128109
},
129110
}
130111

131-
componentWillReceiveProps(nextProps) {
112+
componentWillReceiveProps(nextProps: Props) {
132113
if (this.props.active === nextProps.active) {
133114
return
134115
}
@@ -146,22 +127,22 @@ class Row extends React.Component<void, RowProps, RowState> {
146127
Animated.timing(transform[0].scale, {
147128
duration: 100,
148129
easing: Easing.out(Easing.quad),
149-
toValue: Row.endStyle.transform[0].scale,
130+
toValue: EditHomeRow.endStyle.transform[0].scale,
150131
}),
151132
Animated.timing(shadowRadius, {
152133
duration: 100,
153134
easing: Easing.out(Easing.quad),
154-
toValue: Row.endStyle.shadowRadius,
135+
toValue: EditHomeRow.endStyle.shadowRadius,
155136
}),
156137
Animated.timing(opacity, {
157138
duration: 100,
158139
easing: Easing.out(Easing.quad),
159-
toValue: Row.endStyle.opacity,
140+
toValue: EditHomeRow.endStyle.opacity,
160141
}),
161142
Animated.timing(elevation, {
162143
duration: 100,
163144
easing: Easing.out(Easing.quad),
164-
toValue: Row.endStyle.elevation,
145+
toValue: EditHomeRow.endStyle.elevation,
165146
}),
166147
]).start()
167148
}
@@ -172,22 +153,22 @@ class Row extends React.Component<void, RowProps, RowState> {
172153
Animated.timing(transform[0].scale, {
173154
duration: 100,
174155
easing: Easing.out(Easing.quad),
175-
toValue: Row.startStyle.transform[0].scale,
156+
toValue: EditHomeRow.startStyle.transform[0].scale,
176157
}),
177158
Animated.timing(shadowRadius, {
178159
duration: 100,
179160
easing: Easing.out(Easing.quad),
180-
toValue: Row.startStyle.shadowRadius,
161+
toValue: EditHomeRow.startStyle.shadowRadius,
181162
}),
182163
Animated.timing(opacity, {
183164
duration: 100,
184165
easing: Easing.out(Easing.quad),
185-
toValue: Row.startStyle.opacity,
166+
toValue: EditHomeRow.startStyle.opacity,
186167
}),
187168
Animated.timing(elevation, {
188169
duration: 100,
189170
easing: Easing.out(Easing.quad),
190-
toValue: Row.startStyle.elevation,
171+
toValue: EditHomeRow.startStyle.elevation,
191172
}),
192173
]).start()
193174
}
@@ -206,62 +187,3 @@ class Row extends React.Component<void, RowProps, RowState> {
206187
)
207188
}
208189
}
209-
210-
type Props = {
211-
onSaveOrder: (ViewType[]) => any,
212-
order: string[],
213-
}
214-
type State = {
215-
width: number,
216-
}
217-
218-
class EditHomeView extends React.PureComponent<void, Props, State> {
219-
static navigationOptions = {
220-
title: 'Edit Home',
221-
}
222-
223-
state = {
224-
width: Dimensions.get('window').width,
225-
}
226-
227-
componentWillMount() {
228-
Dimensions.addEventListener('change', this.handleResizeEvent)
229-
}
230-
231-
componentWillUnmount() {
232-
Dimensions.removeEventListener('change', this.handleResizeEvent)
233-
}
234-
235-
handleResizeEvent = event => {
236-
this.setState(() => ({width: event.window.width}))
237-
}
238-
239-
render() {
240-
return (
241-
<SortableList
242-
contentContainerStyle={[
243-
styles.contentContainer,
244-
{width: this.state.width},
245-
]}
246-
data={objViews}
247-
order={this.props.order}
248-
onChangeOrder={(order: ViewType[]) => this.props.onSaveOrder(order)}
249-
renderRow={({data, active}: {data: ViewType, active: boolean}) => (
250-
<Row data={data} active={active} width={this.state.width} />
251-
)}
252-
/>
253-
)
254-
}
255-
}
256-
257-
function mapStateToProps(state) {
258-
return {
259-
order: state.homescreen.order,
260-
}
261-
}
262-
function mapDispatchToProps(dispatch) {
263-
return {
264-
onSaveOrder: newOrder => dispatch(saveHomescreenOrder(newOrder)),
265-
}
266-
}
267-
export default connect(mapStateToProps, mapDispatchToProps)(EditHomeView)

source/views/home/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
// @flow
22

33
export {default as HomeView} from './home'
4-
export {default as EditHomeView} from './edit'
4+
export {ConnectedEditHomeView as EditHomeView} from './edit'

0 commit comments

Comments
 (0)