Skip to content

Commit

Permalink
style: de-lint headless task
Browse files Browse the repository at this point in the history
  • Loading branch information
mikehardy committed Dec 20, 2024
1 parent a5a466f commit 4baca4f
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
*/
package io.invertase.notifee;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;
Expand Down Expand Up @@ -224,7 +225,7 @@ public void onHeadlessJsTaskFinish(int taskId) {
}
if (taskConfig != null) {
// Clear it from the Queue.
Log.d(HEADLESS_TASK_NAME, "taskId: " + taskConfig.getTaskId());
Log.d(HEADLESS_TASK_NAME, "completed taskId: " + taskConfig.getTaskId());
mTaskQueue.remove(taskConfig);
if (taskConfig.getCallback() != null) {
taskConfig.getCallback().call();
Expand All @@ -241,7 +242,7 @@ public void onHeadlessJsTaskFinish(int taskId) {
// Provide the RN taskId to our private TaskConfig instance, mapping the RN taskId to our
// TaskConfig's internal taskId.
taskConfig.setReactTaskId(taskId);
Log.d(HEADLESS_TASK_NAME, "taskId: " + taskId);
Log.d(HEADLESS_TASK_NAME, "launched taskId: " + taskId);
} catch (IllegalStateException e) {
Log.e(HEADLESS_TASK_NAME, e.getMessage(), e);
}
Expand All @@ -262,11 +263,13 @@ public static ReactNativeHost getReactNativeHost(Context context) {
}
}

@SuppressLint("VisibleForTests")
public static ReactContext getReactContext(Context context) {
if (isBridgelessArchitectureEnabled()) {
Object reactHost = getReactHost(context);
Assertions.assertNotNull(reactHost, "getReactHost() is null in New Architecture");
try {
assert reactHost != null;
Method getCurrentReactContext = reactHost.getClass().getMethod("getCurrentReactContext");
return (ReactContext) getCurrentReactContext.invoke(reactHost);
} catch (Exception e) {
Expand Down Expand Up @@ -299,6 +302,7 @@ public void onReactContextInitialized(@NonNull ReactContext reactContext) {
mIsReactContextInitialized.set(true);
drainTaskQueue(reactContext);
try {
assert reactHost != null;
Method removeReactInstanceEventListener =
reactHost
.getClass()
Expand All @@ -311,6 +315,7 @@ public void onReactContextInitialized(@NonNull ReactContext reactContext) {
}
};
try {
assert reactHost != null;
Method addReactInstanceEventListener =
reactHost
.getClass()
Expand Down Expand Up @@ -341,7 +346,7 @@ public void onReactContextInitialized(@NonNull ReactContext reactContext) {
/**
* Invokes HeadlessEvents queued while waiting for the ReactContext to initialize.
*
* @param reactContext
* @param reactContext context to use for task invocation
*/
private void drainTaskQueue(final ReactContext reactContext) {
if (mWillDrainTaskQueue.compareAndSet(false, true)) {
Expand All @@ -362,7 +367,7 @@ private void drainTaskQueue(final ReactContext reactContext) {
* Return true if this app is running with RN's bridgeless architecture. Cheers to @mikehardy for
* this idea.
*
* @return
* @return true if new arch bridgeless mode is enabled
*/
public static boolean isBridgelessArchitectureEnabled() {
try {
Expand Down

0 comments on commit 4baca4f

Please sign in to comment.