1- /**
2- * @flow
3- * All About Olaf
4- * Edit Home page
5- */
1+ // @flow
62
73import React from 'react'
84import {
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
2214import EntypoIcon from 'react-native-vector-icons/Entypo'
2315import 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
3119const ROW_HORIZONTAL_MARGIN = 15
3220const 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 )
0 commit comments