Skip to content

Commit

Permalink
Use UiThreadUtil in android (gre#493)
Browse files Browse the repository at this point in the history
  • Loading branch information
jspehrer committed May 29, 2024
1 parent 8fb3ade commit 2cb1477
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -177,7 +174,6 @@ public ViewShot(
this.currentActivity = currentActivity;
this.handleGLSurfaceView = handleGLSurfaceView;
this.promise = promise;
this.executor = executor;
}
//endregion

Expand All @@ -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 {
Expand Down

0 comments on commit 2cb1477

Please sign in to comment.