@holper/react-native-holper-storybook 0.7.1 → 0.8.0

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 (92) hide show
  1. package/index.js +2 -3
  2. package/lib/components/Button/index.js +104 -0
  3. package/lib/components/Button/{style.ts → style.js} +7 -8
  4. package/lib/components/Card/index.js +49 -0
  5. package/lib/components/Card/{style.ts → style.js} +4 -5
  6. package/lib/components/ConfirmationModal/{index.tsx → index.js} +79 -25
  7. package/lib/components/ConfirmationModal/{style.tsx → style.js} +13 -14
  8. package/lib/components/Container/{index.tsx → index.js} +28 -7
  9. package/lib/components/Container/{style.ts → style.js} +5 -6
  10. package/lib/components/CustomChatView/{index.tsx → index.js} +30 -22
  11. package/lib/components/CustomChatView/{style.ts → style.js} +1 -1
  12. package/lib/components/DeckSwiper/index.js +118 -0
  13. package/lib/components/DeckSwiper/{style.ts → style.js} +12 -13
  14. package/lib/components/FlashMessage/index.js +83 -0
  15. package/lib/components/FloatingContainer/index.js +69 -0
  16. package/lib/components/FloatingContainer/{style.ts → style.js} +6 -7
  17. package/lib/components/Footer/index.js +61 -0
  18. package/lib/components/Footer/{style.ts → style.js} +3 -4
  19. package/lib/components/Header/index.js +45 -0
  20. package/lib/components/Header/{style.ts → style.js} +3 -4
  21. package/lib/components/ImagePicker/{index.tsx → index.js} +12 -3
  22. package/lib/components/ImageResponsive/index.js +39 -0
  23. package/lib/components/ImageResponsive/style.js +7 -0
  24. package/lib/components/ImageViewer/index.js +62 -0
  25. package/lib/components/ImageViewer/{style.ts → style.js} +3 -4
  26. package/lib/components/Input/{index.tsx → index.js} +33 -6
  27. package/lib/components/Input/{style.ts → style.js} +18 -7
  28. package/lib/components/InputPin/{index.tsx → index.js} +13 -6
  29. package/lib/components/InputPin/{style.ts → style.js} +6 -7
  30. package/lib/components/MenuItem/index.js +44 -0
  31. package/lib/components/MenuItem/{style.ts → style.js} +7 -9
  32. package/lib/components/NavigationTitle/{index.tsx → index.js} +30 -9
  33. package/lib/components/NavigationTitle/{style.ts → style.js} +11 -12
  34. package/lib/components/Notification/index.js +80 -0
  35. package/lib/components/Notification/{style.ts → style.js} +11 -13
  36. package/lib/components/PreventDoubleClick/index.js +21 -0
  37. package/lib/components/Select/index.js +89 -0
  38. package/lib/components/Select/style.js +81 -0
  39. package/lib/components/SwipeablePanel/{index.tsx → index.js} +85 -58
  40. package/lib/components/SwipeablePanel/{style.ts → style.js} +14 -15
  41. package/lib/components/Switch/index.js +57 -0
  42. package/lib/components/TakePicture/{confirmPictureModal.tsx → confirmPictureModal.js} +33 -9
  43. package/lib/components/TakePicture/index.js +198 -0
  44. package/lib/components/TakePicture/{style.ts → style.js} +4 -4
  45. package/lib/components/Text/index.js +75 -0
  46. package/lib/components/Text/{style.ts → style.js} +2 -4
  47. package/lib/components/Textarea/{index.tsx → index.js} +24 -5
  48. package/lib/components/Textarea/{style.ts → style.js} +4 -5
  49. package/lib/components/TimeOutButton/index.js +104 -0
  50. package/lib/components/TimeOutButton/{style.ts → style.js} +3 -4
  51. package/lib/components/UploadDocument/index.js +222 -0
  52. package/lib/components/UploadDocument/{style.ts → style.js} +15 -16
  53. package/lib/components/VirtualKeyboard/index.js +86 -0
  54. package/lib/components/VirtualKeyboard/{style.ts → style.js} +8 -9
  55. package/lib/components/index.js +28 -0
  56. package/lib/configs/constants.js +276 -0
  57. package/lib/configs/loadFonts.js +11 -0
  58. package/lib/hooks/index.js +1 -0
  59. package/lib/hooks/{useDebounce.tsx → useDebounce.js} +4 -6
  60. package/lib/index.js +2 -3
  61. package/package.json +58 -72
  62. package/{README.md → readme.md} +20 -19
  63. package/LICENSE +0 -21
  64. package/lib/components/Button/index.tsx +0 -66
  65. package/lib/components/Card/index.tsx +0 -33
  66. package/lib/components/DeckSwiper/index.tsx +0 -90
  67. package/lib/components/DonutCountdown/index.tsx +0 -86
  68. package/lib/components/DonutCountdown/style.ts +0 -8
  69. package/lib/components/FloatingContainer/index.tsx +0 -35
  70. package/lib/components/Footer/index.tsx +0 -35
  71. package/lib/components/Header/index.tsx +0 -21
  72. package/lib/components/ImageResponsive/index.tsx +0 -24
  73. package/lib/components/ImageResponsive/style.ts +0 -9
  74. package/lib/components/ImageViewer/index.tsx +0 -36
  75. package/lib/components/MenuItem/index.tsx +0 -25
  76. package/lib/components/Notification/index.tsx +0 -44
  77. package/lib/components/PreventDoubleClick/index.tsx +0 -28
  78. package/lib/components/Select/index.tsx +0 -51
  79. package/lib/components/Select/style.ts +0 -64
  80. package/lib/components/Switch/index.tsx +0 -30
  81. package/lib/components/TakePicture/index.tsx +0 -148
  82. package/lib/components/Text/index.tsx +0 -33
  83. package/lib/components/TimeOutButton/index.tsx +0 -67
  84. package/lib/components/Toast/index.tsx +0 -34
  85. package/lib/components/Toast/style.ts +0 -12
  86. package/lib/components/UploadDocument/index.tsx +0 -179
  87. package/lib/components/VirtualKeyboard/index.tsx +0 -75
  88. package/lib/components/index.ts +0 -29
  89. package/lib/configs/constants.ts +0 -273
  90. package/lib/configs/types.ts +0 -326
  91. package/lib/hooks/index.ts +0 -2
  92. package/lib/hooks/useLoadFonts.tsx +0 -13
package/index.js CHANGED
@@ -1,4 +1,3 @@
1
+ export {asyncLoadFont} from './configs/loadFonts';
2
+ export {Colors, MapStyle, ConstantsWS, HiringStatus, CouponStatus, NotificationsTypes} from './configs/constants';
1
3
  export * from './components';
2
- export { Colors, ConstantsWS, CouponStatus, HiringStatus, MapStyle, NotificationsTypes } from './configs/constants';
3
- export * from './configs/types';
4
- export { useDebounce, useLoadFonts } from './hooks';
@@ -0,0 +1,104 @@
1
+ import React, { useState, useEffect } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { TouchableOpacity, ActivityIndicator } from 'react-native';
4
+ import withPreventDoubleClick from './../PreventDoubleClick';
5
+ import { Colors } from '../../configs/constants';
6
+ import style from './style';
7
+
8
+ const Button = ({
9
+ onPress,
10
+ disabled,
11
+ isLoading,
12
+ bordered,
13
+ variant = 'primary',
14
+ size = 'medium',
15
+ noShadow,
16
+ style: customStyle,
17
+ debounceDelay = 0,
18
+ children,
19
+ }) => {
20
+ const [isDisabled, setIsDisabled] = useState(disabled);
21
+
22
+ useEffect(() => setIsDisabled(disabled), [disabled]);
23
+
24
+ const getSpinnerColor = () => {
25
+ switch (variant) {
26
+ case 'primary':
27
+ case 'inverted':
28
+ case 'error':
29
+ return Colors.white;
30
+ default:
31
+ return Colors.darkblue;
32
+ }
33
+ };
34
+
35
+ const handleTap = () => {
36
+ onPress();
37
+ setIsDisabled(true);
38
+ setTimeout(() => {
39
+ setIsDisabled(false);
40
+ }, debounceDelay);
41
+ };
42
+
43
+ return (
44
+ <TouchableOpacity
45
+ style={[
46
+ style.button,
47
+ style[variant],
48
+ style[size],
49
+ bordered ? style.bordered : {},
50
+ isDisabled ? style.disabled : {},
51
+ noShadow ? style.noShadow : {},
52
+ customStyle,
53
+ ]}
54
+ disabled={isLoading || isDisabled}
55
+ onPress={handleTap}
56
+ >
57
+ {isLoading ? (
58
+ <ActivityIndicator color={getSpinnerColor()} size={28} />
59
+ ) : (
60
+ children
61
+ )}
62
+ </TouchableOpacity>
63
+ );
64
+ };
65
+
66
+ Button.defaultProps = {
67
+ children: null,
68
+ disabled: false,
69
+ isLoading: false,
70
+ bordered: false,
71
+ noShadow: false,
72
+ variant: 'primary',
73
+ size: 'medium',
74
+ style: {},
75
+ onPress: () => {},
76
+ debounceDelay: 0,
77
+ };
78
+
79
+ Button.propTypes = {
80
+ children: PropTypes.node,
81
+ disabled: PropTypes.bool,
82
+ isLoading: PropTypes.bool,
83
+ bordered: PropTypes.bool,
84
+ noShadow: PropTypes.bool,
85
+ variant: PropTypes.oneOf([
86
+ 'brightblue',
87
+ 'brightviolet',
88
+ 'darkyellow',
89
+ 'dim',
90
+ 'electricblue',
91
+ 'error',
92
+ 'inverted',
93
+ 'light',
94
+ 'lightgreen',
95
+ 'primary',
96
+ 'secondary',
97
+ ]),
98
+ size: PropTypes.oneOf(['tiny', 'small', 'medium', 'fit', 'icon']),
99
+ style: PropTypes.any,
100
+ onPress: PropTypes.func,
101
+ debounceDelay: PropTypes.number,
102
+ };
103
+
104
+ export default withPreventDoubleClick(Button);
@@ -1,10 +1,9 @@
1
- import { Dimensions, StyleSheet } from 'react-native';
2
-
3
- import { borderRadius, Colors } from '../../configs/constants';
1
+ import { Dimensions } from 'react-native';
2
+ import { Colors, borderRadius } from '../../configs/constants';
4
3
 
5
4
  const { width } = Dimensions.get('window');
6
5
 
7
- export default StyleSheet.create({
6
+ export default {
8
7
  // Default button shape
9
8
  button: {
10
9
  height: 50,
@@ -38,9 +37,9 @@ export default StyleSheet.create({
38
37
  shadowColor: Colors.dimgray,
39
38
  },
40
39
  light: {
41
- borderColor: Colors.gray,
42
- backgroundColor: Colors.gray,
43
- shadowColor: Colors.gray,
40
+ borderColor: Colors.lightblue,
41
+ backgroundColor: Colors.lightblue,
42
+ shadowColor: Colors.lightblue,
44
43
  },
45
44
  brightblue: {
46
45
  borderColor: Colors.brightblue,
@@ -108,4 +107,4 @@ export default StyleSheet.create({
108
107
  shadowColor: Colors.transparent,
109
108
  elevation: 0,
110
109
  },
111
- });
110
+ };
@@ -0,0 +1,49 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { View, TouchableOpacity } from 'react-native';
4
+ import withPreventDoubleClick from '../PreventDoubleClick';
5
+ import style from './style';
6
+
7
+ const TappedTouchableOpacity = withPreventDoubleClick(TouchableOpacity);
8
+
9
+ const Card = (
10
+ { children, isButton, onPress, noShadow, style: customStyle },
11
+ ...props
12
+ ) => (
13
+ <>
14
+ {isButton ? (
15
+ <TappedTouchableOpacity
16
+ onPress={onPress}
17
+ style={[style.card, customStyle, noShadow ? style.noShadow : {}]}
18
+ {...props}
19
+ >
20
+ {children}
21
+ </TappedTouchableOpacity>
22
+ ) : (
23
+ <View
24
+ style={[style.card, customStyle, noShadow ? style.noShadow : {}]}
25
+ {...props}
26
+ >
27
+ {children}
28
+ </View>
29
+ )}
30
+ </>
31
+ );
32
+
33
+ Card.defaultProps = {
34
+ style: {},
35
+ children: null,
36
+ isButton: false,
37
+ noShadow: false,
38
+ onPress: () => {},
39
+ };
40
+
41
+ Card.propTypes = {
42
+ style: PropTypes.any,
43
+ children: PropTypes.node,
44
+ isButton: PropTypes.bool,
45
+ noShadow: PropTypes.bool,
46
+ onPress: PropTypes.func,
47
+ };
48
+
49
+ export default Card;
@@ -1,11 +1,10 @@
1
- import { Dimensions, Platform, StyleSheet } from 'react-native';
2
-
3
- import { borderRadius, Colors } from '../../configs/constants';
1
+ import { Dimensions, Platform } from 'react-native';
2
+ import { Colors, borderRadius } from '../../configs/constants';
4
3
 
5
4
  const { width } = Dimensions.get('window');
6
5
  const isAndroid = Platform.OS === 'android';
7
6
 
8
- export default StyleSheet.create({
7
+ export default {
9
8
  card: {
10
9
  margin: 8,
11
10
  minHeight: 50,
@@ -31,4 +30,4 @@ export default StyleSheet.create({
31
30
  elevation: 0,
32
31
  borderColor: Colors.lightblue,
33
32
  },
34
- });
33
+ };
@@ -1,21 +1,20 @@
1
- import { Ionicons } from '@expo/vector-icons';
1
+ import React from 'react';
2
2
  import {
3
- Keyboard,
4
- KeyboardAvoidingView,
5
3
  Modal,
6
- Platform,
7
4
  TouchableOpacity,
8
- TouchableWithoutFeedback,
9
5
  View,
6
+ Keyboard,
7
+ TouchableWithoutFeedback,
8
+ Platform,
9
+ KeyboardAvoidingView,
10
10
  } from 'react-native';
11
-
12
- import { Colors } from '../../configs/constants';
13
- import Button from '../Button';
11
+ import PropTypes from 'prop-types';
12
+ import Ionicons from 'react-native-vector-icons/Ionicons';
14
13
  import Text from '../Text';
14
+ import Button from '../Button';
15
+ import { Colors } from '../../configs/constants';
15
16
  import style from './style';
16
17
 
17
- import type { ConfirmationModalProps } from '../../configs/types';
18
-
19
18
  const ConfirmationModal = ({
20
19
  visible,
21
20
  title,
@@ -30,18 +29,25 @@ const ConfirmationModal = ({
30
29
  inverted,
31
30
  isPrime,
32
31
  children,
33
- }: ConfirmationModalProps) => (
34
- <Modal animationType="slide" transparent visible={visible} onRequestClose={() => {}}>
35
- <KeyboardAvoidingView behavior={Platform.OS === 'ios' ? 'padding' : 'height'}>
32
+ }) => (
33
+ <Modal
34
+ animationType='slide'
35
+ transparent={true}
36
+ visible={visible}
37
+ onRequestClose={() => {}}
38
+ >
39
+ <KeyboardAvoidingView
40
+ behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
41
+ >
36
42
  <TouchableWithoutFeedback onPress={() => Keyboard.dismiss()}>
37
43
  <View style={style.container}>
38
44
  <View style={style.content}>
39
45
  <View style={alertMode && !closeButton ? {} : style.title}>
40
46
  <Text
41
47
  style={alertMode && !closeButton ? {} : style.titleText}
42
- size="large"
48
+ size='large'
43
49
  align={alertMode && !closeButton ? 'center' : 'left'}
44
- weight="semiBold"
50
+ weight='semiBold'
45
51
  numberOfLines={1}
46
52
  >
47
53
  {title}
@@ -52,33 +58,46 @@ const ConfirmationModal = ({
52
58
  if (onClose) {
53
59
  onClose();
54
60
  } else {
55
- if (onCancel) {
56
- onCancel();
57
- }
61
+ onCancel();
58
62
  }
59
63
  }}
60
64
  style={style.button}
61
65
  >
62
- <Ionicons name="close-outline" size={24} color={Colors.darkblue} />
66
+ <Ionicons
67
+ name='close-outline'
68
+ size={24}
69
+ color={Colors.darkblue}
70
+ />
63
71
  </TouchableOpacity>
64
72
  )}
65
73
  </View>
66
74
 
67
- <View style={infoMode ? style.bodyInfo : style.body}>{children}</View>
75
+ <View style={infoMode ? style.bodyInfo : style.body}>
76
+ {children}
77
+ </View>
68
78
 
69
79
  {!infoMode && (
70
80
  <>
71
81
  {alertMode ? (
72
- <Button size="fit" variant={inverted ? 'inverted' : 'primary'} onPress={onConfirm}>
73
- <Text size="large" color={isPrime ? 'lightgold' : 'white'}>
82
+ <Button
83
+ size='fit'
84
+ variant={inverted ? 'inverted' : 'primary'}
85
+ onPress={onConfirm}
86
+ >
87
+ <Text size='large' color={isPrime ? 'lightgold' : 'white'}>
74
88
  {confirmText}
75
89
  </Text>
76
90
  </Button>
77
91
  ) : (
78
92
  <View style={style.buttons}>
79
93
  {onCancel && (
80
- <Button size="small" bordered variant={inverted ? 'inverted' : 'primary'} onPress={onCancel}>
81
- <Text size="large">{cancelText}</Text>
94
+ <Button
95
+ size='small'
96
+ bordered
97
+ variant={inverted ? 'inverted' : 'primary'}
98
+ onPress={onCancel}
99
+ >
100
+ <Text size='large'>{cancelText}</Text>
82
101
  </Button>
83
102
  )}
84
103
  <Button
@@ -86,7 +105,10 @@ const ConfirmationModal = ({
86
105
  size={onCancel ? 'small' : 'fit'}
87
106
  onPress={onConfirm}
88
107
  >
89
- <Text size="large" color={isPrime ? 'lightgold' : 'white'}>
108
+ <Text
109
+ size='large'
110
+ color={isPrime ? 'lightgold' : 'white'}
111
+ >
90
112
  {confirmText}
91
113
  </Text>
92
114
  </Button>
@@ -101,4 +123,36 @@ const ConfirmationModal = ({
101
123
  </Modal>
102
124
  );
103
125
 
126
+ ConfirmationModal.defaultProps = {
127
+ visible: false,
128
+ title: ' ',
129
+ confirmText: ' ',
130
+ cancelText: ' ',
131
+ onCancel: () => {},
132
+ onConfirm: () => {},
133
+ onClose: null,
134
+ alertMode: false,
135
+ closeButton: false,
136
+ infoMode: false,
137
+ inverted: false,
138
+ isPrime: false,
139
+ children: null,
140
+ };
141
+
142
+ ConfirmationModal.propTypes = {
143
+ visible: PropTypes.bool,
144
+ title: PropTypes.string,
145
+ confirmText: PropTypes.string,
146
+ cancelText: PropTypes.string,
147
+ onCancel: PropTypes.func,
148
+ onConfirm: PropTypes.func,
149
+ onClose: PropTypes.func,
150
+ alertMode: PropTypes.bool,
151
+ closeButton: PropTypes.bool,
152
+ infoMode: PropTypes.bool,
153
+ inverted: PropTypes.bool,
154
+ isPrime: PropTypes.bool,
155
+ children: PropTypes.node,
156
+ };
157
+
104
158
  export default ConfirmationModal;
@@ -1,15 +1,14 @@
1
- import { Dimensions, StyleSheet } from 'react-native';
2
-
1
+ import { Dimensions } from 'react-native';
3
2
  import { Colors } from '../../configs/constants';
4
3
 
5
4
  const { width, height } = Dimensions.get('window');
6
5
 
7
- export default StyleSheet.create({
6
+ export default {
8
7
  container: {
9
8
  backgroundColor: 'rgba(0,0,0,0.3)',
10
9
  height,
11
10
  justifyContent: 'center',
12
- alignItems: 'center',
11
+ alignItems: 'center'
13
12
  },
14
13
  content: {
15
14
  width: width - 60,
@@ -17,30 +16,30 @@ export default StyleSheet.create({
17
16
  padding: 20,
18
17
  borderRadius: 20,
19
18
  shadowOffset: { width: 0, height: 4 },
20
- shadowOpacity: 0.4,
19
+ shadowOpacity: 0.4,
21
20
  shadowRadius: 3,
22
21
  elevation: 5,
23
- shadowColor: Colors.gray,
22
+ shadowColor: Colors.gray
24
23
  },
25
24
  title: {
26
25
  flexDirection: 'row',
27
26
  justifyContent: 'space-between',
28
- alignItems: 'center',
27
+ alignItems: 'center'
29
28
  },
30
29
  titleText: {
31
- width: '90%',
30
+ width: '90%'
32
31
  },
33
32
  body: {
34
33
  marginTop: 20,
35
- marginBottom: 35,
34
+ marginBottom: 35
36
35
  },
37
36
  bodyInfo: {
38
- marginTop: 20,
37
+ marginTop: 20
39
38
  },
40
39
  buttons: {
41
40
  flexDirection: 'row',
42
41
  justifyContent: 'space-between',
43
- alignItems: 'center',
42
+ alignItems: 'center'
44
43
  },
45
44
  button: {
46
45
  height: 30,
@@ -48,6 +47,6 @@ export default StyleSheet.create({
48
47
  borderRadius: 15,
49
48
  backgroundColor: Colors.lightblue,
50
49
  alignItems: 'center',
51
- justifyContent: 'center',
52
- },
53
- });
50
+ justifyContent: 'center'
51
+ }
52
+ };
@@ -1,10 +1,14 @@
1
- import { Keyboard, ScrollView, TouchableWithoutFeedback, View } from 'react-native';
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
2
3
  import { SafeAreaView } from 'react-native-safe-area-context';
3
-
4
+ import {
5
+ TouchableWithoutFeedback,
6
+ Keyboard,
7
+ ScrollView,
8
+ View,
9
+ } from 'react-native';
4
10
  import style from './style';
5
11
 
6
- import type { ContainerProps } from '../../configs/types';
7
-
8
12
  const Container = ({
9
13
  fullScreen = true,
10
14
  enableScroll,
@@ -12,13 +16,16 @@ const Container = ({
12
16
  scrollStyle,
13
17
  children,
14
18
  ...props
15
- }: ContainerProps) => (
16
- <SafeAreaView {...props} style={[fullScreen ? style.fullScreen : {}, customStyle]}>
19
+ }) => (
20
+ <SafeAreaView
21
+ {...props}
22
+ style={[fullScreen ? style.fullScreen : {}, customStyle]}
23
+ >
17
24
  {enableScroll ? (
18
25
  <ScrollView
19
26
  contentContainerStyle={scrollStyle}
20
27
  showsVerticalScrollIndicator={false}
21
- keyboardDismissMode="on-drag"
28
+ keyboardDismissMode='on-drag'
22
29
  >
23
30
  {children}
24
31
  </ScrollView>
@@ -30,4 +37,18 @@ const Container = ({
30
37
  </SafeAreaView>
31
38
  );
32
39
 
40
+ Container.defaultProps = {
41
+ fullScreen: true,
42
+ enableScroll: false,
43
+ style: {},
44
+ scrollStyle: {},
45
+ };
46
+
47
+ Container.propTypes = {
48
+ fullScreen: PropTypes.bool,
49
+ enableScroll: PropTypes.bool,
50
+ style: PropTypes.any,
51
+ scrollStyle: PropTypes.any,
52
+ };
53
+
33
54
  export default Container;
@@ -1,13 +1,12 @@
1
- import { Dimensions, StyleSheet } from 'react-native';
2
-
1
+ import { Dimensions } from 'react-native';
3
2
  import { Colors } from '../../configs/constants';
4
3
 
5
4
  const { width } = Dimensions.get('window');
6
5
 
7
- export default StyleSheet.create({
6
+ export default {
8
7
  fullScreen: {
9
8
  flex: 1,
10
9
  width,
11
- backgroundColor: Colors.white,
12
- },
13
- });
10
+ backgroundColor: Colors.white
11
+ }
12
+ };
@@ -1,47 +1,43 @@
1
- import { Alert, Linking, Platform, TouchableOpacity } from 'react-native';
2
- import MapView, { PROVIDER_GOOGLE } from 'react-native-maps';
1
+ import MapView, { PROVIDER_GOOGLE } from "react-native-maps";
2
+ import PropTypes from "prop-types";
3
+ import React from "react";
4
+ import { Platform, TouchableOpacity, Alert, Linking } from "react-native";
5
+ import { MapStyle } from "../../configs/constants";
6
+ import styles from "./style";
3
7
 
4
- import { MapStyle } from '../../configs/constants';
5
- import styles from './style';
6
-
7
- import type { CustomChatViewProps } from '../../configs/types';
8
-
9
- const CustomChatView = ({ currentMessage, containerStyle, mapViewStyle }: CustomChatViewProps) => {
8
+ const CustomChatView = ({ currentMessage, containerStyle, mapViewStyle }) => {
10
9
  const openMapAsync = async () => {
11
- const { location } = currentMessage || {};
12
-
13
- if (!location) {
14
- Alert.alert('Location data is missing.');
15
- return null;
16
- }
10
+ const { location = {} } = currentMessage;
17
11
 
18
12
  const mapScheme = Platform.select({
19
- ios: 'maps:0,0?q=',
20
- android: 'geo:0,0?q=',
13
+ ios: "maps:0,0?q=",
14
+ android: "geo:0,0?q=",
21
15
  });
22
16
  const latLng = `${location.latitude},${location.longitude}`;
23
- const label = `${currentMessage?.user?.name ?? ''}`;
17
+ const label = `${currentMessage.user.name}`;
24
18
 
25
19
  const url = Platform.select({
26
20
  ios: `${mapScheme}${label}@${latLng}`,
27
21
  android: `${mapScheme}${latLng}(${label})`,
28
- }) as string;
22
+ });
29
23
 
30
24
  try {
31
25
  const supported = await Linking.canOpenURL(url);
32
26
  if (supported) {
33
27
  return Linking.openURL(url);
34
28
  }
35
- Alert.alert('Opening the map is not supported.');
29
+ Alert.alert("Opening the map is not supported.");
36
30
  } catch ({ message }) {
37
31
  Alert.alert(message);
38
32
  }
39
- return null;
40
33
  };
41
34
 
42
- if (currentMessage?.location) {
35
+ if (currentMessage.location) {
43
36
  return (
44
- <TouchableOpacity style={[styles.container, containerStyle]} onPress={openMapAsync}>
37
+ <TouchableOpacity
38
+ style={[styles.container, containerStyle]}
39
+ onPress={openMapAsync}
40
+ >
45
41
  <MapView
46
42
  style={[styles.mapView, mapViewStyle]}
47
43
  region={{
@@ -62,4 +58,16 @@ const CustomChatView = ({ currentMessage, containerStyle, mapViewStyle }: Custom
62
58
  return null;
63
59
  };
64
60
 
61
+ CustomChatView.propTypes = {
62
+ currentMessage: PropTypes.object,
63
+ containerStyle: PropTypes.object,
64
+ mapViewStyle: PropTypes.object,
65
+ };
66
+
67
+ CustomChatView.defaultProps = {
68
+ currentMessage: {},
69
+ containerStyle: {},
70
+ mapViewStyle: {},
71
+ };
72
+
65
73
  export default CustomChatView;
@@ -1,7 +1,7 @@
1
1
  export default {
2
2
  container: {},
3
3
  mapView: {
4
- flexDirection: 'column-reverse',
4
+ flexDirection: "column-reverse",
5
5
  width: 250,
6
6
  height: 150,
7
7
  borderRadius: 13,