@@ -7,6 +7,7 @@ import {Navigation} from 'react-native-navigation';
77import {
88 Assets ,
99 Colors ,
10+ Typography ,
1011 Spacings ,
1112 View ,
1213 Text ,
@@ -19,7 +20,7 @@ import {
1920 Dividers
2021} from 'react-native-ui-lib' ; //eslint-disable-line
2122import { navigationData } from './MenuStructure' ;
22- import Storage , { DEFAULT_SCREEN } from '../storage' ;
23+ import Storage , { DEFAULT_SCREEN , RECENT_SCREENS } from '../storage' ;
2324
2425const settingsIcon = require ( '../assets/icons/settings.png' ) ;
2526const chevronIcon = require ( '../assets/icons/chevronRight.png' ) ;
@@ -52,12 +53,15 @@ class MainScreen extends Component {
5253 constructor ( props ) {
5354 super ( props ) ;
5455
56+ const recentScreens = Storage . getString ( RECENT_SCREENS ) ;
57+
5558 const data = props . navigationData || navigationData ;
5659 this . state = {
5760 currentPage : 0 ,
5861 filteredNavigationData : data ,
5962 chipsLabels : _ . map ( data , section => section . title ) ,
6063 sectionsData : _ . map ( data , section => ( { title : section . title , data : section . screens } ) ) ,
64+ recentScreens : recentScreens ? JSON . parse ( recentScreens ) : [ ] ,
6165 selectedSection : 0 ,
6266 faderStart : false ,
6367 faderEnd : true
@@ -155,8 +159,21 @@ class MainScreen extends Component {
155159 this . openScreen ( { customValue : item } ) ;
156160 } ;
157161
162+ updateRecentScreens ( screen ) {
163+ const { recentScreens} = this . state ;
164+ recentScreens . unshift ( screen ) ;
165+ const uniqueArr = [ ...new Set ( recentScreens . map ( item => JSON . stringify ( item ) ) ) ] . map ( item => JSON . parse ( item ) ) ;
166+
167+ Storage . set ( RECENT_SCREENS , JSON . stringify ( uniqueArr ) ) ;
168+
169+ this . setState ( {
170+ recentScreens : uniqueArr
171+ } ) ;
172+ }
173+
158174 openScreen = ( { customValue : row } ) => {
159175 this . closeSearchBox ( ) ;
176+ this . updateRecentScreens ( row ) ;
160177
161178 setTimeout ( ( ) => {
162179 this . pushScreen ( row ) ;
@@ -303,6 +320,34 @@ class MainScreen extends Component {
303320 return < SectionHeader section = { section } /> ;
304321 } ;
305322
323+ renderRecentScreens = ( ) => {
324+ const { recentScreens} = this . state ;
325+
326+ if ( recentScreens . length > 0 ) {
327+ return (
328+ < View row paddingV-s2 paddingH-s5 centerV >
329+ < Text text90BO marginR-s2 >
330+ Recent:
331+ </ Text >
332+ < ScrollView horizontal showsHorizontalScrollIndicator = { false } >
333+ { recentScreens . map ( screen => {
334+ return (
335+ < Chip
336+ marginR-s2
337+ label = { screen . title }
338+ key = { screen . title }
339+ onPress = { this . openScreen }
340+ customValue = { screen }
341+ labelStyle = { Typography . text100BO }
342+ />
343+ ) ;
344+ } ) }
345+ </ ScrollView >
346+ </ View >
347+ ) ;
348+ }
349+ } ;
350+
306351 renderItem = ( { item} ) => {
307352 const { renderItem} = this . props ;
308353
@@ -337,12 +382,10 @@ class MainScreen extends Component {
337382
338383 render ( ) {
339384 const { containerStyle} = this . props ;
340- const { filteredNavigationData, filterText} = this . state ;
385+ const { filteredNavigationData, filterText, chipsLabels , sectionsData } = this . state ;
341386 const showNoResults = _ . isEmpty ( filteredNavigationData ) && ! ! filterText ;
342387 const showResults = ! _ . isEmpty ( filteredNavigationData ) && ! ! filterText ;
343388 const showSectionList = ! filterText ;
344- const chipsLabels = this . state . chipsLabels ;
345- const sectionsData = this . state . sectionsData ;
346389
347390 return (
348391 < View testID = "demo_main_screen" flex style = { containerStyle } useSafeArea >
@@ -366,6 +409,8 @@ class MainScreen extends Component {
366409 </ View >
367410 ) }
368411
412+ { this . renderRecentScreens ( ) }
413+
369414 { showSectionList && (
370415 < SectionList
371416 sections = { sectionsData }
0 commit comments