-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMapHelper.kt
More file actions
35 lines (29 loc) · 866 Bytes
/
MapHelper.kt
File metadata and controls
35 lines (29 loc) · 866 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package com.rngooglemapsplus
import com.facebook.react.bridge.UiThreadUtil
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.runBlocking
inline fun onUi(crossinline block: () -> Unit) {
if (UiThreadUtil.isOnUiThread()) {
block()
} else {
UiThreadUtil.runOnUiThread { block() }
}
}
inline fun <T> onUiSync(crossinline block: () -> T): T {
if (UiThreadUtil.isOnUiThread()) return block()
val result = CompletableDeferred<T>()
UiThreadUtil.runOnUiThread {
runCatching(block).onSuccess(result::complete).onFailure(result::completeExceptionally)
}
return runBlocking { result.await() }
}
private const val MAPS_LOG_TAG = "react-native-google-maps-plus"
fun mapsLog(msg: String) {
android.util.Log.w(MAPS_LOG_TAG, msg)
}
fun mapsLog(
msg: String,
t: Throwable,
) {
android.util.Log.w(MAPS_LOG_TAG, msg, t)
}