@codeleap/mobile 2.3.0 → 2.3.2

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 (126) hide show
  1. package/dist/components/Button/index.d.ts +0 -1
  2. package/dist/components/Button/index.js +5 -12
  3. package/dist/components/Button/index.js.map +1 -1
  4. package/dist/components/List/styles.js +1 -1
  5. package/dist/components/List/styles.js.map +1 -1
  6. package/dist/components/Touchable/index.js +11 -9
  7. package/dist/components/Touchable/index.js.map +1 -1
  8. package/dist/utils/theme.d.ts +1 -0
  9. package/dist/utils/theme.js +7 -2
  10. package/dist/utils/theme.js.map +1 -1
  11. package/package.json +1 -1
  12. package/src/components/ActionIcon/index.tsx +32 -0
  13. package/src/components/ActionIcon/styles.ts +97 -0
  14. package/src/components/ActivityIndicator/index.tsx +50 -0
  15. package/src/components/ActivityIndicator/styles.ts +68 -0
  16. package/src/components/Animated.tsx +34 -0
  17. package/src/components/AutoComplete/index.tsx +163 -0
  18. package/src/components/AutoComplete/styles.ts +44 -0
  19. package/src/components/Backdrop/index.tsx +48 -0
  20. package/src/components/Backdrop/styles.ts +33 -0
  21. package/src/components/Button/index.tsx +154 -0
  22. package/src/components/Button/styles.ts +129 -0
  23. package/src/components/Calendar/index.tsx +65 -0
  24. package/src/components/Calendar/style.ts +35 -0
  25. package/src/components/Calendar/types.ts +102 -0
  26. package/src/components/Checkbox/index.tsx +91 -0
  27. package/src/components/Checkbox/styles.ts +81 -0
  28. package/src/components/ContentView/index.tsx +63 -0
  29. package/src/components/ContentView/styles.ts +24 -0
  30. package/src/components/Drawer/index.tsx +33 -0
  31. package/src/components/Drawer/styles.ts +43 -0
  32. package/src/components/EmptyPlaceholder/index.tsx +88 -0
  33. package/src/components/EmptyPlaceholder/styles.ts +58 -0
  34. package/src/components/FileInput/index.tsx +181 -0
  35. package/src/components/FileInput/styles.ts +15 -0
  36. package/src/components/Grid/index.tsx +117 -0
  37. package/src/components/Grid/styles.ts +11 -0
  38. package/src/components/Icon/index.tsx +69 -0
  39. package/src/components/Icon/styles.ts +57 -0
  40. package/src/components/Image/index.tsx +91 -0
  41. package/src/components/Image/styles.ts +20 -0
  42. package/src/components/ImageView/Spotlight.tsx +157 -0
  43. package/src/components/ImageView/component.tsx +38 -0
  44. package/src/components/ImageView/index.ts +2 -0
  45. package/src/components/InputLabel/index.tsx +38 -0
  46. package/src/components/InputLabel/styles.ts +19 -0
  47. package/src/components/List/PaginationIndicator.tsx +71 -0
  48. package/src/components/List/index.tsx +114 -0
  49. package/src/components/List/styles.ts +19 -0
  50. package/src/components/Modal/index.tsx +218 -0
  51. package/src/components/Modal/styles.ts +153 -0
  52. package/src/components/MultiSelect/index.tsx +138 -0
  53. package/src/components/MultiSelect/styles.ts +18 -0
  54. package/src/components/MultiSelect/types.ts +42 -0
  55. package/src/components/Navigation/Navigation.tsx +54 -0
  56. package/src/components/Navigation/constants.ts +8 -0
  57. package/src/components/Navigation/index.tsx +3 -0
  58. package/src/components/Navigation/types.ts +35 -0
  59. package/src/components/Navigation/utils.tsx +57 -0
  60. package/src/components/Pager/index.tsx +121 -0
  61. package/src/components/Pager/styles.ts +81 -0
  62. package/src/components/RadioInput/index.tsx +106 -0
  63. package/src/components/RadioInput/styles.ts +67 -0
  64. package/src/components/Scroll/index.tsx +124 -0
  65. package/src/components/Scroll/styles.ts +18 -0
  66. package/src/components/Sections/index.tsx +91 -0
  67. package/src/components/SegmentedControl/index.tsx +204 -0
  68. package/src/components/SegmentedControl/styles.ts +89 -0
  69. package/src/components/Select/index.tsx +167 -0
  70. package/src/components/Select/styles.ts +62 -0
  71. package/src/components/Select/types.ts +43 -0
  72. package/src/components/Slider/Mark.tsx +46 -0
  73. package/src/components/Slider/Thumb.tsx +29 -0
  74. package/src/components/Slider/index.tsx +130 -0
  75. package/src/components/Slider/styles.ts +76 -0
  76. package/src/components/Slider/types.ts +30 -0
  77. package/src/components/Switch/index.tsx +91 -0
  78. package/src/components/Switch/styles.ts +38 -0
  79. package/src/components/Text/index.tsx +97 -0
  80. package/src/components/Text/styles.ts +50 -0
  81. package/src/components/TextInput/index.tsx +319 -0
  82. package/src/components/TextInput/styles.ts +127 -0
  83. package/src/components/Touchable/index.tsx +174 -0
  84. package/src/components/Touchable/styles.ts +28 -0
  85. package/src/components/View/index.tsx +103 -0
  86. package/src/components/View/styles.ts +24 -0
  87. package/src/components/components.ts +42 -0
  88. package/src/components/defaultStyles.ts +62 -0
  89. package/src/components/legacy/Modal/index.tsx +163 -0
  90. package/src/components/legacy/Modal/styles.ts +125 -0
  91. package/src/components/legacy/Pager/index.tsx +242 -0
  92. package/src/components/legacy/Pager/styles.ts +51 -0
  93. package/src/components/legacy/index.ts +2 -0
  94. package/src/modules/documentPicker.ts +7 -0
  95. package/src/modules/fastImage.ts +2 -0
  96. package/src/modules/imageCropPicker.d.ts +497 -0
  97. package/src/modules/index.d.ts +682 -0
  98. package/src/modules/reactNavigation.ts +15 -0
  99. package/src/modules/textInputMask.ts +11 -0
  100. package/src/modules/types/documentPicker.d.ts +215 -0
  101. package/src/modules/types/fileTypes.ts +138 -0
  102. package/src/modules/types/textInputMask.ts +9 -0
  103. package/src/types/index.ts +1 -0
  104. package/src/types/utility.ts +9 -0
  105. package/src/utils/KeyboardAware/context.tsx +75 -0
  106. package/src/utils/KeyboardAware/index.ts +17 -0
  107. package/src/utils/KeyboardAware/keyboardHooks.ts +124 -0
  108. package/src/utils/KeyboardAware/lib/KeyboardAwareFlatList.ts +4 -0
  109. package/src/utils/KeyboardAware/lib/KeyboardAwareHOC.tsx +618 -0
  110. package/src/utils/KeyboardAware/lib/KeyboardAwareInterface.ts +13 -0
  111. package/src/utils/KeyboardAware/lib/KeyboardAwareScrollView.ts +6 -0
  112. package/src/utils/KeyboardAware/lib/KeyboardAwareSectionList.ts +6 -0
  113. package/src/utils/KeyboardAware/types.ts +159 -0
  114. package/src/utils/ModalManager/components.tsx +112 -0
  115. package/src/utils/ModalManager/context.tsx +260 -0
  116. package/src/utils/ModalManager/index.ts +16 -0
  117. package/src/utils/OSAlert.ts +180 -0
  118. package/src/utils/PermissionManager/context.tsx +302 -0
  119. package/src/utils/PermissionManager/index.ts +20 -0
  120. package/src/utils/PermissionManager/types.ts +24 -0
  121. package/src/utils/hooks.ts +163 -0
  122. package/src/utils/index.ts +11 -0
  123. package/src/utils/input.ts +51 -0
  124. package/src/utils/misc.ts +83 -0
  125. package/src/utils/notifications.ts +206 -0
  126. package/src/utils/theme.ts +58 -0
@@ -0,0 +1,206 @@
1
+ import { FunctionType, silentLogger } from '@codeleap/common'
2
+ // @ts-ignore
3
+ import { firebase, FirebaseMessagingTypes } from '@react-native-firebase/messaging'
4
+
5
+ const messaging = firebase.messaging
6
+
7
+ const MODULE = 'Notifications'
8
+
9
+ export type Message = FirebaseMessagingTypes.RemoteMessage
10
+ export type MessageType = 'foreground' | 'background' | 'press' | 'initial'
11
+
12
+ export type NotificationHandler = FunctionType<[message: Message, type: MessageType], any>
13
+
14
+ export type HandleNotificationParam = {
15
+ data: Message
16
+ type: MessageType
17
+ }
18
+
19
+ export type NotificationStateChangeListener = FunctionType<[isInitialized: boolean, token?: string], any>
20
+ export class NotificationManager {
21
+
22
+ stateChangeListeners:NotificationStateChangeListener[] = []
23
+
24
+ messageListeners:NotificationHandler[] = []
25
+
26
+ _initialized = false
27
+
28
+ unsubscribeFromMessage = null
29
+
30
+ unsubscribeFromBackgroundMessage = null
31
+
32
+ unsubscribeFromPress = null
33
+
34
+ _currentToken = null
35
+
36
+ _initialNoficationHandled = false
37
+
38
+ constructor(private logger = silentLogger, public autoHandleInitialNotification = true) {
39
+ }
40
+
41
+ async init() {
42
+ // return
43
+ if (this.initialized) return
44
+
45
+ try {
46
+
47
+ await messaging().registerDeviceForRemoteMessages()
48
+ // logger.log('firebase registeted', '', MODULE)
49
+
50
+ const token = await messaging().getToken()
51
+ // logger.log('init token', { token }, MODULE)
52
+
53
+ if (token) {
54
+ this.currentToken = token
55
+
56
+ this.initialized = true
57
+ } else {
58
+ this.currentToken = null
59
+ this.initialized = false
60
+ }
61
+
62
+ messaging().onTokenRefresh(newToken => {
63
+ // logger.log('onTokenRefresh', { newToken }, MODULE)
64
+ if (token) {
65
+ this.currentToken = newToken
66
+
67
+ this.initialized = true
68
+ } else {
69
+ this.currentToken = null
70
+ this.initialized = false
71
+ }
72
+
73
+ })
74
+ // logger.log('init success', {}, MODULE)
75
+ } catch (e) {
76
+ this.logger.error('Failed to initialize notification services', e, MODULE)
77
+ // OSAlert.error({ title: 'Failed to initialize notification services' })
78
+ }
79
+ }
80
+
81
+ async deinit() {
82
+ [
83
+ this.unsubscribeFromMessage,
84
+ this.unsubscribeFromBackgroundMessage,
85
+ this.unsubscribeFromPress,
86
+ ].forEach(unsubscribe => {
87
+ if (unsubscribe) {
88
+ unsubscribe()
89
+ }
90
+ })
91
+
92
+ this.initialized = false
93
+ }
94
+
95
+ private async handleNotification(args:HandleNotificationParam) {
96
+ for (const listener of this.messageListeners) {
97
+ await listener(args.data, args.type)
98
+ }
99
+ }
100
+
101
+ get currentToken() {
102
+ return this._currentToken
103
+ }
104
+
105
+ set currentToken(token: string) {
106
+ this._currentToken = token
107
+ this.triggerStateChange()
108
+ }
109
+
110
+ get initialized() {
111
+ return this._initialized
112
+ }
113
+
114
+ set initialized(to:boolean) {
115
+
116
+ if (to) {
117
+ this.logger.info('Initialized', '', MODULE)
118
+ this.unsubscribeFromMessage = messaging().onMessage((msg) => {
119
+ this.handleNotification({
120
+ data: msg,
121
+ type: 'foreground',
122
+ })
123
+ })
124
+
125
+ this.unsubscribeFromBackgroundMessage = messaging().setBackgroundMessageHandler(async (msg) => {
126
+ this.handleNotification({
127
+ data: msg,
128
+ type: 'background',
129
+ })
130
+ })
131
+
132
+ this.unsubscribeFromPress = messaging().onNotificationOpenedApp(msg => {
133
+ this.logger.info('Notification press', msg, MODULE)
134
+ this.handleNotification({
135
+ data: msg,
136
+ type: 'press',
137
+ })
138
+ })
139
+
140
+ if (!this._initialNoficationHandled && this.autoHandleInitialNotification) {
141
+ this.getInitialNotification().then(msg => {
142
+ if (!msg.data) return
143
+ this.logger.info('Notification initial', msg, MODULE)
144
+ this.handleNotification(msg).then(() => {
145
+ this._initialNoficationHandled = true
146
+ }).catch(e => {
147
+ this._initialNoficationHandled = true
148
+ this.logger.error('Error handling initial notification', e, MODULE)
149
+ })
150
+ })
151
+ }
152
+ } else {
153
+ this.unsubscribeFromMessage = null
154
+
155
+ this.unsubscribeFromBackgroundMessage = null
156
+
157
+ this.unsubscribeFromPress = null
158
+
159
+ this.logger.info('Deinitialized', '', MODULE)
160
+ }
161
+ this._initialized = to
162
+
163
+ this.triggerStateChange()
164
+ }
165
+
166
+ onNotification(handler:NotificationHandler) {
167
+ const newLen = this.messageListeners.push(handler)
168
+
169
+ return () => {
170
+ this.messageListeners.splice(newLen - 1)
171
+ }
172
+ }
173
+
174
+ private triggerStateChange() {
175
+ this.stateChangeListeners.forEach(l => {
176
+ l(this._initialized, this.currentToken)
177
+ })
178
+ }
179
+
180
+ onStateChange(handler:NotificationStateChangeListener) {
181
+ const newLen = this.stateChangeListeners.push(handler)
182
+
183
+ return () => {
184
+ this.stateChangeListeners.splice(newLen - 1)
185
+ }
186
+
187
+ }
188
+
189
+ async getInitialNotification():Promise<HandleNotificationParam> {
190
+ try {
191
+
192
+ const msg = await messaging().getInitialNotification()
193
+ return {
194
+ data: msg as Message,
195
+ type: 'initial',
196
+ }
197
+
198
+ } catch (e) {
199
+ return {
200
+ data: null,
201
+ type: 'initial',
202
+ }
203
+ }
204
+ }
205
+ }
206
+
@@ -0,0 +1,58 @@
1
+ import { Platform, Dimensions, StatusBar, StyleSheet } from 'react-native'
2
+ import DeviceInfo from 'react-native-device-info'
3
+
4
+ type AppValues = {
5
+ headerHeight: number
6
+ tabBarHeight: number
7
+ }
8
+
9
+ export function getMobileThemeValues(initialWindowMetrics, values: AppValues) {
10
+ const screenDimensions = Dimensions.get('screen')
11
+
12
+ const hasNotch = Platform.OS === 'ios' ? (Dimensions.get('window').height >= 812) : (initialWindowMetrics?.insets?.top > 24 || StatusBar.currentHeight > 24)
13
+ const hasIsland = DeviceInfo.hasDynamicIsland()
14
+ const bottomNavHeight = Platform.OS === 'android' ? initialWindowMetrics?.insets?.bottom : 0
15
+
16
+ const prefersConstantNavigationBar = bottomNavHeight > 0
17
+
18
+ const safeAreaTop = Platform.OS === 'ios' ? (hasNotch ? 34 + (hasIsland ? 12 : 0) : 20) : StatusBar.currentHeight
19
+
20
+ const safeAreaBottom = (hasNotch && !prefersConstantNavigationBar ? 20 : 0)
21
+ return {
22
+ ...screenDimensions,
23
+
24
+ pixel: StyleSheet.hairlineWidth,
25
+ hasNotch,
26
+ hasIsland,
27
+ prefersConstantNavigationBar,
28
+ safeAreaTop,
29
+ safeAreaBottom,
30
+ keyboardVerticalOffset: Platform.OS === 'ios' ? 57 : 47,
31
+ get headerHeight() { return values.headerHeight + safeAreaTop },
32
+ get tabBarHeight() { return values.tabBarHeight + (prefersConstantNavigationBar ? 0 : this.safeAreaBottom) },
33
+ bottomNavHeight,
34
+ get window() {
35
+ return {
36
+ height: screenDimensions.height - (bottomNavHeight + safeAreaTop),
37
+ width: screenDimensions.width,
38
+ }
39
+ },
40
+ transitions: {
41
+ modal: {
42
+ duration: 100,
43
+ type: 'timing',
44
+ },
45
+ },
46
+ buttons: {
47
+ small: {
48
+ height: 40,
49
+ },
50
+ default: {
51
+ height: 50,
52
+ },
53
+ large: {
54
+ height: 60,
55
+ },
56
+ },
57
+ }
58
+ }