From 2cb147771e137488b0de825295c96da8143b2cdc Mon Sep 17 00:00:00 2001 From: Julia Spehrer Date: Wed, 29 May 2024 12:04:14 +0200 Subject: [PATCH] Use UiThreadUtil in android (#493) --- .../greweb/reactnativeviewshot/RNViewShotModule.java | 6 +----- .../java/fr/greweb/reactnativeviewshot/ViewShot.java | 10 +++------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/android/src/main/java/fr/greweb/reactnativeviewshot/RNViewShotModule.java b/android/src/main/java/fr/greweb/reactnativeviewshot/RNViewShotModule.java index 8710b0af..757bcd28 100644 --- a/android/src/main/java/fr/greweb/reactnativeviewshot/RNViewShotModule.java +++ b/android/src/main/java/fr/greweb/reactnativeviewshot/RNViewShotModule.java @@ -28,8 +28,6 @@ import java.io.IOException; import java.util.Collections; import java.util.Map; -import java.util.concurrent.Executor; -import java.util.concurrent.Executors; import fr.greweb.reactnativeviewshot.ViewShot.Formats; import fr.greweb.reactnativeviewshot.ViewShot.Results; @@ -40,8 +38,6 @@ public class RNViewShotModule extends ReactContextBaseJavaModule implements Turb private final ReactApplicationContext reactContext; - private final Executor executor = Executors.newCachedThreadPool(); - public RNViewShotModule(ReactApplicationContext reactContext) { super(reactContext); this.reactContext = reactContext; @@ -108,7 +104,7 @@ public void captureRef(double tagFromJs, ReadableMap options, Promise promise) { ViewShot uiBlock = new ViewShot( tag, extension, imageFormat, quality, scaleWidth, scaleHeight, outputFile, resultStreamFormat, - snapshotContentContainer, reactContext, activity, handleGLSurfaceView, promise, executor + snapshotContentContainer, reactContext, activity, handleGLSurfaceView, promise ); if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) { diff --git a/android/src/main/java/fr/greweb/reactnativeviewshot/ViewShot.java b/android/src/main/java/fr/greweb/reactnativeviewshot/ViewShot.java index ce81dda6..3517fd65 100644 --- a/android/src/main/java/fr/greweb/reactnativeviewshot/ViewShot.java +++ b/android/src/main/java/fr/greweb/reactnativeviewshot/ViewShot.java @@ -26,6 +26,7 @@ import com.facebook.react.bridge.Promise; import com.facebook.react.bridge.ReactApplicationContext; +import com.facebook.react.bridge.UiThreadUtil; import com.facebook.react.fabric.interop.UIBlockViewResolver; import com.facebook.react.uimanager.NativeViewHierarchyManager; import com.facebook.react.uimanager.UIBlock; @@ -46,8 +47,6 @@ import java.util.Set; import java.util.WeakHashMap; import java.util.concurrent.CountDownLatch; -import java.util.concurrent.Executor; -import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import java.util.zip.Deflater; @@ -144,7 +143,6 @@ public class ViewShot implements UIBlock, com.facebook.react.fabric.interop.UIBl private final ReactApplicationContext reactContext; private final boolean handleGLSurfaceView; private final Activity currentActivity; - private final Executor executor; //endregion //region Constructors @@ -162,8 +160,7 @@ public ViewShot( final ReactApplicationContext reactContext, final Activity currentActivity, final boolean handleGLSurfaceView, - final Promise promise, - final Executor executor) { + final Promise promise) { this.tag = tag; this.extension = extension; this.format = format; @@ -177,7 +174,6 @@ public ViewShot( this.currentActivity = currentActivity; this.handleGLSurfaceView = handleGLSurfaceView; this.promise = promise; - this.executor = executor; } //endregion @@ -195,7 +191,7 @@ public void execute(@NonNull UIBlockViewResolver uiBlockViewResolver) { //region Implementation private void executeImpl(final NativeViewHierarchyManager nativeViewHierarchyManager, final UIBlockViewResolver uiBlockViewResolver) { - executor.execute(new Runnable () { + UiThreadUtil.runOnUiThread(new Runnable () { @Override public void run() { try {