@nativue/core 0.12.0 → 0.14.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 +33 -8
- package/README.md +2 -1
- package/android/build.gradle.kts +4 -0
- package/android/nativue.settings.gradle.kts +2 -0
- package/android/src/main/java/dev/nativue/Bridge.kt +118 -12
- package/android/src/main/java/dev/nativue/DownloadBanner.kt +45 -0
- package/android/src/main/java/dev/nativue/NativueActivity.kt +26 -5
- package/android/src/main/java/dev/nativue/Permissions.kt +107 -0
- package/android/src/main/java/dev/nativue/Plugins.kt +98 -15
- package/cli/android-project.mjs +377 -0
- package/cli/app-config.mjs +515 -0
- package/cli/config.d.mts +162 -3
- package/cli/hot-client.js +192 -0
- package/cli/ios-project.mjs +652 -0
- package/cli/link.mjs +66 -71
- package/cli/nativue.mjs +262 -58
- package/cli/plugins.mjs +236 -0
- package/cli/prebuild.mjs +458 -0
- package/cli/run.mjs +2 -2
- package/cli/serialize.mjs +168 -0
- package/cli/symbolicate.mjs +26 -14
- package/ios/AppLifecycle.swift +165 -0
- package/ios/Bridge.swift +110 -9
- package/ios/DownloadBanner.swift +38 -0
- package/ios/NativueView.swift +24 -1
- package/ios/Permissions.swift +19 -0
- package/ios/Plugins.swift +24 -0
- package/package.json +3 -2
- package/src/globals.ts +8 -1
- package/src/native-events.ts +99 -0
- package/src/native-functions.ts +16 -2
- package/src/permissions.ts +57 -0
- package/src/renderer.ts +6 -1
- package/src/router.ts +31 -1
- package/src/types.ts +6 -0
- package/template/android/app/src/debug/AndroidManifest.xml +4 -0
- package/template/android/app/src/main/java/MainActivity.kt +5 -0
- package/template/android/app/src/main/res/drawable-night-xxxhdpi/splash_logo.png +0 -0
- package/template/android/app/src/main/res/drawable-xxxhdpi/splash_logo.png +0 -0
- package/template/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml +6 -0
- package/template/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png +0 -0
- package/template/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png +0 -0
- package/template/android/app/src/main/res/values/colors.xml +4 -0
- package/template/android/app/src/main/res/values/styles.xml +15 -0
- package/template/android/app/src/main/res/values-night/styles.xml +5 -0
- package/template/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/template/android/gradle/wrapper/gradle-wrapper.properties +9 -0
- package/template/android/gradlew +248 -0
- package/template/android/gradlew.bat +112 -0
- package/template/ios/App/App.swift +18 -0
- package/template/ios/App/Assets.xcassets/AppIcon.appiconset/Contents.json +1 -0
- package/template/ios/App/Assets.xcassets/AppIcon.appiconset/icon.png +0 -0
- package/template/ios/App/Assets.xcassets/Contents.json +1 -0
- package/template/ios/App/Assets.xcassets/LaunchLogo.imageset/Contents.json +11 -0
- package/template/ios/App/Assets.xcassets/LaunchLogo.imageset/logo-dark@1x.png +0 -0
- package/template/ios/App/Assets.xcassets/LaunchLogo.imageset/logo-dark@2x.png +0 -0
- package/template/ios/App/Assets.xcassets/LaunchLogo.imageset/logo-dark@3x.png +0 -0
- package/template/ios/App/Assets.xcassets/LaunchLogo.imageset/logo@1x.png +0 -0
- package/template/ios/App/Assets.xcassets/LaunchLogo.imageset/logo@2x.png +0 -0
- package/template/ios/App/Assets.xcassets/LaunchLogo.imageset/logo@3x.png +0 -0
- package/template/ios/App.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +15 -0
package/ios/NativueView.swift
CHANGED
|
@@ -13,7 +13,11 @@ public struct NativueView: View {
|
|
|
13
13
|
public var body: some View {
|
|
14
14
|
VueRoot(plugins: plugins)
|
|
15
15
|
.ignoresSafeArea()
|
|
16
|
-
.onOpenURL { url in
|
|
16
|
+
.onOpenURL { url in
|
|
17
|
+
guard !NativueAppDelegate.open(url, plugins: plugins) else { return }
|
|
18
|
+
|
|
19
|
+
NotificationCenter.default.post(name: Bridge.openURLNotification, object: url)
|
|
20
|
+
}
|
|
17
21
|
}
|
|
18
22
|
}
|
|
19
23
|
|
|
@@ -48,4 +52,23 @@ final class RootView: UIView {
|
|
|
48
52
|
super.traitCollectionDidChange(previous)
|
|
49
53
|
onTraitCollectionChange?(previous)
|
|
50
54
|
}
|
|
55
|
+
|
|
56
|
+
#if DEBUG
|
|
57
|
+
var onReloadShortcut: (() -> Void)?
|
|
58
|
+
|
|
59
|
+
override var canBecomeFirstResponder: Bool { true }
|
|
60
|
+
|
|
61
|
+
override var keyCommands: [UIKeyCommand]? {
|
|
62
|
+
[UIKeyCommand(input: "r", modifierFlags: .command, action: #selector(reloadShortcutPressed))]
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
override func didMoveToWindow() {
|
|
66
|
+
super.didMoveToWindow()
|
|
67
|
+
becomeFirstResponder()
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
@objc private func reloadShortcutPressed() {
|
|
71
|
+
onReloadShortcut?()
|
|
72
|
+
}
|
|
73
|
+
#endif
|
|
51
74
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/// What JavaScript's PermissionResponse is, for an async function to return.
|
|
2
|
+
public enum PermissionStatus: String {
|
|
3
|
+
case granted, denied, undetermined
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
/// `{ status, granted, canAskAgain }` plus the plugin's own fields, e.g. `["accessPrivileges": "limited"]`.
|
|
7
|
+
/// canAskAgain is false only when denied: iOS shows the prompt once.
|
|
8
|
+
public func permissionResponse(
|
|
9
|
+
_ status: PermissionStatus,
|
|
10
|
+
extra: [String: Any] = [:]
|
|
11
|
+
) -> [String: Any] {
|
|
12
|
+
let response: [String: Any] = [
|
|
13
|
+
"status": status.rawValue,
|
|
14
|
+
"granted": status == .granted,
|
|
15
|
+
"canAskAgain": status != .denied,
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
return response.merging(extra) { _, extraValue in extraValue }
|
|
19
|
+
}
|
package/ios/Plugins.swift
CHANGED
|
@@ -15,6 +15,8 @@ public final class PluginRegistry {
|
|
|
15
15
|
public typealias SendEvent = (_ eventName: String, _ payload: Any?) -> Void
|
|
16
16
|
public typealias MakeView = (_ sendEvent: @escaping SendEvent) -> UIView
|
|
17
17
|
|
|
18
|
+
/// Set by the Bridge: calls JavaScript's listeners.
|
|
19
|
+
var sendToJavaScript: (_ eventName: String, _ payload: Any?) -> Void = { _, _ in }
|
|
18
20
|
private(set) var functions: [String: Function] = [:]
|
|
19
21
|
private(set) var asyncFunctions: [String: AsyncFunction] = [:]
|
|
20
22
|
private(set) var viewMakers: [String: MakeView] = [:]
|
|
@@ -34,12 +36,34 @@ public final class PluginRegistry {
|
|
|
34
36
|
asyncFunctions[name] = function
|
|
35
37
|
}
|
|
36
38
|
|
|
39
|
+
/// Reaches JavaScript's addNativeListener(eventName) listeners, from any thread, e.g.
|
|
40
|
+
/// sendEvent("notifications.received", payload). Dropped while no JavaScript runs: keep what must
|
|
41
|
+
/// outlive it (a push token) and let JavaScript read it with a function.
|
|
42
|
+
public func sendEvent(_ eventName: String, _ payload: Any? = nil) {
|
|
43
|
+
sendToJavaScript(eventName, payload)
|
|
44
|
+
}
|
|
45
|
+
|
|
37
46
|
/// `type` is the element's tag, e.g. "MapView" for h('MapView'). Created on the main thread.
|
|
38
47
|
public func addView(_ type: String, _ makeView: @escaping MakeView) {
|
|
39
48
|
viewMakers[type] = makeView
|
|
40
49
|
}
|
|
41
50
|
}
|
|
42
51
|
|
|
52
|
+
/// Thrown by an async function: JavaScript's Promise rejects with an Error whose `code` is this one.
|
|
53
|
+
/// Codes nativue's packages share: ERR_PERMISSION_DENIED, ERR_UNAVAILABLE, ERR_CANCELED,
|
|
54
|
+
/// ERR_INVALID_ARGUMENT.
|
|
55
|
+
public struct PluginError: LocalizedError {
|
|
56
|
+
public let code: String
|
|
57
|
+
public let message: String
|
|
58
|
+
|
|
59
|
+
public init(code: String, message: String) {
|
|
60
|
+
self.code = code
|
|
61
|
+
self.message = message
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public var errorDescription: String? { message }
|
|
65
|
+
}
|
|
66
|
+
|
|
43
67
|
/// A plugin view gets its props here, all but `style`, which nativue applies (layout included).
|
|
44
68
|
public protocol PluginView: UIView {
|
|
45
69
|
func setProp(_ key: String, value: Any?)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nativue/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
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",
|
|
35
|
+
"test": "(cd ../../examples/demo && nativue build) && node test/test.mjs && node test/native-events.test.mjs && node test/prebuild.test.mjs",
|
|
36
36
|
"typecheck": "vue-tsc"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
@@ -50,6 +50,7 @@
|
|
|
50
50
|
"files": [
|
|
51
51
|
"src",
|
|
52
52
|
"cli",
|
|
53
|
+
"template",
|
|
53
54
|
"ios",
|
|
54
55
|
"Package.swift",
|
|
55
56
|
"tsconfig.base.json",
|
package/src/globals.ts
CHANGED
|
@@ -5,13 +5,20 @@ 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
|
|
11
12
|
var __fireTimer: (timerId: number) => void
|
|
12
13
|
var __colorSchemeChanged: (colorScheme: ColorScheme) => void
|
|
13
14
|
var __windowSizeChanged: (windowSize: WindowSize) => void
|
|
14
|
-
var __asyncFunctionFinished: (
|
|
15
|
+
var __asyncFunctionFinished: (
|
|
16
|
+
callId: number,
|
|
17
|
+
value: unknown,
|
|
18
|
+
errorMessage: string | null,
|
|
19
|
+
errorCode: string | null,
|
|
20
|
+
) => void
|
|
21
|
+
var __nativeEvent: (eventName: string, payload: unknown) => void
|
|
15
22
|
var __animationFinished: (animationId: number, finished: boolean) => void
|
|
16
23
|
var __networkEvent: <Name extends keyof NetworkEventPayloads>(
|
|
17
24
|
requestId: number,
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// What the native side tells JavaScript without being asked: a plugin's events (registry.sendEvent),
|
|
2
|
+
// the URLs the app is opened with, and whether it's in front.
|
|
3
|
+
import { getCurrentInstance, onUnmounted } from '@vue/runtime-core'
|
|
4
|
+
|
|
5
|
+
export type NativeSubscription = { remove(): void }
|
|
6
|
+
export type AppStateStatus = 'active' | 'background'
|
|
7
|
+
|
|
8
|
+
type URLListener = (url: string) => boolean | void
|
|
9
|
+
// An object per subscription: the same function added twice is removed one at a time.
|
|
10
|
+
type Entry<Listener> = { listener: Listener }
|
|
11
|
+
|
|
12
|
+
const entriesByEventName = new Map<string, Set<Entry<(payload: never) => void>>>()
|
|
13
|
+
const urlEntries = new Set<Entry<URLListener>>()
|
|
14
|
+
let navigateToURL: ((url: string) => void) | undefined
|
|
15
|
+
|
|
16
|
+
/** In a component's setup, also removed when it unmounts. */
|
|
17
|
+
function subscribe<Listener>(
|
|
18
|
+
entries: Set<Entry<Listener>>,
|
|
19
|
+
listener: Listener,
|
|
20
|
+
): NativeSubscription {
|
|
21
|
+
const entry = { listener }
|
|
22
|
+
const remove = () => entries.delete(entry)
|
|
23
|
+
|
|
24
|
+
entries.add(entry)
|
|
25
|
+
if (getCurrentInstance()) onUnmounted(remove)
|
|
26
|
+
|
|
27
|
+
return { remove }
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** In the order they were added, skipping any an earlier one removed; a throw doesn't stop the rest. */
|
|
31
|
+
function callEach<Listener>(
|
|
32
|
+
entries: Set<Entry<Listener>>,
|
|
33
|
+
call: (listener: Listener) => boolean | void,
|
|
34
|
+
) {
|
|
35
|
+
for (const entry of [...entries]) {
|
|
36
|
+
if (!entries.has(entry)) continue
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
if (call(entry.listener) === true) return true
|
|
40
|
+
} catch (error) {
|
|
41
|
+
console.error(error)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return false
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Calls listener with the payload of each `eventName` the native side sends (registry.sendEvent),
|
|
50
|
+
* e.g. addNativeListener('notifications.received', (notification) => ...). Events sent while no
|
|
51
|
+
* JavaScript ran (the app closed, a reload) are lost.
|
|
52
|
+
*/
|
|
53
|
+
export function addNativeListener<Payload = unknown>(
|
|
54
|
+
eventName: string,
|
|
55
|
+
listener: (payload: Payload) => void,
|
|
56
|
+
): NativeSubscription {
|
|
57
|
+
const entries = entriesByEventName.get(eventName) ?? new Set()
|
|
58
|
+
|
|
59
|
+
entriesByEventName.set(eventName, entries)
|
|
60
|
+
|
|
61
|
+
return subscribe(entries, listener as (payload: never) => void)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
globalThis.__nativeEvent = (eventName, payload) => {
|
|
65
|
+
const entries = entriesByEventName.get(eventName)
|
|
66
|
+
|
|
67
|
+
if (entries) callEach(entries, (listener) => listener(payload as never))
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Calls listener with each URL the app is opened with (deep links, OAuth redirects), before the
|
|
72
|
+
* router: returning true keeps the router from navigating to it. Listeners run in the order they
|
|
73
|
+
* were added; the first to return true stops the rest. The URL that opens the app arrives right
|
|
74
|
+
* after it starts: add the listener for it in src/app.ts or the root layout, not on a later screen.
|
|
75
|
+
*/
|
|
76
|
+
export function onOpenURL(listener: URLListener): NativeSubscription {
|
|
77
|
+
return subscribe(urlEntries, listener)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** The router's: where a URL no onOpenURL listener took goes. */
|
|
81
|
+
export function setURLNavigation(navigate: (url: string) => void): void {
|
|
82
|
+
navigateToURL = navigate
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
globalThis.__openURL = (url) => {
|
|
86
|
+
if (callEach(urlEntries, (listener) => listener(url))) return
|
|
87
|
+
|
|
88
|
+
navigateToURL?.(url)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Whether the app is in front ('active') or not ('background'). Changes reach
|
|
93
|
+
* addNativeListener('app.state', (state: AppStateStatus) => ...).
|
|
94
|
+
*/
|
|
95
|
+
export const AppState = {
|
|
96
|
+
get current(): AppStateStatus {
|
|
97
|
+
return __native.appState()
|
|
98
|
+
},
|
|
99
|
+
}
|
package/src/native-functions.ts
CHANGED
|
@@ -9,13 +9,27 @@ type PendingCall = { resolve: (value: unknown) => void; reject: (error: Error) =
|
|
|
9
9
|
const pendingCalls = new Map<number, PendingCall>()
|
|
10
10
|
let nextCallId = 1
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
/**
|
|
13
|
+
* An async native function's rejection. `code` is the plugin's, when it gave one:
|
|
14
|
+
* 'ERR_PERMISSION_DENIED', 'ERR_UNAVAILABLE', 'ERR_CANCELED', 'ERR_INVALID_ARGUMENT', or its own.
|
|
15
|
+
*/
|
|
16
|
+
export class NativeError extends Error {
|
|
17
|
+
readonly code: string | undefined
|
|
18
|
+
|
|
19
|
+
constructor(message: string, code: string | undefined) {
|
|
20
|
+
super(message)
|
|
21
|
+
this.name = 'NativeError'
|
|
22
|
+
this.code = code
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
globalThis.__asyncFunctionFinished = (callId, value, errorMessage, errorCode) => {
|
|
13
27
|
const call = pendingCalls.get(callId)
|
|
14
28
|
if (!call) return
|
|
15
29
|
|
|
16
30
|
pendingCalls.delete(callId)
|
|
17
31
|
if (errorMessage === null) call.resolve(value)
|
|
18
|
-
else call.reject(new
|
|
32
|
+
else call.reject(new NativeError(errorMessage, errorCode ?? undefined))
|
|
19
33
|
}
|
|
20
34
|
|
|
21
35
|
function asyncCaller(nativeFunction: (...args: unknown[]) => unknown) {
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// Permissions as packages report them, the same on iOS and Android.
|
|
2
|
+
import { getCurrentInstance, onMounted, shallowRef, type ShallowRef } from '@vue/runtime-core'
|
|
3
|
+
import { addNativeListener } from './native-events'
|
|
4
|
+
import { NativeError } from './native-functions'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* granted: the feature works, maybe partly (limited photos), as the package's own fields say.
|
|
8
|
+
* canAskAgain false: only the system's Settings can change it now (openSettings()).
|
|
9
|
+
*/
|
|
10
|
+
export interface PermissionResponse {
|
|
11
|
+
status: 'granted' | 'denied' | 'undetermined'
|
|
12
|
+
granted: boolean
|
|
13
|
+
canAskAgain: boolean
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type PermissionResponseWith<Extra extends object> = PermissionResponse & Extra
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* A permission's state, read on mount, after request, and when the app comes back to the front (the
|
|
20
|
+
* user may have changed it in Settings), e.g. usePermission(Camera.getPermission, Camera.requestPermission).
|
|
21
|
+
*/
|
|
22
|
+
export function usePermission<Response extends PermissionResponse, Arguments extends unknown[]>(
|
|
23
|
+
get: () => Promise<Response>,
|
|
24
|
+
request: (...args: Arguments) => Promise<Response>,
|
|
25
|
+
): { permission: ShallowRef<Response | null>; request: (...args: Arguments) => Promise<Response> } {
|
|
26
|
+
const permission: ShallowRef<Response | null> = shallowRef(null)
|
|
27
|
+
let latestRead = 0
|
|
28
|
+
|
|
29
|
+
// Only the latest read or request is kept: an older one may finish after it.
|
|
30
|
+
async function track(read: Promise<Response>) {
|
|
31
|
+
const readNumber = ++latestRead
|
|
32
|
+
const response = await read
|
|
33
|
+
|
|
34
|
+
if (readNumber === latestRead) permission.value = response
|
|
35
|
+
|
|
36
|
+
return response
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function refresh() {
|
|
40
|
+
track(get()).catch((error) => console.error(error))
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (getCurrentInstance()) onMounted(refresh)
|
|
44
|
+
else refresh()
|
|
45
|
+
addNativeListener('app.state', (state) => {
|
|
46
|
+
if (state === 'active') refresh()
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
return { permission, request: (...args) => track(request(...args)) }
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** The app's page in the system's Settings: where a permission with canAskAgain false is turned on. */
|
|
53
|
+
export async function openSettings(): Promise<void> {
|
|
54
|
+
if (!__native.openSettings()) {
|
|
55
|
+
throw new NativeError('This device has no settings page for the app', 'ERR_UNAVAILABLE')
|
|
56
|
+
}
|
|
57
|
+
}
|
package/src/renderer.ts
CHANGED
|
@@ -36,7 +36,11 @@ export {
|
|
|
36
36
|
type PlatformOS,
|
|
37
37
|
type WindowSize,
|
|
38
38
|
} from './appearance'
|
|
39
|
-
export { requireNativeFunction } from './native-functions'
|
|
39
|
+
export { NativeError, requireNativeFunction } from './native-functions'
|
|
40
|
+
export { addNativeListener, AppState, onOpenURL } from './native-events'
|
|
41
|
+
export type { AppStateStatus, NativeSubscription } from './native-events'
|
|
42
|
+
export { openSettings, usePermission } from './permissions'
|
|
43
|
+
export type { PermissionResponse, PermissionResponseWith } from './permissions'
|
|
40
44
|
export { AsyncStorage } from './storage'
|
|
41
45
|
export type * from './types'
|
|
42
46
|
export type { SvgElement, SvgIcon } from './native-components'
|
|
@@ -83,6 +87,7 @@ const textInputsById = new Map<number, Node>()
|
|
|
83
87
|
*/
|
|
84
88
|
export function setClassStyleResolver(resolver: ClassStyleResolver): void {
|
|
85
89
|
resolveClassStyle = resolver
|
|
90
|
+
nodesWithClass.forEach((node) => updateStyle(node, {}))
|
|
86
91
|
}
|
|
87
92
|
|
|
88
93
|
function createNode(type: string): Node {
|
package/src/router.ts
CHANGED
|
@@ -29,6 +29,7 @@ import {
|
|
|
29
29
|
import { processColor } from './colors'
|
|
30
30
|
import { Pressable } from './components'
|
|
31
31
|
import type { SvgIcon } from './native-components'
|
|
32
|
+
import { setURLNavigation } from './native-events'
|
|
32
33
|
import { createApp } from './renderer'
|
|
33
34
|
|
|
34
35
|
export type Params = Record<string, string | string[]>
|
|
@@ -549,7 +550,7 @@ function hrefFromURL(url: string): string {
|
|
|
549
550
|
return url.replace(/^[a-z][a-z0-9+.-]*:\/\//i, '/')
|
|
550
551
|
}
|
|
551
552
|
|
|
552
|
-
|
|
553
|
+
setURLNavigation((url) => router.navigate(hrefFromURL(url)))
|
|
553
554
|
|
|
554
555
|
// ---------- Components ----------
|
|
555
556
|
|
|
@@ -832,6 +833,34 @@ export const Link = defineComponent({
|
|
|
832
833
|
})
|
|
833
834
|
|
|
834
835
|
type RouteFiles = Record<string, { default: Component }>
|
|
836
|
+
type OpenedRoute = [href: string, mode: NavigationMode]
|
|
837
|
+
|
|
838
|
+
// The routes to open again for the same screens: each stack's screens above its first, and the active
|
|
839
|
+
// tab. The tabs in the background start over.
|
|
840
|
+
function openedRoutes(entry: Entry): OpenedRoute[] {
|
|
841
|
+
const navigator = entry.navigator
|
|
842
|
+
if (!navigator) return []
|
|
843
|
+
|
|
844
|
+
if ('tabs' in navigator) {
|
|
845
|
+
const { tabs, state } = navigator as TabsNavigator
|
|
846
|
+
const activeTab = tabs[state.activeIndex]
|
|
847
|
+
|
|
848
|
+
return [[activeTab.href, 'navigate'], ...openedRoutes(activeTab)]
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
return (navigator as StackNavigator).entries.flatMap((child, index): OpenedRoute[] => [
|
|
852
|
+
...(index > 0 ? [[child.href, 'push'] as OpenedRoute] : []),
|
|
853
|
+
...openedRoutes(child),
|
|
854
|
+
])
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
function keepNavigationAcrossReloads() {
|
|
858
|
+
const savedRoutes = __native.savedNavigation()
|
|
859
|
+
if (savedRoutes)
|
|
860
|
+
for (const [href, mode] of JSON.parse(savedRoutes) as OpenedRoute[]) go(href, mode)
|
|
861
|
+
|
|
862
|
+
watchEffect(() => __native.saveNavigation(JSON.stringify(openedRoutes(rootEntry))))
|
|
863
|
+
}
|
|
835
864
|
|
|
836
865
|
// routeFiles: import.meta.glob('/src/app/**/*.vue', { eager: true }), see entry.ts
|
|
837
866
|
export function createRouterApp(routeFiles: RouteFiles) {
|
|
@@ -839,6 +868,7 @@ export function createRouterApp(routeFiles: RouteFiles) {
|
|
|
839
868
|
|
|
840
869
|
const { chain, target } = resolveHref('/')
|
|
841
870
|
rootEntry = createEntry(layoutsByDirectory.get('')!, chain.slice(1), target)
|
|
871
|
+
if (globalThis.__NATIVUE_HOT__) keepNavigationAcrossReloads()
|
|
842
872
|
|
|
843
873
|
return createApp(defineComponent(() => () => h(LayoutContent, { entry: rootEntry })))
|
|
844
874
|
}
|
package/src/types.ts
CHANGED
|
@@ -115,6 +115,12 @@ export interface NativeModule {
|
|
|
115
115
|
windowSize(): { width: number; height: number }
|
|
116
116
|
platform(): 'ios' | 'android'
|
|
117
117
|
colorScheme(): 'light' | 'dark'
|
|
118
|
+
appState(): 'active' | 'background'
|
|
119
|
+
/** false: the device has no settings page for the app (Android; iOS always has one). */
|
|
120
|
+
openSettings(): boolean
|
|
121
|
+
/** Development: the navigation saveNavigation kept, which outlives the JavaScript runtime. */
|
|
122
|
+
savedNavigation(): string | null
|
|
123
|
+
saveNavigation(routes: string): void
|
|
118
124
|
accessibilityInfo(): { screenReaderEnabled: boolean; reduceMotionEnabled: boolean }
|
|
119
125
|
announce(message: string): void
|
|
120
126
|
create(id: number, type: string): void
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
+
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
|
3
|
+
<background android:drawable="@color/ic_launcher_background" />
|
|
4
|
+
<foreground android:drawable="@mipmap/ic_launcher_foreground" />
|
|
5
|
+
<monochrome android:drawable="@mipmap/ic_launcher_foreground" />
|
|
6
|
+
</adaptive-icon>
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<resources xmlns:tools="http://schemas.android.com/tools">
|
|
2
|
+
<!-- Light or dark with the system: values-night/styles.xml has the dark ones. -->
|
|
3
|
+
<style name="AppTheme.Base" parent="@android:style/Theme.Material.Light.NoActionBar" />
|
|
4
|
+
<bool name="light_system_bars">true</bool>
|
|
5
|
+
<color name="splash_background">__SPLASH_BACKGROUND__</color>
|
|
6
|
+
|
|
7
|
+
<!-- Status and navigation bar icons that contrast with the screens. The splash screen (Android
|
|
8
|
+
12+) matches the iOS launch screen: the logo, 120dp, on white, or on ink in dark mode. -->
|
|
9
|
+
<style name="AppTheme" parent="AppTheme.Base">
|
|
10
|
+
<item name="android:windowLightStatusBar">@bool/light_system_bars</item>
|
|
11
|
+
<item name="android:windowLightNavigationBar" tools:targetApi="27">@bool/light_system_bars</item>
|
|
12
|
+
<item name="android:windowSplashScreenBackground" tools:targetApi="31">@color/splash_background</item>
|
|
13
|
+
<item name="android:windowSplashScreenAnimatedIcon" tools:targetApi="31">@drawable/splash_logo</item>
|
|
14
|
+
</style>
|
|
15
|
+
</resources>
|
|
Binary file
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
distributionBase=GRADLE_USER_HOME
|
|
2
|
+
distributionPath=wrapper/dists
|
|
3
|
+
distributionUrl=https\://services.gradle.org/distributions/gradle-9.9.1-bin.zip
|
|
4
|
+
networkTimeout=10000
|
|
5
|
+
retries=0
|
|
6
|
+
retryBackOffMs=500
|
|
7
|
+
validateDistributionUrl=true
|
|
8
|
+
zipStoreBase=GRADLE_USER_HOME
|
|
9
|
+
zipStorePath=wrapper/dists
|