diff --git a/android/src/main/java/fr/greweb/reactnativeviewshot/RNViewShotModule.java b/android/src/main/java/fr/greweb/reactnativeviewshot/RNViewShotModule.java index 38413de..ef175e3 100644 --- a/android/src/main/java/fr/greweb/reactnativeviewshot/RNViewShotModule.java +++ b/android/src/main/java/fr/greweb/reactnativeviewshot/RNViewShotModule.java @@ -25,8 +25,6 @@ import java.io.File; import java.io.FilenameFilter; import java.io.IOException; -import java.util.concurrent.Executor; -import java.util.concurrent.Executors; import fr.greweb.reactnativeviewshot.ViewShot.Formats; import fr.greweb.reactnativeviewshot.ViewShot.Results; @@ -35,8 +33,6 @@ public class RNViewShotModule extends NativeRNViewShotSpec { private final ReactApplicationContext reactContext; - private final Executor executor = Executors.newCachedThreadPool(); - public RNViewShotModule(ReactApplicationContext reactContext) { super(reactContext); this.reactContext = reactContext; @@ -93,7 +89,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 ce81dda..3517fd6 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 {