@blotch/angular-lynx-native 22.3.1 → 22.3.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 +47 -15
- package/dist/android/project.d.ts +114 -1
- package/dist/android/project.d.ts.map +1 -1
- package/dist/android/project.js +440 -5
- package/dist/eject.d.ts +15 -1
- package/dist/eject.d.ts.map +1 -1
- package/dist/eject.js +14 -2
- package/dist/features.d.ts +70 -0
- package/dist/features.d.ts.map +1 -0
- package/dist/features.js +115 -0
- package/dist/files.d.ts +24 -0
- package/dist/files.d.ts.map +1 -0
- package/dist/files.js +41 -0
- package/dist/generate.d.ts +34 -3
- package/dist/generate.d.ts.map +1 -1
- package/dist/generate.js +78 -19
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -2
- package/dist/ios/build.d.ts.map +1 -1
- package/dist/ios/build.js +8 -2
- package/dist/ios/frameworks.d.ts +6 -5
- package/dist/ios/frameworks.d.ts.map +1 -1
- package/dist/ios/frameworks.js +46 -15
- package/dist/ios/project.d.ts +192 -11
- package/dist/ios/project.d.ts.map +1 -1
- package/dist/ios/project.js +823 -33
- package/dist/options.d.ts +208 -1
- package/dist/options.d.ts.map +1 -1
- package/dist/options.js +154 -0
- package/dist/permissions.d.ts +18 -1
- package/dist/permissions.d.ts.map +1 -1
- package/dist/permissions.js +79 -4
- package/dist/plugins.d.ts +245 -0
- package/dist/plugins.d.ts.map +1 -0
- package/dist/plugins.js +1244 -0
- package/package.json +1 -1
- package/templates/android/README.md +46 -5
- package/templates/android/angular-lynx.properties +2 -0
- package/templates/android/app/build.gradle.kts +78 -11
- package/templates/android/app/src/main/AndroidManifest.xml +19 -3
- package/templates/android/app/src/main/java/dev/angularlynx/shell/AngularLynxPlugins.kt +13 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/AudioRecorderModule.kt +520 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/BarcodeScannerModule.kt +144 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/BiometricsModule.kt +433 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/BitmapPresenter.kt +98 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/BitmapRendererContext.kt +175 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/BluetoothModule.kt +1288 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/CalendarModule.kt +127 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/Canvas2DContext.kt +1557 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/Canvas2DOps.kt +63 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/CanvasFilter.kt +357 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/CanvasUI.kt +4 -3
- package/templates/android/app/src/main/java/dev/angularlynx/shell/EdgeToEdgeOverlay.kt +24 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/EngineThreadHint.kt +156 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/FilePickerModule.kt +263 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/GeolocationModule.kt +557 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/HapticsModule.kt +82 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/HostElementUI.kt +331 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/ImagePickerModule.kt +143 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/ImagePipeline.kt +83 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/MainActivity.kt +523 -9
- package/templates/android/app/src/main/java/dev/angularlynx/shell/ModuleBytes.kt +58 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/MotionModule.kt +332 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/NetworkStatus.kt +121 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/NfcModule.kt +274 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/PermissionRequests.kt +35 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/PhotoLibraryModule.kt +355 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/ShareTargetModule.kt +234 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/ShellApplication.kt +7 -8
- package/templates/android/app/src/main/java/dev/angularlynx/shell/ShellModule.kt +58 -4
- package/templates/android/app/src/main/java/dev/angularlynx/shell/StoreReviewModule.kt +66 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/SystemFontFamilies.kt +68 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/TrackingModule.kt +74 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/VideoFrameTarget.kt +429 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/VideoUI.kt +676 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/WebGLContext.kt +128 -13
- package/templates/android/app/src/main/java/dev/angularlynx/shell/WebGLModule.kt +493 -65
- package/templates/android/app/src/main/java/dev/angularlynx/shell/WifiModule.kt +429 -0
- package/templates/android/app/src/main/res/values/biometrics.xml +9 -0
- package/templates/android/app/src/main/res/values/share_target.xml +11 -0
- package/templates/android/app/src/main/res/xml/backup_rules.xml +5 -3
- package/templates/android/app/src/main/res/xml/data_extraction_rules.xml +6 -3
- package/templates/android/app/src/main/res/xml/share_paths.xml +7 -2
- package/templates/android/build.gradle.kts +1 -1
- package/templates/android/gradle/wrapper/gradle-wrapper.properties +2 -2
- package/templates/ios/App/AngularLynxBitmapRendererContext.m +188 -0
- package/templates/ios/App/AngularLynxCanvas2DContext.m +2467 -0
- package/templates/ios/App/AngularLynxCanvas2DOps.h +61 -0
- package/templates/ios/App/AngularLynxPlugins.swift +22 -0
- package/templates/ios/App/AngularLynxVideo.h +37 -0
- package/templates/ios/App/AngularLynxVideo.m +435 -0
- package/templates/ios/App/AngularLynxWebGL.h +69 -7
- package/templates/ios/App/AngularLynxWebGL.m +538 -29
- package/templates/ios/App/AngularLynxWebGLContext.m +148 -46
- package/templates/ios/App/AnimationFrameRate.swift +66 -0
- package/templates/ios/App/AppDelegate.swift +37 -3
- package/templates/ios/App/AppleSignInButton.swift +106 -0
- package/templates/ios/App/AppleSignInModule.swift +222 -0
- package/templates/ios/App/AudioRecorderModule.swift +433 -0
- package/templates/ios/App/BarcodeScannerModule.swift +284 -0
- package/templates/ios/App/BiometricsModule.swift +256 -0
- package/templates/ios/App/BluetoothModule.swift +1086 -0
- package/templates/ios/App/CalendarModule.swift +158 -0
- package/templates/ios/App/FilePickerModule.swift +240 -0
- package/templates/ios/App/GeolocationModule.swift +455 -0
- package/templates/ios/App/HapticsModule.swift +90 -0
- package/templates/ios/App/HostElementUI.swift +270 -0
- package/templates/ios/App/ImagePickerModule.swift +160 -1
- package/templates/ios/App/Info.plist +2 -0
- package/templates/ios/App/LynxViewController.swift +274 -9
- package/templates/ios/App/MotionModule.swift +430 -0
- package/templates/ios/App/NetworkStatus.swift +41 -0
- package/templates/ios/App/NfcModule.swift +346 -0
- package/templates/ios/App/PhotoLibraryModule.swift +169 -0
- package/templates/ios/App/ShareTargetModule.swift +150 -0
- package/templates/ios/App/ShellModule.swift +17 -0
- package/templates/ios/App/StoreReviewModule.swift +61 -0
- package/templates/ios/App/TrackingModule.swift +121 -0
- package/templates/ios/App/WifiModule.swift +237 -0
- package/templates/ios/App/XElementRegistry.swift +13 -3
- package/templates/ios/ShareExtension/Info.plist +42 -0
- package/templates/ios/ShareExtension/ShareViewController.swift +387 -0
|
@@ -3,9 +3,38 @@ import UIKit
|
|
|
3
3
|
|
|
4
4
|
/// Hosts the app's single LynxView. Angular Router does all navigation inside
|
|
5
5
|
/// it, so the shell never pushes another view controller.
|
|
6
|
-
final class LynxViewController: UIViewController {
|
|
6
|
+
final class LynxViewController: UIViewController, LynxViewLifecycle {
|
|
7
7
|
private var lynxView: LynxView?
|
|
8
|
+
/// The font scale the LynxView was built with, which Lynx gives each engine
|
|
9
|
+
/// it sets up (see lynxView(_:didLoadFinishedWithUrl:)).
|
|
10
|
+
private var builtFontScale: CGFloat = 1
|
|
8
11
|
private var lastViewport: CGRect = .zero
|
|
12
|
+
/// The window's size, as Lynx last heard it: the screen's, which the
|
|
13
|
+
/// LynxView is built with, until layoutLynxView finds the view in its window.
|
|
14
|
+
private var lastScreen: CGSize = .zero
|
|
15
|
+
|
|
16
|
+
/// Where the app is, for LynxAppState: "active", "inactive" or
|
|
17
|
+
/// "background". Sent in the global props, and again as the scene's
|
|
18
|
+
/// activation changes (appStateDidChange). It starts from the app's state
|
|
19
|
+
/// when the view loads, which is "inactive" while the app launches: the
|
|
20
|
+
/// scene becomes active just after.
|
|
21
|
+
private var appState = LynxViewController.appState(of: UIApplication.shared.applicationState)
|
|
22
|
+
|
|
23
|
+
/// The block observers observeAppState() adds. NotificationCenter keeps a
|
|
24
|
+
/// block observer until it's removed, and iOS can disconnect the scene and
|
|
25
|
+
/// build a new controller, so deinit removes them.
|
|
26
|
+
private var appStateObservers: [NSObjectProtocol] = []
|
|
27
|
+
|
|
28
|
+
/// Whether the phone is online, for LynxNetwork: sent in the global props,
|
|
29
|
+
/// and again each time it changes. Released with the controller, which
|
|
30
|
+
/// stops its monitor.
|
|
31
|
+
private var networkStatus: NetworkStatus?
|
|
32
|
+
|
|
33
|
+
deinit {
|
|
34
|
+
for observer in appStateObservers {
|
|
35
|
+
NotificationCenter.default.removeObserver(observer)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
9
38
|
|
|
10
39
|
/// Whether the page fills the screen, under the status bar and the home
|
|
11
40
|
/// indicator: angular.json's `edgeToEdge`, which the generator writes into
|
|
@@ -14,6 +43,15 @@ final class LynxViewController: UIViewController {
|
|
|
14
43
|
private let edgeToEdge =
|
|
15
44
|
Bundle.main.object(forInfoDictionaryKey: "AngularLynxEdgeToEdge") as? Bool ?? true
|
|
16
45
|
|
|
46
|
+
/// Whether the app's text follows Dynamic Type, and the largest scale it
|
|
47
|
+
/// takes: angular.json's `textScaling`, which the generator writes into
|
|
48
|
+
/// Info.plist. A project generated before the option existed follows it,
|
|
49
|
+
/// without a cap.
|
|
50
|
+
private let textScaling =
|
|
51
|
+
Bundle.main.object(forInfoDictionaryKey: "AngularLynxTextScaling") as? Bool ?? true
|
|
52
|
+
private let maxTextScale =
|
|
53
|
+
(Bundle.main.object(forInfoDictionaryKey: "AngularLynxMaxTextScale") as? NSNumber)?.doubleValue
|
|
54
|
+
|
|
17
55
|
override func viewDidLoad() {
|
|
18
56
|
super.viewDidLoad()
|
|
19
57
|
// The launch screen's color (angular.json's splash.backgroundColor),
|
|
@@ -21,7 +59,7 @@ final class LynxViewController: UIViewController {
|
|
|
21
59
|
view.backgroundColor = UIColor(named: "LaunchBackground") ?? .systemBackground
|
|
22
60
|
|
|
23
61
|
let fetcher = BundleResourceFetcher.shared
|
|
24
|
-
|
|
62
|
+
lastScreen = UIScreen.main.bounds.size
|
|
25
63
|
// The shell's native modules, which the runtime's services call.
|
|
26
64
|
let config = LynxConfig(provider: LynxEnv.sharedInstance().config.templateProvider)
|
|
27
65
|
config.register(WebAuthModule.self)
|
|
@@ -29,17 +67,123 @@ final class LynxViewController: UIViewController {
|
|
|
29
67
|
config.register(SecureStorageModule.self)
|
|
30
68
|
// LynxClipboard's text (ClipboardModule).
|
|
31
69
|
config.register(ClipboardModule.self)
|
|
70
|
+
// LynxHaptics' taps (HapticsModule).
|
|
71
|
+
config.register(HapticsModule.self)
|
|
32
72
|
config.register(LinkingModule.self)
|
|
33
73
|
// The photo picker behind LynxImagePicker (ImagePickerModule).
|
|
34
74
|
config.register(ImagePickerModule.self)
|
|
35
75
|
// The share sheet behind LynxShare (ShareModule).
|
|
36
76
|
config.register(ShareModule.self)
|
|
77
|
+
// Face ID and Touch ID behind LynxBiometrics (BiometricsModule), which
|
|
78
|
+
// only an app with permissions.biometrics keeps: by name, so the shell
|
|
79
|
+
// builds without it.
|
|
80
|
+
if let biometrics = NSClassFromString("AngularLynxBiometricsModule") as? LynxModule.Type {
|
|
81
|
+
config.register(biometrics)
|
|
82
|
+
}
|
|
83
|
+
// The document picker behind LynxFilePicker (FilePickerModule), which
|
|
84
|
+
// only an app with angular.json's filePicker keeps: by name too.
|
|
85
|
+
if let filePicker = NSClassFromString("AngularLynxFilePickerModule") as? LynxModule.Type {
|
|
86
|
+
config.register(filePicker)
|
|
87
|
+
}
|
|
88
|
+
// Saving to the photo library behind LynxPhotoLibrary
|
|
89
|
+
// (PhotoLibraryModule), which only an app with permissions.savePhotos
|
|
90
|
+
// keeps: by name, so the shell builds without it.
|
|
91
|
+
if let photoLibrary = NSClassFromString("AngularLynxPhotoLibraryModule")
|
|
92
|
+
as? LynxModule.Type
|
|
93
|
+
{
|
|
94
|
+
config.register(photoLibrary)
|
|
95
|
+
}
|
|
96
|
+
// The camera's code scanner behind LynxBarcodeScanner
|
|
97
|
+
// (BarcodeScannerModule), by name: the generator leaves its source out
|
|
98
|
+
// of an app whose angular.json doesn't set permissions.camera, since App
|
|
99
|
+
// Store Connect flags an app whose code uses the camera without a camera
|
|
100
|
+
// usage description.
|
|
101
|
+
if let barcodeScanner = NSClassFromString("AngularLynxBarcodeScannerModule")
|
|
102
|
+
as? LynxModule.Type
|
|
103
|
+
{
|
|
104
|
+
config.register(barcodeScanner)
|
|
105
|
+
}
|
|
106
|
+
// The motion sensors, the compass and shakes behind LynxMotion
|
|
107
|
+
// (MotionModule), by name too: the generator leaves its source out of an
|
|
108
|
+
// app whose angular.json doesn't set motion.
|
|
109
|
+
if let motion = NSClassFromString("AngularLynxMotionModule") as? LynxModule.Type {
|
|
110
|
+
config.register(motion)
|
|
111
|
+
}
|
|
37
112
|
// <canvas>'s WebGL (AngularLynxWebGL.h), which the runtime calls from
|
|
38
113
|
// the main thread. It's Objective-C, which Swift reaches without a
|
|
39
114
|
// bridging header by name.
|
|
40
115
|
if let webGL = NSClassFromString("AngularLynxWebGLModule") as? LynxModule.Type {
|
|
41
116
|
config.register(webGL)
|
|
42
117
|
}
|
|
118
|
+
// Bluetooth LE behind LynxBluetooth (BluetoothModule), by name too: the
|
|
119
|
+
// generator leaves its source out of an app whose angular.json doesn't
|
|
120
|
+
// set permissions.bluetooth, since App Store Connect flags an app whose
|
|
121
|
+
// code uses CoreBluetooth without a Bluetooth usage description.
|
|
122
|
+
if let bluetooth = NSClassFromString("AngularLynxBluetoothModule") as? LynxModule.Type {
|
|
123
|
+
config.register(bluetooth)
|
|
124
|
+
}
|
|
125
|
+
// StoreKit's rating prompt behind LynxStoreReview (StoreReviewModule), by
|
|
126
|
+
// name too: the generator leaves its source out of an app whose
|
|
127
|
+
// angular.json doesn't set storeReview.
|
|
128
|
+
if let storeReview = NSClassFromString("AngularLynxStoreReviewModule") as? LynxModule.Type {
|
|
129
|
+
config.register(storeReview)
|
|
130
|
+
}
|
|
131
|
+
// The event editor behind LynxCalendar (CalendarModule), by name too:
|
|
132
|
+
// the generator leaves its source out of an app whose angular.json
|
|
133
|
+
// doesn't set calendar.
|
|
134
|
+
if let calendar = NSClassFromString("AngularLynxCalendarModule") as? LynxModule.Type {
|
|
135
|
+
config.register(calendar)
|
|
136
|
+
}
|
|
137
|
+
// Sign in with Apple's sheet behind LynxAppleSignIn (AppleSignInModule),
|
|
138
|
+
// by name too: the generator leaves its source out of an app whose
|
|
139
|
+
// angular.json doesn't set signInWithApple, with the entitlement it needs.
|
|
140
|
+
if let appleSignIn = NSClassFromString("AngularLynxAppleSignInModule") as? LynxModule.Type {
|
|
141
|
+
config.register(appleSignIn)
|
|
142
|
+
}
|
|
143
|
+
// What other apps share to this one, behind LynxShareTarget
|
|
144
|
+
// (ShareTargetModule), by name too: the generator leaves its source, and
|
|
145
|
+
// the Share Extension that leaves the shares, out of an app whose
|
|
146
|
+
// angular.json has no shareTarget.
|
|
147
|
+
if let shareTarget = NSClassFromString("AngularLynxShareTargetModule") as? LynxModule.Type {
|
|
148
|
+
config.register(shareTarget)
|
|
149
|
+
}
|
|
150
|
+
// App Tracking Transparency's prompt behind LynxTracking (TrackingModule),
|
|
151
|
+
// by name too: the generator leaves its source out of an app whose
|
|
152
|
+
// angular.json doesn't set permissions.tracking, since iOS ends an app
|
|
153
|
+
// that asks without NSUserTrackingUsageDescription.
|
|
154
|
+
if let tracking = NSClassFromString("AngularLynxTrackingModule") as? LynxModule.Type {
|
|
155
|
+
config.register(tracking)
|
|
156
|
+
}
|
|
157
|
+
// The microphone's recorder behind LynxAudioRecorder
|
|
158
|
+
// (AudioRecorderModule), by name too: the generator leaves its source out
|
|
159
|
+
// of an app whose angular.json doesn't set permissions.microphone, since
|
|
160
|
+
// App Store Connect flags an app whose code uses the microphone without
|
|
161
|
+
// a microphone usage description.
|
|
162
|
+
if let audioRecorder = NSClassFromString("AngularLynxAudioRecorderModule")
|
|
163
|
+
as? LynxModule.Type
|
|
164
|
+
{
|
|
165
|
+
config.register(audioRecorder)
|
|
166
|
+
}
|
|
167
|
+
// Core NFC's reader behind LynxNfc (NfcModule), by name too: the
|
|
168
|
+
// generator leaves its source out of an app whose angular.json doesn't
|
|
169
|
+
// set permissions.nfc, with the usage description and entitlement it
|
|
170
|
+
// needs.
|
|
171
|
+
if let nfc = NSClassFromString("AngularLynxNfcModule") as? LynxModule.Type {
|
|
172
|
+
config.register(nfc)
|
|
173
|
+
}
|
|
174
|
+
// The Wi-Fi network reads and joins behind LynxWifi (WifiModule), by
|
|
175
|
+
// name too: the generator leaves its source out of an app whose
|
|
176
|
+
// angular.json doesn't set wifi, with the entitlements it needs.
|
|
177
|
+
if let wifi = NSClassFromString("AngularLynxWifiModule") as? LynxModule.Type {
|
|
178
|
+
config.register(wifi)
|
|
179
|
+
}
|
|
180
|
+
// Core Location behind LynxGeolocation (GeolocationModule), by name
|
|
181
|
+
// too: the generator leaves its source out of an app whose angular.json
|
|
182
|
+
// doesn't set permissions.location, since App Store Connect flags Core
|
|
183
|
+
// Location code without NSLocationWhenInUseUsageDescription.
|
|
184
|
+
if let geolocation = NSClassFromString("AngularLynxGeolocationModule") as? LynxModule.Type {
|
|
185
|
+
config.register(geolocation)
|
|
186
|
+
}
|
|
43
187
|
// Bundled files for the main thread's fetch and Image (AssetsModule).
|
|
44
188
|
config.register(AssetsModule.self)
|
|
45
189
|
// The full collections the runtime asks for after screens go
|
|
@@ -50,6 +194,12 @@ final class LynxViewController: UIViewController {
|
|
|
50
194
|
config.register(ShortcutsModule.self)
|
|
51
195
|
// `ng serve --platform ios`'s live reload, in the development build.
|
|
52
196
|
DevServer.shared.register(in: config)
|
|
197
|
+
// The app's native plugins' modules and elements (angular.json's
|
|
198
|
+
// `nativePlugins`), after the shell's own and the dev server's, as on
|
|
199
|
+
// Android. A module gets this controller, held weakly, in its param, to
|
|
200
|
+
// present a screen from.
|
|
201
|
+
AngularLynxPlugins.register(in: config, host: self)
|
|
202
|
+
builtFontScale = textScale()
|
|
53
203
|
let lynxView = LynxView { builder in
|
|
54
204
|
builder.config = config
|
|
55
205
|
// Lynx's engine thread, which runs the main thread's JavaScript (the
|
|
@@ -66,8 +216,11 @@ final class LynxViewController: UIViewController {
|
|
|
66
216
|
// with lynx.module(name): WebGL needs answers synchronously. Lynx calls
|
|
67
217
|
// them on its engine thread, not the UI thread (see AngularLynxWebGL.h).
|
|
68
218
|
builder.enableMTSModule = true
|
|
69
|
-
builder.screenSize =
|
|
70
|
-
|
|
219
|
+
builder.screenSize = self.lastScreen
|
|
220
|
+
// The user's text size (see textScale()). The build tells Lynx to
|
|
221
|
+
// scale only `sp` lengths by it, which the page's root font size is
|
|
222
|
+
// written in, so every rem grows with it and a px size doesn't.
|
|
223
|
+
builder.fontScale = self.builtFontScale
|
|
71
224
|
builder.enableGenericResourceFetcher = .true
|
|
72
225
|
builder.genericResourceFetcher = fetcher
|
|
73
226
|
builder.templateResourceFetcher = fetcher
|
|
@@ -77,6 +230,7 @@ final class LynxViewController: UIViewController {
|
|
|
77
230
|
lynxView.layoutHeightMode = .exact
|
|
78
231
|
view.addSubview(lynxView)
|
|
79
232
|
self.lynxView = lynxView
|
|
233
|
+
lynxView.addLifecycleClient(self)
|
|
80
234
|
// Who hears that a shortcut ran, or a link arrived, while the app is open.
|
|
81
235
|
ShortcutCenter.shared.lynxView = lynxView
|
|
82
236
|
LinkCenter.shared.lynxView = lynxView
|
|
@@ -115,12 +269,92 @@ final class LynxViewController: UIViewController {
|
|
|
115
269
|
NotificationCenter.default.addObserver(
|
|
116
270
|
self, selector: #selector(accessibilitySettingsDidChange), name: name, object: nil)
|
|
117
271
|
}
|
|
272
|
+
NotificationCenter.default.addObserver(
|
|
273
|
+
self, selector: #selector(contentSizeCategoryDidChange),
|
|
274
|
+
name: UIContentSizeCategory.didChangeNotification, object: nil)
|
|
275
|
+
|
|
276
|
+
// Send the app's state again each time the scene's activation changes.
|
|
277
|
+
observeAppState()
|
|
278
|
+
|
|
279
|
+
// Send whether the phone is online again each time it changes.
|
|
280
|
+
networkStatus = NetworkStatus { [weak self] _ in
|
|
281
|
+
guard let self else { return }
|
|
282
|
+
self.lynxView?.updateGlobalProps(with: self.globalProps())
|
|
283
|
+
}
|
|
118
284
|
}
|
|
119
285
|
|
|
120
286
|
@objc private func accessibilitySettingsDidChange() {
|
|
121
287
|
lynxView?.updateGlobalProps(with: globalProps())
|
|
122
288
|
}
|
|
123
289
|
|
|
290
|
+
/// The scene's activation changes, as the state each one leads to. Lynx
|
|
291
|
+
/// tells the app's code nothing when it leaves the screen or comes back,
|
|
292
|
+
/// so the shell sends the state itself (LynxAppState). Resigning active,
|
|
293
|
+
/// for Control Center, Notification Center, the app switcher or a call,
|
|
294
|
+
/// is "inactive", and leaving the screen is "background".
|
|
295
|
+
private static let appStateNotifications: [(Notification.Name, String)] = [
|
|
296
|
+
(UIScene.didActivateNotification, "active"),
|
|
297
|
+
(UIScene.willDeactivateNotification, "inactive"),
|
|
298
|
+
(UIScene.didEnterBackgroundNotification, "background"),
|
|
299
|
+
(UIScene.willEnterForegroundNotification, "inactive"),
|
|
300
|
+
]
|
|
301
|
+
|
|
302
|
+
private static func appState(of state: UIApplication.State) -> String {
|
|
303
|
+
switch state {
|
|
304
|
+
case .active: return "active"
|
|
305
|
+
case .background: return "background"
|
|
306
|
+
default: return "inactive"
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
private func observeAppState() {
|
|
311
|
+
appStateObservers = Self.appStateNotifications.map { name, state in
|
|
312
|
+
NotificationCenter.default.addObserver(forName: name, object: nil, queue: .main) {
|
|
313
|
+
[weak self] _ in
|
|
314
|
+
guard let self, self.appState != state else { return }
|
|
315
|
+
self.appState = state
|
|
316
|
+
self.lynxView?.updateGlobalProps(with: self.globalProps())
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/// The user chose another text size while the app was open: the page's
|
|
322
|
+
/// root font size, and with it every rem, takes the new scale at once, as
|
|
323
|
+
/// UIKit's own text does, and LynxAccessibilitySettings.textScale() hears it.
|
|
324
|
+
@objc private func contentSizeCategoryDidChange() {
|
|
325
|
+
lynxView?.updateFontScale(textScale())
|
|
326
|
+
lynxView?.updateGlobalProps(with: globalProps())
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/// A load sets up a new engine, as the development build's reload does, and
|
|
330
|
+
/// Lynx gives it the font scale the LynxView was built with: updateFontScale
|
|
331
|
+
/// doesn't change that. So a size chosen since then would be lost on reload
|
|
332
|
+
/// while `textScale` kept it; give the new page the current scale.
|
|
333
|
+
func lynxView(_ view: LynxView!, didLoadFinishedWithUrl url: String!) {
|
|
334
|
+
let scale = textScale()
|
|
335
|
+
if scale != builtFontScale {
|
|
336
|
+
view.updateFontScale(scale)
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/// How much larger than the default the user's Dynamic Type size draws body
|
|
341
|
+
/// text: 1 at the default (Large), about 1.24 at the largest of the
|
|
342
|
+
/// standard sizes and 3.1 at the largest accessibility size, and below 1 at
|
|
343
|
+
/// the smaller sizes. Capped at angular.json's `textScaling.max`, and 1
|
|
344
|
+
/// with `"textScaling": false`.
|
|
345
|
+
///
|
|
346
|
+
/// Read from the app's content size category rather than the view's
|
|
347
|
+
/// traits, which may not have changed yet when the notification arrives.
|
|
348
|
+
private func textScale() -> CGFloat {
|
|
349
|
+
guard textScaling else { return 1 }
|
|
350
|
+
let traits = UITraitCollection(
|
|
351
|
+
preferredContentSizeCategory: UIApplication.shared.preferredContentSizeCategory)
|
|
352
|
+
let body: CGFloat = 17
|
|
353
|
+
let scale = UIFontMetrics(forTextStyle: .body).scaledValue(for: body, compatibleWith: traits) / body
|
|
354
|
+
guard let maxTextScale else { return scale }
|
|
355
|
+
return min(scale, CGFloat(maxTextScale))
|
|
356
|
+
}
|
|
357
|
+
|
|
124
358
|
@available(iOS, deprecated: 17.0, message: "registerForTraitChanges in viewDidLoad replaces it")
|
|
125
359
|
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
|
|
126
360
|
super.traitCollectionDidChange(previousTraitCollection)
|
|
@@ -158,10 +392,25 @@ final class LynxViewController: UIViewController {
|
|
|
158
392
|
/// env(safe-area-inset-*) the safeArea* global props below instead, as CSS
|
|
159
393
|
/// variables on the page that restyle what reads them when they change, and
|
|
160
394
|
/// 0 when the LynxView is inside the safe area (see `edgeToEdge` there).
|
|
395
|
+
///
|
|
396
|
+
/// It runs again whenever the window changes size: a rotation, and on an
|
|
397
|
+
/// iPad, split view and Stage Manager. Lynx 4 lays the page out again at
|
|
398
|
+
/// the new size by itself, once it's told, in its foldable guide's order:
|
|
399
|
+
/// the window's size, which rpx lengths are a 750th of, then the
|
|
400
|
+
/// LynxView's, which %, vw, vh and @media measure against, then the global
|
|
401
|
+
/// props LynxViewport reads, all in points. A new window size alone
|
|
402
|
+
/// doesn't lay the page out again, which the viewport and triggerLayout do.
|
|
161
403
|
private func layoutLynxView() {
|
|
162
404
|
guard let lynxView else { return }
|
|
163
405
|
let frame = edgeToEdge ? view.bounds : view.bounds.inset(by: view.safeAreaInsets)
|
|
164
|
-
|
|
406
|
+
// The window's bounds, once the view is in it; before, the screen's,
|
|
407
|
+
// which the LynxView was built with.
|
|
408
|
+
let screen = view.window?.bounds.size ?? lastScreen
|
|
409
|
+
guard frame != lastViewport || screen != lastScreen else { return }
|
|
410
|
+
if screen != lastScreen {
|
|
411
|
+
lastScreen = screen
|
|
412
|
+
lynxView.updateScreenMetrics(withWidth: screen.width, height: screen.height)
|
|
413
|
+
}
|
|
165
414
|
lastViewport = frame
|
|
166
415
|
lynxView.frame = frame
|
|
167
416
|
lynxView.preferredLayoutWidth = frame.width
|
|
@@ -175,10 +424,12 @@ final class LynxViewController: UIViewController {
|
|
|
175
424
|
/// The global props the runtime reads: `theme` (LynxTheme), `isNotchScreen`
|
|
176
425
|
/// (LynxSafeArea), `appLocale` (LynxLocale), `appTimeZone` (the `intl`
|
|
177
426
|
/// build option's Intl.DateTimeFormat), the accessibility settings
|
|
178
|
-
/// (LynxAccessibilitySettings), `
|
|
179
|
-
/// `
|
|
180
|
-
///
|
|
181
|
-
///
|
|
427
|
+
/// and text scale (LynxAccessibilitySettings), `appState` (LynxAppState),
|
|
428
|
+
/// `online` (LynxNetwork), `osVersion` (LynxSystemInfo), `initialURL` (LynxLinking and the
|
|
429
|
+
/// router) and the window's and the LynxView's sizes (LynxViewport), plus
|
|
430
|
+
/// the safe-area insets and `edgeToEdge`, which
|
|
431
|
+
/// env(safe-area-inset-*) reads. The Android shell sends the same keys, and
|
|
432
|
+
/// Lynx Explorer sends theme and isNotchScreen too.
|
|
182
433
|
private func globalProps() -> LynxTemplateData {
|
|
183
434
|
let insets = view.safeAreaInsets
|
|
184
435
|
var props: [String: Any] = [
|
|
@@ -201,10 +452,24 @@ final class LynxViewController: UIViewController {
|
|
|
201
452
|
"reduceTransparency": UIAccessibility.isReduceTransparencyEnabled,
|
|
202
453
|
// Increase Contrast.
|
|
203
454
|
"increaseContrast": UIAccessibility.isDarkerSystemColorsEnabled,
|
|
455
|
+
// The text size, as the LynxView's font scale has it
|
|
456
|
+
// (LynxAccessibilitySettings.textScale).
|
|
457
|
+
"textScale": textScale(),
|
|
458
|
+
// Whether the app is in the foreground, taking touches.
|
|
459
|
+
"appState": appState,
|
|
460
|
+
// Whether the phone has a connection to the internet. Online until the
|
|
461
|
+
// monitor first answers, which comes after the first props go out.
|
|
462
|
+
"online": networkStatus?.online ?? true,
|
|
204
463
|
// Lynx builds the main thread's SystemInfo, where Angular runs, without
|
|
205
464
|
// the OS version, so LynxSystemInfo reads it from here. The glass
|
|
206
465
|
// components need it: blur-view draws Liquid Glass only from iOS 26.
|
|
207
466
|
"osVersion": UIDevice.current.systemVersion,
|
|
467
|
+
// The sizes Lynx's foldable guide names, in points: the window's, and
|
|
468
|
+
// the LynxView's, which is smaller with "edgeToEdge": false.
|
|
469
|
+
"screenWidth": lastScreen.width,
|
|
470
|
+
"screenHeight": lastScreen.height,
|
|
471
|
+
"viewportWidth": lastViewport.width,
|
|
472
|
+
"viewportHeight": lastViewport.height,
|
|
208
473
|
]
|
|
209
474
|
// The user's first language as a BCP 47 tag, such as "fr-FR". iOS
|
|
210
475
|
// restarts the app when the language changes, so there's no update to send.
|