Skip to content

Commit 4a72040

Browse files
Rider WBA
1 parent 27e02b1 commit 4a72040

File tree

1 file changed

+21
-34
lines changed
  • packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge

1 file changed

+21
-34
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/UiThreadUtil.kt

Lines changed: 21 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@
1818

1919
@Volatile private var mainHandlerInternal: Handler? = null
2020

21-
/**
22-
* Handler associated with the main (UI) thread.
23-
* Exposed for Java interop as `getUiThreadHandler()`.
24-
*/
21+
2522
private val mainHandler: Handler
2623
get() {
2724
if (mainHandlerInternal == null) {
@@ -35,66 +32,56 @@
3532
}
3633

3734
/**
38-
* Java-compatible static getter for the UI thread handler.
39-
*/
35+
* Returns the handler associated with the main (UI) thread.
36+
* @return The handler for the main thread
37+
*/
4038
@JvmStatic
4139
public fun getUiThreadHandler(): Handler = mainHandler
40+
41+
4242
/**
43-
* Checks if the current thread is the UI thread.
44-
*
45-
* @return `true` if the current thread is the UI thread, `false` otherwise
46-
*/
43+
* @return `true` if the current thread is the UI thread.
44+
*/
4745
@JvmStatic
4846
public fun isOnUiThread(): Boolean = Looper.getMainLooper().thread == Thread.currentThread()
4947

48+
5049
/**
5150
* Throws an [AssertionException] if the current thread is not the UI thread.
52-
* This method is only active in debug mode and is a no-op in production.
53-
*/
51+
* This is a no-op in production and is only meant to run in debug mode!
52+
* If you need to check for incorrect-thread issues in production, duplicate this code and call it elsewhere.
53+
*/
5454
@JvmStatic
5555
public fun assertOnUiThread() {
5656
if (ReactBuildConfig.DEBUG) {
5757
SoftAssertions.assertCondition(isOnUiThread(), "Expected to run on UI thread!")
5858
}
5959
}
6060

61+
6162
/**
62-
* Throws an [AssertionException] if the current thread is the UI thread.
63-
* This method is only active in debug mode and is a no-op in production.
64-
*/
63+
* Throws an [AssertionException] if the current thread is the UI thread. This is a noop in
64+
* production, and is only meant to run in debug mode! If you need to check for incorrect-thread
65+
* issues in production, duplicate this code and call it elsewhere.
66+
*/
6567
@JvmStatic
6668
public fun assertNotOnUiThread() {
6769
if (ReactBuildConfig.DEBUG) {
6870
SoftAssertions.assertCondition(!isOnUiThread(), "Expected not to run on UI thread!")
6971
}
7072
}
71-
72-
/**
73-
* Runs the given [Runnable] on the UI thread.
74-
*
75-
* @param runnable the task to run
76-
* @return `true` if the runnable was successfully placed in the message queue
77-
*/
73+
74+
/** Runs the given [Runnable] on the UI thread. */
7875
@JvmStatic
7976
public fun runOnUiThread(runnable: Runnable): Boolean =
8077
mainHandler.postDelayed(runnable, 0)
8178

82-
/**
83-
* Posts a [Runnable] to run on the UI thread after a specified delay.
84-
*
85-
* @param runnable the task to run
86-
* @param delayInMs the delay in milliseconds before the task is executed
87-
* @return `true` if the runnable was successfully placed in the message queue
88-
*/
79+
/** Runs the given [Runnable] on the UI thread after the specified delay. */
8980
@JvmStatic
9081
public fun runOnUiThread(runnable: Runnable, delayInMs: Long): Boolean =
9182
mainHandler.postDelayed(runnable, delayInMs)
9283

93-
/**
94-
* Removes the given [Runnable] from the UI thread queue.
95-
*
96-
* @param runnable the task to remove
97-
*/
84+
/** Removes the given [Runnable] on the UI thread. */
9885
@JvmStatic
9986
public fun removeOnUiThread(runnable: Runnable?) {
10087
runnable?.let { mainHandler.removeCallbacks(it) }

0 commit comments

Comments
 (0)