@nativue/core 0.4.0 → 0.4.2

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/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # @nativue/core
2
2
 
3
- Vue rendering real native views on iOS and Android: UIKit on iOS, Android views with Material 3 on
4
- Android, laid out with Yoga.
3
+ Vue for real native apps on iOS and Android: Vue components rendered as the platform's own views,
4
+ UIKit on iOS and Android views with Material 3 on Android, laid out with flexbox.
5
5
 
6
6
  Start a new app with:
7
7
 
@@ -9,8 +9,11 @@ Start a new app with:
9
9
  npm create nativue@latest my-app
10
10
  ```
11
11
 
12
- This package holds the runtime (renderer, router, Animated, AsyncStorage, fetch), the native side
13
- for iOS (a Swift package) and Android (a Gradle library), and the `nativue` CLI:
12
+ This package holds:
13
+
14
+ - the runtime: the renderer, native components, the router, `Animated`, `AsyncStorage`, `fetch`
15
+ - the native side: a Swift package for iOS and a Gradle library for Android
16
+ - the `nativue` CLI:
14
17
 
15
18
  ```sh
16
19
  nativue run ios # or android: builds, opens the app on a simulator or emulator, then dev
@@ -18,4 +21,12 @@ nativue dev # rebuilds on save and reloads the running app
18
21
  nativue build # bundles the app into ios/ and android/ (--production for releases)
19
22
  ```
20
23
 
21
- Docs and source: https://github.com/nativue/nativue
24
+ ## Documentation
25
+
26
+ - [Getting started](https://github.com/nativue/nativue/blob/main/docs/getting-started.md)
27
+ - [Components](https://github.com/nativue/nativue/blob/main/docs/components/README.md)
28
+ - [Styling](https://github.com/nativue/nativue/blob/main/docs/styling.md)
29
+ - [Navigation](https://github.com/nativue/nativue/blob/main/docs/navigation.md)
30
+ - [Animations and gestures](https://github.com/nativue/nativue/blob/main/docs/animations.md)
31
+ - [APIs](https://github.com/nativue/nativue/blob/main/docs/apis.md)
32
+ - [Packages](https://github.com/nativue/nativue/blob/main/docs/packages.md)
@@ -10,7 +10,7 @@ plugins {
10
10
  * This computer's address on the local network (Wi-Fi or Ethernet first), for a physical device to
11
11
  * reach the dev server.
12
12
  */
13
- // ponytail: fixed at build time, like the iOS app's host; rebuild after switching networks.
13
+ // Limitation: Fixed at build time, like the iOS app's host; rebuild after switching networks.
14
14
  fun localNetworkAddress(): String? = NetworkInterface.getNetworkInterfaces().toList()
15
15
  .filter { it.isUp && !it.isLoopback && !it.isVirtual }
16
16
  .sortedBy { if (it.name.startsWith("en") || it.name.startsWith("eth") || it.name.startsWith("wlan")) 0 else 1 }
@@ -24,7 +24,7 @@ android {
24
24
  ndkVersion = "27.1.12297006"
25
25
 
26
26
  defaultConfig {
27
- // ponytail: 30 for the WindowInsets.Type API (safe area, keyboard); lower it with the compat insets if needed.
27
+ // Limitation: 30 for the WindowInsets.Type API (safe area, keyboard); lower it with the compat insets if needed.
28
28
  minSdk = 30
29
29
  consumerProguardFiles("consumer-rules.pro")
30
30
 
@@ -378,7 +378,7 @@ class Bridge(private val activity: Activity, private val rootView: RootView) {
378
378
  * fetch: HttpURLConnection runs the request; JS hears back through
379
379
  * __fetchFinished(requestId, response, error).
380
380
  */
381
- // ponytail: text bodies only (no binary, FormData or streaming) and no abort, like on iOS.
381
+ // Limitation: Text bodies only (no binary, FormData or streaming) and no abort, like on iOS.
382
382
  private fun fetchFunctions(): Map<String, NativeFunction> = mapOf(
383
383
  "fetch" to { arguments ->
384
384
  val requestId = arguments[0]
@@ -491,7 +491,7 @@ class Bridge(private val activity: Activity, private val rootView: RootView) {
491
491
  collectViews(root.view, removedViews)
492
492
  root.contentNode?.let { collectViews(it.view, removedViews) }
493
493
 
494
- // ponytail: a nested <Modal>'s content isn't under the root's views, so its nodes stay; walk the
494
+ // Limitation: A nested <Modal>'s content isn't under the root's views, so its nodes stay; walk the
495
495
  // modal hosts too if apps nest many. Hosts stay: layout dismisses the detached ones.
496
496
  val removedIds = nodesById.filterValues { it.view in removedViews }.keys
497
497
  removedIds.forEach { id ->
@@ -17,6 +17,8 @@ import kotlin.math.hypot
17
17
  * gesture's state ("began", "changed", "ended", "cancelled"), so it can move the view through its
18
18
  * style; with Animated.event the values move natively and JS only hears the start and the end.
19
19
  * Numbers are in dp (and dp per second); rotation in radians. Mirrors ios/GestureReporter.swift.
20
+ * Limitation: Unlike on iOS, a parent doesn't see touches a child consumes (a <Pressable> inside a draggable
21
+ * card); intercept moves past the touch slop if that's needed.
20
22
  */
21
23
  class GestureReporter(
22
24
  private val view: View,
@@ -17,7 +17,7 @@ import com.facebook.yoga.YogaOverflow
17
17
  import com.facebook.yoga.YogaPositionType
18
18
  import com.facebook.yoga.YogaWrap
19
19
 
20
- // ponytail: removed layout properties arrive as null and keep their last value, like on iOS.
20
+ // Limitation: Removed layout properties arrive as null and keep their last value, like on iOS.
21
21
 
22
22
  /** Receives only the properties that changed: the JS renderer diffs style objects before sending. */
23
23
  fun NativeNode.applyStyle(changes: Map<String, Any?>) {
@@ -25,7 +25,7 @@ import kotlin.math.tan
25
25
  * with `color` (round caps and joins, as icon sets expect); those whose fill isn't "none" are also
26
26
  * filled with it. Mirrors ios/SvgView.swift.
27
27
  */
28
- // ponytail: only the shapes icon sets use and a single color; add per-element colors, gradients or
28
+ // Limitation: Only the shapes icon sets use and a single color; add per-element colors, gradients or
29
29
  // transforms when a real-world SVG needs them.
30
30
  class SvgView(context: Context) : View(context) {
31
31
  var viewBox = RectF(0f, 0f, 24f, 24f)
@@ -488,7 +488,7 @@ class TextInputView(context: Context) : android.widget.EditText(context), ThemeA
488
488
  applyThemeColors()
489
489
  }
490
490
 
491
- // ponytail: a value JS sets on purpose that equals text typed earlier in the same editing session is
491
+ // Limitation: A value JS sets on purpose that equals text typed earlier in the same editing session is
492
492
  // ignored too; tag each change with a counter if that ever matters.
493
493
  private val textsSentToJavaScript = mutableSetOf<String>()
494
494
  var isSettingTextFromJavaScript = false
package/cli/nativue.mjs CHANGED
@@ -13,7 +13,7 @@ import net from 'node:net'
13
13
  import { execFileSync } from 'node:child_process'
14
14
  import { copyFileSync, existsSync, mkdirSync, readFileSync, renameSync, rmSync } from 'node:fs'
15
15
  import { createRequire } from 'node:module'
16
- import { dirname } from 'node:path'
16
+ import { dirname, relative } from 'node:path'
17
17
  import { fileURLToPath } from 'node:url'
18
18
  import { linkIosPlugins } from './link.mjs'
19
19
  import { runOnAndroid, runOnIOS } from './run.mjs'
@@ -86,6 +86,30 @@ function finishBundle(mode) {
86
86
  }
87
87
  }
88
88
 
89
+ // A .vue file's <style> would become CSS that native views never read: warn instead of dropping it
90
+ // silently, once per file, and leave the CSS out of the build.
91
+ function ignoreStyleBlocks() {
92
+ const warnedFiles = new Set()
93
+
94
+ return {
95
+ name: 'nativue-ignore-style-blocks',
96
+ enforce: 'pre',
97
+ load(id) {
98
+ if (!id.includes('?vue&type=style')) return null
99
+
100
+ const file = relative(process.cwd(), id.split('?')[0])
101
+ if (!warnedFiles.has(file)) {
102
+ warnedFiles.add(file)
103
+ this.warn(
104
+ `${file}: <style> blocks aren't supported, native views don't read CSS. Use StyleSheet or @nativue/tailwind instead: https://github.com/nativue/nativue/blob/main/docs/styling.md`,
105
+ )
106
+ }
107
+
108
+ return ''
109
+ },
110
+ }
111
+ }
112
+
89
113
  const CONFIG_FILES = [
90
114
  'nativue.config.ts',
91
115
  'nativue.config.mts',
@@ -143,6 +167,7 @@ function viteConfig({ mode, plugins = [], watch = null, sourcemap = false }) {
143
167
  compilerOptions: { isCustomElement: (tag) => NATIVE_COMPONENT_TAGS.includes(tag) },
144
168
  },
145
169
  }),
170
+ ignoreStyleBlocks(),
146
171
  ...APP_VITE_PLUGINS,
147
172
  finishBundle(mode),
148
173
  ...plugins,
@@ -218,6 +243,7 @@ function startDevServer() {
218
243
  else if (request.url === '/symbolicate') handleSymbolicate(request, response)
219
244
  else handleBundle(response)
220
245
  })
246
+ // Limitation: Every interface, so phones reach it, and anyone on the network can download the bundle.
221
247
  .listen(PORT, () => console.log(`dev server: http://localhost:${PORT}`))
222
248
 
223
249
  // Without a keepalive, URLSession drops the idle connection.
package/cli/run.mjs CHANGED
@@ -132,7 +132,7 @@ function connectedDevices(adb) {
132
132
  .map((line) => line.split('\t')[0])
133
133
  }
134
134
 
135
- // ponytail: the first device or emulator wins; a --device option when people run several at once.
135
+ // Limitation: The first device or emulator wins; a --device option when people run several at once.
136
136
  async function pickDevice(sdkPath, adb) {
137
137
  const [device] = connectedDevices(adb)
138
138
  if (device) return device
package/ios/Bridge.swift CHANGED
@@ -22,7 +22,7 @@ final class Bridge {
22
22
  return URL(string: "http://\(host):40836")!
23
23
  }()
24
24
 
25
- // ponytail: GCD threads have a 512 KB stack; move to a Thread with a bigger stack if deep trees hit
25
+ // Limitation: GCD threads have a 512 KB stack; move to a Thread with a bigger stack if deep trees hit
26
26
  // "RangeError: Maximum call stack size exceeded".
27
27
  private let javaScriptQueue = DispatchQueue(label: "dev.nativue.javascript", qos: .userInteractive)
28
28
 
@@ -39,11 +39,12 @@ final class Bridge {
39
39
  var rootView: RootView!
40
40
  private var gestureReportersByNodeId: [Int: GestureReporter] = [:]
41
41
  private let animatedGraph = AnimatedGraph()
42
- // ponytail: children of a removed node stay in the dictionary; clean up recursively if memory leaks.
42
+ // Limitation: Children of a removed node stay in the dictionary; clean up recursively if memory leaks.
43
43
  var nodesById: [Int: NativeNode] = [:]
44
44
  /// Modals and screens: their content is laid out as a separate Yoga root.
45
- // ponytail: Vue removes only a subtree's root, so the modals and screens inside a removed subtree stay
45
+ // Limitation: Vue removes only a subtree's root, so the modals and screens inside a removed subtree stay
46
46
  // here and are laid out on every pass; drop the detached ones on remove if navigators come and go.
47
+ // Likewise a sheet a <ScreenStack> presented stays up when a v-if removes the stack (a reload closes it).
47
48
  private var contentRootsByNodeId: [Int: ContentRoot] = [:]
48
49
  /// Read on the main thread at start, for Dimensions.get('window').
49
50
  private var windowSize: CGSize = .zero
@@ -223,7 +224,7 @@ final class Bridge {
223
224
  reportError(message: string(arguments[0]), details: string(arguments[1]))
224
225
  }
225
226
 
226
- // ponytail: the size at launch; report rotation and split view changes if the app supports them.
227
+ // Limitation: The size at launch; report rotation and split view changes if the app supports them.
227
228
  defineGetter("windowSize") { [unowned self] _ in
228
229
  ["width": windowSize.width, "height": windowSize.height]
229
230
  }
@@ -552,7 +553,7 @@ final class Bridge {
552
553
  }
553
554
 
554
555
  /// fetch: URLSession runs the request; JS hears back through __fetchFinished(requestId, response, error).
555
- /// ponytail: text bodies only (no binary, FormData or streaming) and no abort.
556
+ /// Limitation: Text bodies only (no binary, FormData or streaming) and no abort.
556
557
  private func defineFetch(_ define: Define) {
557
558
  define("fetch") { [unowned self] arguments in
558
559
  let (requestId, url, method) = (int(arguments[0]), string(arguments[1]), string(arguments[2]))
@@ -2,7 +2,7 @@ import UIKit
2
2
 
3
3
  /// Image view behind <Image>. Loads `source` (an http(s) or data: url) through URLSession, which also
4
4
  /// gives HTTP caching through URLCache.
5
- // ponytail: no decoded-image cache and no intrinsic size; add an NSCache / measure function if lists of
5
+ // Limitation: No decoded-image cache and no intrinsic size; add an NSCache / measure function if lists of
6
6
  // images stutter or sizing by hand gets annoying.
7
7
  final class ImageView: UIImageView {
8
8
  static let resizeModes: [String: UIView.ContentMode] = [
@@ -3,7 +3,7 @@ import Foundation
3
3
  /// Behind AsyncStorage. Every value lives in memory, so reads never touch the disk; changes
4
4
  /// are saved to a file in the background, coalesced, so a burst of writes costs one save. Used only on
5
5
  /// the JS queue; the save itself runs on its own queue with a snapshot.
6
- /// ponytail: each save rewrites the whole file; switch to SQLite or an append log if data grows large.
6
+ /// Limitation: Each save rewrites the whole file; switch to SQLite or an append log if data grows large.
7
7
  final class KeyValueStorage {
8
8
  private let javaScriptQueue: DispatchQueue
9
9
  private let saveQueue = DispatchQueue(label: "dev.nativue.storage", qos: .utility)
package/ios/Style.swift CHANGED
@@ -1,7 +1,7 @@
1
1
  import UIKit
2
2
  import yoga
3
3
 
4
- // ponytail: removed layout properties arrive as null and keep their last value; reset them to Yoga's
4
+ // Limitation: Removed layout properties arrive as null and keep their last value; reset them to Yoga's
5
5
  // defaults when it matters. Visual properties already fall back to UIKit's defaults on null.
6
6
  extension NativeNode {
7
7
  /// Receives only the properties that changed: the JS renderer diffs style objects before sending.
@@ -96,6 +96,8 @@ extension NativeNode {
96
96
  fontWeight = fontWeights[String(describing: weightName)] ?? .regular
97
97
  }
98
98
 
99
+ // Limitation: A fixed size on both platforms, ignoring the system's text size; scale it (UIFontMetrics,
100
+ // sp on Android) when accessibility sizes matter.
99
101
  let font = UIFont.systemFont(ofSize: fontSize, weight: fontWeight)
100
102
  (view as? UILabel)?.font = font
101
103
  (view as? UITextField)?.font = font
package/ios/SvgView.swift CHANGED
@@ -4,7 +4,7 @@ import UIKit
4
4
  /// scaled from `viewBox` to its bounds like preserveAspectRatio="xMidYMid meet". Elements are stroked
5
5
  /// with `color` (round caps and joins, as icon sets expect); those whose fill isn't "none" are also
6
6
  /// filled with it.
7
- /// ponytail: only the shapes icon sets use and a single color; add per-element colors, gradients or
7
+ /// Limitation: Only the shapes icon sets use and a single color; add per-element colors, gradients or
8
8
  /// transforms when a real-world SVG needs them.
9
9
  final class SvgView: UIView {
10
10
  var viewBox = CGRect(x: 0, y: 0, width: 24, height: 24) {
@@ -16,7 +16,7 @@ final class TextInputView: UITextField {
16
16
  didSet { setNeedsLayout() }
17
17
  }
18
18
 
19
- // ponytail: a value JS sets on purpose that equals text typed earlier in the same editing session is
19
+ // Limitation: A value JS sets on purpose that equals text typed earlier in the same editing session is
20
20
  // ignored too; tag each change with a counter if that ever matters.
21
21
  private var textsSentToJavaScript: Set<String> = []
22
22
 
@@ -24,7 +24,7 @@ final class VueScrollView: UIScrollView {
24
24
  var adjustsForKeyboard = false
25
25
 
26
26
  /// Set when JS listens to @scroll. Called on every scroll step and size change (FlatList windowing).
27
- // ponytail: one JS call per frame while scrolling; coalesce / add scrollEventThrottle if JS falls behind.
27
+ // Limitation: One JS call per frame while scrolling; coalesce / add scrollEventThrottle if JS falls behind.
28
28
  var onScroll: ((CGRect) -> Void)? {
29
29
  didSet { lastReportedBounds = nil }
30
30
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nativue/core",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "Vue rendering real native views on iOS and Android",
5
5
  "keywords": [
6
6
  "vue",
package/src/components.ts CHANGED
@@ -87,11 +87,11 @@ const OFFSCREEN_ROWS_RENDERED = 10
87
87
 
88
88
  // Renders only the rows near the visible area; the rest is empty padding of the same height.
89
89
  // Slots: #item="{ item, index }", plus #header, #footer and #empty.
90
- // ponytail: rows have a fixed `itemHeight`; measure rows natively if
90
+ // Limitation: Rows have a fixed `itemHeight`; measure rows natively if
91
91
  // variable heights are ever needed. Vertical only. The window ignores the header's height, which the
92
92
  // offscreen rows absorb while the header is shorter than them; measure it if tall headers show gaps.
93
- // ponytail: items are `any` in the #item slot; make FlatList generic if typed rows are wanted.
94
- // ponytail: an Animated.event `:on-scroll` replaces the window's own scroll handler, and a mapped event
93
+ // Limitation: Items are `any` in the #item slot; make FlatList generic if typed rows are wanted.
94
+ // Limitation: An Animated.event `:on-scroll` replaces the window's own scroll handler, and a mapped event
95
95
  // reaches JS only when a scroll starts and ends; report frames to both natively if that's needed.
96
96
  export const FlatList = defineComponent({
97
97
  name: 'FlatList',
package/src/fetch.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  // fetch, Headers and Response, like the browser's: native runs the request with
2
2
  // URLSession and calls back __fetchFinished.
3
- // ponytail: text bodies only (no Blob, FormData or streaming) and no AbortController.
3
+ // Limitation: Text bodies only (no Blob, FormData or streaming) and no AbortController.
4
4
  const native = globalThis.__native
5
5
 
6
6
  interface PendingRequest {
@@ -68,7 +68,7 @@ class FetchResponse {
68
68
  return this.body
69
69
  }
70
70
 
71
- // ponytail: `any` like the DOM's json(); type it at the call site.
71
+ // Limitation: `any` like the DOM's json(); type it at the call site.
72
72
  async json(): Promise<any> {
73
73
  return JSON.parse(this.body)
74
74
  }
package/src/renderer.ts CHANGED
@@ -395,7 +395,7 @@ export const Keyboard = {
395
395
 
396
396
  // Replaces Vue's DOM-only vModelText, which the template compiler emits for v-model on
397
397
  // <TextInput> and <Switch>.
398
- // ponytail: v-model modifiers (.trim, .number, .lazy) are not supported yet.
398
+ // Limitation: v-model modifiers (.trim, .number, .lazy) are not supported yet.
399
399
  export const vModelText: Directive<Node> = {
400
400
  created(element, { value }) {
401
401
  native.setProp(element.id, 'value', value ?? '')
package/src/router.ts CHANGED
@@ -501,7 +501,7 @@ export function useLocalSearchParams<RouteParams extends Params = Params>(): Rou
501
501
  })
502
502
  }
503
503
 
504
- // ponytail: the path when the page opened; make it a ref if pages need to follow in-place navigation.
504
+ // Limitation: The path when the page opened; make it a ref if pages need to follow in-place navigation.
505
505
  export function usePathname(): string {
506
506
  return injectPageEntry('usePathname').href.split('?')[0]
507
507
  }