@ammarahmed/notifee-react-native 7.4.9 → 7.4.11
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.
|
@@ -13,9 +13,15 @@ import android.os.Handler;
|
|
|
13
13
|
import android.os.Looper;
|
|
14
14
|
import android.util.Log;
|
|
15
15
|
import android.util.SparseArray;
|
|
16
|
+
|
|
17
|
+
import androidx.annotation.NonNull;
|
|
16
18
|
import androidx.annotation.Nullable;
|
|
19
|
+
|
|
17
20
|
import app.notifee.core.EventSubscriber;
|
|
21
|
+
|
|
18
22
|
import com.facebook.react.ReactApplication;
|
|
23
|
+
import com.facebook.react.ReactHost;
|
|
24
|
+
import com.facebook.react.ReactInstanceEventListener;
|
|
19
25
|
import com.facebook.react.ReactInstanceManager;
|
|
20
26
|
import com.facebook.react.ReactNativeHost;
|
|
21
27
|
import com.facebook.react.bridge.Arguments;
|
|
@@ -28,217 +34,216 @@ import com.facebook.react.jstasks.HeadlessJsTaskConfig;
|
|
|
28
34
|
import com.facebook.react.jstasks.HeadlessJsTaskContext;
|
|
29
35
|
import com.facebook.react.jstasks.HeadlessJsTaskEventListener;
|
|
30
36
|
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
|
37
|
+
|
|
31
38
|
import java.lang.reflect.Method;
|
|
32
39
|
import java.util.List;
|
|
33
40
|
|
|
34
41
|
class NotifeeReactUtils {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
42
|
+
private static final SparseArray<GenericCallback> headlessTasks = new SparseArray<>();
|
|
43
|
+
private static final HeadlessJsTaskEventListener headlessTasksListener =
|
|
44
|
+
new HeadlessJsTaskEventListener() {
|
|
45
|
+
@Override
|
|
46
|
+
public void onHeadlessJsTaskStart(int taskId) {
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
@Override
|
|
50
|
+
public void onHeadlessJsTaskFinish(int taskId) {
|
|
51
|
+
synchronized (headlessTasks) {
|
|
52
|
+
GenericCallback callback = headlessTasks.get(taskId);
|
|
53
|
+
if (callback != null) {
|
|
54
|
+
headlessTasks.remove(taskId);
|
|
55
|
+
callback.call();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
static void promiseResolver(Promise promise, Exception e, Bundle bundle) {
|
|
62
|
+
if (e != null) {
|
|
63
|
+
// TODO custom error class with message/code
|
|
64
|
+
promise.reject(e);
|
|
65
|
+
} else if (bundle != null) {
|
|
66
|
+
promise.resolve(Arguments.fromBundle(bundle));
|
|
67
|
+
} else {
|
|
68
|
+
promise.resolve(null);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
static void promiseResolver(Promise promise, Exception e, List<Bundle> bundleList) {
|
|
73
|
+
if (e != null) {
|
|
74
|
+
// TODO custom error class with message/code
|
|
75
|
+
promise.reject(e);
|
|
76
|
+
} else {
|
|
77
|
+
WritableArray writableArray = Arguments.createArray();
|
|
78
|
+
for (Bundle bundle : bundleList) {
|
|
79
|
+
writableArray.pushMap(Arguments.fromBundle(bundle));
|
|
48
80
|
}
|
|
49
|
-
|
|
81
|
+
promise.resolve(writableArray);
|
|
50
82
|
}
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
static void promiseResolver(Promise promise, Exception e, Bundle bundle) {
|
|
54
|
-
if (e != null) {
|
|
55
|
-
// TODO custom error class with message/code
|
|
56
|
-
promise.reject(e);
|
|
57
|
-
} else if (bundle != null) {
|
|
58
|
-
promise.resolve(Arguments.fromBundle(bundle));
|
|
59
|
-
} else {
|
|
60
|
-
promise.resolve(null);
|
|
61
83
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
for (Bundle bundle : bundleList) {
|
|
71
|
-
writableArray.pushMap(Arguments.fromBundle(bundle));
|
|
72
|
-
}
|
|
73
|
-
promise.resolve(writableArray);
|
|
84
|
+
|
|
85
|
+
static void promiseBooleanResolver(Promise promise, Exception e, Boolean bool) {
|
|
86
|
+
if (e != null) {
|
|
87
|
+
// TODO custom error class with message/code
|
|
88
|
+
promise.reject(e);
|
|
89
|
+
} else {
|
|
90
|
+
promise.resolve(bool);
|
|
91
|
+
}
|
|
74
92
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
93
|
+
|
|
94
|
+
static void promiseStringListResolver(Promise promise, Exception e, List<String> stringList) {
|
|
95
|
+
if (e != null) {
|
|
96
|
+
// TODO custom error class with message/code
|
|
97
|
+
promise.reject(e);
|
|
98
|
+
} else {
|
|
99
|
+
WritableArray writableArray = Arguments.createArray();
|
|
100
|
+
for (String string : stringList) {
|
|
101
|
+
writableArray.pushString(string);
|
|
102
|
+
}
|
|
103
|
+
promise.resolve(writableArray);
|
|
104
|
+
}
|
|
83
105
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
for (String string : stringList) {
|
|
93
|
-
writableArray.pushString(string);
|
|
94
|
-
}
|
|
95
|
-
promise.resolve(writableArray);
|
|
106
|
+
|
|
107
|
+
static void promiseResolver(Promise promise, Exception e) {
|
|
108
|
+
if (e != null) {
|
|
109
|
+
// TODO custom error class with message/code
|
|
110
|
+
promise.reject(e);
|
|
111
|
+
} else {
|
|
112
|
+
promise.resolve(null);
|
|
113
|
+
}
|
|
96
114
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
} else {
|
|
104
|
-
promise.resolve(null);
|
|
115
|
+
|
|
116
|
+
private static @Nullable ReactContext getReactContext() {
|
|
117
|
+
ReactHost reactNativeHost =
|
|
118
|
+
((ReactApplication) EventSubscriber.getContext()).getReactHost();
|
|
119
|
+
if (reactNativeHost == null) return null;
|
|
120
|
+
return reactNativeHost.getCurrentReactContext();
|
|
105
121
|
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
private static @Nullable ReactContext getReactContext() {
|
|
109
|
-
ReactNativeHost reactNativeHost =
|
|
110
|
-
((ReactApplication) EventSubscriber.getContext()).getReactNativeHost();
|
|
111
|
-
ReactInstanceManager reactInstanceManager = reactNativeHost.getReactInstanceManager();
|
|
112
|
-
return reactInstanceManager.getCurrentReactContext();
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
private static void initializeReactContext(GenericCallback callback) {
|
|
116
|
-
ReactNativeHost reactNativeHost =
|
|
117
|
-
((ReactApplication) EventSubscriber.getContext()).getReactNativeHost();
|
|
118
|
-
|
|
119
|
-
ReactInstanceManager reactInstanceManager = reactNativeHost.getReactInstanceManager();
|
|
120
|
-
|
|
121
|
-
reactInstanceManager.addReactInstanceEventListener(
|
|
122
|
-
new ReactInstanceManager.ReactInstanceEventListener() {
|
|
123
|
-
@Override
|
|
124
|
-
public void onReactContextInitialized(final ReactContext reactContext) {
|
|
125
|
-
reactInstanceManager.removeReactInstanceEventListener(this);
|
|
126
|
-
new Handler(Looper.getMainLooper()).postDelayed(callback::call, 100);
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
122
|
|
|
130
|
-
|
|
131
|
-
|
|
123
|
+
private static void initializeReactContext(GenericCallback callback) {
|
|
124
|
+
ReactHost reactNativeHost =
|
|
125
|
+
((ReactApplication) EventSubscriber.getContext()).getReactHost();
|
|
126
|
+
|
|
127
|
+
if (reactNativeHost != null) {
|
|
128
|
+
reactNativeHost.addReactInstanceEventListener(
|
|
129
|
+
new ReactInstanceEventListener() {
|
|
130
|
+
@Override
|
|
131
|
+
public void onReactContextInitialized(@NonNull final ReactContext reactContext) {
|
|
132
|
+
reactNativeHost.removeReactInstanceEventListener(this);
|
|
133
|
+
new Handler(Looper.getMainLooper()).postDelayed(callback::call, 100);
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
reactNativeHost.start();
|
|
137
|
+
}
|
|
132
138
|
}
|
|
133
|
-
}
|
|
134
139
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
+
static void clearRunningHeadlessTasks() {
|
|
141
|
+
for (int i = 0; i < headlessTasks.size(); i++) {
|
|
142
|
+
GenericCallback callback = headlessTasks.valueAt(i);
|
|
143
|
+
callback.call();
|
|
144
|
+
headlessTasks.remove(i);
|
|
145
|
+
}
|
|
140
146
|
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
static void startHeadlessTask(
|
|
144
|
-
String taskName,
|
|
145
|
-
WritableMap taskData,
|
|
146
|
-
long taskTimeout,
|
|
147
|
-
@Nullable GenericCallback taskCompletionCallback) {
|
|
148
|
-
GenericCallback callback =
|
|
149
|
-
() -> {
|
|
150
|
-
HeadlessJsTaskContext taskContext = HeadlessJsTaskContext.getInstance(getReactContext());
|
|
151
|
-
HeadlessJsTaskConfig taskConfig =
|
|
152
|
-
new HeadlessJsTaskConfig(taskName, taskData, taskTimeout, true);
|
|
153
|
-
|
|
154
|
-
synchronized (headlessTasks) {
|
|
155
|
-
if (headlessTasks.size() == 0) {
|
|
156
|
-
taskContext.addTaskEventListener(headlessTasksListener);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
headlessTasks.put(
|
|
161
|
-
taskContext.startTask(taskConfig),
|
|
162
|
-
() -> {
|
|
163
|
-
synchronized (headlessTasks) {
|
|
164
|
-
if (headlessTasks.size() == 0) {
|
|
165
|
-
taskContext.removeTaskEventListener(headlessTasksListener);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
if (taskCompletionCallback != null) {
|
|
169
|
-
taskCompletionCallback.call();
|
|
170
|
-
}
|
|
171
|
-
});
|
|
172
|
-
};
|
|
173
147
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
148
|
+
static void startHeadlessTask(
|
|
149
|
+
String taskName,
|
|
150
|
+
WritableMap taskData,
|
|
151
|
+
long taskTimeout,
|
|
152
|
+
@Nullable GenericCallback taskCompletionCallback) {
|
|
153
|
+
GenericCallback callback =
|
|
154
|
+
() -> {
|
|
155
|
+
HeadlessJsTaskContext taskContext = HeadlessJsTaskContext.getInstance(getReactContext());
|
|
156
|
+
HeadlessJsTaskConfig taskConfig =
|
|
157
|
+
new HeadlessJsTaskConfig(taskName, taskData, taskTimeout, true);
|
|
158
|
+
|
|
159
|
+
synchronized (headlessTasks) {
|
|
160
|
+
if (headlessTasks.size() == 0) {
|
|
161
|
+
taskContext.addTaskEventListener(headlessTasksListener);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
headlessTasks.put(
|
|
166
|
+
taskContext.startTask(taskConfig),
|
|
167
|
+
() -> {
|
|
168
|
+
synchronized (headlessTasks) {
|
|
169
|
+
if (headlessTasks.size() == 0) {
|
|
170
|
+
taskContext.removeTaskEventListener(headlessTasksListener);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
if (taskCompletionCallback != null) {
|
|
174
|
+
taskCompletionCallback.call();
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
if (getReactContext() == null) {
|
|
180
|
+
initializeReactContext(callback);
|
|
181
|
+
} else {
|
|
182
|
+
new Handler(Looper.getMainLooper()).postDelayed(callback::call, 100);
|
|
183
|
+
}
|
|
178
184
|
}
|
|
179
|
-
}
|
|
180
185
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
186
|
+
static void sendEvent(String eventName, WritableMap eventMap) {
|
|
187
|
+
try {
|
|
188
|
+
ReactContext reactContext = getReactContext();
|
|
184
189
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
190
|
+
if (reactContext == null || !reactContext.hasActiveReactInstance()) {
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
188
193
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
194
|
+
reactContext
|
|
195
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
|
196
|
+
.emit(eventName, eventMap);
|
|
192
197
|
|
|
193
|
-
|
|
194
|
-
|
|
198
|
+
} catch (Exception e) {
|
|
199
|
+
Log.e("SEND_EVENT", "", e);
|
|
200
|
+
}
|
|
195
201
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
(
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
202
|
+
|
|
203
|
+
static boolean isAppInForeground() {
|
|
204
|
+
Context context = EventSubscriber.getContext();
|
|
205
|
+
|
|
206
|
+
ActivityManager activityManager =
|
|
207
|
+
(ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
|
208
|
+
if (activityManager == null) return false;
|
|
209
|
+
|
|
210
|
+
List<ActivityManager.RunningAppProcessInfo> appProcesses =
|
|
211
|
+
activityManager.getRunningAppProcesses();
|
|
212
|
+
if (appProcesses == null) return false;
|
|
213
|
+
|
|
214
|
+
final String packageName = context.getPackageName();
|
|
215
|
+
for (ActivityManager.RunningAppProcessInfo appProcess : appProcesses) {
|
|
216
|
+
if (appProcess.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND
|
|
217
|
+
&& appProcess.processName.equals(packageName)) {
|
|
218
|
+
ReactContext reactContext = getReactContext();
|
|
219
|
+
if (reactContext == null) {
|
|
220
|
+
return false;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
return reactContext.getLifecycleState() == LifecycleState.RESUMED;
|
|
224
|
+
}
|
|
216
225
|
}
|
|
217
226
|
|
|
218
|
-
return
|
|
219
|
-
}
|
|
227
|
+
return false;
|
|
220
228
|
}
|
|
221
229
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
} catch (Exception e) {
|
|
237
|
-
Log.e("HIDE_NOTIF_DRAWER", "", e);
|
|
230
|
+
static void hideNotificationDrawer() {
|
|
231
|
+
Context context = EventSubscriber.getContext();
|
|
232
|
+
|
|
233
|
+
try {
|
|
234
|
+
@SuppressLint("WrongConstant")
|
|
235
|
+
Object service = context.getSystemService("statusbar");
|
|
236
|
+
Class<?> statusbarManager = Class.forName("android.app.StatusBarManager");
|
|
237
|
+
Method collapse =
|
|
238
|
+
statusbarManager.getMethod((Build.VERSION.SDK_INT >= 17) ? "collapsePanels" : "collapse");
|
|
239
|
+
collapse.setAccessible(true);
|
|
240
|
+
collapse.invoke(service);
|
|
241
|
+
} catch (Exception e) {
|
|
242
|
+
Log.e("HIDE_NOTIF_DRAWER", "", e);
|
|
243
|
+
}
|
|
238
244
|
}
|
|
239
|
-
}
|
|
240
245
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
246
|
+
interface GenericCallback {
|
|
247
|
+
void call();
|
|
248
|
+
}
|
|
244
249
|
}
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "7.4.
|
|
1
|
+
export declare const version = "7.4.11";
|
package/dist/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":";;;AAAA,2BAA2B;AACd,QAAA,OAAO,GAAG,
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":";;;AAAA,2BAA2B;AACd,QAAA,OAAO,GAAG,QAAQ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ammarahmed/notifee-react-native",
|
|
3
|
-
"version": "7.4.
|
|
3
|
+
"version": "7.4.11",
|
|
4
4
|
"author": "Invertase <oss@invertase.io> (http://invertase.io)",
|
|
5
5
|
"description": "Notifee - a feature rich notifications library for React Native.",
|
|
6
6
|
"main": "dist/index.js",
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated by genversion.
|
|
2
|
-
export const version = '7.4.
|
|
2
|
+
export const version = '7.4.11';
|