@ammarahmed/notifee-react-native 7.4.9 → 7.4.10

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
- private static final SparseArray<GenericCallback> headlessTasks = new SparseArray<>();
36
- private static final HeadlessJsTaskEventListener headlessTasksListener =
37
- new HeadlessJsTaskEventListener() {
38
- @Override
39
- public void onHeadlessJsTaskStart(int taskId) {}
40
-
41
- @Override
42
- public void onHeadlessJsTaskFinish(int taskId) {
43
- synchronized (headlessTasks) {
44
- GenericCallback callback = headlessTasks.get(taskId);
45
- if (callback != null) {
46
- headlessTasks.remove(taskId);
47
- callback.call();
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
- static void promiseResolver(Promise promise, Exception e, List<Bundle> bundleList) {
65
- if (e != null) {
66
- // TODO custom error class with message/code
67
- promise.reject(e);
68
- } else {
69
- WritableArray writableArray = Arguments.createArray();
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
- static void promiseBooleanResolver(Promise promise, Exception e, Boolean bool) {
78
- if (e != null) {
79
- // TODO custom error class with message/code
80
- promise.reject(e);
81
- } else {
82
- promise.resolve(bool);
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
+ }
105
+ }
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
+ }
83
114
  }
84
- }
85
-
86
- static void promiseStringListResolver(Promise promise, Exception e, List<String> stringList) {
87
- if (e != null) {
88
- // TODO custom error class with message/code
89
- promise.reject(e);
90
- } else {
91
- WritableArray writableArray = Arguments.createArray();
92
- for (String string : stringList) {
93
- writableArray.pushString(string);
94
- }
95
- promise.resolve(writableArray);
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();
96
121
  }
97
- }
98
-
99
- static void promiseResolver(Promise promise, Exception e) {
100
- if (e != null) {
101
- // TODO custom error class with message/code
102
- promise.reject(e);
103
- } else {
104
- promise.resolve(null);
122
+
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
+ }
105
138
  }
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
-
130
- if (!reactInstanceManager.hasStartedCreatingInitialContext()) {
131
- reactInstanceManager.createReactContextInBackground();
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
+ }
132
146
  }
133
- }
134
147
 
135
- static void clearRunningHeadlessTasks() {
136
- for (int i = 0; i < headlessTasks.size(); i++) {
137
- GenericCallback callback = headlessTasks.valueAt(i);
138
- callback.call();
139
- headlessTasks.remove(i);
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
+ callback.call();
183
+ }
140
184
  }
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);
185
+
186
+ static void sendEvent(String eventName, WritableMap eventMap) {
187
+ try {
188
+ ReactContext reactContext = getReactContext();
189
+
190
+ if (reactContext == null || !reactContext.hasActiveReactInstance()) {
191
+ return;
157
192
  }
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
193
 
174
- if (getReactContext() == null) {
175
- initializeReactContext(callback);
176
- } else {
177
- callback.call();
194
+ reactContext
195
+ .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
196
+ .emit(eventName, eventMap);
197
+
198
+ } catch (Exception e) {
199
+ Log.e("SEND_EVENT", "", e);
200
+ }
178
201
  }
179
- }
180
202
 
181
- static void sendEvent(String eventName, WritableMap eventMap) {
182
- try {
183
- ReactContext reactContext = getReactContext();
203
+ static boolean isAppInForeground() {
204
+ Context context = EventSubscriber.getContext();
184
205
 
185
- if (reactContext == null || !reactContext.hasActiveCatalystInstance()) {
186
- return;
187
- }
206
+ ActivityManager activityManager =
207
+ (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
208
+ if (activityManager == null) return false;
188
209
 
189
- reactContext
190
- .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
191
- .emit(eventName, eventMap);
210
+ List<ActivityManager.RunningAppProcessInfo> appProcesses =
211
+ activityManager.getRunningAppProcesses();
212
+ if (appProcesses == null) return false;
192
213
 
193
- } catch (Exception e) {
194
- Log.e("SEND_EVENT", "", e);
195
- }
196
- }
197
-
198
- static boolean isAppInForeground() {
199
- Context context = EventSubscriber.getContext();
200
-
201
- ActivityManager activityManager =
202
- (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
203
- if (activityManager == null) return false;
204
-
205
- List<ActivityManager.RunningAppProcessInfo> appProcesses =
206
- activityManager.getRunningAppProcesses();
207
- if (appProcesses == null) return false;
208
-
209
- final String packageName = context.getPackageName();
210
- for (ActivityManager.RunningAppProcessInfo appProcess : appProcesses) {
211
- if (appProcess.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND
212
- && appProcess.processName.equals(packageName)) {
213
- ReactContext reactContext = getReactContext();
214
- if (reactContext == null) {
215
- return false;
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 reactContext.getLifecycleState() == LifecycleState.RESUMED;
219
- }
227
+ return false;
220
228
  }
221
229
 
222
- return false;
223
- }
224
-
225
- static void hideNotificationDrawer() {
226
- Context context = EventSubscriber.getContext();
227
-
228
- try {
229
- @SuppressLint("WrongConstant")
230
- Object service = context.getSystemService("statusbar");
231
- Class<?> statusbarManager = Class.forName("android.app.StatusBarManager");
232
- Method collapse =
233
- statusbarManager.getMethod((Build.VERSION.SDK_INT >= 17) ? "collapsePanels" : "collapse");
234
- collapse.setAccessible(true);
235
- collapse.invoke(service);
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
- interface GenericCallback {
242
- void call();
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.6";
1
+ export declare const version = "7.4.10";
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":";;;AAAA,2BAA2B;AACd,QAAA,OAAO,GAAG,OAAO,CAAC"}
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.9",
3
+ "version": "7.4.10",
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.6';
2
+ export const version = '7.4.10';