Browse Source

removed more arrow functions

keplyx 4 years ago
parent
commit
67357227c0
3 changed files with 53 additions and 34 deletions
  1. 4
    2
      App.js
  2. 6
    11
      components/EventDashboardItem.js
  3. 43
    21
      screens/About/AboutScreen.js

+ 4
- 2
App.js View File

@@ -37,18 +37,20 @@ export default class App extends React.Component<Props, State> {
37 37
     };
38 38
 
39 39
     onIntroDone: Function;
40
+    onUpdateTheme: Function;
40 41
 
41 42
     constructor() {
42 43
         super();
43 44
         LocaleManager.initTranslations();
44 45
         this.onIntroDone = this.onIntroDone.bind(this);
46
+        this.onUpdateTheme = this.onUpdateTheme.bind(this);
45 47
         SplashScreen.preventAutoHide();
46 48
     }
47 49
 
48 50
     /**
49 51
      * Updates the theme
50 52
      */
51
-    updateTheme() {
53
+    onUpdateTheme() {
52 54
         this.setState({
53 55
             currentTheme: ThemeManager.getCurrentTheme()
54 56
         });
@@ -86,7 +88,7 @@ export default class App extends React.Component<Props, State> {
86 88
     async loadAssetsAsync() {
87 89
         // Wait for custom fonts to be loaded before showing the app
88 90
         await AsyncStorageManager.getInstance().loadPreferences();
89
-        ThemeManager.getInstance().setUpdateThemeCallback(() => this.updateTheme());
91
+        ThemeManager.getInstance().setUpdateThemeCallback(this.onUpdateTheme);
90 92
         // await NotificationsManager.initExpoToken();
91 93
         this.onLoadFinished();
92 94
     }

+ 6
- 11
components/EventDashboardItem.js View File

@@ -3,16 +3,6 @@
3 3
 import * as React from 'react';
4 4
 import {Avatar, Card, withTheme} from 'react-native-paper';
5 5
 
6
-function getIcon(icon, color) {
7
-    return (
8
-        <Avatar.Icon
9
-            icon={icon}
10
-            color={color}
11
-            size={60}
12
-            style={{backgroundColor: 'transparent'}}/>
13
-    );
14
-}
15
-
16 6
 function EventDashBoardItem(props) {
17 7
     const {colors} = props.theme;
18 8
     const iconColor = props.isAvailable ?
@@ -37,7 +27,12 @@ function EventDashBoardItem(props) {
37 27
                 titleStyle={{color: textColor}}
38 28
                 subtitle={props.subtitle}
39 29
                 subtitleStyle={{color: textColor}}
40
-                left={() => getIcon(props.icon, iconColor)}
30
+                left={() =>
31
+                    <Avatar.Icon
32
+                        icon={props.icon}
33
+                        color={iconColor}
34
+                        size={60}
35
+                        style={{backgroundColor: 'transparent'}}/>}
41 36
             />
42 37
             <Card.Content>
43 38
                 {props.children}

+ 43
- 21
screens/About/AboutScreen.js View File

@@ -186,33 +186,47 @@ class AboutScreen extends React.Component<Props, State> {
186 186
     getCardItem: Function;
187 187
     getMainCard: Function;
188 188
     onModalRef: Function;
189
+    onPressMail: Function;
190
+    onPressGit: Function;
189 191
 
190
-    colors: object;
192
+    colors: Object;
191 193
 
192 194
     constructor(props) {
193 195
         super(props);
194 196
         this.getCardItem = this.getCardItem.bind(this);
195 197
         this.getMainCard = this.getMainCard.bind(this);
196 198
         this.onModalRef = this.onModalRef.bind(this);
199
+        this.onPressMail = openWebLink.bind(this, links.bugsMail);
200
+        this.onPressGit = openWebLink.bind(this, links.bugsGit);
197 201
         this.colors = props.theme.colors;
198 202
     }
199 203
 
204
+    getAppIcon(props) {
205
+        return (
206
+            <Avatar.Image
207
+                {...props}
208
+                source={require('../../assets/android.icon.png')}
209
+                style={{backgroundColor: 'transparent'}}
210
+            />
211
+        );
212
+    }
213
+
214
+    keyExtractor(item: Object) {
215
+        return item.icon;
216
+    }
217
+
200 218
     getAppCard() {
201 219
         return (
202 220
             <Card style={{marginBottom: 10}}>
203 221
                 <Card.Title
204 222
                     title={appJson.expo.name}
205 223
                     subtitle={appJson.expo.version}
206
-                    left={(props) => <Avatar.Image
207
-                        {...props}
208
-                        source={require('../../assets/android.icon.png')}
209
-                        style={{backgroundColor: 'transparent'}}
210
-                    />}/>
224
+                    left={this.getAppIcon}/>
211 225
                 <Card.Content>
212 226
                     <FlatList
213 227
                         data={this.appData}
214 228
                         extraData={this.state}
215
-                        keyExtractor={(item) => item.icon}
229
+                        keyExtractor={this.keyExtractor}
216 230
                         listKey={"app"}
217 231
                         renderItem={this.getCardItem}
218 232
                     />
@@ -232,7 +246,7 @@ class AboutScreen extends React.Component<Props, State> {
232 246
                     <FlatList
233 247
                         data={this.authorData}
234 248
                         extraData={this.state}
235
-                        keyExtractor={(item) => item.icon}
249
+                        keyExtractor={this.keyExtractor}
236 250
                         listKey={"team1"}
237 251
                         renderItem={this.getCardItem}
238 252
                     />
@@ -240,7 +254,7 @@ class AboutScreen extends React.Component<Props, State> {
240 254
                     <FlatList
241 255
                         data={this.additionalDevData}
242 256
                         extraData={this.state}
243
-                        keyExtractor={(item) => item.icon}
257
+                        keyExtractor={this.keyExtractor}
244 258
                         listKey={"team2"}
245 259
                         renderItem={this.getCardItem}
246 260
                     />
@@ -257,7 +271,7 @@ class AboutScreen extends React.Component<Props, State> {
257 271
                     <FlatList
258 272
                         data={this.technoData}
259 273
                         extraData={this.state}
260
-                        keyExtractor={(item) => item.icon}
274
+                        keyExtractor={this.keyExtractor}
261 275
                         listKey={"techno"}
262 276
                         renderItem={this.getCardItem}
263 277
                     />
@@ -266,6 +280,18 @@ class AboutScreen extends React.Component<Props, State> {
266 280
         );
267 281
     }
268 282
 
283
+    getChevronIcon(props: Object) {
284
+        return (
285
+            <List.Icon {...props} icon={'chevron-right'}/>
286
+        );
287
+    }
288
+
289
+    getItemIcon(item: Object, props: Object) {
290
+        return (
291
+            <List.Icon {...props} icon={item.icon}/>
292
+        );
293
+    }
294
+
269 295
     /**
270 296
      * Get a clickable card item to be rendered inside a card.
271 297
      *
@@ -273,13 +299,14 @@ class AboutScreen extends React.Component<Props, State> {
273 299
      */
274 300
     getCardItem({item}: Object) {
275 301
         let shouldShow = !item.showOnlyInDebug || (item.showOnlyInDebug && this.state.isDebugUnlocked);
302
+        const getItemIcon = this.getItemIcon.bind(this, item);
276 303
         if (shouldShow) {
277 304
             if (item.showChevron) {
278 305
                 return (
279 306
                     <List.Item
280 307
                         title={item.text}
281
-                        left={props => <List.Icon {...props} icon={item.icon}/>}
282
-                        right={props => <List.Icon {...props} icon={'chevron-right'}/>}
308
+                        left={getItemIcon}
309
+                        right={this.getChevronIcon}
283 310
                         onPress={item.onPressCallback}
284 311
                     />
285 312
                 );
@@ -287,16 +314,13 @@ class AboutScreen extends React.Component<Props, State> {
287 314
                 return (
288 315
                     <List.Item
289 316
                         title={item.text}
290
-                        left={props => <List.Icon {...props} icon={item.icon}/>}
317
+                        left={getItemIcon}
291 318
                         onPress={item.onPressCallback}
292 319
                     />
293 320
                 );
294 321
             }
295
-
296
-        } else {
322
+        } else
297 323
             return null;
298
-        }
299
-
300 324
     }
301 325
 
302 326
     tryUnlockDebugMode() {
@@ -313,8 +337,6 @@ class AboutScreen extends React.Component<Props, State> {
313 337
     }
314 338
 
315 339
     getBugReportModal() {
316
-        const onPressMail = openWebLink.bind(this, links.bugsMail);
317
-        const onPressGit = openWebLink.bind(this, links.bugsGit);
318 340
         return (
319 341
             <View style={{
320 342
                 flex: 1,
@@ -334,7 +356,7 @@ class AboutScreen extends React.Component<Props, State> {
334 356
                         marginLeft: 'auto',
335 357
                         marginRight: 'auto',
336 358
                     }}
337
-                    onPress={onPressMail}>
359
+                    onPress={this.onPressMail}>
338 360
                     <Text>{i18n.t('aboutScreen.bugsMail')}</Text>
339 361
                 </Button>
340 362
                 <Button
@@ -347,7 +369,7 @@ class AboutScreen extends React.Component<Props, State> {
347 369
                         marginLeft: 'auto',
348 370
                         marginRight: 'auto',
349 371
                     }}
350
-                    onPress={onPressGit}>
372
+                    onPress={this.onPressGit}>
351 373
                     <Text>{i18n.t('aboutScreen.bugsGit')}</Text>
352 374
                 </Button>
353 375
             </View>

Loading…
Cancel
Save