@thelacanians/vue-native-cli 0.4.2 → 0.4.4
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.
- package/dist/cli.js +43 -23
- package/native/android/README.md +205 -0
- package/native/android/VueNativeCore/build.gradle.kts +100 -0
- package/native/android/VueNativeCore/consumer-rules.pro +12 -0
- package/native/android/VueNativeCore/proguard-rules.pro +33 -0
- package/native/android/VueNativeCore/src/main/AndroidManifest.xml +17 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Bridge/ErrorOverlayView.kt +94 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Bridge/HotReloadManager.kt +105 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Bridge/JSPolyfills.kt +652 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Bridge/JSRuntime.kt +207 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Bridge/NativeBridge.kt +417 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/ComponentRegistry.kt +76 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VActionSheetFactory.kt +78 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VActivityIndicatorFactory.kt +46 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VAlertDialogFactory.kt +84 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VButtonFactory.kt +73 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VCheckboxFactory.kt +93 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VDropdownFactory.kt +125 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VImageFactory.kt +75 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VInputFactory.kt +210 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VKeyboardAvoidingFactory.kt +31 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VListFactory.kt +183 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VModalFactory.kt +105 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VPickerFactory.kt +57 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VPressableFactory.kt +109 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VProgressBarFactory.kt +43 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VRadioFactory.kt +103 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VRefreshControlFactory.kt +73 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VRootFactory.kt +39 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VSafeAreaFactory.kt +48 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VScrollViewFactory.kt +105 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VSectionListFactory.kt +144 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VSegmentedControlFactory.kt +77 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VSliderFactory.kt +74 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VStatusBarFactory.kt +52 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VSwitchFactory.kt +62 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VTextFactory.kt +53 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VVideoFactory.kt +191 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VViewFactory.kt +48 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VWebViewFactory.kt +90 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/NativeComponentFactory.kt +40 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/VTextNodeView.kt +23 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Helpers/GestureHelper.kt +16 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Helpers/TouchableView.kt +105 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/AnimationModule.kt +292 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/AppStateModule.kt +41 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/AsyncStorageModule.kt +59 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/AudioModule.kt +331 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/BackgroundTaskModule.kt +166 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/BiometryModule.kt +56 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/BluetoothModule.kt +302 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/CalendarModule.kt +198 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/CameraModule.kt +64 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/ClipboardModule.kt +36 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/ContactsModule.kt +288 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/DatabaseModule.kt +229 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/DeviceInfoModule.kt +39 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/FileSystemModule.kt +193 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/GeolocationModule.kt +68 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/HapticsModule.kt +61 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/HttpModule.kt +111 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/IAPModule.kt +302 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/KeyboardModule.kt +26 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/LinkingModule.kt +43 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/NativeModule.kt +27 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/NativeModuleRegistry.kt +92 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/NetworkModule.kt +75 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/NotificationsModule.kt +181 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/OTAModule.kt +255 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/PerformanceModule.kt +147 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/PermissionsModule.kt +126 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/SecureStorageModule.kt +51 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/SensorsModule.kt +134 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/ShareModule.kt +36 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/SocialAuthModule.kt +160 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/WebSocketModule.kt +155 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Styling/StyleEngine.kt +802 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Tags.kt +43 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/VueNativeActivity.kt +169 -0
- package/native/android/VueNativeCore/src/main/res/values/ids.xml +8 -0
- package/native/android/app/build.gradle.kts +45 -0
- package/native/android/app/proguard-rules.pro +5 -0
- package/native/android/app/src/main/AndroidManifest.xml +25 -0
- package/native/android/app/src/main/assets/.gitkeep +0 -0
- package/native/android/app/src/main/kotlin/com/vuenative/example/counter/MainActivity.kt +14 -0
- package/native/android/app/src/main/res/layout/activity_main.xml +6 -0
- package/native/android/app/src/main/res/values/strings.xml +3 -0
- package/native/android/app/src/main/res/values/themes.xml +9 -0
- package/native/android/app/src/main/res/xml/network_security_config.xml +8 -0
- package/native/android/build.gradle.kts +6 -0
- package/native/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/native/android/gradle/wrapper/gradle-wrapper.properties +7 -0
- package/native/android/gradle.properties +4 -0
- package/native/android/gradlew +87 -0
- package/native/android/gradlew.bat +48 -0
- package/native/android/settings.gradle.kts +20 -0
- package/native/ios/VueNativeCore/Package.resolved +23 -0
- package/native/ios/VueNativeCore/Package.swift +32 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Bridge/CertificatePinning.swift +132 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Bridge/ErrorOverlayView.swift +92 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Bridge/HotReloadManager.swift +147 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Bridge/JSPolyfills.swift +711 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Bridge/JSRuntime.swift +421 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Bridge/NativeBridge.swift +891 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Bridge/VueNativeViewController.swift +88 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/ComponentRegistry.swift +193 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VActionSheetFactory.swift +91 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VActivityIndicatorFactory.swift +74 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VAlertDialogFactory.swift +150 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VButtonFactory.swift +93 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VCheckboxFactory.swift +114 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VDropdownFactory.swift +112 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VImageFactory.swift +172 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VInputFactory.swift +357 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VKeyboardAvoidingFactory.swift +99 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VListFactory.swift +250 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VModalFactory.swift +112 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VPickerFactory.swift +96 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VPressableFactory.swift +168 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VProgressBarFactory.swift +39 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VRadioFactory.swift +167 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VRefreshControlFactory.swift +153 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VSafeAreaFactory.swift +56 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VScrollViewFactory.swift +240 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VSectionListFactory.swift +248 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VSegmentedControlFactory.swift +73 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VSliderFactory.swift +63 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VStatusBarFactory.swift +50 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VSwitchFactory.swift +108 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VTextFactory.swift +290 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VVideoFactory.swift +246 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VViewFactory.swift +157 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VWebViewFactory.swift +172 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/NativeComponentFactory.swift +53 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Helpers/GestureWrapper.swift +107 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Helpers/TouchableView.swift +136 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Helpers/UIColor+Hex.swift +80 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/AnimationModule.swift +291 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/AppStateModule.swift +65 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/AsyncStorageModule.swift +68 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/AudioModule.swift +366 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/BackgroundTaskModule.swift +135 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/BiometryModule.swift +61 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/BluetoothModule.swift +387 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/CalendarModule.swift +161 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/CameraModule.swift +318 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/ClipboardModule.swift +33 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/ContactsModule.swift +173 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/DatabaseModule.swift +259 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/DeviceInfoModule.swift +34 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/FileSystemModule.swift +233 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/GeolocationModule.swift +147 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/HapticsModule.swift +50 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/IAPModule.swift +194 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/KeyboardModule.swift +31 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/LinkingModule.swift +42 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/NativeModule.swift +28 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/NativeModuleRegistry.swift +78 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/NetworkModule.swift +62 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/NotificationsModule.swift +215 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/OTAModule.swift +281 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/PerformanceModule.swift +138 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/PermissionsModule.swift +190 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/SecureStorageModule.swift +118 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/SensorsModule.swift +103 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/ShareModule.swift +49 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/SocialAuthModule.swift +240 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/WebSocketModule.swift +213 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Resources/vue-native-placeholder.js +8 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Styling/StyleEngine.swift +885 -0
- package/native/ios/VueNativeCore/Tests/VueNativeCoreTests/JSRuntimeTests.swift +362 -0
- package/package.json +3 -2
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
package com.vuenative.core
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.view.View
|
|
5
|
+
import android.view.ViewGroup
|
|
6
|
+
import androidx.appcompat.app.AlertDialog
|
|
7
|
+
import org.json.JSONArray
|
|
8
|
+
|
|
9
|
+
class VActionSheetFactory : NativeComponentFactory {
|
|
10
|
+
data class SheetProps(
|
|
11
|
+
var title: String = "",
|
|
12
|
+
var message: String = "",
|
|
13
|
+
var actions: List<Map<String, String>> = emptyList()
|
|
14
|
+
)
|
|
15
|
+
private val props = mutableMapOf<View, SheetProps>()
|
|
16
|
+
private val actionHandlers = mutableMapOf<View, (Any?) -> Unit>()
|
|
17
|
+
private val cancelHandlers = mutableMapOf<View, (Any?) -> Unit>()
|
|
18
|
+
|
|
19
|
+
override fun createView(context: Context): View = View(context).apply {
|
|
20
|
+
layoutParams = ViewGroup.LayoutParams(0, 0)
|
|
21
|
+
visibility = View.GONE
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
override fun updateProp(view: View, key: String, value: Any?) {
|
|
25
|
+
val p = props.getOrPut(view) { SheetProps() }
|
|
26
|
+
when (key) {
|
|
27
|
+
"visible" -> { if (value == true || value == "true") showSheet(view, p) }
|
|
28
|
+
"title" -> p.title = value?.toString() ?: ""
|
|
29
|
+
"message" -> p.message = value?.toString() ?: ""
|
|
30
|
+
"actions" -> {
|
|
31
|
+
p.actions = when (value) {
|
|
32
|
+
is JSONArray -> (0 until value.length()).map { i ->
|
|
33
|
+
val a = value.getJSONObject(i)
|
|
34
|
+
mapOf("label" to a.optString("label",""), "style" to a.optString("style","default"))
|
|
35
|
+
}
|
|
36
|
+
is List<*> -> value.filterIsInstance<Map<String, String>>()
|
|
37
|
+
else -> emptyList()
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
private fun showSheet(view: View, p: SheetProps) {
|
|
44
|
+
val ctx = view.context
|
|
45
|
+
val items = p.actions.map { it["label"] ?: "" }.toTypedArray()
|
|
46
|
+
val cancelIdx = p.actions.indexOfFirst { it["style"] == "cancel" }
|
|
47
|
+
|
|
48
|
+
AlertDialog.Builder(ctx)
|
|
49
|
+
.setTitle(p.title.ifEmpty { null })
|
|
50
|
+
.setMessage(p.message.ifEmpty { null })
|
|
51
|
+
.setItems(items) { _, which ->
|
|
52
|
+
val action = p.actions.getOrNull(which)
|
|
53
|
+
if (action?.get("style") == "cancel") {
|
|
54
|
+
cancelHandlers[view]?.invoke(null)
|
|
55
|
+
} else {
|
|
56
|
+
actionHandlers[view]?.invoke(mapOf("label" to (action?.get("label") ?: ""), "index" to which))
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
.setNegativeButton("Cancel") { d, _ ->
|
|
60
|
+
d.dismiss()
|
|
61
|
+
cancelHandlers[view]?.invoke(null)
|
|
62
|
+
}
|
|
63
|
+
.show()
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
override fun addEventListener(view: View, event: String, handler: (Any?) -> Unit) {
|
|
67
|
+
when (event) {
|
|
68
|
+
"action" -> actionHandlers[view] = handler
|
|
69
|
+
"cancel" -> cancelHandlers[view] = handler
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
override fun removeEventListener(view: View, event: String) {
|
|
73
|
+
when (event) {
|
|
74
|
+
"action" -> actionHandlers.remove(view)
|
|
75
|
+
"cancel" -> cancelHandlers.remove(view)
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
package com.vuenative.core
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.content.res.ColorStateList
|
|
5
|
+
import android.view.View
|
|
6
|
+
import android.view.ViewGroup
|
|
7
|
+
import android.widget.ProgressBar
|
|
8
|
+
|
|
9
|
+
class VActivityIndicatorFactory : NativeComponentFactory {
|
|
10
|
+
override fun createView(context: Context): View {
|
|
11
|
+
return ProgressBar(context).apply {
|
|
12
|
+
isIndeterminate = true
|
|
13
|
+
layoutParams = ViewGroup.LayoutParams(
|
|
14
|
+
ViewGroup.LayoutParams.WRAP_CONTENT,
|
|
15
|
+
ViewGroup.LayoutParams.WRAP_CONTENT
|
|
16
|
+
)
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
override fun updateProp(view: View, key: String, value: Any?) {
|
|
21
|
+
val pb = view as? ProgressBar ?: return
|
|
22
|
+
when (key) {
|
|
23
|
+
"animating" -> pb.visibility = if (value == true || value == "true") View.VISIBLE else View.GONE
|
|
24
|
+
"size" -> {
|
|
25
|
+
val sizePx = when (value) {
|
|
26
|
+
"small" -> (20 * view.context.resources.displayMetrics.density).toInt()
|
|
27
|
+
"large" -> (48 * view.context.resources.displayMetrics.density).toInt()
|
|
28
|
+
else -> (32 * view.context.resources.displayMetrics.density).toInt()
|
|
29
|
+
}
|
|
30
|
+
pb.layoutParams?.also { lp ->
|
|
31
|
+
lp.width = sizePx
|
|
32
|
+
lp.height = sizePx
|
|
33
|
+
pb.layoutParams = lp
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
"color" -> {
|
|
37
|
+
val color = StyleEngine.parseColor(value) ?: return
|
|
38
|
+
pb.indeterminateTintList = ColorStateList.valueOf(color)
|
|
39
|
+
}
|
|
40
|
+
else -> StyleEngine.apply(key, value, view)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
override fun addEventListener(view: View, event: String, handler: (Any?) -> Unit) {}
|
|
45
|
+
override fun removeEventListener(view: View, event: String) {}
|
|
46
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
package com.vuenative.core
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.view.View
|
|
5
|
+
import android.view.ViewGroup
|
|
6
|
+
import androidx.appcompat.app.AlertDialog
|
|
7
|
+
import org.json.JSONArray
|
|
8
|
+
|
|
9
|
+
class VAlertDialogFactory : NativeComponentFactory {
|
|
10
|
+
data class DialogProps(
|
|
11
|
+
var title: String = "",
|
|
12
|
+
var message: String = "",
|
|
13
|
+
var buttons: List<Map<String, String>> = emptyList()
|
|
14
|
+
)
|
|
15
|
+
private val props = mutableMapOf<View, DialogProps>()
|
|
16
|
+
private val confirmHandlers = mutableMapOf<View, (Any?) -> Unit>()
|
|
17
|
+
private val cancelHandlers = mutableMapOf<View, (Any?) -> Unit>()
|
|
18
|
+
private val actionHandlers = mutableMapOf<View, (Any?) -> Unit>()
|
|
19
|
+
|
|
20
|
+
override fun createView(context: Context): View {
|
|
21
|
+
return View(context).apply {
|
|
22
|
+
layoutParams = ViewGroup.LayoutParams(0, 0)
|
|
23
|
+
visibility = View.GONE
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
override fun updateProp(view: View, key: String, value: Any?) {
|
|
28
|
+
val p = props.getOrPut(view) { DialogProps() }
|
|
29
|
+
when (key) {
|
|
30
|
+
"visible" -> {
|
|
31
|
+
if (value == true || value == "true") showDialog(view, p)
|
|
32
|
+
}
|
|
33
|
+
"title" -> p.title = value?.toString() ?: ""
|
|
34
|
+
"message" -> p.message = value?.toString() ?: ""
|
|
35
|
+
"buttons" -> {
|
|
36
|
+
p.buttons = when (value) {
|
|
37
|
+
is JSONArray -> (0 until value.length()).map { i ->
|
|
38
|
+
val btn = value.getJSONObject(i)
|
|
39
|
+
mapOf("label" to btn.optString("label","OK"), "style" to btn.optString("style","default"))
|
|
40
|
+
}
|
|
41
|
+
is List<*> -> value.filterIsInstance<Map<String, String>>()
|
|
42
|
+
else -> emptyList()
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
private fun showDialog(view: View, p: DialogProps) {
|
|
49
|
+
val ctx = view.context
|
|
50
|
+
val builder = AlertDialog.Builder(ctx)
|
|
51
|
+
.setTitle(p.title.ifEmpty { null })
|
|
52
|
+
.setMessage(p.message.ifEmpty { null })
|
|
53
|
+
|
|
54
|
+
if (p.buttons.isEmpty()) {
|
|
55
|
+
builder.setPositiveButton("OK") { d, _ -> d.dismiss(); confirmHandlers[view]?.invoke(null) }
|
|
56
|
+
} else {
|
|
57
|
+
p.buttons.forEach { btn ->
|
|
58
|
+
val label = btn["label"] ?: "OK"
|
|
59
|
+
val style = btn["style"] ?: "default"
|
|
60
|
+
when (style) {
|
|
61
|
+
"cancel" -> builder.setNegativeButton(label) { d, _ -> d.dismiss(); cancelHandlers[view]?.invoke(null) }
|
|
62
|
+
"destructive" -> builder.setNeutralButton(label) { d, _ -> d.dismiss(); confirmHandlers[view]?.invoke(mapOf("label" to label)) }
|
|
63
|
+
else -> builder.setPositiveButton(label) { d, _ -> d.dismiss(); confirmHandlers[view]?.invoke(mapOf("label" to label)) }
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
builder.create().show()
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
override fun addEventListener(view: View, event: String, handler: (Any?) -> Unit) {
|
|
71
|
+
when (event) {
|
|
72
|
+
"confirm" -> confirmHandlers[view] = handler
|
|
73
|
+
"cancel" -> cancelHandlers[view] = handler
|
|
74
|
+
"action" -> actionHandlers[view] = handler
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
override fun removeEventListener(view: View, event: String) {
|
|
78
|
+
when (event) {
|
|
79
|
+
"confirm" -> confirmHandlers.remove(view)
|
|
80
|
+
"cancel" -> cancelHandlers.remove(view)
|
|
81
|
+
"action" -> actionHandlers.remove(view)
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
package com.vuenative.core
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.view.View
|
|
5
|
+
import android.widget.TextView
|
|
6
|
+
import com.google.android.flexbox.FlexboxLayout
|
|
7
|
+
|
|
8
|
+
class VButtonFactory : NativeComponentFactory {
|
|
9
|
+
override fun createView(context: Context): View {
|
|
10
|
+
return TouchableView(context)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
override fun updateProp(view: View, key: String, value: Any?) {
|
|
14
|
+
val touchable = view as? TouchableView
|
|
15
|
+
if (touchable == null) {
|
|
16
|
+
StyleEngine.apply(key, value, view)
|
|
17
|
+
return
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
when (key) {
|
|
21
|
+
"disabled" -> {
|
|
22
|
+
touchable.isDisabled = value == true || value == "true" ||
|
|
23
|
+
(value is Number && value.toInt() != 0)
|
|
24
|
+
}
|
|
25
|
+
"activeOpacity" -> {
|
|
26
|
+
touchable.activeOpacity = when (value) {
|
|
27
|
+
is Double -> value.toFloat()
|
|
28
|
+
is Float -> value
|
|
29
|
+
is Int -> value.toFloat()
|
|
30
|
+
is String -> value.toFloatOrNull() ?: 0.7f
|
|
31
|
+
else -> 0.7f
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
"title" -> {
|
|
35
|
+
val flex = view as? FlexboxLayout
|
|
36
|
+
val tv = (0 until (flex?.childCount ?: 0))
|
|
37
|
+
.mapNotNull { flex?.getChildAt(it) as? TextView }
|
|
38
|
+
.firstOrNull()
|
|
39
|
+
tv?.text = value?.toString() ?: ""
|
|
40
|
+
}
|
|
41
|
+
else -> StyleEngine.apply(key, value, view)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
override fun addEventListener(view: View, event: String, handler: (Any?) -> Unit) {
|
|
46
|
+
val touchable = view as? TouchableView ?: return
|
|
47
|
+
|
|
48
|
+
when (event) {
|
|
49
|
+
"press" -> touchable.onPress = { handler(null) }
|
|
50
|
+
"longPress", "longpress" -> touchable.onLongPress = { handler(null) }
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
override fun removeEventListener(view: View, event: String) {
|
|
55
|
+
val touchable = view as? TouchableView ?: return
|
|
56
|
+
|
|
57
|
+
when (event) {
|
|
58
|
+
"press" -> touchable.onPress = null
|
|
59
|
+
"longPress", "longpress" -> touchable.onLongPress = null
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
override fun insertChild(parent: View, child: View, index: Int) {
|
|
64
|
+
val flex = parent as? FlexboxLayout ?: return
|
|
65
|
+
val lp = StyleEngine.buildFlexLayoutParams(child)
|
|
66
|
+
if (index >= flex.childCount) flex.addView(child, lp)
|
|
67
|
+
else flex.addView(child, index, lp)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
override fun removeChild(parent: View, child: View) {
|
|
71
|
+
(parent as? FlexboxLayout)?.removeView(child)
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
package com.vuenative.core
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.view.View
|
|
5
|
+
import android.view.ViewGroup
|
|
6
|
+
import android.widget.CheckBox
|
|
7
|
+
import android.widget.LinearLayout
|
|
8
|
+
import android.widget.TextView
|
|
9
|
+
|
|
10
|
+
class VCheckboxFactory : NativeComponentFactory {
|
|
11
|
+
private val changeHandlers = mutableMapOf<View, (Any?) -> Unit>()
|
|
12
|
+
|
|
13
|
+
override fun createView(context: Context): View {
|
|
14
|
+
return LinearLayout(context).apply {
|
|
15
|
+
orientation = LinearLayout.HORIZONTAL
|
|
16
|
+
gravity = android.view.Gravity.CENTER_VERTICAL
|
|
17
|
+
layoutParams = ViewGroup.LayoutParams(
|
|
18
|
+
ViewGroup.LayoutParams.WRAP_CONTENT,
|
|
19
|
+
ViewGroup.LayoutParams.WRAP_CONTENT
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
val checkbox = CheckBox(context).apply {
|
|
23
|
+
tag = "checkbox"
|
|
24
|
+
layoutParams = LinearLayout.LayoutParams(
|
|
25
|
+
LinearLayout.LayoutParams.WRAP_CONTENT,
|
|
26
|
+
LinearLayout.LayoutParams.WRAP_CONTENT
|
|
27
|
+
)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
val label = TextView(context).apply {
|
|
31
|
+
tag = "label"
|
|
32
|
+
textSize = 16f
|
|
33
|
+
layoutParams = LinearLayout.LayoutParams(
|
|
34
|
+
LinearLayout.LayoutParams.WRAP_CONTENT,
|
|
35
|
+
LinearLayout.LayoutParams.WRAP_CONTENT
|
|
36
|
+
).apply { marginStart = 8 }
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
addView(checkbox)
|
|
40
|
+
addView(label)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
override fun updateProp(view: View, key: String, value: Any?) {
|
|
45
|
+
val container = view as? LinearLayout ?: return
|
|
46
|
+
val checkbox = container.findViewWithTag<CheckBox>("checkbox") ?: return
|
|
47
|
+
val label = container.findViewWithTag<TextView>("label") ?: return
|
|
48
|
+
|
|
49
|
+
when (key) {
|
|
50
|
+
"value" -> {
|
|
51
|
+
val checked = value == true || value == "true" || value == 1
|
|
52
|
+
if (checkbox.isChecked != checked) checkbox.isChecked = checked
|
|
53
|
+
}
|
|
54
|
+
"label" -> {
|
|
55
|
+
label.text = value?.toString() ?: ""
|
|
56
|
+
label.visibility = if ((value?.toString() ?: "").isEmpty()) View.GONE else View.VISIBLE
|
|
57
|
+
}
|
|
58
|
+
"disabled" -> {
|
|
59
|
+
val disabled = value == true || value == "true"
|
|
60
|
+
checkbox.isEnabled = !disabled
|
|
61
|
+
container.alpha = if (disabled) 0.4f else 1.0f
|
|
62
|
+
}
|
|
63
|
+
"checkColor", "tintColor" -> {
|
|
64
|
+
val color = StyleEngine.parseColor(value) ?: return
|
|
65
|
+
checkbox.buttonTintList = android.content.res.ColorStateList.valueOf(color)
|
|
66
|
+
}
|
|
67
|
+
else -> StyleEngine.apply(key, value, view)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
override fun addEventListener(view: View, event: String, handler: (Any?) -> Unit) {
|
|
72
|
+
if (event != "change") return
|
|
73
|
+
val container = view as? LinearLayout ?: return
|
|
74
|
+
val checkbox = container.findViewWithTag<CheckBox>("checkbox") ?: return
|
|
75
|
+
changeHandlers[view] = handler
|
|
76
|
+
checkbox.setOnCheckedChangeListener { _, isChecked ->
|
|
77
|
+
changeHandlers[view]?.invoke(mapOf("value" to isChecked))
|
|
78
|
+
}
|
|
79
|
+
// Also allow tapping the whole row
|
|
80
|
+
container.setOnClickListener {
|
|
81
|
+
checkbox.isChecked = !checkbox.isChecked
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
override fun removeEventListener(view: View, event: String) {
|
|
86
|
+
if (event != "change") return
|
|
87
|
+
val container = view as? LinearLayout ?: return
|
|
88
|
+
val checkbox = container.findViewWithTag<CheckBox>("checkbox")
|
|
89
|
+
changeHandlers.remove(view)
|
|
90
|
+
checkbox?.setOnCheckedChangeListener(null)
|
|
91
|
+
container.setOnClickListener(null)
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
package com.vuenative.core
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.view.View
|
|
5
|
+
import android.view.ViewGroup
|
|
6
|
+
import android.widget.AdapterView
|
|
7
|
+
import android.widget.ArrayAdapter
|
|
8
|
+
import android.widget.Spinner
|
|
9
|
+
import org.json.JSONArray
|
|
10
|
+
|
|
11
|
+
class VDropdownFactory : NativeComponentFactory {
|
|
12
|
+
private val changeHandlers = mutableMapOf<Spinner, (Any?) -> Unit>()
|
|
13
|
+
private val optionValues = mutableMapOf<Spinner, List<String>>()
|
|
14
|
+
private val optionLabels = mutableMapOf<Spinner, List<String>>()
|
|
15
|
+
|
|
16
|
+
override fun createView(context: Context): View {
|
|
17
|
+
return Spinner(context).apply {
|
|
18
|
+
layoutParams = ViewGroup.LayoutParams(
|
|
19
|
+
ViewGroup.LayoutParams.WRAP_CONTENT,
|
|
20
|
+
ViewGroup.LayoutParams.WRAP_CONTENT
|
|
21
|
+
)
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
override fun updateProp(view: View, key: String, value: Any?) {
|
|
26
|
+
val spinner = view as? Spinner ?: return
|
|
27
|
+
when (key) {
|
|
28
|
+
"options" -> {
|
|
29
|
+
val items = when (value) {
|
|
30
|
+
is JSONArray -> (0 until value.length()).map { i ->
|
|
31
|
+
val obj = value.getJSONObject(i)
|
|
32
|
+
Pair(obj.optString("label", ""), obj.optString("value", ""))
|
|
33
|
+
}
|
|
34
|
+
is List<*> -> value.filterIsInstance<Map<*, *>>().map { m ->
|
|
35
|
+
Pair(m["label"]?.toString() ?: "", m["value"]?.toString() ?: "")
|
|
36
|
+
}
|
|
37
|
+
else -> emptyList()
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
val labels = items.map { it.first }
|
|
41
|
+
val values = items.map { it.second }
|
|
42
|
+
optionLabels[spinner] = labels
|
|
43
|
+
optionValues[spinner] = values
|
|
44
|
+
|
|
45
|
+
// Add placeholder if set
|
|
46
|
+
val placeholder = spinner.tag as? String ?: "Select..."
|
|
47
|
+
val displayLabels = listOf(placeholder) + labels
|
|
48
|
+
|
|
49
|
+
val adapter = ArrayAdapter(
|
|
50
|
+
spinner.context,
|
|
51
|
+
android.R.layout.simple_spinner_item,
|
|
52
|
+
displayLabels
|
|
53
|
+
).apply {
|
|
54
|
+
setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
|
|
55
|
+
}
|
|
56
|
+
spinner.adapter = adapter
|
|
57
|
+
|
|
58
|
+
// Re-apply selection
|
|
59
|
+
applySelection(spinner)
|
|
60
|
+
}
|
|
61
|
+
"selectedValue" -> {
|
|
62
|
+
spinner.setTag(android.R.id.text1, value?.toString())
|
|
63
|
+
applySelection(spinner)
|
|
64
|
+
}
|
|
65
|
+
"placeholder" -> {
|
|
66
|
+
spinner.tag = value?.toString() ?: "Select..."
|
|
67
|
+
// Rebuild adapter with new placeholder
|
|
68
|
+
val labels = optionLabels[spinner] ?: return
|
|
69
|
+
val displayLabels = listOf(value?.toString() ?: "Select...") + labels
|
|
70
|
+
val adapter = ArrayAdapter(
|
|
71
|
+
spinner.context,
|
|
72
|
+
android.R.layout.simple_spinner_item,
|
|
73
|
+
displayLabels
|
|
74
|
+
).apply {
|
|
75
|
+
setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
|
|
76
|
+
}
|
|
77
|
+
spinner.adapter = adapter
|
|
78
|
+
}
|
|
79
|
+
"disabled" -> {
|
|
80
|
+
spinner.isEnabled = value != true && value != "true"
|
|
81
|
+
}
|
|
82
|
+
else -> StyleEngine.apply(key, value, view)
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
override fun addEventListener(view: View, event: String, handler: (Any?) -> Unit) {
|
|
87
|
+
val spinner = view as? Spinner ?: return
|
|
88
|
+
if (event == "change") {
|
|
89
|
+
changeHandlers[spinner] = handler
|
|
90
|
+
spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
|
91
|
+
override fun onItemSelected(parent: AdapterView<*>?, v: View?, position: Int, id: Long) {
|
|
92
|
+
// Position 0 is placeholder
|
|
93
|
+
if (position == 0) return
|
|
94
|
+
val values = optionValues[spinner] ?: return
|
|
95
|
+
val labels = optionLabels[spinner] ?: return
|
|
96
|
+
val idx = position - 1
|
|
97
|
+
if (idx < values.size) {
|
|
98
|
+
changeHandlers[spinner]?.invoke(mapOf(
|
|
99
|
+
"value" to values[idx],
|
|
100
|
+
"label" to labels[idx]
|
|
101
|
+
))
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
override fun onNothingSelected(parent: AdapterView<*>?) {}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
override fun removeEventListener(view: View, event: String) {
|
|
110
|
+
val spinner = view as? Spinner ?: return
|
|
111
|
+
if (event == "change") {
|
|
112
|
+
changeHandlers.remove(spinner)
|
|
113
|
+
spinner.onItemSelectedListener = null
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
private fun applySelection(spinner: Spinner) {
|
|
118
|
+
val selected = spinner.getTag(android.R.id.text1) as? String ?: return
|
|
119
|
+
val values = optionValues[spinner] ?: return
|
|
120
|
+
val idx = values.indexOf(selected)
|
|
121
|
+
if (idx >= 0) {
|
|
122
|
+
spinner.setSelection(idx + 1) // +1 for placeholder
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
package com.vuenative.core
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.view.View
|
|
5
|
+
import android.view.ViewGroup
|
|
6
|
+
import android.widget.ImageView
|
|
7
|
+
import coil.load
|
|
8
|
+
import coil.request.CachePolicy
|
|
9
|
+
import org.json.JSONObject
|
|
10
|
+
|
|
11
|
+
class VImageFactory : NativeComponentFactory {
|
|
12
|
+
private val loadHandlers = mutableMapOf<ImageView, (Any?) -> Unit>()
|
|
13
|
+
private val errorHandlers = mutableMapOf<ImageView, (Any?) -> Unit>()
|
|
14
|
+
|
|
15
|
+
override fun createView(context: Context): View {
|
|
16
|
+
return ImageView(context).apply {
|
|
17
|
+
scaleType = ImageView.ScaleType.CENTER_CROP
|
|
18
|
+
layoutParams = ViewGroup.LayoutParams(
|
|
19
|
+
ViewGroup.LayoutParams.WRAP_CONTENT,
|
|
20
|
+
ViewGroup.LayoutParams.WRAP_CONTENT
|
|
21
|
+
)
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
override fun updateProp(view: View, key: String, value: Any?) {
|
|
26
|
+
val iv = view as? ImageView ?: return
|
|
27
|
+
when (key) {
|
|
28
|
+
"source" -> {
|
|
29
|
+
val uri = when (value) {
|
|
30
|
+
is Map<*, *> -> value["uri"]?.toString()
|
|
31
|
+
is JSONObject -> value.optString("uri")
|
|
32
|
+
else -> null
|
|
33
|
+
}
|
|
34
|
+
if (uri.isNullOrEmpty()) {
|
|
35
|
+
iv.setImageDrawable(null)
|
|
36
|
+
return
|
|
37
|
+
}
|
|
38
|
+
iv.load(uri) {
|
|
39
|
+
memoryCachePolicy(CachePolicy.ENABLED)
|
|
40
|
+
diskCachePolicy(CachePolicy.ENABLED)
|
|
41
|
+
listener(
|
|
42
|
+
onSuccess = { _, _ -> loadHandlers[iv]?.invoke(null) },
|
|
43
|
+
onError = { _, err -> errorHandlers[iv]?.invoke(mapOf("message" to (err.throwable.message ?: "Load failed"))) }
|
|
44
|
+
)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
"resizeMode" -> {
|
|
48
|
+
iv.scaleType = when (value) {
|
|
49
|
+
"cover" -> ImageView.ScaleType.CENTER_CROP
|
|
50
|
+
"contain" -> ImageView.ScaleType.FIT_CENTER
|
|
51
|
+
"stretch" -> ImageView.ScaleType.FIT_XY
|
|
52
|
+
"center" -> ImageView.ScaleType.CENTER
|
|
53
|
+
else -> ImageView.ScaleType.CENTER_CROP
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
else -> StyleEngine.apply(key, value, view)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
override fun addEventListener(view: View, event: String, handler: (Any?) -> Unit) {
|
|
61
|
+
val iv = view as? ImageView ?: return
|
|
62
|
+
when (event) {
|
|
63
|
+
"load" -> loadHandlers[iv] = handler
|
|
64
|
+
"error" -> errorHandlers[iv] = handler
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
override fun removeEventListener(view: View, event: String) {
|
|
69
|
+
val iv = view as? ImageView ?: return
|
|
70
|
+
when (event) {
|
|
71
|
+
"load" -> loadHandlers.remove(iv)
|
|
72
|
+
"error" -> errorHandlers.remove(iv)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|