@@ -7,6 +7,7 @@ import {Navigation} from 'react-native-navigation';
7
7
import {
8
8
Assets ,
9
9
Colors ,
10
+ Typography ,
10
11
Spacings ,
11
12
View ,
12
13
Text ,
@@ -19,7 +20,7 @@ import {
19
20
Dividers
20
21
} from 'react-native-ui-lib' ; //eslint-disable-line
21
22
import { navigationData } from './MenuStructure' ;
22
- import Storage , { DEFAULT_SCREEN } from '../storage' ;
23
+ import Storage , { DEFAULT_SCREEN , RECENT_SCREENS } from '../storage' ;
23
24
24
25
const settingsIcon = require ( '../assets/icons/settings.png' ) ;
25
26
const chevronIcon = require ( '../assets/icons/chevronRight.png' ) ;
@@ -52,12 +53,15 @@ class MainScreen extends Component {
52
53
constructor ( props ) {
53
54
super ( props ) ;
54
55
56
+ const recentScreens = Storage . getString ( RECENT_SCREENS ) ;
57
+
55
58
const data = props . navigationData || navigationData ;
56
59
this . state = {
57
60
currentPage : 0 ,
58
61
filteredNavigationData : data ,
59
62
chipsLabels : _ . map ( data , section => section . title ) ,
60
63
sectionsData : _ . map ( data , section => ( { title : section . title , data : section . screens } ) ) ,
64
+ recentScreens : recentScreens ? JSON . parse ( recentScreens ) : [ ] ,
61
65
selectedSection : 0 ,
62
66
faderStart : false ,
63
67
faderEnd : true
@@ -155,8 +159,21 @@ class MainScreen extends Component {
155
159
this . openScreen ( { customValue : item } ) ;
156
160
} ;
157
161
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
+
158
174
openScreen = ( { customValue : row } ) => {
159
175
this . closeSearchBox ( ) ;
176
+ this . updateRecentScreens ( row ) ;
160
177
161
178
setTimeout ( ( ) => {
162
179
this . pushScreen ( row ) ;
@@ -303,6 +320,34 @@ class MainScreen extends Component {
303
320
return < SectionHeader section = { section } /> ;
304
321
} ;
305
322
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
+
306
351
renderItem = ( { item} ) => {
307
352
const { renderItem} = this . props ;
308
353
@@ -337,12 +382,10 @@ class MainScreen extends Component {
337
382
338
383
render ( ) {
339
384
const { containerStyle} = this . props ;
340
- const { filteredNavigationData, filterText} = this . state ;
385
+ const { filteredNavigationData, filterText, chipsLabels , sectionsData } = this . state ;
341
386
const showNoResults = _ . isEmpty ( filteredNavigationData ) && ! ! filterText ;
342
387
const showResults = ! _ . isEmpty ( filteredNavigationData ) && ! ! filterText ;
343
388
const showSectionList = ! filterText ;
344
- const chipsLabels = this . state . chipsLabels ;
345
- const sectionsData = this . state . sectionsData ;
346
389
347
390
return (
348
391
< View testID = "demo_main_screen" flex style = { containerStyle } useSafeArea >
@@ -366,6 +409,8 @@ class MainScreen extends Component {
366
409
</ View >
367
410
) }
368
411
412
+ { this . renderRecentScreens ( ) }
413
+
369
414
{ showSectionList && (
370
415
< SectionList
371
416
sections = { sectionsData }
0 commit comments