-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathHybridViewModelEnumProperty.kt
More file actions
49 lines (43 loc) · 1.38 KB
/
HybridViewModelEnumProperty.kt
File metadata and controls
49 lines (43 loc) · 1.38 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package com.margelo.nitro.rive
import androidx.annotation.Keep
import app.rive.ViewModelInstance
import com.facebook.proguard.annotations.DoNotStrip
import com.margelo.nitro.core.Promise
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.runBlocking
@Keep
@DoNotStrip
class HybridViewModelEnumProperty(
private val instance: ViewModelInstance,
private val path: String
) : HybridViewModelEnumPropertySpec(),
BaseHybridViewModelProperty<String> by BaseHybridViewModelPropertyImpl() {
companion object {
private const val TAG = "HybridViewModelEnumProperty"
}
// Deprecated: Use getValueAsync (read) or set(value) (write) instead
override var value: String
get() {
DeprecationWarning.warn("EnumProperty.value", "getValueAsync")
return try {
runBlocking { instance.getEnumFlow(path).first() }
} catch (e: Exception) {
RiveLog.e(TAG, "getValue failed for path '$path': ${e.message}")
""
}
}
set(value) {
set(value)
}
override fun set(value: String) {
instance.setEnum(path, value)
}
override fun getValueAsync(): Promise<String> {
return Promise.async { instance.getEnumFlow(path).first() }
}
override fun addListener(onChanged: (value: String) -> Unit): () -> Unit {
val remover = addListenerInternal(onChanged)
ensureValueListenerJob(instance.getEnumFlow(path))
return remover
}
}