@nativue/core 0.11.1 → 0.13.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 +2 -1
- package/Package.swift +1 -1
- package/README.md +1 -1
- package/android/build.gradle.kts +5 -3
- package/android/src/main/java/dev/nativue/Accessibility.kt +5 -3
- package/android/src/main/java/dev/nativue/AnimatedGraph.kt +2 -0
- package/android/src/main/java/dev/nativue/Bridge.kt +81 -22
- package/android/src/main/java/dev/nativue/DownloadBanner.kt +45 -0
- package/android/src/main/java/dev/nativue/ErrorOverlay.kt +5 -4
- package/android/src/main/java/dev/nativue/LayoutAnimation.kt +14 -11
- package/android/src/main/java/dev/nativue/NativeNode.kt +11 -6
- package/android/src/main/java/dev/nativue/NativueActivity.kt +34 -7
- package/android/src/main/java/dev/nativue/Navigation.kt +7 -4
- package/android/src/main/java/dev/nativue/Style.kt +7 -1
- package/android/src/main/java/dev/nativue/SystemBars.kt +14 -16
- package/cli/hot-client.js +192 -0
- package/cli/link.mjs +1 -1
- package/cli/nativue.mjs +228 -54
- package/cli/symbolicate.mjs +26 -14
- package/ios/Accessibility.swift +18 -5
- package/ios/AnimatedGraph.swift +20 -12
- package/ios/Bridge.swift +68 -16
- package/ios/DownloadBanner.swift +38 -0
- package/ios/KeyValueStorage.swift +2 -2
- package/ios/NativeNode.swift +23 -9
- package/ios/NativueView.swift +25 -0
- package/ios/TextLabel.swift +14 -0
- package/package.json +1 -1
- package/src/globals.ts +1 -0
- package/src/renderer.ts +1 -0
- package/src/router.ts +29 -0
- package/src/types.ts +3 -0
package/ios/Accessibility.swift
CHANGED
|
@@ -7,10 +7,17 @@ extension NativeNode {
|
|
|
7
7
|
"heading": .header,
|
|
8
8
|
"img": .image,
|
|
9
9
|
"text": .staticText,
|
|
10
|
-
"switch":
|
|
11
|
-
"checkbox":
|
|
10
|
+
"switch": toggleTraits,
|
|
11
|
+
"checkbox": toggleTraits,
|
|
12
12
|
]
|
|
13
13
|
|
|
14
|
+
/// Before iOS 17, VoiceOver has no toggle trait: a button that says its state is the closest.
|
|
15
|
+
private static var toggleTraits: UIAccessibilityTraits {
|
|
16
|
+
if #available(iOS 17, *) { return .toggleButton }
|
|
17
|
+
|
|
18
|
+
return .button
|
|
19
|
+
}
|
|
20
|
+
|
|
14
21
|
/// role, alt and aria-*, from the renderer: all of them, whenever one changes.
|
|
15
22
|
func applyAccessibility(_ attributes: [String: Any]) {
|
|
16
23
|
let role = attributes["role"] as? String
|
|
@@ -24,9 +31,15 @@ extension NativeNode {
|
|
|
24
31
|
view.accessibilityHint = attributes["hint"] as? String
|
|
25
32
|
view.accessibilityTraits = traits(role: role, attributes: attributes)
|
|
26
33
|
// A container read as one element says the text inside it, as a <button> does on the web.
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
34
|
+
let readsTextInside = isElement && label == nil && !defaultAccessibility.isElement
|
|
35
|
+
if #available(iOS 17, *) {
|
|
36
|
+
view.accessibilityLabelBlock = readsTextInside
|
|
37
|
+
? { [weak view] in view.map { Self.labels(inside: $0).joined(separator: ", ") } }
|
|
38
|
+
: nil
|
|
39
|
+
} else if readsTextInside {
|
|
40
|
+
// ponytail: before iOS 17 the label is read once, here: text changed later inside keeps the old one.
|
|
41
|
+
view.accessibilityLabel = Self.labels(inside: view).joined(separator: ", ")
|
|
42
|
+
}
|
|
30
43
|
|
|
31
44
|
if role == "switch" || role == "checkbox" {
|
|
32
45
|
view.accessibilityValue = attributes["checked"] != nil ? "1" : "0"
|
package/ios/AnimatedGraph.swift
CHANGED
|
@@ -81,6 +81,10 @@ final class AnimatedGraph {
|
|
|
81
81
|
updateBoundViews()
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
+
func drives(_ view: UIView) -> Bool {
|
|
85
|
+
bindingsByViewId.values.contains { $0.view === view }
|
|
86
|
+
}
|
|
87
|
+
|
|
84
88
|
// MARK: - Animations
|
|
85
89
|
|
|
86
90
|
func startAnimation(id: Int, nodeId: Int, config: [String: Any]) {
|
|
@@ -124,19 +128,23 @@ final class AnimatedGraph {
|
|
|
124
128
|
|
|
125
129
|
// MARK: - Views
|
|
126
130
|
|
|
131
|
+
/// Never animated by UIKit: a binding made in a layout animation's batch would hold the view at
|
|
132
|
+
/// its first value until the layout animation ends.
|
|
127
133
|
private func updateBoundViews() {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
let
|
|
139
|
-
|
|
134
|
+
UIView.performWithoutAnimation {
|
|
135
|
+
for (viewId, binding) in bindingsByViewId {
|
|
136
|
+
guard let view = binding.view else {
|
|
137
|
+
bindingsByViewId[viewId] = nil
|
|
138
|
+
continue
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if let opacityNodeId = binding.opacityNodeId {
|
|
142
|
+
view.alpha = CGFloat(value(ofNode: opacityNodeId))
|
|
143
|
+
}
|
|
144
|
+
if let steps = binding.transformSteps {
|
|
145
|
+
let resolvedSteps = steps.map { step in [step.name: step.nodeId.map(value(ofNode:)) ?? step.value] }
|
|
146
|
+
view.transform = NativeNode.affineTransform(resolvedSteps)
|
|
147
|
+
}
|
|
140
148
|
}
|
|
141
149
|
}
|
|
142
150
|
}
|
package/ios/Bridge.swift
CHANGED
|
@@ -36,6 +36,8 @@ final class Bridge {
|
|
|
36
36
|
private var colorScheme = "light"
|
|
37
37
|
/// Kept on the JS queue, for AccessibilityInfo.
|
|
38
38
|
private var accessibilityStatus = AccessibilityStatus()
|
|
39
|
+
/// Kept on the JS queue: the router's screens, reopened after a reload in development.
|
|
40
|
+
private var savedNavigation: String?
|
|
39
41
|
|
|
40
42
|
// Only touched on the main thread.
|
|
41
43
|
var rootView: RootView!
|
|
@@ -53,6 +55,9 @@ final class Bridge {
|
|
|
53
55
|
/// The bundle running now, for the error overlay's Reload.
|
|
54
56
|
private var bundle = Data()
|
|
55
57
|
private let errorOverlay = ErrorOverlay()
|
|
58
|
+
#if DEBUG
|
|
59
|
+
private let downloadBanner = DownloadBanner()
|
|
60
|
+
#endif
|
|
56
61
|
private let pluginRegistry: PluginRegistry
|
|
57
62
|
|
|
58
63
|
init(plugins: [NativuePlugin]) {
|
|
@@ -63,20 +68,19 @@ final class Bridge {
|
|
|
63
68
|
self.rootView = rootView
|
|
64
69
|
rootView.onLayoutSubviews = { [unowned self] in layout() }
|
|
65
70
|
NativeNode.onLayoutCalculated = { [unowned self] in reportLayoutChanges() }
|
|
71
|
+
NativeNode.isDrivenByAnimated = { [unowned self] view in animatedGraph.drives(view) }
|
|
66
72
|
networking.onEvent = { [unowned self] owner, requestId, eventName, payload in
|
|
67
73
|
sendNetworkEvent(owner: owner, requestId: requestId, eventName: eventName, payload: payload)
|
|
68
74
|
}
|
|
69
75
|
let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene
|
|
70
76
|
windowSize = windowScene?.screen.bounds.size ?? .zero
|
|
71
77
|
colorScheme = Self.colorScheme(of: windowScene?.traitCollection ?? rootView.traitCollection)
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
colorSchemeDidChange(to: Self.colorScheme(of: rootView.traitCollection))
|
|
78
|
+
rootView.onTraitCollectionChange = { [unowned self, unowned rootView] previous in
|
|
79
|
+
let traits = rootView.traitCollection
|
|
80
|
+
if traits.userInterfaceStyle != previous?.userInterfaceStyle {
|
|
81
|
+
colorSchemeDidChange(to: Self.colorScheme(of: traits))
|
|
77
82
|
}
|
|
78
|
-
|
|
79
|
-
[unowned self] (rootView: RootView, _: UITraitCollection) in
|
|
83
|
+
if traits.preferredContentSizeCategory != previous?.preferredContentSizeCategory {
|
|
80
84
|
nodesById.values.forEach { $0.updateFont() }
|
|
81
85
|
rootView.setNeedsLayout()
|
|
82
86
|
}
|
|
@@ -102,12 +106,20 @@ final class Bridge {
|
|
|
102
106
|
run(try! Data(contentsOf: bundleURL))
|
|
103
107
|
#if DEBUG
|
|
104
108
|
Task { await listenForReload() }
|
|
109
|
+
rootView.onReloadShortcut = { [unowned self] in Task { try? await reload() } }
|
|
105
110
|
#endif
|
|
106
111
|
}
|
|
107
112
|
|
|
108
113
|
/// Discards the current node tree and runtime, then runs the bundle from scratch: JavaScript, or
|
|
109
114
|
/// Hermes bytecode (production builds).
|
|
110
115
|
func run(_ bundle: Data) {
|
|
116
|
+
// UIKit ignores a dismissal while a modal is presenting or dismissing, so resetNodeTree would leave
|
|
117
|
+
// the old tree's modal up, and the new tree's couldn't present.
|
|
118
|
+
if let transition = modalTransitionInProgress() {
|
|
119
|
+
transition.animate(alongsideTransition: nil) { [unowned self] _ in run(bundle) }
|
|
120
|
+
return
|
|
121
|
+
}
|
|
122
|
+
|
|
111
123
|
self.bundle = bundle
|
|
112
124
|
errorOverlay.hide()
|
|
113
125
|
|
|
@@ -119,6 +131,16 @@ final class Bridge {
|
|
|
119
131
|
}
|
|
120
132
|
}
|
|
121
133
|
|
|
134
|
+
private func modalTransitionInProgress() -> UIViewControllerTransitionCoordinator? {
|
|
135
|
+
guard let presentedViewController = rootView.window?.rootViewController?.presentedViewController else {
|
|
136
|
+
return nil
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return sequence(first: presentedViewController, next: \.presentedViewController)
|
|
140
|
+
.compactMap(\.transitionCoordinator)
|
|
141
|
+
.last
|
|
142
|
+
}
|
|
143
|
+
|
|
122
144
|
/// Runs `work` on the JS queue, then applies every native operation it produced, in one batch, on the
|
|
123
145
|
/// main thread. The runtime drains promise jobs after each call, so Vue's updates are included.
|
|
124
146
|
func evaluate(_ work: @escaping () -> Void) {
|
|
@@ -202,25 +224,53 @@ final class Bridge {
|
|
|
202
224
|
/// UIKit coalesces these requests, so the layout pass runs once per batch.
|
|
203
225
|
func requestLayout() {
|
|
204
226
|
rootView.setNeedsLayout()
|
|
227
|
+
if rootView.window == nil { rootView.layoutIfNeeded() }
|
|
205
228
|
}
|
|
206
229
|
|
|
207
230
|
#if DEBUG
|
|
208
231
|
@MainActor func listenForReload() async {
|
|
209
|
-
let eventsURL = Self.devServerURL.
|
|
210
|
-
let bundleURL = Self.devServerURL.appending(path: "bundle.js")
|
|
232
|
+
let eventsURL = Self.devServerURL.appendingPathComponent("events")
|
|
211
233
|
|
|
212
234
|
while true {
|
|
213
235
|
do {
|
|
214
236
|
let (events, _) = try await URLSession.shared.bytes(from: eventsURL)
|
|
215
237
|
|
|
216
|
-
for try await line in events.lines
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
238
|
+
for try await line in events.lines {
|
|
239
|
+
if line == "data: reload" {
|
|
240
|
+
try await reload()
|
|
241
|
+
} else if line.hasPrefix("data: hot ") {
|
|
242
|
+
let update = String(line.dropFirst("data: hot ".count))
|
|
243
|
+
evaluate { [unowned self] in runtime?.call("__hotUpdate", arguments: [update]) }
|
|
244
|
+
}
|
|
220
245
|
}
|
|
221
246
|
} catch {}
|
|
222
247
|
|
|
223
|
-
try? await Task.sleep(
|
|
248
|
+
try? await Task.sleep(nanoseconds: 2_000_000_000) // dev server is down: retry
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
@MainActor func reload() async throws {
|
|
253
|
+
let data = try await download(Self.devServerURL.appendingPathComponent("bundle.js"))
|
|
254
|
+
print("[Nativue] reload")
|
|
255
|
+
run(data)
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
@MainActor private func download(_ url: URL) async throws -> Data {
|
|
259
|
+
try await withCheckedThrowingContinuation { continuation in
|
|
260
|
+
var observation: NSKeyValueObservation?
|
|
261
|
+
let task = URLSession.shared.dataTask(with: url) { [unowned self] data, _, error in
|
|
262
|
+
DispatchQueue.main.async {
|
|
263
|
+
observation?.invalidate()
|
|
264
|
+
self.downloadBanner.hide()
|
|
265
|
+
if let data { continuation.resume(returning: data) } else { continuation.resume(throwing: error!) }
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
observation = task.observe(\.countOfBytesReceived) { [unowned self] task, _ in
|
|
269
|
+
let progress = Double(task.countOfBytesReceived) / Double(max(task.countOfBytesExpectedToReceive, 1))
|
|
270
|
+
DispatchQueue.main.async { self.downloadBanner.show(progress: progress) }
|
|
271
|
+
}
|
|
272
|
+
downloadBanner.show(progress: 0)
|
|
273
|
+
task.resume()
|
|
224
274
|
}
|
|
225
275
|
}
|
|
226
276
|
#endif
|
|
@@ -291,6 +341,8 @@ final class Bridge {
|
|
|
291
341
|
}
|
|
292
342
|
|
|
293
343
|
defineGetter("colorScheme") { [unowned self] _ in colorScheme }
|
|
344
|
+
defineGetter("savedNavigation") { [unowned self] _ in savedNavigation }
|
|
345
|
+
define("saveNavigation") { [unowned self] arguments in savedNavigation = arguments[0] as? String }
|
|
294
346
|
|
|
295
347
|
define("create") { [unowned self] arguments in
|
|
296
348
|
let (id, type) = (int(arguments[0]), string(arguments[1]))
|
|
@@ -368,7 +420,7 @@ final class Bridge {
|
|
|
368
420
|
/// The dev server maps main.bundle.js lines back to the app's files with the bundle's source map.
|
|
369
421
|
/// Without a dev server, the stack stays as it is.
|
|
370
422
|
private func symbolicated(_ text: String) async -> String {
|
|
371
|
-
var request = URLRequest(url: Self.devServerURL.
|
|
423
|
+
var request = URLRequest(url: Self.devServerURL.appendingPathComponent("symbolicate"), timeoutInterval: 2)
|
|
372
424
|
request.httpMethod = "POST"
|
|
373
425
|
request.httpBody = Data(text.utf8)
|
|
374
426
|
|
|
@@ -487,7 +539,7 @@ final class Bridge {
|
|
|
487
539
|
private func makeUnstyledNode(type: String, id: Int) -> NativeNode {
|
|
488
540
|
switch type {
|
|
489
541
|
case "Text":
|
|
490
|
-
let label =
|
|
542
|
+
let label = TextLabel()
|
|
491
543
|
label.numberOfLines = 0
|
|
492
544
|
return NativeNode(view: label, measuresContent: true)
|
|
493
545
|
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import UIKit
|
|
2
|
+
|
|
3
|
+
/// Development only: a strip at the top of the screen while the app downloads the dev server's bundle.
|
|
4
|
+
final class DownloadBanner {
|
|
5
|
+
private var window: UIWindow?
|
|
6
|
+
private let label = UILabel()
|
|
7
|
+
|
|
8
|
+
func show(progress: Double) {
|
|
9
|
+
if window == nil { makeWindow() }
|
|
10
|
+
|
|
11
|
+
label.text = "Downloading \(Int(progress * 100))%"
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
func hide() {
|
|
15
|
+
window?.isHidden = true
|
|
16
|
+
window = nil
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
private func makeWindow() {
|
|
20
|
+
guard let scene = UIApplication.shared.connectedScenes.first as? UIWindowScene else { return }
|
|
21
|
+
|
|
22
|
+
let topInset = scene.windows.first?.safeAreaInsets.top ?? 0
|
|
23
|
+
let window = UIWindow(windowScene: scene)
|
|
24
|
+
window.frame = CGRect(x: 0, y: 0, width: scene.screen.bounds.width, height: topInset + 24)
|
|
25
|
+
window.windowLevel = .alert + 2
|
|
26
|
+
window.isUserInteractionEnabled = false
|
|
27
|
+
window.backgroundColor = UIColor(red: 0.04, green: 0.07, blue: 0.13, alpha: 1)
|
|
28
|
+
|
|
29
|
+
label.frame = CGRect(x: 0, y: topInset, width: window.frame.width, height: 24)
|
|
30
|
+
label.font = .systemFont(ofSize: 12, weight: .semibold)
|
|
31
|
+
label.textColor = UIColor(red: 0.95, green: 0.96, blue: 0.98, alpha: 1)
|
|
32
|
+
label.textAlignment = .center
|
|
33
|
+
window.addSubview(label)
|
|
34
|
+
|
|
35
|
+
window.isHidden = false
|
|
36
|
+
self.window = window
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -55,7 +55,7 @@ final class KeyValueStorage {
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
private func load() -> [String: String] {
|
|
58
|
-
let path = directory.
|
|
58
|
+
let path = directory.appendingPathComponent("async-storage.db").path
|
|
59
59
|
guard sqlite3_open(path, &database) == SQLITE_OK else { return [:] }
|
|
60
60
|
|
|
61
61
|
execute("PRAGMA journal_mode = WAL")
|
|
@@ -72,7 +72,7 @@ final class KeyValueStorage {
|
|
|
72
72
|
|
|
73
73
|
/// Before SQLite, values were saved to a JSON file: moved into the table once, then deleted.
|
|
74
74
|
private func importJSONFile() {
|
|
75
|
-
let fileURL = directory.
|
|
75
|
+
let fileURL = directory.appendingPathComponent("async-storage.json")
|
|
76
76
|
guard let data = try? Data(contentsOf: fileURL),
|
|
77
77
|
let saved = try? JSONDecoder().decode([String: String].self, from: data)
|
|
78
78
|
else { return }
|
package/ios/NativeNode.swift
CHANGED
|
@@ -85,6 +85,8 @@ final class NativeNode {
|
|
|
85
85
|
/// After every layout pass, of the root or of a screen's or modal's content: for @layout.
|
|
86
86
|
static var onLayoutCalculated: (() -> Void)?
|
|
87
87
|
|
|
88
|
+
static var isDrivenByAnimated: (UIView) -> Bool = { _ in false }
|
|
89
|
+
|
|
88
90
|
func calculateLayout(width: CGFloat, height: CGFloat) {
|
|
89
91
|
YGNodeCalculateLayout(yogaNode, Float(width), Float(height), .LTR)
|
|
90
92
|
Self.applyFrames(of: yogaNode)
|
|
@@ -93,14 +95,25 @@ final class NativeNode {
|
|
|
93
95
|
|
|
94
96
|
/// A view inserted during a layout animation would grow from the corner: it fades in where it lands.
|
|
95
97
|
private static func appearWithoutMoving(_ view: UIView, at frame: CGRect) {
|
|
98
|
+
let fades = !isDrivenByAnimated(view)
|
|
96
99
|
let finalAlpha = view.alpha
|
|
97
100
|
|
|
98
101
|
UIView.performWithoutAnimation {
|
|
99
|
-
view
|
|
100
|
-
view.alpha = 0
|
|
102
|
+
place(view, at: frame)
|
|
103
|
+
if fades { view.alpha = 0 }
|
|
101
104
|
view.layoutIfNeeded()
|
|
102
105
|
}
|
|
103
|
-
view.alpha = finalAlpha
|
|
106
|
+
if fades { view.alpha = finalAlpha }
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
private static func place(_ view: UIView, at frame: CGRect) {
|
|
110
|
+
if view.transform == .identity {
|
|
111
|
+
if view.frame != frame { view.frame = frame }
|
|
112
|
+
} else {
|
|
113
|
+
// With a transform, `frame` is the transformed box: place the untransformed one.
|
|
114
|
+
view.bounds.size = frame.size
|
|
115
|
+
view.center = CGPoint(x: frame.midX, y: frame.midY)
|
|
116
|
+
}
|
|
104
117
|
}
|
|
105
118
|
|
|
106
119
|
/// Only visits subtrees Yoga laid out again; untouched subtrees keep their frames.
|
|
@@ -121,14 +134,12 @@ final class NativeNode {
|
|
|
121
134
|
|
|
122
135
|
// Yoga flags whole dirty paths as new layout. Reassigning a scroll view's frame or content
|
|
123
136
|
// size, even unchanged, makes UIKit readjust its offset and shakes a bounce, so skip no-ops.
|
|
124
|
-
|
|
137
|
+
// Never placed: a transform moves `frame`, so check its untransformed box.
|
|
138
|
+
let isNew = childView.bounds.size == .zero && childView.center == .zero
|
|
139
|
+
if isNew, UIView.inheritedAnimationDuration > 0 {
|
|
125
140
|
appearWithoutMoving(childView, at: frame)
|
|
126
|
-
} else if childView.transform == .identity {
|
|
127
|
-
if childView.frame != frame { childView.frame = frame }
|
|
128
141
|
} else {
|
|
129
|
-
|
|
130
|
-
childView.bounds.size = frame.size
|
|
131
|
-
childView.center = CGPoint(x: frame.midX, y: frame.midY)
|
|
142
|
+
place(childView, at: frame)
|
|
132
143
|
}
|
|
133
144
|
childView.applyCornerRadius()
|
|
134
145
|
|
|
@@ -142,6 +153,9 @@ final class NativeNode {
|
|
|
142
153
|
if let textInput = childView as? TextInputView {
|
|
143
154
|
textInput.contentPadding = padding(of: child)
|
|
144
155
|
}
|
|
156
|
+
if let label = childView as? TextLabel {
|
|
157
|
+
label.contentPadding = padding(of: child)
|
|
158
|
+
}
|
|
145
159
|
}
|
|
146
160
|
}
|
|
147
161
|
|
package/ios/NativueView.swift
CHANGED
|
@@ -37,9 +37,34 @@ struct VueRoot: UIViewRepresentable {
|
|
|
37
37
|
/// Root of the native tree; runs the Yoga layout pass whenever UIKit lays it out.
|
|
38
38
|
final class RootView: UIView {
|
|
39
39
|
var onLayoutSubviews: (() -> Void)?
|
|
40
|
+
var onTraitCollectionChange: ((_ previous: UITraitCollection?) -> Void)?
|
|
40
41
|
|
|
41
42
|
override func layoutSubviews() {
|
|
42
43
|
super.layoutSubviews()
|
|
43
44
|
onLayoutSubviews?()
|
|
44
45
|
}
|
|
46
|
+
|
|
47
|
+
override func traitCollectionDidChange(_ previous: UITraitCollection?) {
|
|
48
|
+
super.traitCollectionDidChange(previous)
|
|
49
|
+
onTraitCollectionChange?(previous)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
#if DEBUG
|
|
53
|
+
var onReloadShortcut: (() -> Void)?
|
|
54
|
+
|
|
55
|
+
override var canBecomeFirstResponder: Bool { true }
|
|
56
|
+
|
|
57
|
+
override var keyCommands: [UIKeyCommand]? {
|
|
58
|
+
[UIKeyCommand(input: "r", modifierFlags: .command, action: #selector(reloadShortcutPressed))]
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
override func didMoveToWindow() {
|
|
62
|
+
super.didMoveToWindow()
|
|
63
|
+
becomeFirstResponder()
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
@objc private func reloadShortcutPressed() {
|
|
67
|
+
onReloadShortcut?()
|
|
68
|
+
}
|
|
69
|
+
#endif
|
|
45
70
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import UIKit
|
|
2
|
+
|
|
3
|
+
/// <Text>: its text starts at the top of a taller box, as on Android and the web (UILabel centers it).
|
|
4
|
+
final class TextLabel: UILabel {
|
|
5
|
+
var contentPadding: UIEdgeInsets = .zero {
|
|
6
|
+
didSet { setNeedsDisplay() }
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
override func drawText(in bounds: CGRect) {
|
|
10
|
+
let rect = bounds.inset(by: contentPadding)
|
|
11
|
+
let textHeight = textRect(forBounds: rect, limitedToNumberOfLines: numberOfLines).height
|
|
12
|
+
super.drawText(in: CGRect(x: rect.minX, y: rect.minY, width: rect.width, height: min(textHeight, rect.height)))
|
|
13
|
+
}
|
|
14
|
+
}
|
package/package.json
CHANGED
package/src/globals.ts
CHANGED
|
@@ -5,6 +5,7 @@ import type { LayoutEvent, NativeModule, NetworkEventPayloads } from './types'
|
|
|
5
5
|
|
|
6
6
|
declare global {
|
|
7
7
|
var __native: NativeModule
|
|
8
|
+
var __NATIVUE_HOT__: { clientId: string; serverURL: string } | undefined
|
|
8
9
|
var __dispatch: (nodeId: number, eventName: string, payload: unknown) => void
|
|
9
10
|
var __layoutsChanged: (layouts: ({ id: number } & LayoutEvent)[]) => void
|
|
10
11
|
var __openURL: (url: string) => void
|
package/src/renderer.ts
CHANGED
|
@@ -83,6 +83,7 @@ const textInputsById = new Map<number, Node>()
|
|
|
83
83
|
*/
|
|
84
84
|
export function setClassStyleResolver(resolver: ClassStyleResolver): void {
|
|
85
85
|
resolveClassStyle = resolver
|
|
86
|
+
nodesWithClass.forEach((node) => updateStyle(node, {}))
|
|
86
87
|
}
|
|
87
88
|
|
|
88
89
|
function createNode(type: string): Node {
|
package/src/router.ts
CHANGED
|
@@ -832,6 +832,34 @@ export const Link = defineComponent({
|
|
|
832
832
|
})
|
|
833
833
|
|
|
834
834
|
type RouteFiles = Record<string, { default: Component }>
|
|
835
|
+
type OpenedRoute = [href: string, mode: NavigationMode]
|
|
836
|
+
|
|
837
|
+
// The routes to open again for the same screens: each stack's screens above its first, and the active
|
|
838
|
+
// tab. The tabs in the background start over.
|
|
839
|
+
function openedRoutes(entry: Entry): OpenedRoute[] {
|
|
840
|
+
const navigator = entry.navigator
|
|
841
|
+
if (!navigator) return []
|
|
842
|
+
|
|
843
|
+
if ('tabs' in navigator) {
|
|
844
|
+
const { tabs, state } = navigator as TabsNavigator
|
|
845
|
+
const activeTab = tabs[state.activeIndex]
|
|
846
|
+
|
|
847
|
+
return [[activeTab.href, 'navigate'], ...openedRoutes(activeTab)]
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
return (navigator as StackNavigator).entries.flatMap((child, index): OpenedRoute[] => [
|
|
851
|
+
...(index > 0 ? [[child.href, 'push'] as OpenedRoute] : []),
|
|
852
|
+
...openedRoutes(child),
|
|
853
|
+
])
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
function keepNavigationAcrossReloads() {
|
|
857
|
+
const savedRoutes = __native.savedNavigation()
|
|
858
|
+
if (savedRoutes)
|
|
859
|
+
for (const [href, mode] of JSON.parse(savedRoutes) as OpenedRoute[]) go(href, mode)
|
|
860
|
+
|
|
861
|
+
watchEffect(() => __native.saveNavigation(JSON.stringify(openedRoutes(rootEntry))))
|
|
862
|
+
}
|
|
835
863
|
|
|
836
864
|
// routeFiles: import.meta.glob('/src/app/**/*.vue', { eager: true }), see entry.ts
|
|
837
865
|
export function createRouterApp(routeFiles: RouteFiles) {
|
|
@@ -839,6 +867,7 @@ export function createRouterApp(routeFiles: RouteFiles) {
|
|
|
839
867
|
|
|
840
868
|
const { chain, target } = resolveHref('/')
|
|
841
869
|
rootEntry = createEntry(layoutsByDirectory.get('')!, chain.slice(1), target)
|
|
870
|
+
if (globalThis.__NATIVUE_HOT__) keepNavigationAcrossReloads()
|
|
842
871
|
|
|
843
872
|
return createApp(defineComponent(() => () => h(LayoutContent, { entry: rootEntry })))
|
|
844
873
|
}
|
package/src/types.ts
CHANGED
|
@@ -115,6 +115,9 @@ export interface NativeModule {
|
|
|
115
115
|
windowSize(): { width: number; height: number }
|
|
116
116
|
platform(): 'ios' | 'android'
|
|
117
117
|
colorScheme(): 'light' | 'dark'
|
|
118
|
+
/** Development: the navigation saveNavigation kept, which outlives the JavaScript runtime. */
|
|
119
|
+
savedNavigation(): string | null
|
|
120
|
+
saveNavigation(routes: string): void
|
|
118
121
|
accessibilityInfo(): { screenReaderEnabled: boolean; reduceMotionEnabled: boolean }
|
|
119
122
|
announce(message: string): void
|
|
120
123
|
create(id: number, type: string): void
|