Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use UiThreadUtil in android (#493) #531

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
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