Skip to content

Commit f553217

Browse files
committed
Merge branch 'master' into release
2 parents 128e995 + a74c326 commit f553217

37 files changed

+3426
-2161
lines changed

.eslintrc.js

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module.exports = {
1212
// TODO: remove after migration of legacy lifecycle methods
1313
camelcase: 'off',
1414
'comma-dangle': ['error', 'never'],
15+
complexity: ['warn', {max: 25}],
1516
'no-mixed-operators': ['off'],
1617
'no-trailing-spaces': 'off',
1718
'operator-linebreak': 'off',

demo/src/screens/MainScreen.js

+49-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {Navigation} from 'react-native-navigation';
77
import {
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
2122
import {navigationData} from './MenuStructure';
22-
import Storage, {DEFAULT_SCREEN} from '../storage';
23+
import Storage, {DEFAULT_SCREEN, RECENT_SCREENS} from '../storage';
2324

2425
const settingsIcon = require('../assets/icons/settings.png');
2526
const 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}

demo/src/screens/SettingsScreen.js

+28-25
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import _ from 'lodash';
22
import React, {Component} from 'react';
33
import {StyleSheet, I18nManager} from 'react-native';
4-
import {Colors, View, Text, Picker, Incubator, Switch} from 'react-native-ui-lib'; //eslint-disable-line
4+
import {Colors, View, Text, Picker, Incubator, Switch, Spacings} from 'react-native-ui-lib'; //eslint-disable-line
55
import {navigationData} from './MenuStructure';
66
import Storage, {DEFAULT_SCREEN, IS_RTL} from '../storage';
77

@@ -66,10 +66,15 @@ class SettingsScreen extends Component {
6666
const {extraSettingsUI} = this.props;
6767
const filteredScreens = _.filter(screens, screen => !_.isUndefined(screen.value));
6868

69+
const _extraSettingsUI = extraSettingsUI?.();
70+
6971
return (
7072
<View flex padding-25 bg-grey80>
71-
<View flex>
72-
<Text text60>Default Screen</Text>
73+
<Text text40 marginB-s5>
74+
Settings
75+
</Text>
76+
77+
<View style={styles.block}>
7378
<Text text70 marginB-20>
7479
Set default screen to open on app startup
7580
</Text>
@@ -82,31 +87,27 @@ class SettingsScreen extends Component {
8287
onChange={this.setDefaultScreen}
8388
items={filteredScreens}
8489
/>
90+
</View>
8591

86-
<View style={{borderWidth: 1, borderColor: Colors.grey70, marginTop: 40}}>
87-
<View style={[{padding: 5, borderBottomWidth: 1}, styles.block]}>
88-
<Text text80 grey20>
89-
Current layout direction
90-
</Text>
91-
</View>
92-
<View center margin-5 padding-10>
93-
<Text text70>{isRTL ? 'RIGHT to LEFT' : 'LEFT to RIGHT'}</Text>
94-
</View>
95-
96-
<View row spread centerV style={[{padding: 12, borderTopWidth: 1}, styles.block]}>
97-
<Switch value={isRTL} onValueChange={this.onDirectionChange}/>
98-
<Text text80 grey20>
99-
Force RTL
100-
</Text>
101-
</View>
92+
<View style={styles.block} marginT-s4>
93+
<View row spread centerV>
94+
<Text text80 grey20>
95+
Force RTL
96+
</Text>
97+
<Switch value={isRTL} onValueChange={this.onDirectionChange}/>
10298
</View>
10399

104-
{extraSettingsUI?.()}
100+
<View center marginT-5>
101+
<Text text70>{isRTL ? 'RIGHT to LEFT' : 'LEFT to RIGHT'}</Text>
102+
</View>
105103
</View>
106104

107-
<Text text30 grey10>
108-
Settings
109-
</Text>
105+
{_extraSettingsUI && (
106+
<View marginT-s4 style={styles.block}>
107+
{_extraSettingsUI}
108+
</View>
109+
)}
110+
110111
<Incubator.Toast
111112
visible={showRefreshMessage}
112113
message={`Default screen set to: ${defaultScreen?.label}. Please refresh the app.`}
@@ -118,8 +119,10 @@ class SettingsScreen extends Component {
118119

119120
const styles = StyleSheet.create({
120121
block: {
121-
borderColor: Colors.grey70,
122-
backgroundColor: Colors.grey80
122+
borderWidth: 1,
123+
borderColor: Colors.$outlineNeutral,
124+
backgroundColor: Colors.grey80,
125+
padding: Spacings.s3
123126
}
124127
});
125128

0 commit comments

Comments
 (0)