@nativue/core 0.15.4 → 0.16.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.
- package/AGENTS.md +13 -2
- package/android/nativue.settings.gradle.kts +29 -9
- package/android/src/main/java/dev/nativue/Bridge.kt +4 -14
- package/android/src/main/java/dev/nativue/Navigation.kt +31 -37
- package/android/src/main/java/dev/nativue/NavigationIcons.kt +24 -0
- package/android/src/main/java/dev/nativue/Plugins.kt +13 -1
- package/android/src/main/java/dev/nativue/Views.kt +53 -31
- package/android/src/main/res/drawable/nativue_arrow_back.xml +14 -0
- package/android/src/main/res/drawable/nativue_close.xml +14 -0
- package/cli/link.mjs +25 -6
- package/cli/nativue.mjs +0 -1
- package/ios/Bridge.swift +10 -16
- package/ios/ImageView.swift +32 -10
- package/ios/NavigationIcons.swift +49 -0
- package/ios/Plugins.swift +13 -1
- package/ios/PressableView.swift +3 -1
- package/ios/ScreenController.swift +6 -3
- package/ios/Style.swift +1 -1
- package/package.json +1 -1
- package/src/native-components.ts +0 -14
- package/src/renderer.ts +173 -8
- package/src/router.ts +20 -7
- package/android/src/main/java/dev/nativue/SvgView.kt +0 -443
- package/ios/SvgView.swift +0 -464
package/AGENTS.md
CHANGED
|
@@ -18,7 +18,16 @@ doesn't work. Full docs: https://github.com/nativue/nativue/tree/main/docs
|
|
|
18
18
|
|
|
19
19
|
Global, with no import: `View`, `Text`, `Image`, `ImageBackground`, `Pressable`, `Button`, `TextInput`,
|
|
20
20
|
`Switch`, `ScrollView`, `FlatList`, `Swipeable`, `Modal`, `ActivityIndicator`, `SafeAreaView`,
|
|
21
|
-
`KeyboardAvoidingView
|
|
21
|
+
`KeyboardAvoidingView`.
|
|
22
|
+
|
|
23
|
+
- Charts and drawings: `<svg>` as on the web, with `@nativue/svg` installed (`@nativue/icons` brings
|
|
24
|
+
it): shapes, `text`/`tspan`/`textPath`, gradients and `pattern`s in `defs` (`fill="url(#id)"`),
|
|
25
|
+
`clipPath`, `mask`, `use`/`symbol`, `marker`, `image`, drop shadows and blur filters, and `@press`
|
|
26
|
+
on an element. Also as components to import: `import { Svg, Path, Text as SvgText } from
|
|
27
|
+
'@nativue/svg'` (rename `Text` and `Image`, which are nativue's). Without the package, `<svg>`
|
|
28
|
+
shows nothing. An imported `.svg` file is a component (`import Logo from '@/assets/logo.svg'`, with
|
|
29
|
+
`/// <reference types="@nativue/svg/client" />` in `src/env.d.ts`), and a `<style>` inside an `<svg>`
|
|
30
|
+
styles its elements by tag, class and id.
|
|
22
31
|
|
|
23
32
|
- Text must be inside a `<Text>`, never directly in a `<View>`.
|
|
24
33
|
- Taps: `<Pressable @press="save">` (also `@long-press`, and `v-slot="{ pressed }"`), or
|
|
@@ -94,7 +103,9 @@ Import the runtime from `vue`: `ref`, `computed`, `StyleSheet`, `Animated`, `Lay
|
|
|
94
103
|
|
|
95
104
|
- `@/` points at `src/`. Shared components go in `src/components`, everything else in `src/lib`.
|
|
96
105
|
- Vue plugins (Pinia...) are installed in `src/app.ts`: `export default function setup(app: App)`.
|
|
97
|
-
-
|
|
106
|
+
- Tab and header icons (`tabBarIcon`, a header item's `icon`): an `@nativue/icons` component,
|
|
107
|
+
`svgIcon(viewBox, elements)` from `@nativue/svg`, an image `{ uri }`, or an SF Symbol name (iOS).
|
|
108
|
+
- Official packages: `@nativue/svg`, `@nativue/icons` (icon components), `@nativue/tailwind`, `@nativue/haptics`,
|
|
98
109
|
`@nativue/clipboard` (copy text), `@nativue/notifications` (local notifications), `@nativue/sqlite`.
|
|
99
110
|
A package with native code needs the app
|
|
100
111
|
rebuilt with `npm run ios` or `npm run android`, not just a reload.
|
|
@@ -18,18 +18,38 @@ fun packageDirectory(name: String, appDirectory: File): File? =
|
|
|
18
18
|
.map { File(it, "node_modules/$name") }
|
|
19
19
|
.firstOrNull { File(it, "package.json").isFile }
|
|
20
20
|
|
|
21
|
-
fun dependencyNames(
|
|
21
|
+
fun dependencyNames(packageJson: Map<String, Any?>, keys: List<String>): List<String> =
|
|
22
|
+
keys.flatMap { (packageJson[it] as? Map<*, *>)?.keys.orEmpty() }.map { it.toString() }
|
|
23
|
+
|
|
24
|
+
data class AndroidPlugin(val projectPath: String, val pluginClass: String)
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The app's packages with an Android side, then theirs, as cli/link.mjs finds them: a package made for
|
|
28
|
+
* nativue brings the native packages it depends on (@nativue/icons brings @nativue/svg).
|
|
29
|
+
*/
|
|
30
|
+
fun androidPlugins(appDirectory: File): List<AndroidPlugin> {
|
|
22
31
|
val appPackage = readJson(File(appDirectory, "package.json"))
|
|
32
|
+
val pending = ArrayDeque(dependencyNames(appPackage, listOf("dependencies", "devDependencies")).map { it to appDirectory })
|
|
33
|
+
val visited = mutableSetOf<String>()
|
|
34
|
+
val plugins = mutableListOf<AndroidPlugin>()
|
|
23
35
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
36
|
+
while (pending.isNotEmpty()) {
|
|
37
|
+
val (name, fromDirectory) = pending.removeFirst()
|
|
38
|
+
if (!visited.add(name)) continue
|
|
27
39
|
|
|
28
|
-
|
|
40
|
+
val directory = packageDirectory(name, fromDirectory) ?: continue
|
|
41
|
+
val packageJson = readJson(File(directory, "package.json"))
|
|
42
|
+
val nativue = packageJson["nativue"] as? Map<*, *>
|
|
43
|
+
val isForNativue = nativue != null || (packageJson["peerDependencies"] as? Map<*, *>)?.containsKey("@nativue/core") == true
|
|
44
|
+
|
|
45
|
+
androidPlugin(name, directory, nativue)?.let(plugins::add)
|
|
46
|
+
if (isForNativue) dependencyNames(packageJson, listOf("dependencies")).forEach { pending.add(it to directory) }
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return plugins
|
|
50
|
+
}
|
|
29
51
|
|
|
30
|
-
fun androidPlugin(name: String,
|
|
31
|
-
val directory = packageDirectory(name, appDirectory) ?: return null
|
|
32
|
-
val nativue = readJson(File(directory, "package.json"))["nativue"] as? Map<*, *>
|
|
52
|
+
fun androidPlugin(name: String, directory: File, nativue: Map<*, *>?): AndroidPlugin? {
|
|
33
53
|
val android = nativue?.get("android") as? Map<*, *> ?: return null
|
|
34
54
|
val projectPath = ":" + name.removePrefix("@").replace('/', '-')
|
|
35
55
|
|
|
@@ -44,7 +64,7 @@ fun pascalCase(name: String): String =
|
|
|
44
64
|
name.split(Regex("[^a-zA-Z0-9]+")).filter { it.isNotEmpty() }.joinToString("") { it.replaceFirstChar(Char::uppercaseChar) }
|
|
45
65
|
|
|
46
66
|
val appDirectory: File = settingsDir.parentFile
|
|
47
|
-
val androidPlugins =
|
|
67
|
+
val androidPlugins = androidPlugins(appDirectory)
|
|
48
68
|
val appSourceDirectories = File(appDirectory, "native").listFiles().orEmpty()
|
|
49
69
|
// native/extensions holds iOS extension targets, not modules.
|
|
50
70
|
.filter { it.name != "extensions" }
|
|
@@ -787,8 +787,6 @@ class Bridge(private val activity: ComponentActivity, private val rootView: Root
|
|
|
787
787
|
setIndicatorSize(node, "medium")
|
|
788
788
|
}
|
|
789
789
|
|
|
790
|
-
"Svg" -> NativeNode(SvgView(activity), measuresContent = false)
|
|
791
|
-
|
|
792
790
|
else -> {
|
|
793
791
|
val makeView = pluginRegistry.viewMakers[type]
|
|
794
792
|
val view = makeView?.invoke { eventName, payload -> dispatchEvent(eventName, id, payload) }
|
|
@@ -890,7 +888,7 @@ class Bridge(private val activity: ComponentActivity, private val rootView: Root
|
|
|
890
888
|
val node = nodesById[id] ?: return
|
|
891
889
|
val view = node.view
|
|
892
890
|
|
|
893
|
-
if (key
|
|
891
|
+
if (key !in VIEW_PROPS && view is PluginView) return view.setProp(key, value)
|
|
894
892
|
|
|
895
893
|
when (key) {
|
|
896
894
|
"style" -> {
|
|
@@ -991,16 +989,7 @@ class Bridge(private val activity: ComponentActivity, private val rootView: Root
|
|
|
991
989
|
|
|
992
990
|
"size" -> if (view is ProgressBar) setIndicatorSize(node, value as? String ?: "medium")
|
|
993
991
|
|
|
994
|
-
"color" ->
|
|
995
|
-
(view as? ProgressBar)?.indeterminateTintList = androidColor(value)?.let(ColorStateList::valueOf)
|
|
996
|
-
(view as? SvgView)?.color = androidColor(value) ?: SVG_DEFAULT_COLOR
|
|
997
|
-
}
|
|
998
|
-
|
|
999
|
-
"viewBox" -> SvgView.rect(value)?.let { (view as? SvgView)?.viewBox = it }
|
|
1000
|
-
|
|
1001
|
-
"elements" -> (view as? SvgView)?.elements = value as? List<*> ?: emptyList<Any>()
|
|
1002
|
-
|
|
1003
|
-
"strokeWidth" -> (view as? SvgView)?.strokeWidth = number(value) ?: 2f
|
|
992
|
+
"color" -> (view as? ProgressBar)?.indeterminateTintList = androidColor(value)?.let(ColorStateList::valueOf)
|
|
1004
993
|
|
|
1005
994
|
"placeholder" -> (view as? EditText)?.hint = value as? String
|
|
1006
995
|
|
|
@@ -1182,8 +1171,9 @@ class Bridge(private val activity: ComponentActivity, private val rootView: Root
|
|
|
1182
1171
|
const val JAVASCRIPT_STACK_SIZE = 8L * 1024 * 1024
|
|
1183
1172
|
const val SYMBOLICATE_TIMEOUT_MS = 2000
|
|
1184
1173
|
const val RECONNECT_DELAY_MS = 2000L
|
|
1185
|
-
const val SVG_DEFAULT_COLOR = 0xFF000000.toInt()
|
|
1186
1174
|
const val BUTTON_TINT = 0xFF007AFF.toInt()
|
|
1175
|
+
/** What nativue applies to any view, plugin views included: style, accessibility, layout and gestures. */
|
|
1176
|
+
val VIEW_PROPS = setOf("style", "accessibility", "onLayout", "onPan", "onPinch", "onRotate")
|
|
1187
1177
|
val EDGES = listOf(YogaEdge.LEFT, YogaEdge.TOP, YogaEdge.RIGHT, YogaEdge.BOTTOM)
|
|
1188
1178
|
val SYSTEM_BARS = WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.displayCutout()
|
|
1189
1179
|
val IME = WindowInsetsCompat.Type.ime()
|
|
@@ -17,6 +17,7 @@ import android.view.ViewConfiguration
|
|
|
17
17
|
import android.view.ViewGroup
|
|
18
18
|
import android.view.animation.PathInterpolator
|
|
19
19
|
import android.widget.FrameLayout
|
|
20
|
+
import android.widget.ImageView
|
|
20
21
|
import android.widget.LinearLayout
|
|
21
22
|
import android.widget.TextView
|
|
22
23
|
import kotlin.math.abs
|
|
@@ -202,7 +203,10 @@ class ScreenHeader(context: Context) : LinearLayout(context), ThemeAware {
|
|
|
202
203
|
|
|
203
204
|
private val dragHandle = View(context)
|
|
204
205
|
private val row = LinearLayout(context)
|
|
205
|
-
private val navigationButton =
|
|
206
|
+
private val navigationButton = IconButton(context).apply {
|
|
207
|
+
setIcon(R.drawable.nativue_arrow_back)
|
|
208
|
+
color = ThemeColors.onSurface
|
|
209
|
+
}
|
|
206
210
|
private val leftItems = LinearLayout(context)
|
|
207
211
|
private val title = textView(22f, Typeface.NORMAL)
|
|
208
212
|
private val rightItems = LinearLayout(context)
|
|
@@ -276,30 +280,30 @@ class ScreenHeader(context: Context) : LinearLayout(context), ThemeAware {
|
|
|
276
280
|
}
|
|
277
281
|
|
|
278
282
|
/** Back arrow inside a stack, a close icon on a full screen modal, nothing on a group's first screen. */
|
|
279
|
-
fun setNavigation(icon:
|
|
283
|
+
fun setNavigation(icon: Int?) {
|
|
280
284
|
navigationButton.visibility = if (icon == null) View.GONE else View.VISIBLE
|
|
281
|
-
icon?.let
|
|
285
|
+
icon?.let(navigationButton::setIcon)
|
|
282
286
|
(title.layoutParams as LayoutParams).marginStart = dp(if (icon == null) 12f else 4f)
|
|
283
287
|
}
|
|
284
288
|
|
|
285
289
|
/**
|
|
286
|
-
* [{ title?,
|
|
287
|
-
*
|
|
288
|
-
*
|
|
290
|
+
* [{ title?, image?, drawnIcon?, systemImage? }]: an icon shows as an icon button, otherwise the title as a
|
|
291
|
+
* text button; SF Symbol names are iOS-only. Presses are reported with the side and index, since the
|
|
292
|
+
* handlers live in JS.
|
|
289
293
|
*/
|
|
290
294
|
fun setItems(value: Any?, side: String) {
|
|
291
295
|
val items = if (side == "right") rightItems else leftItems
|
|
292
296
|
items.removeAllViews()
|
|
293
297
|
|
|
294
298
|
(value as? List<*>)?.filterIsInstance<Map<*, *>>()?.forEachIndexed { index, item ->
|
|
295
|
-
val
|
|
296
|
-
val button = if (
|
|
297
|
-
val width = if (
|
|
299
|
+
val hasIcon = item["image"] != null || item["drawnIcon"] != null
|
|
300
|
+
val button = if (hasIcon) IconButton(context).apply { setIcon(item) } else textButton(item["title"] as? String ?: "")
|
|
301
|
+
val width = if (hasIcon) dp(48f) else LayoutParams.WRAP_CONTENT
|
|
298
302
|
|
|
299
303
|
tint(button)
|
|
300
304
|
button.contentDescription = item["title"] as? String
|
|
301
305
|
button.setOnClickListener { onEvent("headeritempress", mapOf("side" to side, "index" to index)) }
|
|
302
|
-
items.addView(button, LayoutParams(width, if (
|
|
306
|
+
items.addView(button, LayoutParams(width, if (hasIcon) dp(48f) else dp(40f)))
|
|
303
307
|
}
|
|
304
308
|
}
|
|
305
309
|
|
|
@@ -324,31 +328,21 @@ class ScreenHeader(context: Context) : LinearLayout(context), ThemeAware {
|
|
|
324
328
|
includeFontPadding = false
|
|
325
329
|
}
|
|
326
330
|
|
|
327
|
-
private fun iconButton(elements: List<List<Any>>) = IconButton(context).apply {
|
|
328
|
-
this.elements = elements
|
|
329
|
-
color = ThemeColors.onSurface
|
|
330
|
-
}
|
|
331
331
|
|
|
332
332
|
companion object {
|
|
333
|
-
val ARROW_BACK =
|
|
334
|
-
val CLOSE =
|
|
333
|
+
val ARROW_BACK = R.drawable.nativue_arrow_back
|
|
334
|
+
val CLOSE = R.drawable.nativue_close
|
|
335
335
|
}
|
|
336
336
|
}
|
|
337
337
|
|
|
338
338
|
/** A 24dp icon in a 48dp round touch target with a ripple. */
|
|
339
339
|
class IconButton(context: Context) : FrameLayout(context) {
|
|
340
|
-
private val icon =
|
|
340
|
+
private val icon = ImageView(context)
|
|
341
341
|
|
|
342
|
-
var
|
|
343
|
-
get() = icon.elements
|
|
342
|
+
var color: Int = 0
|
|
344
343
|
set(value) {
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
var color: Int
|
|
349
|
-
get() = icon.color
|
|
350
|
-
set(value) {
|
|
351
|
-
icon.color = value
|
|
344
|
+
field = value
|
|
345
|
+
icon.imageTintList = ColorStateList.valueOf(value)
|
|
352
346
|
}
|
|
353
347
|
|
|
354
348
|
init {
|
|
@@ -356,10 +350,13 @@ class IconButton(context: Context) : FrameLayout(context) {
|
|
|
356
350
|
addView(icon, LayoutParams(dp(24f), dp(24f), Gravity.CENTER))
|
|
357
351
|
}
|
|
358
352
|
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
353
|
+
fun setIcon(drawable: Int) {
|
|
354
|
+
icon.setImageResource(drawable)
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/** A header item's icon: { image } or { drawnIcon }. */
|
|
358
|
+
fun setIcon(item: Map<*, *>) {
|
|
359
|
+
NavigationIcons.show(item, icon, dp(24f))
|
|
363
360
|
}
|
|
364
361
|
}
|
|
365
362
|
|
|
@@ -639,7 +636,7 @@ class FixedSizeTextView(context: Context) : TextView(context)
|
|
|
639
636
|
/** One destination of the navigation bar: an icon in a pill when selected, a label and a badge. */
|
|
640
637
|
private class TabItemView(context: Context) : LinearLayout(context) {
|
|
641
638
|
private val indicator = FrameLayout(context)
|
|
642
|
-
private val icon =
|
|
639
|
+
private val icon = ImageView(context)
|
|
643
640
|
private val label = FixedSizeTextView(context)
|
|
644
641
|
private val badge = FixedSizeTextView(context)
|
|
645
642
|
|
|
@@ -676,15 +673,12 @@ private class TabItemView(context: Context) : LinearLayout(context) {
|
|
|
676
673
|
background = RippleDrawable(ColorStateList.valueOf(ThemeColors.ripple), null, null)
|
|
677
674
|
}
|
|
678
675
|
|
|
679
|
-
/**
|
|
676
|
+
/** SF Symbol names are iOS-only: an image or a drawn icon shows here. */
|
|
680
677
|
fun update(item: Map<*, *>, isSelected: Boolean, activeTintColor: Int?, inactiveTintColor: Int?) {
|
|
681
678
|
val activeColor = activeTintColor ?: ThemeColors.onSurface
|
|
682
679
|
val color = if (isSelected) activeColor else inactiveTintColor ?: ThemeColors.onSurfaceVariant
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
icon.elements = svg?.get("elements") as? List<*> ?: emptyList<Any>()
|
|
686
|
-
SvgView.rect(svg?.get("viewBox"))?.let { icon.viewBox = it }
|
|
687
|
-
icon.color = color
|
|
680
|
+
NavigationIcons.show(item, icon, dp(24f))
|
|
681
|
+
icon.imageTintList = ColorStateList.valueOf(color)
|
|
688
682
|
label.text = item["label"] as? String ?: ""
|
|
689
683
|
label.setTextColor(color)
|
|
690
684
|
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
package dev.nativue
|
|
2
|
+
|
|
3
|
+
import android.widget.ImageView
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The icons of tab bars and headers: an image (`image`, a url) or one a package draws (`drawnIcon`, registered
|
|
7
|
+
* with PluginRegistry.addIconDrawer). SF Symbol names are iOS-only. Tinted by what shows them.
|
|
8
|
+
*/
|
|
9
|
+
object NavigationIcons {
|
|
10
|
+
internal val drawersByName = mutableMapOf<String, DrawIcon>()
|
|
11
|
+
|
|
12
|
+
/** The item's icon in [view], [size] pixels square; an image from a url once it has loaded. */
|
|
13
|
+
fun show(item: Map<*, *>, view: ImageView, size: Int) {
|
|
14
|
+
val source = item["image"] as? String
|
|
15
|
+
val icon = item["drawnIcon"] as? Map<*, *>
|
|
16
|
+
val draw = (icon?.get("drawer") as? String)?.let(drawersByName::get)
|
|
17
|
+
|
|
18
|
+
view.tag = source
|
|
19
|
+
if (source == null) return view.setImageBitmap(if (icon != null && draw != null) draw(icon, size) else null)
|
|
20
|
+
|
|
21
|
+
view.setImageDrawable(null)
|
|
22
|
+
RemoteImageView.loadBitmap(view.context, source) { bitmap -> if (view.tag == source) view.setImageBitmap(bitmap) }
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
package dev.nativue
|
|
2
2
|
|
|
3
3
|
import android.content.Context
|
|
4
|
+
import android.graphics.Bitmap
|
|
4
5
|
import android.view.View
|
|
5
6
|
import androidx.activity.ComponentActivity
|
|
6
7
|
import java.util.concurrent.atomic.AtomicBoolean
|
|
@@ -47,6 +48,9 @@ class PluginException(val code: String, message: String) : Exception(message)
|
|
|
47
48
|
/** Called on the JavaScript thread; settles `promise` from any thread, when the work is done. */
|
|
48
49
|
typealias AsyncFunction = (arguments: List<Any?>, promise: Promise) -> Unit
|
|
49
50
|
|
|
51
|
+
/** An icon JS describes ({ drawer, ... }) drawn [size] pixels square, for a tab bar or a header. */
|
|
52
|
+
typealias DrawIcon = (icon: Map<*, *>, size: Int) -> Bitmap?
|
|
53
|
+
|
|
50
54
|
interface ActivityListener {
|
|
51
55
|
/** Register activity-result launchers here, every time and in the same order, so results survive a recreation. */
|
|
52
56
|
fun onActivityCreated(activity: ComponentActivity) {}
|
|
@@ -142,6 +146,14 @@ class PluginRegistry private constructor(context: Context) {
|
|
|
142
146
|
fun addView(type: String, makeView: (SendEvent) -> View) {
|
|
143
147
|
viewMakers[type] = makeView
|
|
144
148
|
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Draws the tab bar and header icons whose `drawnIcon.drawer` is [drawer] (see router.ts's DrawnIcon).
|
|
152
|
+
* The bitmap is tinted: only its shape counts.
|
|
153
|
+
*/
|
|
154
|
+
fun addIconDrawer(drawer: String, draw: DrawIcon) {
|
|
155
|
+
NavigationIcons.drawersByName[drawer] = draw
|
|
156
|
+
}
|
|
145
157
|
}
|
|
146
158
|
|
|
147
159
|
/** The string resource nativue.settings.gradle.kts writes: the plugin classes, comma-separated. */
|
|
@@ -152,7 +164,7 @@ private fun pluginClassNames(context: Context): List<String> {
|
|
|
152
164
|
return context.getString(resourceId).split(',').filter { it.isNotEmpty() }
|
|
153
165
|
}
|
|
154
166
|
|
|
155
|
-
/** A plugin view gets its props here, all but `style`, which nativue applies
|
|
167
|
+
/** A plugin view gets its props here, all but `style`, `accessibility`, `@layout` and the gestures (`@pan`...), which nativue applies. */
|
|
156
168
|
interface PluginView {
|
|
157
169
|
fun setProp(key: String, value: Any?)
|
|
158
170
|
}
|
|
@@ -549,28 +549,7 @@ class RemoteImageView(context: Context) : ImageView(context) {
|
|
|
549
549
|
show(if (source != null && cachePolicy != "none") decodedImages.get(source) else null)
|
|
550
550
|
if (source == null || bitmap != null) return
|
|
551
551
|
|
|
552
|
-
|
|
553
|
-
val readsDisk = cachePolicy == "disk"
|
|
554
|
-
loader.execute {
|
|
555
|
-
val cachedBytes = if (readsDisk) diskCache.read(source) else null
|
|
556
|
-
val downloadedBytes = if (cachedBytes == null) runCatching { download(source) }.getOrNull() else null
|
|
557
|
-
val bytes = cachedBytes ?: downloadedBytes ?: return@execute
|
|
558
|
-
val bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.size) ?: return@execute
|
|
559
|
-
|
|
560
|
-
post {
|
|
561
|
-
store(bitmap, downloadedBytes, source, diskCache)
|
|
562
|
-
if (source == this.source) show(bitmap)
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
private fun store(bitmap: Bitmap, downloadedBytes: ByteArray?, source: String, diskCache: ImageDiskCache) {
|
|
568
|
-
if (cachePolicy == "none") return
|
|
569
|
-
|
|
570
|
-
decodedImages.put(source, bitmap)
|
|
571
|
-
if (cachePolicy != "disk" || downloadedBytes == null || isInMemory(source)) return
|
|
572
|
-
|
|
573
|
-
loader.execute { diskCache.write(source, downloadedBytes) }
|
|
552
|
+
loadBitmap(context, source, { cachePolicy }) { loaded -> if (source == this.source) show(loaded) }
|
|
574
553
|
}
|
|
575
554
|
|
|
576
555
|
private fun show(nextBitmap: Bitmap?) {
|
|
@@ -611,18 +590,61 @@ class RemoteImageView(context: Context) : ImageView(context) {
|
|
|
611
590
|
setMeasuredDimension(measuredWidth.roundToInt(), measuredHeight.roundToInt())
|
|
612
591
|
}
|
|
613
592
|
|
|
614
|
-
|
|
615
|
-
|
|
593
|
+
companion object {
|
|
594
|
+
private val loader = Executors.newFixedThreadPool(4)
|
|
595
|
+
private val mainThread = Handler(Looper.getMainLooper())
|
|
596
|
+
|
|
597
|
+
/**
|
|
598
|
+
* An image as <Image> loads it: from memory, the disk cache or its url, then kept as [cachePolicy] says
|
|
599
|
+
* (read once it has loaded, so it applies even when set after the source). [onLoaded], or [onFailed], runs
|
|
600
|
+
* on the main thread.
|
|
601
|
+
*/
|
|
602
|
+
fun loadBitmap(
|
|
603
|
+
context: Context,
|
|
604
|
+
source: String,
|
|
605
|
+
cachePolicy: () -> String = { "disk" },
|
|
606
|
+
onFailed: () -> Unit = {},
|
|
607
|
+
onLoaded: (Bitmap) -> Unit,
|
|
608
|
+
) {
|
|
609
|
+
if (cachePolicy() != "none") decodedImages.get(source)?.let { return onLoaded(it) }
|
|
610
|
+
|
|
611
|
+
val diskCache = ImageDiskCache(context.cacheDir)
|
|
612
|
+
val readsDisk = cachePolicy() == "disk"
|
|
613
|
+
loader.execute {
|
|
614
|
+
val cachedBytes = if (readsDisk) diskCache.read(source) else null
|
|
615
|
+
val downloadedBytes = if (cachedBytes == null) runCatching { download(source) }.getOrNull() else null
|
|
616
|
+
val bytes = cachedBytes ?: downloadedBytes
|
|
617
|
+
val bitmap = bytes?.let { BitmapFactory.decodeByteArray(it, 0, it.size) }
|
|
618
|
+
if (bitmap == null) {
|
|
619
|
+
mainThread.post(onFailed)
|
|
620
|
+
return@execute
|
|
621
|
+
}
|
|
616
622
|
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
623
|
+
mainThread.post {
|
|
624
|
+
store(bitmap, downloadedBytes, source, diskCache, cachePolicy())
|
|
625
|
+
onLoaded(bitmap)
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
}
|
|
620
629
|
|
|
621
|
-
|
|
622
|
-
|
|
630
|
+
private fun store(bitmap: Bitmap, downloadedBytes: ByteArray?, source: String, diskCache: ImageDiskCache, cachePolicy: String) {
|
|
631
|
+
if (cachePolicy == "none") return
|
|
623
632
|
|
|
624
|
-
|
|
625
|
-
|
|
633
|
+
decodedImages.put(source, bitmap)
|
|
634
|
+
if (cachePolicy != "disk" || downloadedBytes == null || isInMemory(source)) return
|
|
635
|
+
|
|
636
|
+
loader.execute { diskCache.write(source, downloadedBytes) }
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
/** data: and blob: images are already on the device: nothing to keep on disk. */
|
|
640
|
+
private fun isInMemory(source: String) = source.startsWith("data:") || source.startsWith("blob:")
|
|
641
|
+
|
|
642
|
+
private fun download(source: String): ByteArray {
|
|
643
|
+
if (source.startsWith("data:")) return Base64.decode(source.substringAfter(","), Base64.DEFAULT)
|
|
644
|
+
if (source.startsWith("blob:")) return BlobStore.shared.bytes(source) ?: throw IOException("The blob has been released")
|
|
645
|
+
|
|
646
|
+
return URL(source).openStream().use { it.readBytes() }
|
|
647
|
+
}
|
|
626
648
|
|
|
627
649
|
/** Decoded images, an eighth of the app's memory at most: one that comes back on screen shows at once. */
|
|
628
650
|
private val decodedImages = object : LruCache<String, Bitmap>((Runtime.getRuntime().maxMemory() / 8).toInt()) {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
+
<!-- The header's back arrow (Lucide's arrow-left), tinted by its button. -->
|
|
3
|
+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
|
4
|
+
android:width="24dp"
|
|
5
|
+
android:height="24dp"
|
|
6
|
+
android:viewportWidth="24"
|
|
7
|
+
android:viewportHeight="24">
|
|
8
|
+
<path
|
|
9
|
+
android:pathData="M19,12H5M12,19l-7,-7 7,-7"
|
|
10
|
+
android:strokeWidth="2"
|
|
11
|
+
android:strokeColor="#FF000000"
|
|
12
|
+
android:strokeLineCap="round"
|
|
13
|
+
android:strokeLineJoin="round" />
|
|
14
|
+
</vector>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
+
<!-- A full screen modal's close icon (Lucide's x), tinted by its button. -->
|
|
3
|
+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
|
4
|
+
android:width="24dp"
|
|
5
|
+
android:height="24dp"
|
|
6
|
+
android:viewportWidth="24"
|
|
7
|
+
android:viewportHeight="24">
|
|
8
|
+
<path
|
|
9
|
+
android:pathData="M18,6 6,18M6,6l12,12"
|
|
10
|
+
android:strokeWidth="2"
|
|
11
|
+
android:strokeColor="#FF000000"
|
|
12
|
+
android:strokeLineCap="round"
|
|
13
|
+
android:strokeLineJoin="round" />
|
|
14
|
+
</vector>
|
package/cli/link.mjs
CHANGED
|
@@ -46,14 +46,33 @@ export function nativuePackages(appDirectory) {
|
|
|
46
46
|
if (!existsSync(join(appDirectory, 'package.json'))) return []
|
|
47
47
|
|
|
48
48
|
const { dependencies = {}, devDependencies = {} } = readJson(join(appDirectory, 'package.json'))
|
|
49
|
-
const
|
|
49
|
+
const visited = new Set()
|
|
50
|
+
const found = []
|
|
51
|
+
const pending = [...Object.keys(dependencies), ...Object.keys(devDependencies)].map((name) => [
|
|
52
|
+
name,
|
|
53
|
+
appDirectory,
|
|
54
|
+
])
|
|
55
|
+
// The app's packages, then theirs: a package made for nativue brings the native packages it
|
|
56
|
+
// depends on (@nativue/icons brings @nativue/svg).
|
|
57
|
+
const visit = (name, fromDirectory) => {
|
|
58
|
+
if (visited.has(name)) return
|
|
59
|
+
visited.add(name)
|
|
60
|
+
|
|
61
|
+
const directory = packageDirectory(name, fromDirectory)
|
|
62
|
+
const manifest = directory && readJson(join(directory, 'package.json'))
|
|
63
|
+
const isForNativue = manifest?.nativue || manifest?.peerDependencies?.['@nativue/core']
|
|
64
|
+
|
|
65
|
+
if (manifest?.nativue) found.push({ name, directory, nativue: manifest.nativue })
|
|
66
|
+
if (isForNativue) {
|
|
67
|
+
Object.keys(manifest.dependencies ?? {}).forEach((dependency) =>
|
|
68
|
+
pending.push([dependency, directory]),
|
|
69
|
+
)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
50
72
|
|
|
51
|
-
|
|
52
|
-
const directory = packageDirectory(name, appDirectory)
|
|
53
|
-
const nativue = directory && readJson(join(directory, 'package.json')).nativue
|
|
73
|
+
while (pending.length > 0) visit(...pending.shift())
|
|
54
74
|
|
|
55
|
-
|
|
56
|
-
})
|
|
75
|
+
return found
|
|
57
76
|
}
|
|
58
77
|
|
|
59
78
|
function iosPlugins(appDirectory) {
|
package/cli/nativue.mjs
CHANGED
package/ios/Bridge.swift
CHANGED
|
@@ -638,9 +638,6 @@ final class Bridge {
|
|
|
638
638
|
case "SwipeableView":
|
|
639
639
|
return NativeNode(view: SwipeableView(frame: .zero), measuresContent: false)
|
|
640
640
|
|
|
641
|
-
case "Svg":
|
|
642
|
-
return NativeNode(view: SvgView(frame: .zero), measuresContent: false)
|
|
643
|
-
|
|
644
641
|
case "PressableView":
|
|
645
642
|
let pressableView = PressableView()
|
|
646
643
|
pressableView.onEvent = { [unowned self] eventName in dispatchEvent(eventName, toNodeId: id) }
|
|
@@ -905,10 +902,13 @@ final class Bridge {
|
|
|
905
902
|
node.markContentChanged()
|
|
906
903
|
}
|
|
907
904
|
|
|
905
|
+
/// What nativue applies to any view, plugin views included: style, accessibility, layout and gestures.
|
|
906
|
+
private static let viewProps: Set<String> = ["style", "accessibility", "onLayout", "onPan", "onPinch", "onRotate"]
|
|
907
|
+
|
|
908
908
|
private func setProp(_ key: String, value: Any?, onNodeId id: Int) {
|
|
909
909
|
guard let node = nodesById[id] else { return }
|
|
910
910
|
|
|
911
|
-
if key
|
|
911
|
+
if !Self.viewProps.contains(key), let pluginView = node.view as? PluginView {
|
|
912
912
|
pluginView.setProp(key, value: value is NSNull ? nil : value)
|
|
913
913
|
return
|
|
914
914
|
}
|
|
@@ -936,9 +936,13 @@ final class Bridge {
|
|
|
936
936
|
|
|
937
937
|
case "tabBarItem":
|
|
938
938
|
let item = value as? [String: Any] ?? [:]
|
|
939
|
-
screenController(id)
|
|
939
|
+
let screen = screenController(id)
|
|
940
|
+
let image = screen.flatMap { screen in
|
|
941
|
+
NavigationIcons.image(item, size: 25, for: screen) { [weak screen] image in screen?.tabBarItem.image = image }
|
|
942
|
+
}
|
|
943
|
+
screen?.setTabBarItem(
|
|
940
944
|
label: item["label"] as? String,
|
|
941
|
-
image:
|
|
945
|
+
image: image,
|
|
942
946
|
badge: (item["badge"] as? CustomStringConvertible)?.description
|
|
943
947
|
)
|
|
944
948
|
|
|
@@ -1001,16 +1005,6 @@ final class Bridge {
|
|
|
1001
1005
|
|
|
1002
1006
|
case "color":
|
|
1003
1007
|
(node.view as? UIActivityIndicatorView)?.color = UIColor(rgba: value as Any)
|
|
1004
|
-
(node.view as? SvgView)?.color = UIColor(rgba: value as Any) ?? .black
|
|
1005
|
-
|
|
1006
|
-
case "viewBox":
|
|
1007
|
-
if let viewBox = SvgView.rect(fromViewBox: value) { (node.view as? SvgView)?.viewBox = viewBox }
|
|
1008
|
-
|
|
1009
|
-
case "elements":
|
|
1010
|
-
(node.view as? SvgView)?.elements = value as? [[Any]] ?? []
|
|
1011
|
-
|
|
1012
|
-
case "strokeWidth":
|
|
1013
|
-
(node.view as? SvgView)?.strokeWidth = CGFloat((value as? NSNumber)?.doubleValue ?? 2)
|
|
1014
1008
|
|
|
1015
1009
|
case "visible":
|
|
1016
1010
|
modalController(id)?.setVisible(isTruthyAttribute(value))
|