@rnmapbox/maps 10.1.43 → 10.1.44-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -21,7 +21,29 @@ typealias ViewRefTag = Double
|
|
|
21
21
|
open class ViewTagResolver(val context: ReactApplicationContext) {
|
|
22
22
|
private val createdViews: HashSet<Int> = hashSetOf<Int>()
|
|
23
23
|
private val viewWaiters: HashMap<Int, MutableList<ViewTagWaiter<View?>>> = hashMapOf()
|
|
24
|
+
private val handler = android.os.Handler(android.os.Looper.getMainLooper())
|
|
24
25
|
|
|
26
|
+
private fun <V>addWaiterWithTimeout(viewTag: Int, reject: Promise?, fn: (V) -> Unit) {
|
|
27
|
+
val waiter = ViewTagWaiter<View?>({ view ->
|
|
28
|
+
if (view != null) {
|
|
29
|
+
fn(view as V)
|
|
30
|
+
} else {
|
|
31
|
+
Logger.e(LOG_TAG, "view: $viewTag but is null (timeout or resolve)")
|
|
32
|
+
reject?.reject(Throwable("view: $viewTag but is null (timeout or resolve)"))
|
|
33
|
+
}
|
|
34
|
+
}, reject)
|
|
35
|
+
viewWaiters.getOrPut(viewTag) { mutableListOf() }.add(waiter)
|
|
36
|
+
handler.postDelayed({
|
|
37
|
+
if (viewWaiters[viewTag]?.contains(waiter) == true) {
|
|
38
|
+
Logger.e(LOG_TAG, "Timeout waiting for view with tag: $viewTag")
|
|
39
|
+
reject?.reject(Throwable("Timeout waiting for view with tag: $viewTag"))
|
|
40
|
+
viewWaiters[viewTag]?.remove(waiter)
|
|
41
|
+
if (viewWaiters[viewTag]?.isEmpty() == true) {
|
|
42
|
+
viewWaiters.remove(viewTag)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}, 200)
|
|
46
|
+
}
|
|
25
47
|
// to be called from view.setId
|
|
26
48
|
fun tagAssigned(viewTag: Int) {
|
|
27
49
|
createdViews.add(viewTag)
|
|
@@ -63,23 +85,15 @@ open class ViewTagResolver(val context: ReactApplicationContext) {
|
|
|
63
85
|
if (view != null) {
|
|
64
86
|
fn(view)
|
|
65
87
|
} else {
|
|
66
|
-
|
|
67
|
-
reject?.reject(Throwable("view: $resolvedView found with tag: $viewTag but it's either null or not the correct type"))
|
|
88
|
+
addWaiterWithTimeout(viewTag, reject, fn)
|
|
68
89
|
}
|
|
69
90
|
} catch (err: IllegalViewOperationException) {
|
|
70
91
|
if (!createdViews.contains(viewTag)) {
|
|
71
|
-
|
|
72
|
-
if (view != null) {
|
|
73
|
-
fn(view as V)
|
|
74
|
-
} else {
|
|
75
|
-
Logger.e(LOG_TAG, "view: $viewTag but is null")
|
|
76
|
-
reject?.reject(Throwable("view: $viewTag but is null"))
|
|
77
|
-
}
|
|
78
|
-
}, reject))
|
|
92
|
+
addWaiterWithTimeout(viewTag, reject, fn)
|
|
79
93
|
} else {
|
|
80
94
|
reject?.reject(err)
|
|
81
95
|
}
|
|
82
96
|
}
|
|
83
97
|
}
|
|
84
98
|
}
|
|
85
|
-
}
|
|
99
|
+
}
|