@swiftbrowser/native 0.26.2 → 0.26.3
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 +7 -7
- package/package.json +3 -3
- package/swift/Sources/SwiftBrowserNative/Runtime/NativeApp.swift +6 -3
- package/swift/Sources/SwiftBrowserNative/Views/NativeRootView.swift +11 -1
- package/swift/Sources/SwiftBrowserProtocol/RendererEvent.swift +5 -2
- package/wasm/SwiftBrowserNative.wasm +2 -2
package/README.md
CHANGED
|
@@ -37,10 +37,10 @@ build against the exact version of the renderer this JavaScript was written
|
|
|
37
37
|
for. `swiftbrowser native init` lays a project out that way:
|
|
38
38
|
|
|
39
39
|
```sh
|
|
40
|
-
npx @swiftbrowser/cli native init MyApp # MyApp.xcodeproj,
|
|
40
|
+
npx @swiftbrowser/cli native init MyApp # MyApp.xcodeproj (iOS and macOS), apple/, src/, web/
|
|
41
41
|
cd MyApp && npm install # React, @swiftbrowser/react, @swiftbrowser/web and this package
|
|
42
|
-
npm run build #
|
|
43
|
-
open MyApp.xcodeproj # run it on a simulator
|
|
42
|
+
npm run build # apple/app.js, the bundle the app ships
|
|
43
|
+
open MyApp.xcodeproj # run it on a simulator, an iPhone or this Mac
|
|
44
44
|
npm run dev:web # the same app as a web page
|
|
45
45
|
```
|
|
46
46
|
|
|
@@ -76,8 +76,8 @@ run(<App />);
|
|
|
76
76
|
```
|
|
77
77
|
|
|
78
78
|
```sh
|
|
79
|
-
npx swiftbrowser-native build src/index.tsx --out ../
|
|
80
|
-
npx swiftbrowser-native dev src/index.tsx --out ../
|
|
79
|
+
npx swiftbrowser-native build src/index.tsx --out ../apple/app.js # the bundle Xcode ships
|
|
80
|
+
npx swiftbrowser-native dev src/index.tsx --out ../apple/app.js # http://localhost:5173/, Fast Refresh on save
|
|
81
81
|
```
|
|
82
82
|
|
|
83
83
|
On the Swift side, `NativeApp().load()` runs the bundled `app.js` and
|
|
@@ -152,7 +152,7 @@ the app's scene phase here (`active`, `inactive`, `background`), as
|
|
|
152
152
|
## Workers
|
|
153
153
|
|
|
154
154
|
```sh
|
|
155
|
-
npx swiftbrowser-native build src/index.tsx --out ../
|
|
155
|
+
npx swiftbrowser-native build src/index.tsx --out ../apple/app.js --worker render=src/render.worker.ts
|
|
156
156
|
```
|
|
157
157
|
|
|
158
158
|
```ts
|
|
@@ -410,7 +410,7 @@ and a page can register its own element under the same name
|
|
|
410
410
|
also from @swiftbrowser/react), so the same element draws on both.
|
|
411
411
|
|
|
412
412
|
Swift that is not a view registers as a function, before the bundle loads
|
|
413
|
-
(`swiftbrowser native init` writes an `
|
|
413
|
+
(`swiftbrowser native init` writes an `apple/NativeFunctions.swift` for them):
|
|
414
414
|
|
|
415
415
|
```swift
|
|
416
416
|
NativeFunctions.register("purchase") { call in // async
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@swiftbrowser/native",
|
|
3
|
-
"version": "0.26.
|
|
3
|
+
"version": "0.26.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Run a @swiftbrowser/react app natively: the runtime a JavaScriptCore-hosted app needs (timers, console, fetch and the other web globals over the SwiftBrowser Native bridge), the `run` entry that renders into the native SwiftUI renderer, and the bundler that builds app.js for the Xcode target.",
|
|
6
6
|
"repository": {
|
|
@@ -63,8 +63,8 @@
|
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
65
|
"@babel/core": "^7.29.7",
|
|
66
|
-
"@swiftbrowser/react": "0.26.
|
|
67
|
-
"@swiftbrowser/web": "0.26.
|
|
66
|
+
"@swiftbrowser/react": "0.26.3",
|
|
67
|
+
"@swiftbrowser/web": "0.26.3",
|
|
68
68
|
"esbuild": "^0.28.2",
|
|
69
69
|
"react-refresh": "^0.17.0"
|
|
70
70
|
},
|
|
@@ -37,6 +37,8 @@ public final class NativeApp {
|
|
|
37
37
|
public private(set) var colorScheme: String?
|
|
38
38
|
public private(set) var dynamicTypeSize: String?
|
|
39
39
|
public private(set) var horizontalSizeClass: String?
|
|
40
|
+
/// The platform the app runs on, `ios` or `macos` (docs/notes/macos.md), once the root view has said.
|
|
41
|
+
public private(set) var platform: String?
|
|
40
42
|
/// URLs the app was opened with before its script could take them (a
|
|
41
43
|
/// universal link that launched it): delivered once it loads.
|
|
42
44
|
private var pendingURLs: [URL] = []
|
|
@@ -312,17 +314,18 @@ public final class NativeApp {
|
|
|
312
314
|
}
|
|
313
315
|
|
|
314
316
|
/// Tells the app the device environment; sent once at load and on change.
|
|
315
|
-
public func setEnvironment(colorScheme: String? = nil, dynamicTypeSize: String? = nil, horizontalSizeClass: String? = nil) {
|
|
317
|
+
public func setEnvironment(colorScheme: String? = nil, dynamicTypeSize: String? = nil, horizontalSizeClass: String? = nil, platform: String? = nil) {
|
|
316
318
|
var changed = false
|
|
317
319
|
if let colorScheme, colorScheme != self.colorScheme { self.colorScheme = colorScheme; changed = true }
|
|
318
320
|
if let dynamicTypeSize, dynamicTypeSize != self.dynamicTypeSize { self.dynamicTypeSize = dynamicTypeSize; changed = true }
|
|
319
321
|
if let horizontalSizeClass, horizontalSizeClass != self.horizontalSizeClass { self.horizontalSizeClass = horizontalSizeClass; changed = true }
|
|
322
|
+
if let platform, platform != self.platform { self.platform = platform; changed = true }
|
|
320
323
|
if changed { sendEnvironment() }
|
|
321
324
|
}
|
|
322
325
|
|
|
323
326
|
private func sendEnvironment() {
|
|
324
|
-
guard isLoaded, colorScheme != nil || dynamicTypeSize != nil || horizontalSizeClass != nil else { return }
|
|
325
|
-
dispatch(.environment(colorScheme: colorScheme, dynamicTypeSize: dynamicTypeSize, horizontalSizeClass: horizontalSizeClass))
|
|
327
|
+
guard isLoaded, colorScheme != nil || dynamicTypeSize != nil || horizontalSizeClass != nil || platform != nil else { return }
|
|
328
|
+
dispatch(.environment(colorScheme: colorScheme, dynamicTypeSize: dynamicTypeSize, horizontalSizeClass: horizontalSizeClass, platform: platform))
|
|
326
329
|
}
|
|
327
330
|
|
|
328
331
|
/// The scene moved between the foreground, inactive and the background.
|
|
@@ -84,9 +84,19 @@ public struct NativeRootView: View {
|
|
|
84
84
|
app.setEnvironment(
|
|
85
85
|
colorScheme: colorScheme == .dark ? "dark" : "light",
|
|
86
86
|
dynamicTypeSize: dynamicTypeSize.protocolName,
|
|
87
|
-
horizontalSizeClass: sizeClassName
|
|
87
|
+
horizontalSizeClass: sizeClassName,
|
|
88
|
+
platform: Self.platformName
|
|
88
89
|
)
|
|
89
90
|
}
|
|
91
|
+
|
|
92
|
+
/// The platform the app is drawn on (docs/notes/macos.md): the OS, as the protocol names it.
|
|
93
|
+
static var platformName: String {
|
|
94
|
+
#if os(macOS)
|
|
95
|
+
"macos"
|
|
96
|
+
#else
|
|
97
|
+
"ios"
|
|
98
|
+
#endif
|
|
99
|
+
}
|
|
90
100
|
}
|
|
91
101
|
|
|
92
102
|
/// Presents the first of `presented` over `content` (a sheet, a full-screen
|
|
@@ -163,18 +163,21 @@ public struct RendererEvent: Equatable, Sendable {
|
|
|
163
163
|
with("registered", id: id, ["name": .string(name), "value": value])
|
|
164
164
|
}
|
|
165
165
|
|
|
166
|
-
/// The device appearance, text size
|
|
166
|
+
/// The device appearance, text size, size class or platform (`ios` or
|
|
167
|
+
/// `macos`, docs/notes/macos.md; sent once at launch and on change).
|
|
167
168
|
public static func environment(
|
|
168
169
|
colorScheme: String? = nil,
|
|
169
170
|
dynamicTypeSize: String? = nil,
|
|
170
171
|
horizontalSizeClass: String? = nil,
|
|
171
|
-
scenePhase: String? = nil
|
|
172
|
+
scenePhase: String? = nil,
|
|
173
|
+
platform: String? = nil
|
|
172
174
|
) -> RendererEvent {
|
|
173
175
|
var fields: JSONObject = [:]
|
|
174
176
|
if let colorScheme { fields["colorScheme"] = .string(colorScheme) }
|
|
175
177
|
if let dynamicTypeSize { fields["dynamicTypeSize"] = .string(dynamicTypeSize) }
|
|
176
178
|
if let horizontalSizeClass { fields["horizontalSizeClass"] = .string(horizontalSizeClass) }
|
|
177
179
|
if let scenePhase { fields["scenePhase"] = .string(scenePhase) }
|
|
180
|
+
if let platform { fields["platform"] = .string(platform) }
|
|
178
181
|
return RendererEvent(type: "environment", fields: fields)
|
|
179
182
|
}
|
|
180
183
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
[diffend] Oversized file quarantined before diffing.
|
|
2
2
|
name: package/wasm/SwiftBrowserNative.wasm
|
|
3
|
-
size:
|
|
4
|
-
sha256:
|
|
3
|
+
size: 50282598 bytes
|
|
4
|
+
sha256: 36221c0c44b7bb993ff03090d3f241303c9b224b90b1b1dc398137d25926ba14
|