diff --git a/ReactAndroid/src/main/java/com/facebook/react/bridge/UiThreadUtil.java b/ReactAndroid/src/main/java/com/facebook/react/bridge/UiThreadUtil.java index 14b43043088..e4587e2711b 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/bridge/UiThreadUtil.java +++ b/ReactAndroid/src/main/java/com/facebook/react/bridge/UiThreadUtil.java @@ -10,6 +10,7 @@ package com.facebook.react.bridge; import android.os.Handler; import android.os.Looper; import androidx.annotation.Nullable; +import com.facebook.react.common.build.ReactBuildConfig; /** Utility for interacting with the UI thread. */ public class UiThreadUtil { @@ -21,14 +22,26 @@ public class UiThreadUtil { return Looper.getMainLooper().getThread() == Thread.currentThread(); } - /** Throws an {@link AssertionException} if the current thread is not the UI thread. */ + /** + * Throws an {@link AssertionException} if the current thread is not the UI thread. This is a noop + * in production, and is only meant to run in debug mode! If you need to check for + * incorrect-thread issues in production, duplicate this code and call it elsewhere. + */ public static void assertOnUiThread() { - SoftAssertions.assertCondition(isOnUiThread(), "Expected to run on UI thread!"); + if (ReactBuildConfig.DEBUG) { + SoftAssertions.assertCondition(isOnUiThread(), "Expected to run on UI thread!"); + } } - /** Throws an {@link AssertionException} if the current thread is the UI thread. */ + /** + * Throws an {@link AssertionException} if the current thread is the UI thread. This is a noop in + * production, and is only meant to run in debug mode! If you need to check for incorrect-thread + * issues in production, duplicate this code and call it elsewhere. + */ public static void assertNotOnUiThread() { - SoftAssertions.assertCondition(!isOnUiThread(), "Expected not to run on UI thread!"); + if (ReactBuildConfig.DEBUG) { + SoftAssertions.assertCondition(!isOnUiThread(), "Expected not to run on UI thread!"); + } } /** Runs the given {@code Runnable} on the UI thread. */