From b9ac29cf7ddca22876a779cca054ddcbb7c94c34 Mon Sep 17 00:00:00 2001 From: William Fernandes Date: Tue, 21 Jan 2025 21:35:03 -0300 Subject: [PATCH] fix: move view resolver out of the executor thread --- .../greweb/reactnativeviewshot/ViewShot.java | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/android/src/main/java/fr/greweb/reactnativeviewshot/ViewShot.java b/android/src/main/java/fr/greweb/reactnativeviewshot/ViewShot.java index ce81dda6..7b7332bf 100644 --- a/android/src/main/java/fr/greweb/reactnativeviewshot/ViewShot.java +++ b/android/src/main/java/fr/greweb/reactnativeviewshot/ViewShot.java @@ -195,26 +195,26 @@ public void execute(@NonNull UIBlockViewResolver uiBlockViewResolver) { //region Implementation private void executeImpl(final NativeViewHierarchyManager nativeViewHierarchyManager, final UIBlockViewResolver uiBlockViewResolver) { + final View view; + + if (tag == -1) { + view = currentActivity.getWindow().getDecorView().findViewById(android.R.id.content); + } else if (uiBlockViewResolver != null) { + view = uiBlockViewResolver.resolveView(tag); + } else { + view = nativeViewHierarchyManager.resolveView(tag); + } + + if (view == null) { + Log.e(TAG, "No view found with reactTag: " + tag, new AssertionError()); + promise.reject(ERROR_UNABLE_TO_SNAPSHOT, "No view found with reactTag: " + tag); + return; + } + executor.execute(new Runnable () { @Override public void run() { try { - final View view; - - if (tag == -1) { - view = currentActivity.getWindow().getDecorView().findViewById(android.R.id.content); - } else if (uiBlockViewResolver != null) { - view = uiBlockViewResolver.resolveView(tag); - } else { - view = nativeViewHierarchyManager.resolveView(tag); - } - - if (view == null) { - Log.e(TAG, "No view found with reactTag: " + tag, new AssertionError()); - promise.reject(ERROR_UNABLE_TO_SNAPSHOT, "No view found with reactTag: " + tag); - return; - } - final ReusableByteArrayOutputStream stream = new ReusableByteArrayOutputStream(outputBuffer); stream.setSize(proposeSize(view)); outputBuffer = stream.innerBuffer();