@nativue/core 0.1.0 → 0.3.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/Package.swift +26 -2
- package/android/build.gradle.kts +2 -2
- package/android/consumer-rules.pro +3 -0
- package/android/nativue.settings.gradle.kts +56 -0
- package/android/src/main/java/dev/nativue/Bridge.kt +51 -7
- package/android/src/main/java/dev/nativue/ModalHost.kt +2 -2
- package/android/src/main/java/dev/nativue/NativueActivity.kt +8 -0
- package/android/src/main/java/dev/nativue/Navigation.kt +32 -24
- package/android/src/main/java/dev/nativue/Plugins.kt +75 -0
- package/android/src/main/java/dev/nativue/Style.kt +5 -1
- package/android/src/main/java/dev/nativue/Theme.kt +61 -0
- package/android/src/main/java/dev/nativue/Views.kt +14 -2
- package/cli/config.d.mts +19 -0
- package/cli/config.mjs +4 -0
- package/cli/link.mjs +129 -0
- package/cli/nativue.mjs +67 -20
- package/cli/symbolicate.mjs +3 -5
- package/ios/Bridge.swift +207 -102
- package/ios/JavaScriptRuntime/JavaScriptRuntime.mm +231 -0
- package/ios/JavaScriptRuntime/include/NativueJavaScriptRuntime.h +29 -0
- package/ios/JavaScriptRuntime/vendor/hermes/LICENSE +21 -0
- package/ios/JavaScriptRuntime/vendor/hermes/Public/CrashManager.h +107 -0
- package/ios/JavaScriptRuntime/vendor/hermes/Public/CtorConfig.h +145 -0
- package/ios/JavaScriptRuntime/vendor/hermes/Public/GCConfig.h +211 -0
- package/ios/JavaScriptRuntime/vendor/hermes/Public/GCTripwireContext.h +40 -0
- package/ios/JavaScriptRuntime/vendor/hermes/Public/HermesExport.h +14 -0
- package/ios/JavaScriptRuntime/vendor/hermes/Public/RuntimeConfig.h +141 -0
- package/ios/JavaScriptRuntime/vendor/hermes/Public/SamplingProfiler.h +270 -0
- package/ios/JavaScriptRuntime/vendor/hermes/hermes.h +242 -0
- package/ios/NativeNode.swift +1 -0
- package/ios/NativueView.swift +10 -3
- package/ios/Plugins.swift +45 -0
- package/ios/Style.swift +14 -1
- package/package.json +7 -2
- package/src/appearance.ts +49 -0
- package/src/components.ts +3 -1
- package/src/entry.ts +2 -1
- package/src/globals.ts +3 -0
- package/src/native-functions.ts +41 -0
- package/src/renderer.ts +58 -1
- package/src/types.ts +2 -0
- package/src/virtual-modules.d.ts +2 -0
package/ios/Bridge.swift
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import UIKit
|
|
2
|
-
import
|
|
2
|
+
import JavaScriptRuntime
|
|
3
3
|
import yoga
|
|
4
4
|
|
|
5
5
|
/// Runs the JS bundle off the main thread and applies the operations sent by the Vue renderer
|
|
@@ -27,13 +27,15 @@ final class Bridge {
|
|
|
27
27
|
private let javaScriptQueue = DispatchQueue(label: "dev.nativue.javascript", qos: .userInteractive)
|
|
28
28
|
|
|
29
29
|
// Only touched on javaScriptQueue.
|
|
30
|
-
private
|
|
30
|
+
private var runtime: JavaScriptRuntime?
|
|
31
31
|
private var pendingOperations: [() -> Void] = []
|
|
32
32
|
private var gestureReportersByNodeId: [Int: GestureReporter] = [:]
|
|
33
33
|
private let animatedGraph = AnimatedGraph()
|
|
34
34
|
private lazy var storage = KeyValueStorage(javaScriptQueue: javaScriptQueue)
|
|
35
35
|
/// Set by LayoutAnimation.configureNext in JS; animates the batch it's sent with.
|
|
36
36
|
private var nextLayoutAnimation: LayoutAnimation?
|
|
37
|
+
/// Appearance.getColorScheme(): read on the main thread at start, then kept up to date.
|
|
38
|
+
private var colorScheme = "light"
|
|
37
39
|
|
|
38
40
|
// Only touched on the main thread.
|
|
39
41
|
var rootView: RootView!
|
|
@@ -45,13 +47,27 @@ final class Bridge {
|
|
|
45
47
|
/// Read on the main thread at start, for Dimensions.get('window').
|
|
46
48
|
private var windowSize: CGSize = .zero
|
|
47
49
|
/// The bundle running now, for the error overlay's Reload.
|
|
48
|
-
private var
|
|
50
|
+
private var bundle = Data()
|
|
49
51
|
private let errorOverlay = ErrorOverlay()
|
|
52
|
+
private let pluginRegistry: PluginRegistry
|
|
53
|
+
|
|
54
|
+
init(plugins: [NativuePlugin]) {
|
|
55
|
+
pluginRegistry = PluginRegistry(plugins: plugins)
|
|
56
|
+
}
|
|
50
57
|
|
|
51
58
|
func start(rootView: RootView) {
|
|
52
59
|
self.rootView = rootView
|
|
53
60
|
rootView.onLayoutSubviews = { [unowned self] in layout() }
|
|
54
|
-
|
|
61
|
+
let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene
|
|
62
|
+
windowSize = windowScene?.screen.bounds.size ?? .zero
|
|
63
|
+
colorScheme = Self.colorScheme(of: windowScene?.traitCollection ?? rootView.traitCollection)
|
|
64
|
+
// start runs on the main thread, from makeUIView.
|
|
65
|
+
MainActor.assumeIsolated {
|
|
66
|
+
_ = rootView.registerForTraitChanges([UITraitUserInterfaceStyle.self]) {
|
|
67
|
+
[unowned self] (rootView: RootView, _: UITraitCollection) in
|
|
68
|
+
colorSchemeDidChange(to: Self.colorScheme(of: rootView.traitCollection))
|
|
69
|
+
}
|
|
70
|
+
}
|
|
55
71
|
|
|
56
72
|
NotificationCenter.default.addObserver(forName: Self.openURLNotification, object: nil, queue: .main) {
|
|
57
73
|
[unowned self] notification in
|
|
@@ -63,29 +79,28 @@ final class Bridge {
|
|
|
63
79
|
guard let bundleURL = Bundle.main.url(forResource: "main.bundle", withExtension: "js") else {
|
|
64
80
|
fatalError("ios/App/main.bundle.js is missing: run `npm run dev` (or `npm run build`), then build again")
|
|
65
81
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
run(source)
|
|
82
|
+
run(try! Data(contentsOf: bundleURL))
|
|
69
83
|
#if DEBUG
|
|
70
84
|
Task { await listenForReload() }
|
|
71
85
|
#endif
|
|
72
86
|
}
|
|
73
87
|
|
|
74
|
-
/// Discards the current node tree and
|
|
75
|
-
|
|
76
|
-
|
|
88
|
+
/// Discards the current node tree and runtime, then runs the bundle from scratch: JavaScript, or
|
|
89
|
+
/// Hermes bytecode (production builds).
|
|
90
|
+
func run(_ bundle: Data) {
|
|
91
|
+
self.bundle = bundle
|
|
77
92
|
errorOverlay.hide()
|
|
78
93
|
|
|
79
94
|
evaluate { [unowned self] in
|
|
80
95
|
enqueue { [unowned self] in resetNodeTree() }
|
|
81
96
|
|
|
82
|
-
|
|
83
|
-
|
|
97
|
+
runtime = makeRuntime()
|
|
98
|
+
runtime?.evaluate(bundle, sourceURL: "main.bundle.js")
|
|
84
99
|
}
|
|
85
100
|
}
|
|
86
101
|
|
|
87
102
|
/// Runs `work` on the JS queue, then applies every native operation it produced, in one batch, on the
|
|
88
|
-
/// main thread.
|
|
103
|
+
/// main thread. The runtime drains promise jobs after each call, so Vue's updates are included.
|
|
89
104
|
func evaluate(_ work: @escaping () -> Void) {
|
|
90
105
|
javaScriptQueue.async { [unowned self] in
|
|
91
106
|
work()
|
|
@@ -121,12 +136,30 @@ final class Bridge {
|
|
|
121
136
|
}
|
|
122
137
|
}
|
|
123
138
|
|
|
139
|
+
private func finishAsyncFunction(_ callId: Int, value: Any?, errorMessage: String?) {
|
|
140
|
+
evaluate { [unowned self] in
|
|
141
|
+
let arguments: [Any] = [callId, value ?? NSNull(), errorMessage ?? NSNull()]
|
|
142
|
+
runtime?.call("__asyncFunctionFinished", arguments: arguments)
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
private static func colorScheme(of traits: UITraitCollection) -> String {
|
|
147
|
+
traits.userInterfaceStyle == .dark ? "dark" : "light"
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
private func colorSchemeDidChange(to nextColorScheme: String) {
|
|
151
|
+
evaluate { [unowned self] in
|
|
152
|
+
guard nextColorScheme != colorScheme else { return }
|
|
153
|
+
|
|
154
|
+
colorScheme = nextColorScheme
|
|
155
|
+
runtime?.call("__colorSchemeChanged", arguments: [nextColorScheme])
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
124
159
|
/// Queued on the JS queue, so a URL that opens the app arrives after the bundle has run.
|
|
125
160
|
private func openURL(_ url: URL) {
|
|
126
161
|
evaluate { [unowned self] in
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
openURL.call(withArguments: [url.absoluteString])
|
|
162
|
+
runtime?.call("__openURL", arguments: [url.absoluteString])
|
|
130
163
|
}
|
|
131
164
|
}
|
|
132
165
|
|
|
@@ -147,7 +180,7 @@ final class Bridge {
|
|
|
147
180
|
for try await line in events.lines where line == "data: reload" {
|
|
148
181
|
let (data, _) = try await URLSession.shared.data(from: bundleURL)
|
|
149
182
|
print("[Nativue] reload")
|
|
150
|
-
run(
|
|
183
|
+
run(data)
|
|
151
184
|
}
|
|
152
185
|
} catch {}
|
|
153
186
|
|
|
@@ -162,78 +195,116 @@ final class Bridge {
|
|
|
162
195
|
pendingOperations.append(operation)
|
|
163
196
|
}
|
|
164
197
|
|
|
165
|
-
private
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
context.exceptionHandler = { [unowned self] _, exception in
|
|
169
|
-
reportError(
|
|
170
|
-
message: exception?.toString() ?? "",
|
|
171
|
-
details: exception?.objectForKeyedSubscript("stack")?.toString() ?? ""
|
|
172
|
-
)
|
|
173
|
-
}
|
|
198
|
+
private typealias NativeFunction = (_ arguments: [Any]) -> Any?
|
|
199
|
+
private typealias Define = (_ name: String, _ function: @escaping (_ arguments: [Any]) -> Void) -> Void
|
|
200
|
+
private typealias DefineGetter = (_ name: String, _ function: @escaping NativeFunction) -> Void
|
|
174
201
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
202
|
+
/// Errors outside Vue (timers, native callbacks, the bundle itself) come from the runtime; Vue's
|
|
203
|
+
/// through `__native.reportError`.
|
|
204
|
+
private func makeRuntime() -> JavaScriptRuntime {
|
|
205
|
+
var functions: [String: Any] = [:]
|
|
206
|
+
func defineGetter(_ name: String, _ function: @escaping NativeFunction) {
|
|
207
|
+
functions[name] = function as @convention(block) ([Any]) -> Any?
|
|
208
|
+
}
|
|
209
|
+
func define(_ name: String, _ function: @escaping (_ arguments: [Any]) -> Void) {
|
|
210
|
+
defineGetter(name) { arguments in
|
|
211
|
+
function(arguments)
|
|
212
|
+
return nil
|
|
213
|
+
}
|
|
178
214
|
}
|
|
179
215
|
|
|
180
|
-
define("log"
|
|
216
|
+
define("log") { arguments in print("[JS]", arguments[0]) }
|
|
181
217
|
|
|
182
|
-
define("reportError"
|
|
183
|
-
reportError(message:
|
|
184
|
-
}
|
|
218
|
+
define("reportError") { [unowned self] arguments in
|
|
219
|
+
reportError(message: string(arguments[0]), details: string(arguments[1]))
|
|
220
|
+
}
|
|
185
221
|
|
|
186
222
|
// ponytail: the size at launch; report rotation and split view changes if the app supports them.
|
|
187
|
-
|
|
223
|
+
defineGetter("windowSize") { [unowned self] _ in
|
|
188
224
|
["width": windowSize.width, "height": windowSize.height]
|
|
189
|
-
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
defineGetter("platform") { _ in "ios" }
|
|
228
|
+
|
|
229
|
+
// Prefixed, so a plugin can't replace nativue's own functions.
|
|
230
|
+
for (name, function) in pluginRegistry.functions {
|
|
231
|
+
defineGetter("plugin:\(name)", function)
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// (callId, ...arguments): settles the call with __asyncFunctionFinished.
|
|
235
|
+
for (name, function) in pluginRegistry.asyncFunctions {
|
|
236
|
+
define("pluginAsync:\(name)") { [unowned self] arguments in
|
|
237
|
+
let callId = int(arguments[0])
|
|
238
|
+
|
|
239
|
+
Task {
|
|
240
|
+
do {
|
|
241
|
+
let value = try await function(Array(arguments.dropFirst()))
|
|
242
|
+
finishAsyncFunction(callId, value: value, errorMessage: nil)
|
|
243
|
+
} catch {
|
|
244
|
+
finishAsyncFunction(callId, value: nil, errorMessage: error.localizedDescription)
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
190
249
|
|
|
191
|
-
|
|
250
|
+
defineGetter("colorScheme") { [unowned self] _ in colorScheme }
|
|
251
|
+
|
|
252
|
+
define("create") { [unowned self] arguments in
|
|
253
|
+
let (id, type) = (int(arguments[0]), string(arguments[1]))
|
|
192
254
|
enqueue { [unowned self] in nodesById[id] = makeNode(type: type, id: id) }
|
|
193
|
-
}
|
|
255
|
+
}
|
|
194
256
|
|
|
195
|
-
define("insert"
|
|
257
|
+
define("insert") { [unowned self] arguments in
|
|
258
|
+
let (parentId, childId, index) = (int(arguments[0]), int(arguments[1]), int(arguments[2]))
|
|
196
259
|
enqueue { [unowned self] in insertNode(childId: childId, parentId: parentId, at: index) }
|
|
197
|
-
}
|
|
260
|
+
}
|
|
198
261
|
|
|
199
|
-
define("remove"
|
|
262
|
+
define("remove") { [unowned self] arguments in
|
|
263
|
+
let id = int(arguments[0])
|
|
200
264
|
enqueue { [unowned self] in removeNode(id: id) }
|
|
201
|
-
}
|
|
265
|
+
}
|
|
202
266
|
|
|
203
|
-
define("setText"
|
|
267
|
+
define("setText") { [unowned self] arguments in
|
|
268
|
+
let (id, text) = (int(arguments[0]), string(arguments[1]))
|
|
204
269
|
enqueue { [unowned self] in setText(text, onNodeId: id) }
|
|
205
|
-
}
|
|
270
|
+
}
|
|
206
271
|
|
|
207
|
-
define("setProp"
|
|
208
|
-
let
|
|
209
|
-
enqueue { [unowned self] in setProp(key, value:
|
|
210
|
-
}
|
|
272
|
+
define("setProp") { [unowned self] arguments in
|
|
273
|
+
let (id, key, value) = (int(arguments[0]), string(arguments[1]), arguments[2])
|
|
274
|
+
enqueue { [unowned self] in setProp(key, value: value, onNodeId: id) }
|
|
275
|
+
}
|
|
211
276
|
|
|
212
277
|
defineAnimatedFunctions(define)
|
|
213
|
-
defineStorageFunctions(define)
|
|
278
|
+
defineStorageFunctions(define, defineGetter)
|
|
214
279
|
defineFetch(define)
|
|
215
280
|
|
|
216
|
-
define("setTimer"
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
evaluate {
|
|
221
|
-
_ = context?.objectForKeyedSubscript("__fireTimer").call(withArguments: [timerId])
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
} as @convention(block) (Int, Int) -> Void)
|
|
281
|
+
define("setTimer") { [unowned self] arguments in
|
|
282
|
+
let (timerId, delayInMilliseconds) = (int(arguments[0]), int(arguments[1]))
|
|
283
|
+
setTimer(timerId, delayInMilliseconds: delayInMilliseconds)
|
|
284
|
+
}
|
|
225
285
|
|
|
226
|
-
define("configureNextLayoutAnimation"
|
|
227
|
-
nextLayoutAnimation = LayoutAnimation(config:
|
|
228
|
-
}
|
|
286
|
+
define("configureNextLayoutAnimation") { [unowned self] arguments in
|
|
287
|
+
nextLayoutAnimation = LayoutAnimation(config: arguments[0] as? [String: Any] ?? [:])
|
|
288
|
+
}
|
|
229
289
|
|
|
230
|
-
define("dismissKeyboard"
|
|
290
|
+
define("dismissKeyboard") { [unowned self] _ in
|
|
231
291
|
enqueue { [unowned self] in rootView.window?.endEditing(true) }
|
|
232
|
-
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
return JavaScriptRuntime(functions: functions) { [unowned self] message, stack in
|
|
295
|
+
reportError(message: message, details: stack)
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/// A timer of a runtime that has since been reloaded doesn't fire: timer ids start over in the new one.
|
|
300
|
+
private func setTimer(_ timerId: Int, delayInMilliseconds: Int) {
|
|
301
|
+
let owner = runtime
|
|
233
302
|
|
|
234
|
-
|
|
303
|
+
javaScriptQueue.asyncAfter(deadline: .now() + .milliseconds(delayInMilliseconds)) { [unowned self] in
|
|
304
|
+
guard runtime === owner else { return }
|
|
235
305
|
|
|
236
|
-
|
|
306
|
+
evaluate { [unowned self] in runtime?.call("__fireTimer", arguments: [timerId]) }
|
|
307
|
+
}
|
|
237
308
|
}
|
|
238
309
|
|
|
239
310
|
/// Logged always; shown over the app in development builds.
|
|
@@ -243,7 +314,7 @@ final class Bridge {
|
|
|
243
314
|
#if DEBUG
|
|
244
315
|
Task { @MainActor [unowned self] in
|
|
245
316
|
let details = await symbolicated(details)
|
|
246
|
-
errorOverlay.show(message: message, details: details) { [unowned self] in run(
|
|
317
|
+
errorOverlay.show(message: message, details: details) { [unowned self] in run(bundle) }
|
|
247
318
|
}
|
|
248
319
|
#endif
|
|
249
320
|
}
|
|
@@ -275,7 +346,7 @@ final class Bridge {
|
|
|
275
346
|
animatedGraph.reset()
|
|
276
347
|
animatedGraph.onAnimationEnd = { [unowned self] animationId, finished in
|
|
277
348
|
evaluate { [unowned self] in
|
|
278
|
-
|
|
349
|
+
runtime?.call("__animationFinished", arguments: [animationId, finished])
|
|
279
350
|
}
|
|
280
351
|
}
|
|
281
352
|
nodesById = [0: NativeNode(view: rootView, measuresContent: false)]
|
|
@@ -410,7 +481,14 @@ final class Bridge {
|
|
|
410
481
|
return node
|
|
411
482
|
|
|
412
483
|
default:
|
|
413
|
-
|
|
484
|
+
guard let makeView = pluginRegistry.viewMakers[type] else {
|
|
485
|
+
return NativeNode(view: UIView(), measuresContent: false)
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
let view = makeView { [unowned self] eventName, payload in
|
|
489
|
+
dispatchEvent(eventName, toNodeId: id, payload: payload)
|
|
490
|
+
}
|
|
491
|
+
return NativeNode(view: view, measuresContent: false)
|
|
414
492
|
}
|
|
415
493
|
}
|
|
416
494
|
|
|
@@ -436,33 +514,35 @@ final class Bridge {
|
|
|
436
514
|
}
|
|
437
515
|
|
|
438
516
|
/// AsyncStorage: synchronous on the JS queue (values are in memory); JS wraps them in promises.
|
|
439
|
-
private func defineStorageFunctions(_ define:
|
|
440
|
-
|
|
441
|
-
storage.value(forKey:
|
|
442
|
-
}
|
|
517
|
+
private func defineStorageFunctions(_ define: Define, _ defineGetter: DefineGetter) {
|
|
518
|
+
defineGetter("storageGet") { [unowned self] arguments in
|
|
519
|
+
storage.value(forKey: string(arguments[0]))
|
|
520
|
+
}
|
|
443
521
|
|
|
444
|
-
define("storageSet"
|
|
445
|
-
storage.setValue(
|
|
446
|
-
}
|
|
522
|
+
define("storageSet") { [unowned self] arguments in
|
|
523
|
+
storage.setValue(string(arguments[1]), forKey: string(arguments[0]))
|
|
524
|
+
}
|
|
447
525
|
|
|
448
|
-
define("storageRemove"
|
|
449
|
-
storage.removeValue(forKey:
|
|
450
|
-
}
|
|
526
|
+
define("storageRemove") { [unowned self] arguments in
|
|
527
|
+
storage.removeValue(forKey: string(arguments[0]))
|
|
528
|
+
}
|
|
451
529
|
|
|
452
|
-
|
|
530
|
+
defineGetter("storageKeys") { [unowned self] _ in
|
|
453
531
|
storage.keys
|
|
454
|
-
}
|
|
532
|
+
}
|
|
455
533
|
|
|
456
|
-
define("storageClear"
|
|
534
|
+
define("storageClear") { [unowned self] _ in
|
|
457
535
|
storage.removeAll()
|
|
458
|
-
}
|
|
536
|
+
}
|
|
459
537
|
}
|
|
460
538
|
|
|
461
539
|
/// fetch: URLSession runs the request; JS hears back through __fetchFinished(requestId, response, error).
|
|
462
540
|
/// ponytail: text bodies only (no binary, FormData or streaming) and no abort.
|
|
463
|
-
private func defineFetch(_ define:
|
|
464
|
-
define("fetch"
|
|
465
|
-
let
|
|
541
|
+
private func defineFetch(_ define: Define) {
|
|
542
|
+
define("fetch") { [unowned self] arguments in
|
|
543
|
+
let (requestId, url, method) = (int(arguments[0]), string(arguments[1]), string(arguments[2]))
|
|
544
|
+
let headers = arguments[3] as? [String: String] ?? [:]
|
|
545
|
+
let bodyText = arguments[4] as? String
|
|
466
546
|
|
|
467
547
|
guard let url = URL(string: url) else {
|
|
468
548
|
return finishFetch(requestId, response: nil, error: "invalid URL \(url)")
|
|
@@ -484,48 +564,54 @@ final class Bridge {
|
|
|
484
564
|
"body": String(decoding: data ?? Data(), as: UTF8.self),
|
|
485
565
|
], error: nil)
|
|
486
566
|
}.resume()
|
|
487
|
-
}
|
|
567
|
+
}
|
|
488
568
|
}
|
|
489
569
|
|
|
490
570
|
private func finishFetch(_ requestId: Int, response: [String: Any]?, error: String?) {
|
|
491
571
|
evaluate { [unowned self] in
|
|
492
572
|
let arguments: [Any] = [requestId, response ?? NSNull(), error ?? NSNull()]
|
|
493
|
-
|
|
573
|
+
runtime?.call("__fetchFinished", arguments: arguments)
|
|
494
574
|
}
|
|
495
575
|
}
|
|
496
576
|
|
|
497
577
|
/// Animated's native driver (see AnimatedGraph); queued like the view operations, so a value bound in
|
|
498
578
|
/// a batch exists when that batch is applied.
|
|
499
|
-
private func defineAnimatedFunctions(_ define:
|
|
500
|
-
define("createAnimatedNode"
|
|
579
|
+
private func defineAnimatedFunctions(_ define: Define) {
|
|
580
|
+
define("createAnimatedNode") { [unowned self] arguments in
|
|
581
|
+
let (id, config) = (int(arguments[0]), arguments[1] as? [String: Any] ?? [:])
|
|
501
582
|
enqueue { [unowned self] in animatedGraph.createNode(id: id, config: config) }
|
|
502
|
-
}
|
|
583
|
+
}
|
|
503
584
|
|
|
504
|
-
define("setAnimatedValue"
|
|
585
|
+
define("setAnimatedValue") { [unowned self] arguments in
|
|
586
|
+
let (id, value) = (int(arguments[0]), double(arguments[1]))
|
|
505
587
|
enqueue { [unowned self] in animatedGraph.setValue(value, ofNode: id) }
|
|
506
|
-
}
|
|
588
|
+
}
|
|
507
589
|
|
|
508
|
-
define("startAnimation"
|
|
590
|
+
define("startAnimation") { [unowned self] arguments in
|
|
591
|
+
let (animationId, nodeId) = (int(arguments[0]), int(arguments[1]))
|
|
592
|
+
let config = arguments[2] as? [String: Any] ?? [:]
|
|
509
593
|
enqueue { [unowned self] in animatedGraph.startAnimation(id: animationId, nodeId: nodeId, config: config) }
|
|
510
|
-
}
|
|
594
|
+
}
|
|
511
595
|
|
|
512
|
-
define("stopAnimation"
|
|
596
|
+
define("stopAnimation") { [unowned self] arguments in
|
|
597
|
+
let nodeId = int(arguments[0])
|
|
513
598
|
enqueue { [unowned self] in animatedGraph.stopAnimation(ofNode: nodeId) }
|
|
514
|
-
}
|
|
599
|
+
}
|
|
515
600
|
|
|
516
|
-
define("setAnimatedStyle"
|
|
517
|
-
let binding =
|
|
601
|
+
define("setAnimatedStyle") { [unowned self] arguments in
|
|
602
|
+
let (viewId, binding) = (int(arguments[0]), arguments[1] as? [String: Any])
|
|
518
603
|
enqueue { [unowned self] in
|
|
519
604
|
guard let view = nodesById[viewId]?.view else { return }
|
|
520
605
|
|
|
521
606
|
animatedGraph.bind(view: view, viewId: viewId, binding: binding)
|
|
522
607
|
}
|
|
523
|
-
}
|
|
608
|
+
}
|
|
524
609
|
|
|
525
|
-
define("setAnimatedEvent"
|
|
526
|
-
let
|
|
610
|
+
define("setAnimatedEvent") { [unowned self] arguments in
|
|
611
|
+
let (viewId, event) = (int(arguments[0]), string(arguments[1]))
|
|
612
|
+
let mapping = (arguments[2] as? [String: Any])?.compactMapValues { ($0 as? NSNumber)?.intValue }
|
|
527
613
|
enqueue { [unowned self] in setAnimatedEvent(event, mapping: mapping, onNodeId: viewId) }
|
|
528
|
-
}
|
|
614
|
+
}
|
|
529
615
|
}
|
|
530
616
|
|
|
531
617
|
private func setAnimatedEvent(_ event: String, mapping: [String: Int]?, onNodeId id: Int) {
|
|
@@ -558,7 +644,7 @@ final class Bridge {
|
|
|
558
644
|
private func dispatchEvent(_ eventName: String, toNodeId id: Int, payload: Any? = nil) {
|
|
559
645
|
evaluate { [unowned self] in
|
|
560
646
|
let arguments: [Any] = [id, eventName, payload ?? NSNull()]
|
|
561
|
-
|
|
647
|
+
runtime?.call("__dispatch", arguments: arguments)
|
|
562
648
|
}
|
|
563
649
|
}
|
|
564
650
|
|
|
@@ -572,6 +658,11 @@ final class Bridge {
|
|
|
572
658
|
private func setProp(_ key: String, value: Any?, onNodeId id: Int) {
|
|
573
659
|
guard let node = nodesById[id] else { return }
|
|
574
660
|
|
|
661
|
+
if key != "style", let pluginView = node.view as? PluginView {
|
|
662
|
+
pluginView.setProp(key, value: value is NSNull ? nil : value)
|
|
663
|
+
return
|
|
664
|
+
}
|
|
665
|
+
|
|
575
666
|
switch key {
|
|
576
667
|
case "title":
|
|
577
668
|
(node.view as? UIButton)?.setTitle(value as? String, for: .normal)
|
|
@@ -745,3 +836,17 @@ final class Bridge {
|
|
|
745
836
|
return false
|
|
746
837
|
}
|
|
747
838
|
}
|
|
839
|
+
|
|
840
|
+
// JS numbers arrive as NSNumber doubles; a missing or mistyped argument reads as 0 or "".
|
|
841
|
+
|
|
842
|
+
private func int(_ argument: Any) -> Int {
|
|
843
|
+
(argument as? NSNumber)?.intValue ?? 0
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
private func double(_ argument: Any) -> Double {
|
|
847
|
+
(argument as? NSNumber)?.doubleValue ?? 0
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
private func string(_ argument: Any) -> String {
|
|
851
|
+
argument as? String ?? ""
|
|
852
|
+
}
|