@codeleap/mobile 4.2.18 → 4.3.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.
- package/dist/components/ActivityIndicator/types.d.ts +1 -1
- package/dist/components/Autocomplete/index.js +2 -1
- package/dist/components/Autocomplete/index.js.map +1 -1
- package/dist/components/Autocomplete/types.d.ts +2 -1
- package/dist/components/Avatar/index.js +3 -1
- package/dist/components/Avatar/index.js.map +1 -1
- package/dist/components/Badge/index.js +1 -1
- package/dist/components/Badge/index.js.map +1 -1
- package/dist/components/Badge/types.d.ts +1 -1
- package/dist/components/Button/styles.d.ts +1 -1
- package/dist/components/Calendar/index.js +1 -1
- package/dist/components/Calendar/index.js.map +1 -1
- package/dist/components/Calendar/types.d.ts +1 -1
- package/dist/components/DatePickerModal/index.js +3 -1
- package/dist/components/DatePickerModal/index.js.map +1 -1
- package/dist/components/DatePickerModal/types.d.ts +2 -1
- package/dist/components/FileInput/index.js +1 -1
- package/dist/components/FileInput/index.js.map +1 -1
- package/dist/components/FileInput/types.d.ts +2 -1
- package/dist/components/Icon/index.js +2 -1
- package/dist/components/Icon/index.js.map +1 -1
- package/dist/components/Image/index.js +2 -1
- package/dist/components/Image/index.js.map +1 -1
- package/dist/components/Image/types.d.ts +1 -1
- package/dist/components/ImageView/Spotlight.js +3 -1
- package/dist/components/ImageView/Spotlight.js.map +1 -1
- package/dist/components/ImageView/component.d.ts +1 -1
- package/dist/components/ImageView/component.js +1 -1
- package/dist/components/ImageView/component.js.map +1 -1
- package/dist/components/InputBase/index.js +2 -1
- package/dist/components/InputBase/index.js.map +1 -1
- package/dist/components/InputBase/styles.js +1 -1
- package/dist/components/InputBase/styles.js.map +1 -1
- package/dist/components/InputBase/types.d.ts +1 -1
- package/dist/components/List/index.js +2 -1
- package/dist/components/List/index.js.map +1 -1
- package/dist/components/Modal/index.js +1 -1
- package/dist/components/Modal/index.js.map +1 -1
- package/dist/components/Modal/types.d.ts +1 -1
- package/dist/components/Navigation/Navigation.js +1 -1
- package/dist/components/Navigation/Navigation.js.map +1 -1
- package/dist/components/NumberIncrement/index.js +2 -1
- package/dist/components/NumberIncrement/index.js.map +1 -1
- package/dist/components/NumberIncrement/types.d.ts +2 -1
- package/dist/components/Pager/PagerDots.d.ts +1 -1
- package/dist/components/Pager/index.js +2 -1
- package/dist/components/Pager/index.js.map +1 -1
- package/dist/components/PaginationIndicator/index.js +1 -1
- package/dist/components/PaginationIndicator/index.js.map +1 -1
- package/dist/components/PlacesAutocomplete/index.js +1 -1
- package/dist/components/PlacesAutocomplete/index.js.map +1 -1
- package/dist/components/PlacesAutocomplete/types.d.ts +1 -1
- package/dist/components/RadioInput/index.js +1 -1
- package/dist/components/RadioInput/index.js.map +1 -1
- package/dist/components/RadioInput/types.d.ts +2 -1
- package/dist/components/Scroll/index.js +2 -1
- package/dist/components/Scroll/index.js.map +1 -1
- package/dist/components/SearchInput/index.js +1 -1
- package/dist/components/SearchInput/index.js.map +1 -1
- package/dist/components/SectionFilters/index.js +2 -1
- package/dist/components/SectionFilters/index.js.map +1 -1
- package/dist/components/SectionFilters/useSectionFilters.js +2 -1
- package/dist/components/SectionFilters/useSectionFilters.js.map +1 -1
- package/dist/components/Sections/index.js +2 -1
- package/dist/components/Sections/index.js.map +1 -1
- package/dist/components/SegmentedControl/Option.d.ts +1 -1
- package/dist/components/SegmentedControl/styles.d.ts +1 -1
- package/dist/components/SegmentedControl/types.d.ts +1 -1
- package/dist/components/Select/index.js +2 -1
- package/dist/components/Select/index.js.map +1 -1
- package/dist/components/Select/types.d.ts +2 -1
- package/dist/components/Slider/index.js +2 -1
- package/dist/components/Slider/index.js.map +1 -1
- package/dist/components/SortablePhotos/useSortablePhotos.d.ts +1 -1
- package/dist/components/SortablePhotos/useSortablePhotos.js +3 -3
- package/dist/components/SortablePhotos/useSortablePhotos.js.map +1 -1
- package/dist/components/Text/index.js +1 -1
- package/dist/components/Text/index.js.map +1 -1
- package/dist/components/Text/styles.d.ts +1 -1
- package/dist/components/TextInput/index.js +3 -1
- package/dist/components/TextInput/index.js.map +1 -1
- package/dist/components/TextInput/types.d.ts +2 -1
- package/dist/components/Touchable/index.js +3 -1
- package/dist/components/Touchable/index.js.map +1 -1
- package/dist/components/Touchable/types.d.ts +1 -1
- package/dist/components/View/types.d.ts +1 -1
- package/dist/modules/types/textInputMask.d.ts +1 -1
- package/dist/utils/KeyboardAware/keyboardHooks.js +1 -1
- package/dist/utils/KeyboardAware/keyboardHooks.js.map +1 -1
- package/dist/utils/MobilePermissionManager/Permission.d.ts +19 -0
- package/dist/utils/MobilePermissionManager/Permission.js +65 -0
- package/dist/utils/MobilePermissionManager/Permission.js.map +1 -0
- package/dist/utils/MobilePermissionManager/PermissionManager.d.ts +24 -0
- package/dist/utils/MobilePermissionManager/PermissionManager.js +84 -0
- package/dist/utils/MobilePermissionManager/PermissionManager.js.map +1 -0
- package/dist/utils/MobilePermissionManager/index.d.ts +3 -0
- package/dist/utils/MobilePermissionManager/index.js +5 -0
- package/dist/utils/MobilePermissionManager/index.js.map +1 -0
- package/dist/utils/MobilePermissionManager/types.d.ts +32 -0
- package/dist/utils/MobilePermissionManager/types.js +2 -0
- package/dist/utils/MobilePermissionManager/types.js.map +1 -0
- package/dist/utils/ModalManager/components.d.ts +1 -1
- package/dist/utils/ModalManager/components.js +1 -1
- package/dist/utils/ModalManager/components.js.map +1 -1
- package/dist/utils/ModalManager/context.d.ts +1 -1
- package/dist/utils/ModalManager/context.js +2 -1
- package/dist/utils/ModalManager/context.js.map +1 -1
- package/dist/utils/NotificationManager/index.d.ts +2 -2
- package/dist/utils/NotificationManager/index.js +1 -1
- package/dist/utils/NotificationManager/index.js.map +1 -1
- package/dist/utils/NotificationManager/types.d.ts +1 -1
- package/dist/utils/PermissionManager/context.d.ts +1 -1
- package/dist/utils/PermissionManager/context.js +2 -1
- package/dist/utils/PermissionManager/context.js.map +1 -1
- package/dist/utils/PermissionManager/types.d.ts +1 -1
- package/dist/utils/StorageManager.d.ts +1 -1
- package/dist/utils/hooks.js +3 -1
- package/dist/utils/hooks.js.map +1 -1
- package/dist/utils/misc.d.ts +1 -1
- package/dist/utils/misc.js +2 -1
- package/dist/utils/misc.js.map +1 -1
- package/dist/utils/useQueryListRefresh.d.ts +2 -1
- package/dist/utils/useQueryListRefresh.js +1 -1
- package/dist/utils/useQueryListRefresh.js.map +1 -1
- package/package.json +19 -5
- package/package.json.bak +18 -4
- package/src/components/ActivityIndicator/types.ts +1 -1
- package/src/components/Autocomplete/index.tsx +3 -1
- package/src/components/Autocomplete/types.ts +2 -1
- package/src/components/Avatar/index.tsx +3 -1
- package/src/components/Badge/index.tsx +2 -2
- package/src/components/Badge/types.ts +1 -1
- package/src/components/Button/index.tsx +1 -1
- package/src/components/Button/styles.ts +1 -1
- package/src/components/Calendar/index.tsx +1 -1
- package/src/components/Calendar/types.ts +1 -2
- package/src/components/DatePickerModal/index.tsx +3 -1
- package/src/components/DatePickerModal/types.ts +2 -1
- package/src/components/FileInput/index.tsx +2 -1
- package/src/components/FileInput/types.ts +2 -1
- package/src/components/Icon/index.tsx +2 -1
- package/src/components/Image/index.tsx +2 -1
- package/src/components/Image/types.ts +1 -1
- package/src/components/ImageView/Spotlight.tsx +3 -1
- package/src/components/ImageView/component.tsx +3 -1
- package/src/components/InputBase/index.tsx +2 -1
- package/src/components/InputBase/styles.ts +1 -1
- package/src/components/InputBase/types.ts +1 -1
- package/src/components/List/index.tsx +2 -1
- package/src/components/Modal/index.tsx +1 -1
- package/src/components/Modal/types.ts +1 -1
- package/src/components/Navigation/Navigation.tsx +1 -1
- package/src/components/NumberIncrement/index.tsx +2 -1
- package/src/components/NumberIncrement/types.ts +2 -1
- package/src/components/Pager/PagerDots.tsx +1 -1
- package/src/components/Pager/index.tsx +2 -1
- package/src/components/PaginationIndicator/index.tsx +1 -1
- package/src/components/PlacesAutocomplete/index.tsx +1 -1
- package/src/components/PlacesAutocomplete/types.ts +1 -1
- package/src/components/RadioInput/index.tsx +1 -1
- package/src/components/RadioInput/types.ts +2 -1
- package/src/components/Scroll/index.tsx +2 -1
- package/src/components/SearchInput/index.tsx +1 -1
- package/src/components/SectionFilters/index.tsx +2 -1
- package/src/components/SectionFilters/useSectionFilters.tsx +2 -1
- package/src/components/Sections/index.tsx +2 -1
- package/src/components/SegmentedControl/Option.tsx +1 -1
- package/src/components/SegmentedControl/styles.ts +1 -1
- package/src/components/SegmentedControl/types.ts +1 -1
- package/src/components/Select/index.tsx +3 -3
- package/src/components/Select/types.ts +2 -1
- package/src/components/Slider/index.tsx +2 -1
- package/src/components/SortablePhotos/useSortablePhotos.ts +3 -3
- package/src/components/Text/index.tsx +1 -1
- package/src/components/Text/styles.ts +1 -1
- package/src/components/TextInput/index.tsx +3 -1
- package/src/components/TextInput/types.ts +2 -1
- package/src/components/Touchable/index.tsx +3 -1
- package/src/components/Touchable/types.ts +1 -1
- package/src/components/View/types.ts +1 -1
- package/src/modules/types/textInputMask.ts +1 -1
- package/src/utils/KeyboardAware/keyboardHooks.ts +1 -1
- package/src/utils/MobilePermissionManager/Permission.ts +79 -0
- package/src/utils/MobilePermissionManager/PermissionManager.ts +124 -0
- package/src/utils/MobilePermissionManager/index.ts +3 -0
- package/src/utils/MobilePermissionManager/types.ts +44 -0
- package/src/utils/ModalManager/components.tsx +2 -1
- package/src/utils/ModalManager/context.tsx +2 -1
- package/src/utils/NotificationManager/index.ts +2 -1
- package/src/utils/NotificationManager/types.ts +1 -1
- package/src/utils/PermissionManager/context.tsx +3 -1
- package/src/utils/PermissionManager/types.ts +1 -1
- package/src/utils/StorageManager.ts +1 -1
- package/src/utils/hooks.ts +3 -1
- package/src/utils/misc.ts +2 -1
- package/src/utils/useQueryListRefresh.ts +2 -1
- package/dist/utils/deprecated/notifications.d.ts +0 -40
- package/dist/utils/deprecated/notifications.js +0 -167
- package/dist/utils/deprecated/notifications.js.map +0 -1
- package/src/utils/deprecated/notifications.ts +0 -213
|
@@ -1,213 +0,0 @@
|
|
|
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
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Class responsible for the notification system
|
|
23
|
-
*
|
|
24
|
-
* @deprecated Use the most updated version
|
|
25
|
-
* @note check the documentation to make the migration
|
|
26
|
-
*/
|
|
27
|
-
export class NotificationManager {
|
|
28
|
-
|
|
29
|
-
stateChangeListeners:NotificationStateChangeListener[] = []
|
|
30
|
-
|
|
31
|
-
messageListeners:NotificationHandler[] = []
|
|
32
|
-
|
|
33
|
-
_initialized = false
|
|
34
|
-
|
|
35
|
-
unsubscribeFromMessage = null
|
|
36
|
-
|
|
37
|
-
unsubscribeFromBackgroundMessage = null
|
|
38
|
-
|
|
39
|
-
unsubscribeFromPress = null
|
|
40
|
-
|
|
41
|
-
_currentToken = null
|
|
42
|
-
|
|
43
|
-
_initialNoficationHandled = false
|
|
44
|
-
|
|
45
|
-
constructor(private logger = silentLogger, public autoHandleInitialNotification = true) {
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
async init() {
|
|
49
|
-
// return
|
|
50
|
-
if (this.initialized) return
|
|
51
|
-
|
|
52
|
-
try {
|
|
53
|
-
|
|
54
|
-
await messaging().registerDeviceForRemoteMessages()
|
|
55
|
-
// logger.log('firebase registeted', '', MODULE)
|
|
56
|
-
|
|
57
|
-
const token = await messaging().getToken()
|
|
58
|
-
// logger.log('init token', { token }, MODULE)
|
|
59
|
-
|
|
60
|
-
if (token) {
|
|
61
|
-
this.currentToken = token
|
|
62
|
-
|
|
63
|
-
this.initialized = true
|
|
64
|
-
} else {
|
|
65
|
-
this.currentToken = null
|
|
66
|
-
this.initialized = false
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
messaging().onTokenRefresh(newToken => {
|
|
70
|
-
// logger.log('onTokenRefresh', { newToken }, MODULE)
|
|
71
|
-
if (token) {
|
|
72
|
-
this.currentToken = newToken
|
|
73
|
-
|
|
74
|
-
this.initialized = true
|
|
75
|
-
} else {
|
|
76
|
-
this.currentToken = null
|
|
77
|
-
this.initialized = false
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
})
|
|
81
|
-
// logger.log('init success', {}, MODULE)
|
|
82
|
-
} catch (e) {
|
|
83
|
-
this.logger.error('Failed to initialize notification services', e, MODULE)
|
|
84
|
-
// OSAlert.error({ title: 'Failed to initialize notification services' })
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
async deinit() {
|
|
89
|
-
[
|
|
90
|
-
this.unsubscribeFromMessage,
|
|
91
|
-
this.unsubscribeFromBackgroundMessage,
|
|
92
|
-
this.unsubscribeFromPress,
|
|
93
|
-
].forEach(unsubscribe => {
|
|
94
|
-
if (unsubscribe) {
|
|
95
|
-
unsubscribe()
|
|
96
|
-
}
|
|
97
|
-
})
|
|
98
|
-
|
|
99
|
-
this.initialized = false
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
private async handleNotification(args:HandleNotificationParam) {
|
|
103
|
-
for (const listener of this.messageListeners) {
|
|
104
|
-
await listener(args.data, args.type)
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
get currentToken() {
|
|
109
|
-
return this._currentToken
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
set currentToken(token: string) {
|
|
113
|
-
this._currentToken = token
|
|
114
|
-
this.triggerStateChange()
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
get initialized() {
|
|
118
|
-
return this._initialized
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
set initialized(to:boolean) {
|
|
122
|
-
|
|
123
|
-
if (to) {
|
|
124
|
-
this.logger.info('Initialized', '', MODULE)
|
|
125
|
-
this.unsubscribeFromMessage = messaging().onMessage((msg) => {
|
|
126
|
-
this.handleNotification({
|
|
127
|
-
data: msg,
|
|
128
|
-
type: 'foreground',
|
|
129
|
-
})
|
|
130
|
-
})
|
|
131
|
-
|
|
132
|
-
this.unsubscribeFromBackgroundMessage = messaging().setBackgroundMessageHandler(async (msg) => {
|
|
133
|
-
this.handleNotification({
|
|
134
|
-
data: msg,
|
|
135
|
-
type: 'background',
|
|
136
|
-
})
|
|
137
|
-
})
|
|
138
|
-
|
|
139
|
-
this.unsubscribeFromPress = messaging().onNotificationOpenedApp(msg => {
|
|
140
|
-
this.logger.info('Notification press', msg, MODULE)
|
|
141
|
-
this.handleNotification({
|
|
142
|
-
data: msg,
|
|
143
|
-
type: 'press',
|
|
144
|
-
})
|
|
145
|
-
})
|
|
146
|
-
|
|
147
|
-
if (!this._initialNoficationHandled && this.autoHandleInitialNotification) {
|
|
148
|
-
this.getInitialNotification().then(msg => {
|
|
149
|
-
if (!msg.data) return
|
|
150
|
-
this.logger.info('Notification initial', msg, MODULE)
|
|
151
|
-
this.handleNotification(msg).then(() => {
|
|
152
|
-
this._initialNoficationHandled = true
|
|
153
|
-
}).catch(e => {
|
|
154
|
-
this._initialNoficationHandled = true
|
|
155
|
-
this.logger.error('Error handling initial notification', e, MODULE)
|
|
156
|
-
})
|
|
157
|
-
})
|
|
158
|
-
}
|
|
159
|
-
} else {
|
|
160
|
-
this.unsubscribeFromMessage = null
|
|
161
|
-
|
|
162
|
-
this.unsubscribeFromBackgroundMessage = null
|
|
163
|
-
|
|
164
|
-
this.unsubscribeFromPress = null
|
|
165
|
-
|
|
166
|
-
this.logger.info('Deinitialized', '', MODULE)
|
|
167
|
-
}
|
|
168
|
-
this._initialized = to
|
|
169
|
-
|
|
170
|
-
this.triggerStateChange()
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
onNotification(handler:NotificationHandler) {
|
|
174
|
-
const newLen = this.messageListeners.push(handler)
|
|
175
|
-
|
|
176
|
-
return () => {
|
|
177
|
-
this.messageListeners.splice(newLen - 1, 1)
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
private triggerStateChange() {
|
|
182
|
-
this.stateChangeListeners.forEach(l => {
|
|
183
|
-
l(this._initialized, this.currentToken)
|
|
184
|
-
})
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
onStateChange(handler:NotificationStateChangeListener) {
|
|
188
|
-
const newLen = this.stateChangeListeners.push(handler)
|
|
189
|
-
|
|
190
|
-
return () => {
|
|
191
|
-
this.stateChangeListeners.splice(newLen - 1, 1)
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
async getInitialNotification():Promise<HandleNotificationParam> {
|
|
197
|
-
try {
|
|
198
|
-
|
|
199
|
-
const msg = await messaging().getInitialNotification()
|
|
200
|
-
return {
|
|
201
|
-
data: msg as Message,
|
|
202
|
-
type: 'initial',
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
} catch (e) {
|
|
206
|
-
return {
|
|
207
|
-
data: null,
|
|
208
|
-
type: 'initial',
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
|