-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathHybridViewModelInstance.kt
More file actions
55 lines (44 loc) · 1.85 KB
/
HybridViewModelInstance.kt
File metadata and controls
55 lines (44 loc) · 1.85 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
50
51
52
53
54
55
package com.margelo.nitro.rive
import androidx.annotation.Keep
import app.rive.runtime.kotlin.core.ViewModelInstance
import app.rive.runtime.kotlin.core.errors.ViewModelException
import com.facebook.proguard.annotations.DoNotStrip
@Keep
@DoNotStrip
class HybridViewModelInstance(val viewModelInstance: ViewModelInstance) : HybridViewModelInstanceSpec() {
override val instanceName: String
get() = viewModelInstance.name
// Returns null if ViewModelException is thrown for iOS parity
// (iOS SDK returns nil when property not found, Android SDK throws)
private inline fun <T> getPropertyOrNull(block: () -> T): T? {
return try {
block()
} catch (e: ViewModelException) {
null
}
}
override fun numberProperty(path: String) = getPropertyOrNull {
HybridViewModelNumberProperty(viewModelInstance.getNumberProperty(path))
}
override fun stringProperty(path: String) = getPropertyOrNull {
HybridViewModelStringProperty(viewModelInstance.getStringProperty(path))
}
override fun booleanProperty(path: String) = getPropertyOrNull {
HybridViewModelBooleanProperty(viewModelInstance.getBooleanProperty(path))
}
override fun colorProperty(path: String) = getPropertyOrNull {
HybridViewModelColorProperty(viewModelInstance.getColorProperty(path))
}
override fun enumProperty(path: String) = getPropertyOrNull {
HybridViewModelEnumProperty(viewModelInstance.getEnumProperty(path))
}
override fun triggerProperty(path: String) = getPropertyOrNull {
HybridViewModelTriggerProperty(viewModelInstance.getTriggerProperty(path))
}
override fun imageProperty(path: String) = getPropertyOrNull {
HybridViewModelImageProperty(viewModelInstance.getImageProperty(path))
}
override fun listProperty(path: String) = getPropertyOrNull {
HybridViewModelListProperty(viewModelInstance.getListProperty(path))
}
}