@@ -28,18 +28,62 @@ import {allViews} from '../views'
2828
2929const objViews = fromPairs ( allViews . map ( v => [ v . view , v ] ) )
3030
31- const ReorderIcon = ( ) =>
31+ const ROW_HORIZONTAL_MARGIN = 15
32+ const styles = StyleSheet . create ( {
33+ contentContainer : {
34+ backgroundColor : c . iosLightBackground ,
35+ paddingTop : 10 ,
36+ paddingBottom : 20 ,
37+ flexDirection : 'column' ,
38+ alignItems : 'stretch' ,
39+ } ,
40+ row : {
41+ flex : 1 ,
42+
43+ flexDirection : 'row' ,
44+ alignItems : 'center' ,
45+
46+ backgroundColor : c . white ,
47+
48+ marginVertical : 5 ,
49+ marginHorizontal : ROW_HORIZONTAL_MARGIN ,
50+ paddingVertical : 12 ,
51+
52+ borderRadius : 4 ,
53+
54+ shadowColor : c . semitransparentGray ,
55+ shadowOpacity : 1 ,
56+ shadowOffset : { height : 0 , width : 0 } ,
57+ } ,
58+ icon : {
59+ paddingLeft : 10 ,
60+ paddingRight : 10 ,
61+ color : c . black ,
62+ } ,
63+ viewIcon : {
64+ marginRight : 20 ,
65+ } ,
66+ text : {
67+ flex : 1 ,
68+ flexShrink : 0 ,
69+ fontSize : 18 ,
70+ color : c . white ,
71+ } ,
72+ } )
73+
74+ const reorderIcon = (
3275 < IonIcon
3376 name = { Platform . OS === 'ios' ? 'ios-reorder' : 'md-reorder' }
3477 size = { 32 }
35- style = { styles . listButtonIcon }
78+ style = { [ styles . icon ] }
3679 />
80+ )
3781
3882const MenuIcon = ( { icon, tint} : { icon : string , tint : string } ) =>
3983 < EntypoIcon
4084 name = { icon }
4185 size = { 32 }
42- style = { [ styles . rectangleButtonIcon , { color : tint } ] }
86+ style = { [ styles . icon , styles . viewIcon , { color : tint } ] }
4387 />
4488
4589type RowProps = {
@@ -148,37 +192,64 @@ class Row extends React.Component<void, RowProps, RowState> {
148192 }
149193
150194 render ( ) {
151- const style = { width : Dimensions . get ( 'window' ) . width - 15 * 2 }
195+ const width = this . props . width - ROW_HORIZONTAL_MARGIN * 2
196+
152197 return (
153- < Animated . View style = { [ styles . row , style , this . state . style ] } >
198+ < Animated . View style = { [ styles . row , this . state . style , { width } ] } >
154199 < MenuIcon icon = { this . props . data . icon } tint = { this . props . data . tint } />
155200 < Text style = { [ styles . text , { color : this . props . data . tint } ] } >
156201 { this . props . data . title }
157202 </ Text >
158- < ReorderIcon />
203+ { reorderIcon }
159204 </ Animated . View >
160205 )
161206 }
162207}
163208
164- function EditHomeView ( props : {
209+ type Props = {
165210 onSaveOrder : ( ViewType [ ] ) => any ,
166211 order : string [ ] ,
167- } ) {
168- const style = { width : Dimensions . get ( 'window' ) . width }
169- return (
170- < SortableList
171- contentContainerStyle = { [ styles . contentContainer , style ] }
172- data = { objViews }
173- order = { props . order }
174- onChangeOrder = { ( order : ViewType [ ] ) => props . onSaveOrder ( order ) }
175- renderRow = { ( { data, active} : { data : ViewType , active : boolean } ) =>
176- < Row data = { data } active = { active } /> }
177- />
178- )
179212}
180- EditHomeView . navigationOptions = {
181- title : 'Edit Home' ,
213+ type State = {
214+ width : number ,
215+ }
216+
217+ class EditHomeView extends React . PureComponent < void , Props , State > {
218+ static navigationOptions = {
219+ title : 'Edit Home' ,
220+ }
221+
222+ state = {
223+ width : Dimensions . get ( 'window' ) . width ,
224+ }
225+
226+ componentWillMount ( ) {
227+ Dimensions . addEventListener ( 'change' , this . handleResizeEvent )
228+ }
229+
230+ componentWillUnmount ( ) {
231+ Dimensions . removeEventListener ( 'change' , this . handleResizeEvent )
232+ }
233+
234+ handleResizeEvent = event => {
235+ this . setState ( ( ) => ( { width : event . window . width } ) )
236+ }
237+
238+ render ( ) {
239+ return (
240+ < SortableList
241+ contentContainerStyle = { [
242+ styles . contentContainer ,
243+ { width : this . state . width } ,
244+ ] }
245+ data = { objViews }
246+ order = { this . props . order }
247+ onChangeOrder = { ( order : ViewType [ ] ) => this . props . onSaveOrder ( order ) }
248+ renderRow = { ( { data, active} : { data : ViewType , active : boolean } ) =>
249+ < Row data = { data } active = { active } width = { this . state . width } /> }
250+ />
251+ )
252+ }
182253}
183254
184255function mapStateToProps ( state ) {
@@ -192,42 +263,3 @@ function mapDispatchToProps(dispatch) {
192263 }
193264}
194265export default connect ( mapStateToProps , mapDispatchToProps ) ( EditHomeView )
195-
196- let styles = StyleSheet . create ( {
197- contentContainer : {
198- backgroundColor : c . iosLightBackground ,
199- paddingTop : 10 ,
200- paddingBottom : 20 ,
201- } ,
202- row : {
203- flexDirection : 'row' ,
204- alignItems : 'center' ,
205- backgroundColor : c . white ,
206- marginVertical : 5 ,
207- marginHorizontal : 15 ,
208- paddingVertical : 12 ,
209- borderRadius : 4 ,
210- shadowColor : c . semitransparentGray ,
211- shadowOpacity : 1 ,
212- shadowOffset : { height : 2 , width : 2 } ,
213- shadowRadius : 2 ,
214- opacity : 1.0 ,
215- elevation : 2 ,
216- } ,
217- rectangleButtonIcon : {
218- marginRight : 20 ,
219- color : c . white ,
220- paddingLeft : 10 ,
221- paddingRight : 10 ,
222- } ,
223- listButtonIcon : {
224- color : c . black ,
225- paddingLeft : 10 ,
226- paddingRight : 10 ,
227- } ,
228- text : {
229- flex : 1 ,
230- fontSize : 18 ,
231- color : c . white ,
232- } ,
233- } )
0 commit comments