@nativue/core 0.15.0 → 0.15.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/android/src/main/cpp/bridge.cpp +3 -1
- package/android/src/main/java/dev/nativue/Bridge.kt +10 -6
- package/android/src/main/java/dev/nativue/Networking.kt +6 -1
- package/cli/hermes.mjs +38 -0
- package/cli/nativue.mjs +3 -36
- package/ios/Bridge.swift +8 -4
- package/ios/JavaScriptRuntime/JavaScriptRuntime.mm +3 -1
- package/ios/Networking.swift +5 -2
- package/package.json +2 -2
|
@@ -463,7 +463,9 @@ extern "C" JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void*) {
|
|
|
463
463
|
|
|
464
464
|
extern "C" JNIEXPORT jlong JNICALL
|
|
465
465
|
Java_dev_nativue_JavaScriptRuntime_create(JNIEnv* env, jobject owner, jobjectArray functionNames) {
|
|
466
|
-
|
|
466
|
+
// Off by default: a let in a loop would be one variable for every iteration, so callbacks made
|
|
467
|
+
// in the loop would all see its last value. Bytecode gets the same from hermesc's -Xes6-block-scoping.
|
|
468
|
+
auto config = ::hermes::vm::RuntimeConfig::Builder().withMicrotaskQueue(true).withES6BlockScoping(true).build();
|
|
467
469
|
auto runtime = new Runtime{facebook::hermes::makeHermesRuntime(config), env->NewGlobalRef(owner)};
|
|
468
470
|
installNativeModule(*runtime, env, functionNames);
|
|
469
471
|
|
|
@@ -88,16 +88,18 @@ class Bridge(private val activity: ComponentActivity, private val rootView: Root
|
|
|
88
88
|
/** Set by LayoutAnimation.configureNext in JS; animates the batch it's sent with. */
|
|
89
89
|
private var nextLayoutAnimation: Map<*, *>? = null
|
|
90
90
|
|
|
91
|
+
/** Thread-safe: used from the JS thread (requests, and clearing them in run) and the requests' own. */
|
|
92
|
+
private val blobStore = BlobStore.shared
|
|
93
|
+
private val networking = Networking(activity, blobStore) { owner, requestId, eventName, payload ->
|
|
94
|
+
callIfStillRunning(owner, "__networkEvent", requestId, eventName, payload)
|
|
95
|
+
}
|
|
96
|
+
|
|
91
97
|
// Only touched on the main thread.
|
|
92
98
|
private val nodesById = HashMap<Int, NativeNode>()
|
|
93
99
|
private val animatedGraph = AnimatedGraph()
|
|
94
100
|
private val modalHostsByNodeId = HashMap<Int, ModalHost>()
|
|
95
101
|
private val gestureReportersByNodeId = HashMap<Int, GestureReporter>()
|
|
96
102
|
/** Views with @layout, and the box they last reported. */
|
|
97
|
-
private val blobStore = BlobStore.shared
|
|
98
|
-
private val networking = Networking(activity, blobStore) { owner, requestId, eventName, payload ->
|
|
99
|
-
callIfStillRunning(owner, "__networkEvent", requestId, eventName, payload)
|
|
100
|
-
}
|
|
101
103
|
private val reportedLayoutsByNodeId = mutableMapOf<Int, Map<String, Float>?>()
|
|
102
104
|
|
|
103
105
|
/** The latest window insets, mid-animation while the keyboard moves. */
|
|
@@ -262,6 +264,10 @@ class Bridge(private val activity: ComponentActivity, private val rootView: Root
|
|
|
262
264
|
errorOverlay.hide()
|
|
263
265
|
|
|
264
266
|
evaluate {
|
|
267
|
+
// Here, not in resetNodeTree: that runs on the main thread after the new bundle has started
|
|
268
|
+
// its own requests, which it would abort, and their responses' blobs.
|
|
269
|
+
networking.abortAll()
|
|
270
|
+
blobStore.removeAll()
|
|
265
271
|
enqueue(::resetNodeTree)
|
|
266
272
|
|
|
267
273
|
runtime?.destroy()
|
|
@@ -670,8 +676,6 @@ class Bridge(private val activity: ComponentActivity, private val rootView: Root
|
|
|
670
676
|
}
|
|
671
677
|
modalHostsByNodeId.clear()
|
|
672
678
|
gestureReportersByNodeId.clear() // node ids start over
|
|
673
|
-
networking.abortAll() // and so do request ids
|
|
674
|
-
blobStore.removeAll() // and the Blobs that held them are gone
|
|
675
679
|
reportedLayoutsByNodeId.clear()
|
|
676
680
|
animatedGraph.reset()
|
|
677
681
|
animatedGraph.onAnimationEnd = { animationId, finished ->
|
|
@@ -242,7 +242,12 @@ class Networking(
|
|
|
242
242
|
"bytes" -> bytes
|
|
243
243
|
"blob" -> {
|
|
244
244
|
val type = contentType?.substringBefore(";")?.trim().orEmpty()
|
|
245
|
-
|
|
245
|
+
val blobId = blobStore.store(bytes)
|
|
246
|
+
|
|
247
|
+
// A reload aborts the request before clearing the store: stored after that, nothing would release it.
|
|
248
|
+
if (request.aborted) blobStore.remove(blobId)
|
|
249
|
+
|
|
250
|
+
mapOf("blobId" to blobId, "offset" to 0, "size" to bytes.size, "type" to type)
|
|
246
251
|
}
|
|
247
252
|
else -> String(bytes, Charsets.UTF_8)
|
|
248
253
|
}
|
package/cli/hermes.mjs
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// Hermes bytecode for production bundles.
|
|
2
|
+
import { execFileSync } from 'node:child_process'
|
|
3
|
+
import { renameSync } from 'node:fs'
|
|
4
|
+
import { createRequire } from 'node:module'
|
|
5
|
+
import { dirname } from 'node:path'
|
|
6
|
+
|
|
7
|
+
const HERMESC_BY_PLATFORM = {
|
|
8
|
+
darwin: 'osx-bin/hermesc',
|
|
9
|
+
linux: 'linux64-bin/hermesc',
|
|
10
|
+
win32: 'win64-bin/hermesc.exe',
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// -Xes6-block-scoping: a let in a loop is a variable per iteration, as when the runtime compiles source
|
|
14
|
+
// in development. Without it, callbacks made in the loop all see its last value.
|
|
15
|
+
export const HERMESC_OPTIONS = ['-O', '-w', '-Xes6-block-scoping']
|
|
16
|
+
|
|
17
|
+
export function hermescPath() {
|
|
18
|
+
const packageDirectory = dirname(
|
|
19
|
+
createRequire(import.meta.url).resolve('hermes-compiler/package.json'),
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
return `${packageDirectory}/hermesc/${HERMESC_BY_PLATFORM[process.platform]}`
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Hermes bytecode starts faster: no parsing when the app opens. The runtime tells bytecode from
|
|
26
|
+
// source on its own, so the file keeps its name.
|
|
27
|
+
export function compileToBytecode(bundlePath) {
|
|
28
|
+
const bytecodePath = `${bundlePath}.hbc`
|
|
29
|
+
|
|
30
|
+
execFileSync(
|
|
31
|
+
hermescPath(),
|
|
32
|
+
['-emit-binary', ...HERMESC_OPTIONS, '-out', bytecodePath, bundlePath],
|
|
33
|
+
{
|
|
34
|
+
stdio: 'inherit',
|
|
35
|
+
},
|
|
36
|
+
)
|
|
37
|
+
renameSync(bytecodePath, bundlePath)
|
|
38
|
+
}
|
package/cli/nativue.mjs
CHANGED
|
@@ -15,20 +15,12 @@ import { build, createServer, loadConfigFromFile, transformWithOxc } from 'vite'
|
|
|
15
15
|
import vue from '@vitejs/plugin-vue'
|
|
16
16
|
import http from 'node:http'
|
|
17
17
|
import net from 'node:net'
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
copyFileSync,
|
|
21
|
-
existsSync,
|
|
22
|
-
mkdirSync,
|
|
23
|
-
readdirSync,
|
|
24
|
-
readFileSync,
|
|
25
|
-
renameSync,
|
|
26
|
-
watch,
|
|
27
|
-
} from 'node:fs'
|
|
18
|
+
import { copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, watch } from 'node:fs'
|
|
28
19
|
import { randomUUID } from 'node:crypto'
|
|
29
20
|
import { createRequire } from 'node:module'
|
|
30
|
-
import {
|
|
21
|
+
import { relative } from 'node:path'
|
|
31
22
|
import { fileURLToPath } from 'node:url'
|
|
23
|
+
import { compileToBytecode } from './hermes.mjs'
|
|
32
24
|
import { resolvePlugins } from './plugins.mjs'
|
|
33
25
|
import { linkNativePackages, PLATFORMS, prebuild } from './prebuild.mjs'
|
|
34
26
|
import { runOnAndroid, runOnIOS } from './run.mjs'
|
|
@@ -62,31 +54,6 @@ function frameworkPath(relativePath) {
|
|
|
62
54
|
}
|
|
63
55
|
|
|
64
56
|
// hermesc ships with the hermes-compiler package, one binary per host system.
|
|
65
|
-
const HERMESC_BY_PLATFORM = {
|
|
66
|
-
darwin: 'osx-bin/hermesc',
|
|
67
|
-
linux: 'linux64-bin/hermesc',
|
|
68
|
-
win32: 'win64-bin/hermesc.exe',
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function hermescPath() {
|
|
72
|
-
const packageDirectory = dirname(
|
|
73
|
-
createRequire(import.meta.url).resolve('hermes-compiler/package.json'),
|
|
74
|
-
)
|
|
75
|
-
|
|
76
|
-
return `${packageDirectory}/hermesc/${HERMESC_BY_PLATFORM[process.platform]}`
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// Hermes bytecode starts faster: no parsing when the app opens. The runtime tells bytecode from
|
|
80
|
-
// source on its own, so the file keeps its name.
|
|
81
|
-
function compileToBytecode(bundlePath) {
|
|
82
|
-
const bytecodePath = `${bundlePath}.hbc`
|
|
83
|
-
|
|
84
|
-
execFileSync(hermescPath(), ['-emit-binary', '-O', '-w', '-out', bytecodePath, bundlePath], {
|
|
85
|
-
stdio: 'inherit',
|
|
86
|
-
})
|
|
87
|
-
renameSync(bytecodePath, bundlePath)
|
|
88
|
-
}
|
|
89
|
-
|
|
90
57
|
// A production bundle becomes bytecode; the Android app packages its assets folder, so it gets a copy.
|
|
91
58
|
function finishBundle(mode) {
|
|
92
59
|
return {
|
package/ios/Bridge.swift
CHANGED
|
@@ -42,6 +42,10 @@ final class Bridge {
|
|
|
42
42
|
/// Kept on the JS queue: the router's screens, reopened after a reload in development.
|
|
43
43
|
private var savedNavigation: String?
|
|
44
44
|
|
|
45
|
+
/// Thread-safe: used from the JS queue (requests, and clearing them in run) and Networking's own.
|
|
46
|
+
private let blobStore = BlobStore.shared
|
|
47
|
+
private lazy var networking = Networking(blobStore: blobStore)
|
|
48
|
+
|
|
45
49
|
// Only touched on the main thread.
|
|
46
50
|
var rootView: RootView!
|
|
47
51
|
private var gestureReportersByNodeId: [Int: GestureReporter] = [:]
|
|
@@ -49,8 +53,6 @@ final class Bridge {
|
|
|
49
53
|
var nodesById: [Int: NativeNode] = [:]
|
|
50
54
|
/// Views with @layout, and the box they last reported.
|
|
51
55
|
private var reportedLayoutsByNodeId: [Int: CGRect] = [:]
|
|
52
|
-
private let blobStore = BlobStore.shared
|
|
53
|
-
private lazy var networking = Networking(blobStore: blobStore)
|
|
54
56
|
/// Modals and screens: their content is laid out as a separate Yoga root.
|
|
55
57
|
private var contentRootsByNodeId: [Int: ContentRoot] = [:]
|
|
56
58
|
/// For Dimensions.get('window'): the screen's at start, then the root view's, kept on the JS queue.
|
|
@@ -144,6 +146,10 @@ final class Bridge {
|
|
|
144
146
|
errorOverlay.hide()
|
|
145
147
|
|
|
146
148
|
evaluate { [unowned self] in
|
|
149
|
+
// Here, not in resetNodeTree: that runs on the main thread after the new bundle has started
|
|
150
|
+
// its own requests, which it would abort, and their responses' blobs.
|
|
151
|
+
networking.abortAll()
|
|
152
|
+
blobStore.removeAll()
|
|
147
153
|
enqueue { [unowned self] in resetNodeTree() }
|
|
148
154
|
|
|
149
155
|
runtime = makeRuntime()
|
|
@@ -491,8 +497,6 @@ final class Bridge {
|
|
|
491
497
|
contentRootsByNodeId.values.forEach { ($0 as? ModalController)?.setVisible(false) }
|
|
492
498
|
contentRootsByNodeId = [:]
|
|
493
499
|
gestureReportersByNodeId = [:] // node ids start over
|
|
494
|
-
networking.abortAll() // and so do request ids
|
|
495
|
-
blobStore.removeAll() // and the Blobs that held them are gone
|
|
496
500
|
reportedLayoutsByNodeId = [:]
|
|
497
501
|
animatedGraph.reset()
|
|
498
502
|
animatedGraph.onAnimationEnd = { [unowned self] animationId, finished in
|
|
@@ -239,7 +239,9 @@ void installBlobCollector(jsi::Runtime &runtime, NativueNativeFunction release)
|
|
|
239
239
|
self = [super init];
|
|
240
240
|
if (self == nil) return nil;
|
|
241
241
|
|
|
242
|
-
|
|
242
|
+
// Off by default: a let in a loop would be one variable for every iteration, so callbacks made
|
|
243
|
+
// in the loop would all see its last value. Bytecode gets the same from hermesc's -Xes6-block-scoping.
|
|
244
|
+
auto config = ::hermes::vm::RuntimeConfig::Builder().withMicrotaskQueue(true).withES6BlockScoping(true).build();
|
|
243
245
|
_hermes = facebook::hermes::makeHermesRuntime(config);
|
|
244
246
|
_onError = onError;
|
|
245
247
|
[self installNativeModule:functions];
|
package/ios/Networking.swift
CHANGED
|
@@ -95,14 +95,17 @@ final class Networking: NSObject, URLSessionDataDelegate {
|
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
/// On reload: the requests' JS is gone.
|
|
98
|
+
/// On reload: the requests' JS is gone. Waits, so no response finishing meanwhile stores a blob after
|
|
99
|
+
/// the bridge clears them. This queue never waits on the JS one.
|
|
99
100
|
func abortAll() {
|
|
100
|
-
|
|
101
|
+
let abort = BlockOperation { [self] in
|
|
101
102
|
tasksByRequestId.values.forEach { $0.cancel() }
|
|
102
103
|
statesByTaskId.values.forEach { $0.deleteTemporaryFile() }
|
|
103
104
|
tasksByRequestId = [:]
|
|
104
105
|
statesByTaskId = [:]
|
|
105
106
|
}
|
|
107
|
+
|
|
108
|
+
queue.addOperations([abort], waitUntilFinished: true)
|
|
106
109
|
}
|
|
107
110
|
|
|
108
111
|
// MARK: URLSessionDataDelegate
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nativue/core",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.2",
|
|
4
4
|
"description": "Vue rendering real native views on iOS and Android",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vue",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
}
|
|
33
33
|
},
|
|
34
34
|
"scripts": {
|
|
35
|
-
"test": "(cd ../../examples/demo && nativue build) && node test/test.mjs && node test/native-events.test.mjs && node test/prebuild.test.mjs",
|
|
35
|
+
"test": "(cd ../../examples/demo && nativue build) && node test/test.mjs && node test/native-events.test.mjs && node test/hermes.test.mjs && node test/prebuild.test.mjs",
|
|
36
36
|
"typecheck": "vue-tsc"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|