Skip to content

Commit 4635e6d

Browse files
committed
chore: load icon module
1 parent 1ff6b27 commit 4635e6d

24 files changed

+200
-1244
lines changed

src/components/MaterialCommunityIcon.tsx

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from 'react';
22
import { ComponentProps } from 'react';
3-
import { StyleSheet, Text, Platform, ViewProps, Role } from 'react-native';
3+
import { StyleSheet, Text, Platform, Role, ViewProps } from 'react-native';
44

55
import { black } from '../styles/themes/v2/colors';
66

@@ -23,19 +23,31 @@ type AccessibilityProps =
2323
importantForAccessibility?: 'auto' | 'yes' | 'no' | 'no-hide-descendants';
2424
};
2525

26+
const loadIconModule = () => {
27+
try {
28+
return require('@react-native-vector-icons/material-design-icons').default;
29+
} catch (e) {
30+
try {
31+
return require('react-native-vector-icons/MaterialCommunityIcons')
32+
.default;
33+
} catch (e) {
34+
return null;
35+
}
36+
}
37+
};
38+
2639
let MaterialCommunityIcons: React.ComponentType<
2740
React.ComponentProps<
28-
typeof import('@react-native-vector-icons/material-design-icons').default
41+
| typeof import('@react-native-vector-icons/material-design-icons').default
42+
| typeof import('react-native-vector-icons/MaterialCommunityIcons').default
2943
> & {
3044
color: string;
3145
pointerEvents?: ViewProps['pointerEvents'];
3246
}
3347
>;
3448

3549
try {
36-
// Optionally require vector-icons
37-
MaterialCommunityIcons =
38-
require('@react-native-vector-icons/material-design-icons').default;
50+
MaterialCommunityIcons = loadIconModule();
3951
} catch (e) {
4052
let isErrorLogged = false;
4153

@@ -52,8 +64,9 @@ try {
5264
}
5365

5466
console.warn(
55-
`Tried to use the icon '${name}' in a component from 'react-native-paper', but 'react-native-vector-icons/MaterialCommunityIcons' could not be loaded.`,
56-
`To remove this warning, try installing 'react-native-vector-icons' or use another method to specify icon: https://callstack.github.io/react-native-paper/docs/guides/icons`
67+
`Tried to use the icon '${name}' in a component from 'react-native-paper', but '@react-native-vector-icons/material-design-icons' or 'react-native-vector-icons/MaterialCommunityIcons' could not be loaded.`,
68+
`To remove this warning, try installing '@react-native-vector-icons/common' along with @react-native-vector-icons/material-design-icons' or 'react-native-vector-icons'.
69+
You can also use another method to specify icon: https://callstack.github.io/react-native-paper/docs/guides/icons`
5770
);
5871

5972
isErrorLogged = true;

src/components/__tests__/Appbar/__snapshots__/Appbar.test.tsx.snap

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ exports[`Appbar does not pass any additional props to Searchbar 1`] = `
183183
>
184184
<Text
185185
accessibilityElementsHidden={true}
186-
allowFontScaling={false}
187186
importantForAccessibility="no-hide-descendants"
188187
pointerEvents="none"
189188
selectable={false}
@@ -206,16 +205,10 @@ exports[`Appbar does not pass any additional props to Searchbar 1`] = `
206205
"backgroundColor": "transparent",
207206
},
208207
],
209-
{
210-
"fontFamily": "Material Design Icons",
211-
"fontStyle": "normal",
212-
"fontWeight": "normal",
213-
},
214-
{},
215208
]
216209
}
217210
>
218-
󰍉
211+
magnify
219212
</Text>
220213
</View>
221214
</View>
@@ -374,7 +367,6 @@ exports[`Appbar does not pass any additional props to Searchbar 1`] = `
374367
>
375368
<Text
376369
accessibilityElementsHidden={true}
377-
allowFontScaling={false}
378370
importantForAccessibility="no-hide-descendants"
379371
pointerEvents="none"
380372
selectable={false}
@@ -397,16 +389,10 @@ exports[`Appbar does not pass any additional props to Searchbar 1`] = `
397389
"backgroundColor": "transparent",
398390
},
399391
],
400-
{
401-
"fontFamily": "Material Design Icons",
402-
"fontStyle": "normal",
403-
"fontWeight": "normal",
404-
},
405-
{},
406392
]
407393
}
408394
>
409-
󰅖
395+
close
410396
</Text>
411397
</View>
412398
</View>
@@ -838,7 +824,6 @@ exports[`Appbar passes additional props to AppbarBackAction, AppbarContent and A
838824
>
839825
<Text
840826
accessibilityElementsHidden={true}
841-
allowFontScaling={false}
842827
importantForAccessibility="no-hide-descendants"
843828
pointerEvents="none"
844829
selectable={false}
@@ -861,16 +846,10 @@ exports[`Appbar passes additional props to AppbarBackAction, AppbarContent and A
861846
"backgroundColor": "transparent",
862847
},
863848
],
864-
{
865-
"fontFamily": "Material Design Icons",
866-
"fontStyle": "normal",
867-
"fontWeight": "normal",
868-
},
869-
{},
870849
]
871850
}
872851
>
873-
󰍜
852+
menu
874853
</Text>
875854
</View>
876855
</View>

src/components/__tests__/Checkbox/__snapshots__/Checkbox.test.tsx.snap

Lines changed: 7 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,10 @@ exports[`renders Checkbox with custom testID 1`] = `
7878
"backgroundColor": "transparent",
7979
},
8080
],
81-
{
82-
"fontFamily": "Material Design Icons",
83-
"fontStyle": "normal",
84-
"fontWeight": "normal",
85-
},
86-
{},
8781
]
8882
}
8983
>
90-
󰄬
84+
check
9185
</Text>
9286
</View>
9387
</View>
@@ -171,16 +165,10 @@ exports[`renders checked Checkbox with color 1`] = `
171165
"backgroundColor": "transparent",
172166
},
173167
],
174-
{
175-
"fontFamily": "Material Design Icons",
176-
"fontStyle": "normal",
177-
"fontWeight": "normal",
178-
},
179-
{},
180168
]
181169
}
182170
>
183-
󰄬
171+
check
184172
</Text>
185173
</View>
186174
</View>
@@ -263,16 +251,10 @@ exports[`renders checked Checkbox with onPress 1`] = `
263251
"backgroundColor": "transparent",
264252
},
265253
],
266-
{
267-
"fontFamily": "Material Design Icons",
268-
"fontStyle": "normal",
269-
"fontWeight": "normal",
270-
},
271-
{},
272254
]
273255
}
274256
>
275-
󰄬
257+
check
276258
</Text>
277259
</View>
278260
</View>
@@ -355,16 +337,10 @@ exports[`renders indeterminate Checkbox 1`] = `
355337
"backgroundColor": "transparent",
356338
},
357339
],
358-
{
359-
"fontFamily": "Material Design Icons",
360-
"fontStyle": "normal",
361-
"fontWeight": "normal",
362-
},
363-
{},
364340
]
365341
}
366342
>
367-
󰍴
343+
minus
368344
</Text>
369345
</View>
370346
</View>
@@ -448,16 +424,10 @@ exports[`renders indeterminate Checkbox with color 1`] = `
448424
"backgroundColor": "transparent",
449425
},
450426
],
451-
{
452-
"fontFamily": "Material Design Icons",
453-
"fontStyle": "normal",
454-
"fontWeight": "normal",
455-
},
456-
{},
457427
]
458428
}
459429
>
460-
󰍴
430+
minus
461431
</Text>
462432
</View>
463433
</View>
@@ -541,16 +511,10 @@ exports[`renders unchecked Checkbox with color 1`] = `
541511
"backgroundColor": "transparent",
542512
},
543513
],
544-
{
545-
"fontFamily": "Material Design Icons",
546-
"fontStyle": "normal",
547-
"fontWeight": "normal",
548-
},
549-
{},
550514
]
551515
}
552516
>
553-
󰄬
517+
check
554518
</Text>
555519
</View>
556520
</View>
@@ -633,16 +597,10 @@ exports[`renders unchecked Checkbox with onPress 1`] = `
633597
"backgroundColor": "transparent",
634598
},
635599
],
636-
{
637-
"fontFamily": "Material Design Icons",
638-
"fontStyle": "normal",
639-
"fontWeight": "normal",
640-
},
641-
{},
642600
]
643601
}
644602
>
645-
󰄬
603+
check
646604
</Text>
647605
</View>
648606
</View>

src/components/__tests__/Checkbox/__snapshots__/CheckboxItem.test.tsx.snap

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,10 @@ exports[`can render leading checkbox control 1`] = `
132132
"backgroundColor": "transparent",
133133
},
134134
],
135-
{
136-
"fontFamily": "Material Design Icons",
137-
"fontStyle": "normal",
138-
"fontWeight": "normal",
139-
},
140-
{},
141135
]
142136
}
143137
>
144-
󰄬
138+
check
145139
</Text>
146140
</View>
147141
</View>
@@ -364,16 +358,10 @@ exports[`can render the Android checkbox on different platforms 1`] = `
364358
"backgroundColor": "transparent",
365359
},
366360
],
367-
{
368-
"fontFamily": "Material Design Icons",
369-
"fontStyle": "normal",
370-
"fontWeight": "normal",
371-
},
372-
{},
373361
]
374362
}
375363
>
376-
󰄱
364+
checkbox-blank-outline
377365
</Text>
378366
<View
379367
style={
@@ -580,16 +568,10 @@ exports[`can render the iOS checkbox on different platforms 1`] = `
580568
"backgroundColor": "transparent",
581569
},
582570
],
583-
{
584-
"fontFamily": "Material Design Icons",
585-
"fontStyle": "normal",
586-
"fontWeight": "normal",
587-
},
588-
{},
589571
]
590572
}
591573
>
592-
󰄬
574+
check
593575
</Text>
594576
</View>
595577
</View>
@@ -767,16 +749,10 @@ exports[`renders unchecked 1`] = `
767749
"backgroundColor": "transparent",
768750
},
769751
],
770-
{
771-
"fontFamily": "Material Design Icons",
772-
"fontStyle": "normal",
773-
"fontWeight": "normal",
774-
},
775-
{},
776752
]
777753
}
778754
>
779-
󰄬
755+
check
780756
</Text>
781757
</View>
782758
</View>

0 commit comments

Comments
 (0)