1- import React , { Component } from 'react' ;
2- import { Platform , StyleSheet , View , ScrollView , TouchableOpacity , Text , Image , I18nManager , Switch } from 'react-native' ;
1+ import React , { useState } from 'react' ;
2+ import { Platform , StyleSheet , I18nManager , View , ScrollView , TouchableOpacity , Text , Image , Switch } from 'react-native' ;
33import { Navigation } from 'react-native-navigation' ;
44import testIDs from '../testIDs' ;
55
@@ -8,54 +8,32 @@ const appIcon = require('../img/logo.png');
88interface Props {
99 componentId ?: string ;
1010 weekView ?: boolean ;
11+ horizontalView ?: boolean ;
1112}
1213
13- export default class MenuScreen extends Component < Props > {
14- state = {
15- forceRTL : false
16- }
17-
18- toggleRTL = ( value ) => {
14+ const MenuScreen = ( props : Props ) => {
15+ const { componentId} = props ;
16+ const [ forceRTL , setForceRTL ] = useState ( false ) ;
17+
18+ const toggleRTL = ( value ) => {
1919 I18nManager . forceRTL ( value ) ;
20- this . setState ( { forceRTL : value } ) ;
21- }
20+ setForceRTL ( value ) ;
21+ } ;
2222
23- renderEntry ( testID : string , title : string , screen : string , options ?: any ) {
23+ const renderEntry = ( testID : string , title : string , screen : string , options ?: any ) => {
2424 return (
2525 < TouchableOpacity
2626 testID = { testID }
2727 style = { styles . menu }
28- onPress = { ( ) => this . openScreen ( screen , options ) }
28+ onPress = { ( ) => openScreen ( screen , options ) }
2929 >
3030 < Text style = { styles . menuText } > { title } </ Text >
3131 </ TouchableOpacity >
3232 ) ;
33- }
33+ } ;
3434
35- render ( ) {
36- return (
37- < ScrollView >
38- < View style = { styles . container } testID = { testIDs . menu . CONTAINER } >
39- < Image source = { appIcon } style = { styles . image } />
40- { this . renderEntry ( testIDs . menu . CALENDARS , 'Calendar' , 'CalendarScreen' ) }
41- { this . renderEntry ( testIDs . menu . CALENDAR_LIST , 'Calendar List' , 'CalendarListScreen' ) }
42- { this . renderEntry ( testIDs . menu . HORIZONTAL_LIST , 'Horizontal Calendar List' , 'HorizontalCalendarListScreen' ) }
43- { this . renderEntry ( testIDs . menu . HORIZONTAL_LIST , 'NEW Calendar List' , 'NewCalendarListScreen' ) }
44- { this . renderEntry ( testIDs . menu . AGENDA , 'Agenda' , 'AgendaScreen' ) }
45- { this . renderEntry ( testIDs . menu . EXPANDABLE_CALENDAR , 'Expandable Calendar' , 'ExpandableCalendarScreen' ) }
46- { this . renderEntry ( testIDs . menu . TIMELINE_CALENDAR , 'Timeline Calendar' , 'TimelineCalendarScreen' ) }
47- { this . renderEntry ( testIDs . menu . WEEK_CALENDAR , 'Week Calendar' , 'ExpandableCalendarScreen' , { weekView : true } ) }
48- < View style = { styles . switchContainer } >
49- < Text > Force RTL</ Text >
50- < Switch value = { this . state . forceRTL } onValueChange = { this . toggleRTL } />
51- </ View >
52- </ View >
53- </ ScrollView >
54- ) ;
55- }
56-
57- pushScreen ( screen : string , props ?: Props ) {
58- Navigation . push ( this . props . componentId , {
35+ const pushScreen = ( screen : string , props ?: Props ) => {
36+ Navigation . push ( componentId , {
5937 component : {
6038 name : screen ,
6139 passProps : props ,
@@ -73,12 +51,34 @@ export default class MenuScreen extends Component<Props> {
7351 }
7452 }
7553 } ) ;
76- }
54+ } ;
7755
78- openScreen = ( screen : string , options : any ) => {
79- this . pushScreen ( screen , options ) ;
80- }
81- }
56+ const openScreen = ( screen : string , options : any ) => {
57+ pushScreen ( screen , options ) ;
58+ } ;
59+
60+ return (
61+ < ScrollView >
62+ < View style = { styles . container } testID = { testIDs . menu . CONTAINER } >
63+ < Image source = { appIcon } style = { styles . image } />
64+ { renderEntry ( testIDs . menu . CALENDARS , 'Calendar' , 'CalendarScreen' ) }
65+ { renderEntry ( testIDs . menu . CALENDAR_LIST , 'Calendar List' , 'CalendarListScreen' ) }
66+ { renderEntry ( testIDs . menu . HORIZONTAL_LIST , 'Horizontal Calendar List' , 'CalendarListScreen' , { horizontalView : true } ) }
67+ { renderEntry ( testIDs . menu . HORIZONTAL_LIST , 'NEW Calendar List' , 'NewCalendarListScreen' ) }
68+ { renderEntry ( testIDs . menu . AGENDA , 'Agenda' , 'AgendaScreen' ) }
69+ { renderEntry ( testIDs . menu . EXPANDABLE_CALENDAR , 'Expandable Calendar' , 'ExpandableCalendarScreen' ) }
70+ { renderEntry ( testIDs . menu . TIMELINE_CALENDAR , 'Timeline Calendar' , 'TimelineCalendarScreen' ) }
71+ { renderEntry ( testIDs . menu . WEEK_CALENDAR , 'Week Calendar' , 'ExpandableCalendarScreen' , { weekView : true } ) }
72+ < View style = { styles . switchContainer } >
73+ < Text > Force RTL</ Text >
74+ < Switch value = { forceRTL } onValueChange = { toggleRTL } />
75+ </ View >
76+ </ View >
77+ </ ScrollView >
78+ ) ;
79+ } ;
80+
81+ export default MenuScreen ;
8282
8383const styles = StyleSheet . create ( {
8484 container : {
@@ -94,7 +94,6 @@ const styles = StyleSheet.create({
9494 width : 300 ,
9595 padding : 10 ,
9696 margin : 10 ,
97- // backgroundColor: '#f2F4f5',
9897 alignItems : 'center' ,
9998 borderRadius : 20 ,
10099 borderWidth : 1 ,
0 commit comments