-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathNotificationModule.kt
More file actions
57 lines (48 loc) · 1.57 KB
/
NotificationModule.kt
File metadata and controls
57 lines (48 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package com.exampleapp
import com.facebook.react.bridge.Arguments
import com.facebook.react.bridge.Promise
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.ReactMethod
import com.facebook.react.module.annotations.ReactModule
@ReactModule(name = NativeNotificationModuleSpec.NAME)
class NotificationModule(
private val reactContext: ReactApplicationContext
) : NativeNotificationModuleSpec(reactContext) {
companion object {
@Volatile
private var activeModule: NotificationModule? = null
fun emitNotificationCenterUpdatedFromExternal() {
activeModule?.emitNotificationCenterUpdated()
}
}
init {
activeModule = this
}
@ReactMethod
override fun getNotifications(promise: Promise) {
try {
val notificationsJson: String = NotificationStorage.getNotificationsJson(reactContext)
promise.resolve(notificationsJson)
} catch (error: Throwable) {
promise.reject("Error", error)
}
}
@ReactMethod
override fun clearNotifications(promise: Promise) {
try {
NotificationStorage.clearNotifications(reactContext)
promise.resolve(null)
} catch (error: Throwable) {
promise.reject("Error", error)
}
}
override fun invalidate() {
if (activeModule === this) {
activeModule = null
}
super.invalidate()
}
private fun emitNotificationCenterUpdated() {
emitOnNotificationCenterUpdated(Arguments.createMap())
}
}