@webspatial/platform-visionos 0.1.23 → 1.0.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.json +1 -1
- package/web-spatial/libs/Utils/CommandManager.swift +1 -0
- package/web-spatial/libs/Utils/WindowContainerMgr.swift +21 -3
- package/web-spatial/libs/webView/backend/NativeWebView.swift +33 -1
- package/web-spatial/libs/webView/manifest.swift +1 -1
- package/web-spatial/views/PlainWindowContainerView.swift +43 -1
package/package.json
CHANGED
|
@@ -617,6 +617,7 @@ class CommandManager {
|
|
|
617
617
|
// Update scene state
|
|
618
618
|
var cfg = WindowContainerPlainDefaultValues()
|
|
619
619
|
cfg.defaultSize = CGSize(width: resolution.width, height: resolution.height)
|
|
620
|
+
// TODO: need set resizeRange?
|
|
620
621
|
WindowContainerMgr.Instance.updateWindowContainerPlainDefaultValues(cfg)
|
|
621
622
|
return
|
|
622
623
|
}
|
|
@@ -16,6 +16,10 @@ struct WindowContainerData: Decodable, Hashable, Encodable {
|
|
|
16
16
|
let windowContainerID: String
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
struct WindowContainerResizability: Decodable, Encodable {
|
|
20
|
+
let resizeRange: ResizeRange?
|
|
21
|
+
}
|
|
22
|
+
|
|
19
23
|
enum LoadingMethod: String, Decodable, Encodable, Hashable {
|
|
20
24
|
case show
|
|
21
25
|
case hide
|
|
@@ -29,6 +33,7 @@ struct LoadingWindowContainerData: Decodable, Hashable, Encodable {
|
|
|
29
33
|
struct WindowContainerPlainDefaultValues {
|
|
30
34
|
var defaultSize: CGSize?
|
|
31
35
|
var windowResizability: WindowResizability?
|
|
36
|
+
var resizeRange: ResizeRange?
|
|
32
37
|
}
|
|
33
38
|
|
|
34
39
|
// support WindowContainerOptions => WindowContainerPlainDefaultValues
|
|
@@ -38,19 +43,28 @@ extension WindowContainerPlainDefaultValues {
|
|
|
38
43
|
width: options.defaultSize?.width ?? DefaultPlainWindowContainerSize.width,
|
|
39
44
|
height: options.defaultSize?.height ?? DefaultPlainWindowContainerSize.height
|
|
40
45
|
)
|
|
41
|
-
windowResizability = getWindowResizability(
|
|
46
|
+
windowResizability = getWindowResizability(nil)
|
|
47
|
+
resizeRange = options.resizability
|
|
42
48
|
}
|
|
43
49
|
}
|
|
44
50
|
|
|
51
|
+
struct ResizeRange: Codable {
|
|
52
|
+
var minWidth: Double?
|
|
53
|
+
var minHeight: Double?
|
|
54
|
+
var maxWidth: Double?
|
|
55
|
+
var maxHeight: Double?
|
|
56
|
+
}
|
|
57
|
+
|
|
45
58
|
// incomming JSB data
|
|
46
59
|
struct WindowContainerOptions: Codable {
|
|
47
60
|
// windowContainer
|
|
48
61
|
let defaultSize: Size?
|
|
49
|
-
let resizability: String?
|
|
50
62
|
struct Size: Codable {
|
|
51
63
|
var width: Double
|
|
52
64
|
var height: Double
|
|
53
65
|
}
|
|
66
|
+
|
|
67
|
+
let resizability: ResizeRange?
|
|
54
68
|
}
|
|
55
69
|
|
|
56
70
|
func getWindowResizability(_ windowResizability: String?) -> WindowResizability {
|
|
@@ -79,7 +93,8 @@ class WindowContainerMgr: ObservableObject {
|
|
|
79
93
|
|
|
80
94
|
private var wgSetting: WindowContainerPlainDefaultValues = .init(
|
|
81
95
|
defaultSize: CGSize(width: 1080, height: 720 + (pwaManager.display != .fullscreen ? NavView.navHeight : 0)),
|
|
82
|
-
windowResizability: .automatic
|
|
96
|
+
windowResizability: .automatic,
|
|
97
|
+
resizeRange: nil
|
|
83
98
|
)
|
|
84
99
|
|
|
85
100
|
func getValue() -> WindowContainerPlainDefaultValues {
|
|
@@ -100,5 +115,8 @@ class WindowContainerMgr: ObservableObject {
|
|
|
100
115
|
if let newResizability = data.windowResizability {
|
|
101
116
|
wgSetting.windowResizability = newResizability
|
|
102
117
|
}
|
|
118
|
+
if let newResizeRange = data.resizeRange {
|
|
119
|
+
wgSetting.resizeRange = newResizeRange
|
|
120
|
+
}
|
|
103
121
|
}
|
|
104
122
|
}
|
|
@@ -125,7 +125,6 @@ class Coordinator: NSObject, WKNavigationDelegate, WKScriptMessageHandler, WKUID
|
|
|
125
125
|
// backward/forward
|
|
126
126
|
webViewRef?.didNavBackForward()
|
|
127
127
|
}
|
|
128
|
-
webViewRef?.navInfo.url = resource
|
|
129
128
|
decisionHandler(.allow)
|
|
130
129
|
} else {
|
|
131
130
|
decisionHandler(.cancel)
|
|
@@ -211,6 +210,34 @@ class Coordinator: NSObject, WKNavigationDelegate, WKScriptMessageHandler, WKUID
|
|
|
211
210
|
wg.updateFrame = !(wg.updateFrame)
|
|
212
211
|
}
|
|
213
212
|
}
|
|
213
|
+
|
|
214
|
+
private var isObserving = false
|
|
215
|
+
func startObserving(webView: WKWebView) {
|
|
216
|
+
guard !isObserving else { return }
|
|
217
|
+
webView.addObserver(self, forKeyPath: #keyPath(WKWebView.url), options: .new, context: nil)
|
|
218
|
+
isObserving = true
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
func stopObserving(webView: WKWebView) {
|
|
222
|
+
guard isObserving else { return }
|
|
223
|
+
webView.removeObserver(self, forKeyPath: #keyPath(WKWebView.url))
|
|
224
|
+
isObserving = false
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
override func observeValue(
|
|
228
|
+
forKeyPath keyPath: String?,
|
|
229
|
+
of object: Any?,
|
|
230
|
+
change: [NSKeyValueChangeKey: Any]?,
|
|
231
|
+
context: UnsafeMutableRawPointer?
|
|
232
|
+
) {
|
|
233
|
+
if keyPath == #keyPath(WKWebView.url),
|
|
234
|
+
let url = (object as? WKWebView)?.url?.absoluteString
|
|
235
|
+
{
|
|
236
|
+
DispatchQueue.main.async {
|
|
237
|
+
self.webViewRef?.navInfo.url = url
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
214
241
|
}
|
|
215
242
|
|
|
216
243
|
struct WebViewNative: UIViewRepresentable {
|
|
@@ -250,6 +277,7 @@ struct WebViewNative: UIViewRepresentable {
|
|
|
250
277
|
myConfig.setURLSchemeHandler(webViewHolder.webViewCoordinator, forURLScheme: "file")
|
|
251
278
|
}
|
|
252
279
|
webViewHolder.appleWebView = WKWebView(frame: .zero, configuration: myConfig)
|
|
280
|
+
webViewHolder.webViewCoordinator!.startObserving(webView: webViewHolder.appleWebView!)
|
|
253
281
|
let configUA = myConfig.applicationNameForUserAgent as? String ?? ""
|
|
254
282
|
|
|
255
283
|
// change webview ua
|
|
@@ -284,6 +312,10 @@ struct WebViewNative: UIViewRepresentable {
|
|
|
284
312
|
func updateUIView(_ webView: WKWebView, context: Context) {
|
|
285
313
|
initialLoad()
|
|
286
314
|
}
|
|
315
|
+
|
|
316
|
+
static func dismantleUIView(_ uiView: WKWebView, coordinator: Coordinator) {
|
|
317
|
+
coordinator.stopObserving(webView: uiView)
|
|
318
|
+
}
|
|
287
319
|
}
|
|
288
320
|
|
|
289
321
|
// extend webview to support file://
|
|
@@ -9,7 +9,38 @@ struct PlainWindowContainerView: View {
|
|
|
9
9
|
@State private var timer: Timer?
|
|
10
10
|
|
|
11
11
|
private func setSize(size: CGSize) {
|
|
12
|
-
sceneDelegate.window?.windowScene
|
|
12
|
+
sceneDelegate.window?.windowScene?
|
|
13
|
+
.requestGeometryUpdate(
|
|
14
|
+
.Vision(
|
|
15
|
+
size: size
|
|
16
|
+
)
|
|
17
|
+
)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
private func setResizibility(resizingRestrictions: UIWindowScene.ResizingRestrictions) {
|
|
21
|
+
sceneDelegate.window?.windowScene?
|
|
22
|
+
.requestGeometryUpdate(
|
|
23
|
+
.Vision(
|
|
24
|
+
resizingRestrictions: resizingRestrictions
|
|
25
|
+
)
|
|
26
|
+
)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
private func setResizeRange(resizeRange: ResizeRange) {
|
|
30
|
+
sceneDelegate.window?.windowScene?
|
|
31
|
+
.requestGeometryUpdate(
|
|
32
|
+
.Vision(
|
|
33
|
+
minimumSize: CGSize(
|
|
34
|
+
width: resizeRange.minWidth ?? 0,
|
|
35
|
+
height: resizeRange
|
|
36
|
+
.minHeight ?? 0
|
|
37
|
+
),
|
|
38
|
+
maximumSize: CGSize(
|
|
39
|
+
width: resizeRange.maxWidth ?? .infinity,
|
|
40
|
+
height: resizeRange.maxHeight ?? .infinity
|
|
41
|
+
)
|
|
42
|
+
)
|
|
43
|
+
)
|
|
13
44
|
}
|
|
14
45
|
|
|
15
46
|
var body: some View {
|
|
@@ -59,6 +90,17 @@ struct PlainWindowContainerView: View {
|
|
|
59
90
|
.onReceive(windowContainerContent.setSize) { newSize in
|
|
60
91
|
setSize(size: newSize)
|
|
61
92
|
}
|
|
93
|
+
.onAppear {
|
|
94
|
+
let wd = WindowContainerMgr.Instance.getValue()
|
|
95
|
+
if let range = wd.resizeRange {
|
|
96
|
+
self.setResizeRange(resizeRange: range)
|
|
97
|
+
if (range.minWidth != nil || range.minWidth != nil) && range.minWidth == range.maxWidth && range.minHeight == range.maxHeight {
|
|
98
|
+
self.setResizibility(resizingRestrictions: .none)
|
|
99
|
+
} else {
|
|
100
|
+
self.setResizibility(resizingRestrictions: .freeform)
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
62
104
|
.onChange(of: proxy3D.size) {
|
|
63
105
|
// WkWebview has an issue where it doesn't resize while the swift window is resized
|
|
64
106
|
// Treid to call didMoveToWindow to force redraw to occur but that seemed to cause rendering artifacts so that solution was rejected
|