rn-erxes-sdk 0.1.4 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/README.md +39 -20
  2. package/lib/commonjs/App.js +9 -44
  3. package/lib/commonjs/App.js.map +1 -1
  4. package/lib/commonjs/FAQ.js +175 -0
  5. package/lib/commonjs/FAQ.js.map +1 -0
  6. package/lib/commonjs/Greetings.js +57 -0
  7. package/lib/commonjs/Greetings.js.map +1 -0
  8. package/lib/commonjs/Social.js +46 -0
  9. package/lib/commonjs/Social.js.map +1 -0
  10. package/lib/commonjs/Support.js +93 -0
  11. package/lib/commonjs/Support.js.map +1 -0
  12. package/lib/commonjs/Supporters.js +73 -0
  13. package/lib/commonjs/Supporters.js.map +1 -0
  14. package/lib/commonjs/Widget.js +132 -0
  15. package/lib/commonjs/Widget.js.map +1 -0
  16. package/lib/commonjs/apolloClient.js +55 -0
  17. package/lib/commonjs/apolloClient.js.map +1 -0
  18. package/lib/commonjs/assets/images/Facebook.png +0 -0
  19. package/lib/commonjs/assets/images/Twitter.png +0 -0
  20. package/lib/commonjs/assets/images/Youtube.png +0 -0
  21. package/lib/commonjs/assets/images/avatar.png +0 -0
  22. package/lib/commonjs/assets/images/index.js +15 -0
  23. package/lib/commonjs/assets/images/index.js.map +1 -0
  24. package/lib/commonjs/graphql/graphql.js +108 -0
  25. package/lib/commonjs/graphql/graphql.js.map +1 -0
  26. package/lib/commonjs/graphql/mutation.js +47 -0
  27. package/lib/commonjs/graphql/mutation.js.map +1 -0
  28. package/lib/commonjs/icons/MaterialCommunityIcons.js +81 -0
  29. package/lib/commonjs/icons/MaterialCommunityIcons.js.map +1 -0
  30. package/lib/module/App.js +9 -44
  31. package/lib/module/App.js.map +1 -1
  32. package/lib/module/FAQ.js +165 -0
  33. package/lib/module/FAQ.js.map +1 -0
  34. package/lib/module/Greetings.js +48 -0
  35. package/lib/module/Greetings.js.map +1 -0
  36. package/lib/module/Social.js +37 -0
  37. package/lib/module/Social.js.map +1 -0
  38. package/lib/module/Support.js +84 -0
  39. package/lib/module/Support.js.map +1 -0
  40. package/lib/module/Supporters.js +64 -0
  41. package/lib/module/Supporters.js.map +1 -0
  42. package/lib/module/Widget.js +123 -0
  43. package/lib/module/Widget.js.map +1 -0
  44. package/lib/module/apolloClient.js +46 -0
  45. package/lib/module/apolloClient.js.map +1 -0
  46. package/lib/module/assets/images/Facebook.png +0 -0
  47. package/lib/module/assets/images/Twitter.png +0 -0
  48. package/lib/module/assets/images/Youtube.png +0 -0
  49. package/lib/module/assets/images/avatar.png +0 -0
  50. package/lib/module/assets/images/index.js +8 -0
  51. package/lib/module/assets/images/index.js.map +1 -0
  52. package/lib/module/graphql/graphql.js +99 -0
  53. package/lib/module/graphql/graphql.js.map +1 -0
  54. package/lib/module/graphql/mutation.js +41 -0
  55. package/lib/module/graphql/mutation.js.map +1 -0
  56. package/lib/module/icons/MaterialCommunityIcons.js +71 -0
  57. package/lib/module/icons/MaterialCommunityIcons.js.map +1 -0
  58. package/lib/typescript/App.d.ts +1 -1
  59. package/lib/typescript/App.d.ts.map +1 -1
  60. package/lib/typescript/FAQ.d.ts +4 -0
  61. package/lib/typescript/FAQ.d.ts.map +1 -0
  62. package/lib/typescript/Greetings.d.ts +4 -0
  63. package/lib/typescript/Greetings.d.ts.map +1 -0
  64. package/lib/typescript/Social.d.ts +4 -0
  65. package/lib/typescript/Social.d.ts.map +1 -0
  66. package/lib/typescript/Support.d.ts +4 -0
  67. package/lib/typescript/Support.d.ts.map +1 -0
  68. package/lib/typescript/Supporters.d.ts +4 -0
  69. package/lib/typescript/Supporters.d.ts.map +1 -0
  70. package/lib/typescript/Widget.d.ts +4 -0
  71. package/lib/typescript/Widget.d.ts.map +1 -0
  72. package/lib/typescript/apolloClient.d.ts +6 -0
  73. package/lib/typescript/apolloClient.d.ts.map +1 -0
  74. package/lib/typescript/assets/images/index.d.ts +8 -0
  75. package/lib/typescript/assets/images/index.d.ts.map +1 -0
  76. package/lib/typescript/graphql/graphql.d.ts +6 -0
  77. package/lib/typescript/graphql/graphql.d.ts.map +1 -0
  78. package/lib/typescript/graphql/mutation.d.ts +3 -0
  79. package/lib/typescript/graphql/mutation.d.ts.map +1 -0
  80. package/lib/typescript/icons/MaterialCommunityIcons.d.ts +22 -0
  81. package/lib/typescript/icons/MaterialCommunityIcons.d.ts.map +1 -0
  82. package/package.json +9 -5
  83. package/src/App.tsx +8 -42
  84. package/src/FAQ.tsx +166 -0
  85. package/src/Greetings.tsx +37 -0
  86. package/src/Social.tsx +46 -0
  87. package/src/Support.tsx +74 -0
  88. package/src/Supporters.tsx +63 -0
  89. package/src/Widget.tsx +138 -0
  90. package/src/apolloClient.ts +57 -0
  91. package/src/assets/images/Facebook.png +0 -0
  92. package/src/assets/images/Twitter.png +0 -0
  93. package/src/assets/images/Youtube.png +0 -0
  94. package/src/assets/images/avatar.png +0 -0
  95. package/src/assets/images/index.ts +8 -0
  96. package/src/graphql/graphql.ts +108 -0
  97. package/src/graphql/mutation.ts +42 -0
  98. package/src/icons/MaterialCommunityIcons.tsx +95 -0
  99. package/lib/commonjs/index.html +0 -114
  100. package/lib/module/index.html +0 -114
  101. package/src/index.html +0 -114
@@ -0,0 +1,37 @@
1
+ /* eslint-disable react-native/no-inline-styles */
2
+ import { View, Text, StyleSheet, SafeAreaView } from 'react-native';
3
+ import React from 'react';
4
+ import Social from './Social';
5
+ import Supporters from './Supporters';
6
+
7
+ const Greetings = (props: any) => {
8
+ const { greetings, bgColor, integrationId } = props;
9
+
10
+ return (
11
+ <SafeAreaView style={{ backgroundColor: bgColor || 'green' }}>
12
+ <View style={[styles.title]}>
13
+ <Social links={greetings?.links} />
14
+ <View style={{ marginTop: 20 }}>
15
+ <Text style={{ fontWeight: '600', fontSize: 18 }}>
16
+ {greetings?.messages?.greetings?.title}
17
+ </Text>
18
+ <Text style={{ marginTop: 20, color: '#393C40' }}>
19
+ {greetings?.messages?.greetings?.message}
20
+ </Text>
21
+ </View>
22
+ <Supporters integrationId={integrationId} />
23
+ </View>
24
+ </SafeAreaView>
25
+ );
26
+ };
27
+
28
+ export default Greetings;
29
+
30
+ const styles = StyleSheet.create({
31
+ title: {
32
+ paddingVertical: 10,
33
+ paddingHorizontal: 10,
34
+ borderTopLeftRadius: 8,
35
+ borderTopRightRadius: 8,
36
+ },
37
+ });
package/src/Social.tsx ADDED
@@ -0,0 +1,46 @@
1
+ /* eslint-disable react-native/no-inline-styles */
2
+ import {
3
+ View,
4
+ StyleSheet,
5
+ TouchableOpacity,
6
+ Image,
7
+ Linking,
8
+ } from 'react-native';
9
+ import React from 'react';
10
+ import images from './assets/images';
11
+
12
+ const Social = (props: any) => {
13
+ const { links } = props;
14
+
15
+ const renderSocial = (link: any, imageUrl: any, index: number) => {
16
+ return (
17
+ <TouchableOpacity
18
+ style={{ marginLeft: index !== 0 ? 10 : 0 }}
19
+ onPress={() => {
20
+ Linking.openURL(link);
21
+ }}
22
+ >
23
+ <Image source={imageUrl} style={styles.image} />
24
+ </TouchableOpacity>
25
+ );
26
+ };
27
+
28
+ return (
29
+ <View style={styles.container}>
30
+ {links?.facebook
31
+ ? renderSocial(links.facebook, images.facebook, 0)
32
+ : null}
33
+ {links?.twitter ? renderSocial(links.twitter, images.twitter, 1) : null}
34
+ {links?.youtube ? renderSocial(links.youtube, images.youtube, 2) : null}
35
+ </View>
36
+ );
37
+ };
38
+
39
+ export default Social;
40
+
41
+ const styles = StyleSheet.create({
42
+ container: {
43
+ flexDirection: 'row',
44
+ },
45
+ image: { width: 30, height: 30, borderRadius: 90 },
46
+ });
@@ -0,0 +1,74 @@
1
+ /* eslint-disable react/no-unstable-nested-components */
2
+ /* eslint-disable react-native/no-inline-styles */
3
+ import { View, Text, StyleSheet, FlatList, Image } from 'react-native';
4
+ import React from 'react';
5
+ import { useQuery } from '@apollo/client';
6
+ import { widgetsConversations } from './graphql/graphql';
7
+ import dayjs from 'dayjs';
8
+ import images from './assets/images';
9
+
10
+ const Support = (props: any) => {
11
+ const { integrationId, customerId } = props;
12
+
13
+ const { data, loading } = useQuery(widgetsConversations, {
14
+ variables: {
15
+ integrationId,
16
+ customerId,
17
+ },
18
+ });
19
+
20
+ if (loading) {
21
+ return null;
22
+ }
23
+
24
+ const renderItem = ({ item, index }: any) => {
25
+ return (
26
+ <View style={{ flexDirection: 'row', alignItems: 'center' }} key={index}>
27
+ <Image source={images.avatar} style={styles.image} />
28
+ <View style={{ marginLeft: 10, flex: 1 }}>
29
+ <Text>Support Staff</Text>
30
+ <Text>{item?.content}</Text>
31
+ </View>
32
+ <Text>{dayjs(item?.createdAt).format('h:mm A')}</Text>
33
+ </View>
34
+ );
35
+ };
36
+
37
+ const renderHeader = () => {
38
+ return <Text>Recent Conversations</Text>;
39
+ };
40
+
41
+ return (
42
+ <View style={styles.container}>
43
+ <FlatList
44
+ data={data?.widgetsConversations}
45
+ renderItem={renderItem}
46
+ keyExtractor={(item) => item.id}
47
+ contentContainerStyle={{ gap: 10 }}
48
+ ItemSeparatorComponent={() => {
49
+ return (
50
+ <View
51
+ style={{ height: 1, backgroundColor: '#000', marginTop: 10 }}
52
+ />
53
+ );
54
+ }}
55
+ ListHeaderComponent={renderHeader()}
56
+ />
57
+ </View>
58
+ );
59
+ };
60
+
61
+ export default Support;
62
+
63
+ const styles = StyleSheet.create({
64
+ container: {
65
+ padding: 10,
66
+ borderRadius: 6,
67
+ flex: 1,
68
+ },
69
+ image: {
70
+ width: 40,
71
+ height: 40,
72
+ borderRadius: 90,
73
+ },
74
+ });
@@ -0,0 +1,63 @@
1
+ /* eslint-disable react-native/no-inline-styles */
2
+ import { View, Image, StyleSheet } from 'react-native';
3
+ import React from 'react';
4
+ import { useQuery } from '@apollo/client';
5
+ import { widgetsMessengerSupporters } from './graphql/graphql';
6
+
7
+ const Supporters = (props: any) => {
8
+ const { integrationId } = props;
9
+
10
+ const { data, loading } = useQuery(widgetsMessengerSupporters, {
11
+ variables: {
12
+ integrationId,
13
+ },
14
+ });
15
+
16
+ if (loading) {
17
+ return null;
18
+ }
19
+
20
+ const supporters = data?.widgetsMessengerSupporters?.supporters;
21
+
22
+ const renderSupporter = (supporter: any, index: number) => {
23
+ const color = supporter?.isOnline ? 'green' : 'white';
24
+ return (
25
+ <View key={index}>
26
+ <Image
27
+ source={{ uri: supporter?.details?.avatar }}
28
+ style={styles.image}
29
+ resizeMode="center"
30
+ />
31
+ <View style={[{ backgroundColor: color }, styles.activeStatus]} />
32
+ </View>
33
+ );
34
+ };
35
+
36
+ return (
37
+ <View style={{ marginTop: 10 }}>
38
+ {supporters
39
+ ?.filter((supporter: any) => supporter?.isActive)
40
+ ?.map((supporter: any, index: number) => {
41
+ return renderSupporter(supporter, index);
42
+ })}
43
+ </View>
44
+ );
45
+ };
46
+
47
+ export default Supporters;
48
+
49
+ const styles = StyleSheet.create({
50
+ image: {
51
+ width: 50,
52
+ height: 50,
53
+ borderRadius: 90,
54
+ },
55
+ activeStatus: {
56
+ width: 15,
57
+ height: 15,
58
+ borderRadius: 90,
59
+ position: 'absolute',
60
+ bottom: 0,
61
+ left: 35,
62
+ },
63
+ });
package/src/Widget.tsx ADDED
@@ -0,0 +1,138 @@
1
+ /* eslint-disable react-native/no-inline-styles */
2
+ import { View, StyleSheet, TouchableOpacity, Text } from 'react-native';
3
+ import React from 'react';
4
+ import { useMutation } from '@apollo/client';
5
+ import { connect } from './graphql/mutation';
6
+ import Greetings from './Greetings';
7
+ import Support from './Support';
8
+ import FAQ from './FAQ';
9
+
10
+ const Widget = (props: any) => {
11
+ const { brandCode } = props;
12
+ const [response, setResponse] = React.useState<any>(null);
13
+ const [index, setIndex] = React.useState<number>(0);
14
+ const [connectMutation] = useMutation(connect);
15
+
16
+ React.useEffect(() => {
17
+ connectMutation({
18
+ variables: {
19
+ brandCode,
20
+ cachedCustomerId: null,
21
+ visitorId: '20675ab50c23e7c8c615a8f4ab9107e2',
22
+ isUser: false,
23
+ },
24
+ })
25
+ .then((res: any) => {
26
+ setResponse(res);
27
+ console.log(res);
28
+ })
29
+ .catch((err) => {
30
+ console.log(err);
31
+ });
32
+ // eslint-disable-next-line react-hooks/exhaustive-deps
33
+ }, []);
34
+
35
+ const bgColor = response?.data?.widgetsMessengerConnect?.uiOptions?.color;
36
+ const integrationId = response?.data?.widgetsMessengerConnect?.integrationId;
37
+ const knowledgeBaseTopicId =
38
+ response?.data?.widgetsMessengerConnect?.messengerData
39
+ ?.knowledgeBaseTopicId;
40
+
41
+ return (
42
+ <View style={styles.container}>
43
+ <Greetings
44
+ greetings={response?.data?.widgetsMessengerConnect?.messengerData}
45
+ bgColor={bgColor}
46
+ integrationId={integrationId}
47
+ />
48
+ <TabBar index={index} setIndex={setIndex} bgColor={bgColor} />
49
+ {index === 0 ? (
50
+ <Support
51
+ customerId={'7o6DA3tFhM5EXRWZX'}
52
+ integrationId={integrationId}
53
+ />
54
+ ) : (
55
+ <FAQ knowledgeBaseTopicId={knowledgeBaseTopicId} />
56
+ )}
57
+ </View>
58
+ );
59
+ };
60
+
61
+ export default Widget;
62
+
63
+ const TabBar = (props: any) => {
64
+ const { index, setIndex, bgColor } = props;
65
+ return (
66
+ <View
67
+ style={{
68
+ backgroundColor: '#fff',
69
+ flexDirection: 'row',
70
+ padding: 3,
71
+ marginBottom: 3,
72
+ borderColor: '#E5E5E5',
73
+ borderWidth: 0.3,
74
+ }}
75
+ >
76
+ <TouchableOpacity onPress={() => setIndex(0)} style={{ flex: 1 }}>
77
+ <View
78
+ style={{
79
+ backgroundColor: index === 0 ? bgColor : 'transparent',
80
+ borderRadius: 5,
81
+ shadowColor: bgColor,
82
+ shadowOffset: {
83
+ width: 0,
84
+ height: index === 0 ? 2 : 0,
85
+ },
86
+ shadowOpacity: 0.5,
87
+ shadowRadius: index === 0 ? 3.84 : 0,
88
+ elevation: index === 0 ? 5 : 0,
89
+ }}
90
+ >
91
+ <Text
92
+ style={{
93
+ textAlign: 'center',
94
+ color: index === 0 ? 'white' : 'black',
95
+ paddingVertical: 10,
96
+ fontWeight: '600',
97
+ }}
98
+ >
99
+ Support
100
+ </Text>
101
+ </View>
102
+ </TouchableOpacity>
103
+ <TouchableOpacity
104
+ onPress={() => setIndex(1)}
105
+ style={{
106
+ flex: 1,
107
+ backgroundColor: index === 1 ? bgColor : 'transparent',
108
+ borderRadius: 5,
109
+ shadowColor: bgColor,
110
+ shadowOffset: {
111
+ width: 0,
112
+ height: index === 1 ? 2 : 0,
113
+ },
114
+ shadowOpacity: 0.5,
115
+ shadowRadius: index === 1 ? 3.84 : 0,
116
+ elevation: index === 1 ? 5 : 0,
117
+ }}
118
+ >
119
+ <Text
120
+ style={{
121
+ paddingVertical: 10,
122
+ color: index === 1 ? 'white' : 'black',
123
+ textAlign: 'center',
124
+ fontWeight: '600',
125
+ }}
126
+ >
127
+ FAQ
128
+ </Text>
129
+ </TouchableOpacity>
130
+ </View>
131
+ );
132
+ };
133
+
134
+ const styles = StyleSheet.create({
135
+ container: {
136
+ flex: 1,
137
+ },
138
+ });
@@ -0,0 +1,57 @@
1
+ import {
2
+ ApolloClient,
3
+ InMemoryCache,
4
+ split,
5
+ from,
6
+ createHttpLink,
7
+ } from '@apollo/client/core';
8
+ import { onError } from '@apollo/client/link/error';
9
+ import { getMainDefinition } from '@apollo/client/utilities';
10
+ import { createClient } from 'graphql-ws';
11
+ import { GraphQLWsLink } from '@apollo/client/link/subscriptions';
12
+
13
+ const baseUrl = 'office.erxes.io/gateway';
14
+
15
+ export const apiUrl = `https://${baseUrl}`;
16
+
17
+ // Subscription config
18
+ export const wsLink: any = new GraphQLWsLink(
19
+ createClient({
20
+ url: `wss://${baseUrl}/graphql` || 'ws://localhost:4000/graphql',
21
+ retryAttempts: 1000,
22
+ retryWait: async () => {
23
+ await new Promise((resolve) => setTimeout(resolve, 5000));
24
+ },
25
+ })
26
+ );
27
+
28
+ const logoutLink = onError(({ networkError, graphQLErrors }) => {
29
+ console.log('--netError', networkError);
30
+ console.log('--gqlError', graphQLErrors);
31
+ });
32
+
33
+ const httpLink = createHttpLink({
34
+ uri: `${apiUrl}/graphql`,
35
+ credentials: 'include',
36
+ });
37
+
38
+ const splitLink = split(
39
+ ({ query }) => {
40
+ const definition = getMainDefinition(query);
41
+ return (
42
+ definition.kind === 'OperationDefinition' &&
43
+ definition.operation === 'subscription'
44
+ );
45
+ },
46
+ wsLink,
47
+ from([logoutLink, httpLink])
48
+ );
49
+
50
+ const ClientProvider = () =>
51
+ new ApolloClient({
52
+ link: splitLink,
53
+ cache: new InMemoryCache(),
54
+ defaultOptions: { watchQuery: { fetchPolicy: 'network-only' } },
55
+ });
56
+
57
+ export default ClientProvider;
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,8 @@
1
+ const images = {
2
+ facebook: require('./Facebook.png'),
3
+ youtube: require('./Youtube.png'),
4
+ twitter: require('./Twitter.png'),
5
+ avatar: require('./avatar.png'),
6
+ };
7
+
8
+ export default images;
@@ -0,0 +1,108 @@
1
+ import { gql } from '@apollo/client';
2
+
3
+ const widgetsMessengerSupporters = gql`
4
+ query widgetsMessengerSupporters($integrationId: String!) {
5
+ widgetsMessengerSupporters(integrationId: $integrationId) {
6
+ supporters {
7
+ _id
8
+ isActive
9
+ details {
10
+ avatar
11
+ fullName
12
+ shortName
13
+ location
14
+ __typename
15
+ }
16
+ isOnline
17
+ __typename
18
+ }
19
+ isOnline
20
+ __typename
21
+ }
22
+ }
23
+ `;
24
+
25
+ const widgetsConversations = gql`
26
+ query widgetsConversations(
27
+ $integrationId: String!
28
+ $customerId: String
29
+ $visitorId: String
30
+ ) {
31
+ widgetsConversations(
32
+ integrationId: $integrationId
33
+ customerId: $customerId
34
+ visitorId: $visitorId
35
+ ) {
36
+ _id
37
+ content
38
+ createdAt
39
+ participatedUsers {
40
+ details {
41
+ avatar
42
+ fullName
43
+ __typename
44
+ }
45
+ __typename
46
+ }
47
+ __typename
48
+ }
49
+ }
50
+ `;
51
+
52
+ const knowledgeBaseTopicDetail = gql`
53
+ query knowledgeBaseTopicDetail($_id: String!) {
54
+ knowledgeBaseTopicDetail(_id: $_id) {
55
+ title
56
+ description
57
+ categories {
58
+ _id
59
+ title
60
+ description
61
+ numOfArticles
62
+ parentCategoryId
63
+ icon
64
+ __typename
65
+ }
66
+ parentCategories {
67
+ _id
68
+ title
69
+ description
70
+ numOfArticles
71
+ parentCategoryId
72
+ icon
73
+ __typename
74
+ }
75
+ __typename
76
+ }
77
+ }
78
+ `;
79
+
80
+ const knowledgeBaseCategoryDetail = gql`
81
+ query knowledgeBaseCategoryDetail($_id: String!) {
82
+ knowledgeBaseCategoryDetail(_id: $_id) {
83
+ _id
84
+ title
85
+ description
86
+ numOfArticles
87
+ parentCategoryId
88
+ icon
89
+ parentCategoryId
90
+ articles {
91
+ _id
92
+ title
93
+ summary
94
+ content
95
+ createdDate
96
+ __typename
97
+ }
98
+ __typename
99
+ }
100
+ }
101
+ `;
102
+
103
+ export {
104
+ widgetsMessengerSupporters,
105
+ widgetsConversations,
106
+ knowledgeBaseTopicDetail,
107
+ knowledgeBaseCategoryDetail,
108
+ };
@@ -0,0 +1,42 @@
1
+ import { gql } from '@apollo/client';
2
+
3
+ const connect = gql`
4
+ mutation connect(
5
+ $brandCode: String!
6
+ $email: String
7
+ $phone: String
8
+ $code: String
9
+ $isUser: Boolean
10
+ $data: JSON
11
+ $companyData: JSON
12
+ $cachedCustomerId: String
13
+ $visitorId: String
14
+ ) {
15
+ widgetsMessengerConnect(
16
+ brandCode: $brandCode
17
+ email: $email
18
+ phone: $phone
19
+ code: $code
20
+ isUser: $isUser
21
+ data: $data
22
+ companyData: $companyData
23
+ cachedCustomerId: $cachedCustomerId
24
+ visitorId: $visitorId
25
+ ) {
26
+ integrationId
27
+ messengerData
28
+ languageCode
29
+ uiOptions
30
+ customerId
31
+ visitorId
32
+ brand {
33
+ name
34
+ description
35
+ __typename
36
+ }
37
+ __typename
38
+ }
39
+ }
40
+ `;
41
+
42
+ export { connect };
@@ -0,0 +1,95 @@
1
+ import * as React from 'react';
2
+ import { StyleSheet, Text, Platform } from 'react-native';
3
+
4
+ export type IconProps = {
5
+ name: string;
6
+ color: string;
7
+ size: number;
8
+ direction: 'rtl' | 'ltr';
9
+ allowFontScaling?: boolean;
10
+ };
11
+
12
+ let MaterialCommunityIcons: any;
13
+
14
+ try {
15
+ // Optionally require vector-icons
16
+ MaterialCommunityIcons =
17
+ require('react-native-vector-icons/MaterialCommunityIcons').default;
18
+ } catch (e) {
19
+ let isErrorLogged = false;
20
+
21
+ // Fallback component for icons
22
+ MaterialCommunityIcons = ({ color, size, ...rest }: any) => {
23
+ if (!isErrorLogged) {
24
+ if (
25
+ !/(Cannot find module|Module not found|Cannot resolve module)/.test(
26
+ (e as any).message
27
+ )
28
+ ) {
29
+ console.error(e);
30
+ }
31
+
32
+ console.warn(
33
+ `To remove this warning, try installing 'react-native-vector-icons'`
34
+ );
35
+
36
+ isErrorLogged = true;
37
+ }
38
+
39
+ return (
40
+ <Text
41
+ {...rest}
42
+ style={[styles.icon, { color, fontSize: size }]}
43
+ pointerEvents="none"
44
+ selectable={false}
45
+ >
46
+
47
+ </Text>
48
+ );
49
+ };
50
+ }
51
+
52
+ export const accessibilityProps =
53
+ Platform.OS === 'web'
54
+ ? {
55
+ role: 'img',
56
+ focusable: false,
57
+ }
58
+ : {
59
+ accessibilityElementsHidden: true,
60
+ importantForAccessibility:
61
+ 'no-hide-descendants' as 'no-hide-descendants',
62
+ };
63
+
64
+ const defaultIcon = ({
65
+ name,
66
+ color,
67
+ size,
68
+ direction,
69
+ allowFontScaling,
70
+ }: IconProps) => (
71
+ <MaterialCommunityIcons
72
+ allowFontScaling={allowFontScaling}
73
+ name={name}
74
+ color={color}
75
+ size={size}
76
+ style={[
77
+ {
78
+ transform: [{ scaleX: direction === 'rtl' ? -1 : 1 }],
79
+ lineHeight: size,
80
+ },
81
+ styles.icon,
82
+ ]}
83
+ pointerEvents="none"
84
+ selectable={false}
85
+ {...accessibilityProps}
86
+ />
87
+ );
88
+
89
+ const styles = StyleSheet.create({
90
+ icon: {
91
+ backgroundColor: 'transparent',
92
+ },
93
+ });
94
+
95
+ export default defaultIcon;