@blotch/angular-lynx-native 22.3.1 → 22.3.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.
Files changed (100) hide show
  1. package/README.md +41 -15
  2. package/dist/android/project.d.ts +90 -1
  3. package/dist/android/project.d.ts.map +1 -1
  4. package/dist/android/project.js +369 -5
  5. package/dist/eject.d.ts +15 -1
  6. package/dist/eject.d.ts.map +1 -1
  7. package/dist/eject.js +13 -2
  8. package/dist/features.d.ts +70 -0
  9. package/dist/features.d.ts.map +1 -0
  10. package/dist/features.js +115 -0
  11. package/dist/generate.d.ts +17 -1
  12. package/dist/generate.d.ts.map +1 -1
  13. package/dist/generate.js +12 -4
  14. package/dist/index.d.ts +1 -0
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +8 -1
  17. package/dist/ios/build.d.ts.map +1 -1
  18. package/dist/ios/build.js +8 -2
  19. package/dist/ios/frameworks.d.ts +6 -5
  20. package/dist/ios/frameworks.d.ts.map +1 -1
  21. package/dist/ios/frameworks.js +46 -15
  22. package/dist/ios/project.d.ts +173 -11
  23. package/dist/ios/project.d.ts.map +1 -1
  24. package/dist/ios/project.js +767 -33
  25. package/dist/options.d.ts +140 -1
  26. package/dist/options.d.ts.map +1 -1
  27. package/dist/options.js +127 -0
  28. package/dist/permissions.d.ts +18 -1
  29. package/dist/permissions.d.ts.map +1 -1
  30. package/dist/permissions.js +63 -3
  31. package/package.json +1 -1
  32. package/templates/android/README.md +35 -2
  33. package/templates/android/angular-lynx.properties +2 -0
  34. package/templates/android/app/build.gradle.kts +51 -2
  35. package/templates/android/app/src/main/AndroidManifest.xml +14 -3
  36. package/templates/android/app/src/main/java/dev/angularlynx/shell/BarcodeScannerModule.kt +144 -0
  37. package/templates/android/app/src/main/java/dev/angularlynx/shell/BiometricsModule.kt +433 -0
  38. package/templates/android/app/src/main/java/dev/angularlynx/shell/BitmapPresenter.kt +98 -0
  39. package/templates/android/app/src/main/java/dev/angularlynx/shell/BitmapRendererContext.kt +175 -0
  40. package/templates/android/app/src/main/java/dev/angularlynx/shell/BluetoothModule.kt +1288 -0
  41. package/templates/android/app/src/main/java/dev/angularlynx/shell/CalendarModule.kt +127 -0
  42. package/templates/android/app/src/main/java/dev/angularlynx/shell/Canvas2DContext.kt +1557 -0
  43. package/templates/android/app/src/main/java/dev/angularlynx/shell/Canvas2DOps.kt +63 -0
  44. package/templates/android/app/src/main/java/dev/angularlynx/shell/CanvasFilter.kt +357 -0
  45. package/templates/android/app/src/main/java/dev/angularlynx/shell/CanvasUI.kt +4 -3
  46. package/templates/android/app/src/main/java/dev/angularlynx/shell/FilePickerModule.kt +263 -0
  47. package/templates/android/app/src/main/java/dev/angularlynx/shell/HapticsModule.kt +82 -0
  48. package/templates/android/app/src/main/java/dev/angularlynx/shell/MainActivity.kt +376 -6
  49. package/templates/android/app/src/main/java/dev/angularlynx/shell/ModuleBytes.kt +58 -0
  50. package/templates/android/app/src/main/java/dev/angularlynx/shell/MotionModule.kt +332 -0
  51. package/templates/android/app/src/main/java/dev/angularlynx/shell/NfcModule.kt +274 -0
  52. package/templates/android/app/src/main/java/dev/angularlynx/shell/PermissionRequests.kt +25 -0
  53. package/templates/android/app/src/main/java/dev/angularlynx/shell/PhotoLibraryModule.kt +168 -0
  54. package/templates/android/app/src/main/java/dev/angularlynx/shell/ShareTargetModule.kt +234 -0
  55. package/templates/android/app/src/main/java/dev/angularlynx/shell/ShellApplication.kt +6 -0
  56. package/templates/android/app/src/main/java/dev/angularlynx/shell/ShellModule.kt +47 -3
  57. package/templates/android/app/src/main/java/dev/angularlynx/shell/StoreReviewModule.kt +66 -0
  58. package/templates/android/app/src/main/java/dev/angularlynx/shell/SystemFontFamilies.kt +68 -0
  59. package/templates/android/app/src/main/java/dev/angularlynx/shell/TrackingModule.kt +74 -0
  60. package/templates/android/app/src/main/java/dev/angularlynx/shell/VideoFrameTarget.kt +429 -0
  61. package/templates/android/app/src/main/java/dev/angularlynx/shell/VideoUI.kt +676 -0
  62. package/templates/android/app/src/main/java/dev/angularlynx/shell/WebGLContext.kt +128 -13
  63. package/templates/android/app/src/main/java/dev/angularlynx/shell/WebGLModule.kt +493 -65
  64. package/templates/android/app/src/main/java/dev/angularlynx/shell/WifiModule.kt +429 -0
  65. package/templates/android/app/src/main/res/values/biometrics.xml +9 -0
  66. package/templates/android/app/src/main/res/values/share_target.xml +11 -0
  67. package/templates/android/app/src/main/res/xml/backup_rules.xml +5 -3
  68. package/templates/android/app/src/main/res/xml/data_extraction_rules.xml +6 -3
  69. package/templates/android/build.gradle.kts +1 -1
  70. package/templates/android/gradle/wrapper/gradle-wrapper.properties +2 -2
  71. package/templates/ios/App/AngularLynxBitmapRendererContext.m +188 -0
  72. package/templates/ios/App/AngularLynxCanvas2DContext.m +2467 -0
  73. package/templates/ios/App/AngularLynxCanvas2DOps.h +61 -0
  74. package/templates/ios/App/AngularLynxVideo.h +37 -0
  75. package/templates/ios/App/AngularLynxVideo.m +435 -0
  76. package/templates/ios/App/AngularLynxWebGL.h +69 -7
  77. package/templates/ios/App/AngularLynxWebGL.m +538 -29
  78. package/templates/ios/App/AngularLynxWebGLContext.m +148 -46
  79. package/templates/ios/App/AppDelegate.swift +34 -2
  80. package/templates/ios/App/AppleSignInButton.swift +106 -0
  81. package/templates/ios/App/AppleSignInModule.swift +222 -0
  82. package/templates/ios/App/BarcodeScannerModule.swift +284 -0
  83. package/templates/ios/App/BiometricsModule.swift +256 -0
  84. package/templates/ios/App/BluetoothModule.swift +1086 -0
  85. package/templates/ios/App/CalendarModule.swift +158 -0
  86. package/templates/ios/App/FilePickerModule.swift +240 -0
  87. package/templates/ios/App/HapticsModule.swift +90 -0
  88. package/templates/ios/App/Info.plist +2 -0
  89. package/templates/ios/App/LynxViewController.swift +210 -6
  90. package/templates/ios/App/MotionModule.swift +430 -0
  91. package/templates/ios/App/NfcModule.swift +346 -0
  92. package/templates/ios/App/PhotoLibraryModule.swift +169 -0
  93. package/templates/ios/App/ShareTargetModule.swift +150 -0
  94. package/templates/ios/App/ShellModule.swift +17 -0
  95. package/templates/ios/App/StoreReviewModule.swift +61 -0
  96. package/templates/ios/App/TrackingModule.swift +121 -0
  97. package/templates/ios/App/WifiModule.swift +237 -0
  98. package/templates/ios/App/XElementRegistry.swift +13 -3
  99. package/templates/ios/ShareExtension/Info.plist +42 -0
  100. package/templates/ios/ShareExtension/ShareViewController.swift +387 -0
@@ -3,10 +3,31 @@ 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
9
12
 
13
+ /// Where the app is, for LynxAppState: "active", "inactive" or
14
+ /// "background". Sent in the global props, and again as the scene's
15
+ /// activation changes (appStateDidChange). It starts from the app's state
16
+ /// when the view loads, which is "inactive" while the app launches: the
17
+ /// scene becomes active just after.
18
+ private var appState = LynxViewController.appState(of: UIApplication.shared.applicationState)
19
+
20
+ /// The block observers observeAppState() adds. NotificationCenter keeps a
21
+ /// block observer until it's removed, and iOS can disconnect the scene and
22
+ /// build a new controller, so deinit removes them.
23
+ private var appStateObservers: [NSObjectProtocol] = []
24
+
25
+ deinit {
26
+ for observer in appStateObservers {
27
+ NotificationCenter.default.removeObserver(observer)
28
+ }
29
+ }
30
+
10
31
  /// Whether the page fills the screen, under the status bar and the home
11
32
  /// indicator: angular.json's `edgeToEdge`, which the generator writes into
12
33
  /// Info.plist. A project generated before the option existed has no key,
@@ -14,6 +35,15 @@ final class LynxViewController: UIViewController {
14
35
  private let edgeToEdge =
15
36
  Bundle.main.object(forInfoDictionaryKey: "AngularLynxEdgeToEdge") as? Bool ?? true
16
37
 
38
+ /// Whether the app's text follows Dynamic Type, and the largest scale it
39
+ /// takes: angular.json's `textScaling`, which the generator writes into
40
+ /// Info.plist. A project generated before the option existed follows it,
41
+ /// without a cap.
42
+ private let textScaling =
43
+ Bundle.main.object(forInfoDictionaryKey: "AngularLynxTextScaling") as? Bool ?? true
44
+ private let maxTextScale =
45
+ (Bundle.main.object(forInfoDictionaryKey: "AngularLynxMaxTextScale") as? NSNumber)?.doubleValue
46
+
17
47
  override func viewDidLoad() {
18
48
  super.viewDidLoad()
19
49
  // The launch screen's color (angular.json's splash.backgroundColor),
@@ -29,17 +59,106 @@ final class LynxViewController: UIViewController {
29
59
  config.register(SecureStorageModule.self)
30
60
  // LynxClipboard's text (ClipboardModule).
31
61
  config.register(ClipboardModule.self)
62
+ // LynxHaptics' taps (HapticsModule).
63
+ config.register(HapticsModule.self)
32
64
  config.register(LinkingModule.self)
33
65
  // The photo picker behind LynxImagePicker (ImagePickerModule).
34
66
  config.register(ImagePickerModule.self)
35
67
  // The share sheet behind LynxShare (ShareModule).
36
68
  config.register(ShareModule.self)
69
+ // Face ID and Touch ID behind LynxBiometrics (BiometricsModule), which
70
+ // only an app with permissions.biometrics keeps: by name, so the shell
71
+ // builds without it.
72
+ if let biometrics = NSClassFromString("AngularLynxBiometricsModule") as? LynxModule.Type {
73
+ config.register(biometrics)
74
+ }
75
+ // The document picker behind LynxFilePicker (FilePickerModule), which
76
+ // only an app with angular.json's filePicker keeps: by name too.
77
+ if let filePicker = NSClassFromString("AngularLynxFilePickerModule") as? LynxModule.Type {
78
+ config.register(filePicker)
79
+ }
80
+ // Saving to the photo library behind LynxPhotoLibrary
81
+ // (PhotoLibraryModule), which only an app with permissions.savePhotos
82
+ // keeps: by name, so the shell builds without it.
83
+ if let photoLibrary = NSClassFromString("AngularLynxPhotoLibraryModule")
84
+ as? LynxModule.Type
85
+ {
86
+ config.register(photoLibrary)
87
+ }
88
+ // The camera's code scanner behind LynxBarcodeScanner
89
+ // (BarcodeScannerModule), by name: the generator leaves its source out
90
+ // of an app whose angular.json doesn't set permissions.camera, since App
91
+ // Store Connect flags an app whose code uses the camera without a camera
92
+ // usage description.
93
+ if let barcodeScanner = NSClassFromString("AngularLynxBarcodeScannerModule")
94
+ as? LynxModule.Type
95
+ {
96
+ config.register(barcodeScanner)
97
+ }
98
+ // The motion sensors, the compass and shakes behind LynxMotion
99
+ // (MotionModule), by name too: the generator leaves its source out of an
100
+ // app whose angular.json doesn't set motion.
101
+ if let motion = NSClassFromString("AngularLynxMotionModule") as? LynxModule.Type {
102
+ config.register(motion)
103
+ }
37
104
  // <canvas>'s WebGL (AngularLynxWebGL.h), which the runtime calls from
38
105
  // the main thread. It's Objective-C, which Swift reaches without a
39
106
  // bridging header by name.
40
107
  if let webGL = NSClassFromString("AngularLynxWebGLModule") as? LynxModule.Type {
41
108
  config.register(webGL)
42
109
  }
110
+ // Bluetooth LE behind LynxBluetooth (BluetoothModule), by name too: the
111
+ // generator leaves its source out of an app whose angular.json doesn't
112
+ // set permissions.bluetooth, since App Store Connect flags an app whose
113
+ // code uses CoreBluetooth without a Bluetooth usage description.
114
+ if let bluetooth = NSClassFromString("AngularLynxBluetoothModule") as? LynxModule.Type {
115
+ config.register(bluetooth)
116
+ }
117
+ // StoreKit's rating prompt behind LynxStoreReview (StoreReviewModule), by
118
+ // name too: the generator leaves its source out of an app whose
119
+ // angular.json doesn't set storeReview.
120
+ if let storeReview = NSClassFromString("AngularLynxStoreReviewModule") as? LynxModule.Type {
121
+ config.register(storeReview)
122
+ }
123
+ // The event editor behind LynxCalendar (CalendarModule), by name too:
124
+ // the generator leaves its source out of an app whose angular.json
125
+ // doesn't set calendar.
126
+ if let calendar = NSClassFromString("AngularLynxCalendarModule") as? LynxModule.Type {
127
+ config.register(calendar)
128
+ }
129
+ // Sign in with Apple's sheet behind LynxAppleSignIn (AppleSignInModule),
130
+ // by name too: the generator leaves its source out of an app whose
131
+ // angular.json doesn't set signInWithApple, with the entitlement it needs.
132
+ if let appleSignIn = NSClassFromString("AngularLynxAppleSignInModule") as? LynxModule.Type {
133
+ config.register(appleSignIn)
134
+ }
135
+ // What other apps share to this one, behind LynxShareTarget
136
+ // (ShareTargetModule), by name too: the generator leaves its source, and
137
+ // the Share Extension that leaves the shares, out of an app whose
138
+ // angular.json has no shareTarget.
139
+ if let shareTarget = NSClassFromString("AngularLynxShareTargetModule") as? LynxModule.Type {
140
+ config.register(shareTarget)
141
+ }
142
+ // App Tracking Transparency's prompt behind LynxTracking (TrackingModule),
143
+ // by name too: the generator leaves its source out of an app whose
144
+ // angular.json doesn't set permissions.tracking, since iOS ends an app
145
+ // that asks without NSUserTrackingUsageDescription.
146
+ if let tracking = NSClassFromString("AngularLynxTrackingModule") as? LynxModule.Type {
147
+ config.register(tracking)
148
+ }
149
+ // Core NFC's reader behind LynxNfc (NfcModule), by name too: the
150
+ // generator leaves its source out of an app whose angular.json doesn't
151
+ // set permissions.nfc, with the usage description and entitlement it
152
+ // needs.
153
+ if let nfc = NSClassFromString("AngularLynxNfcModule") as? LynxModule.Type {
154
+ config.register(nfc)
155
+ }
156
+ // The Wi-Fi network reads and joins behind LynxWifi (WifiModule), by
157
+ // name too: the generator leaves its source out of an app whose
158
+ // angular.json doesn't set wifi, with the entitlements it needs.
159
+ if let wifi = NSClassFromString("AngularLynxWifiModule") as? LynxModule.Type {
160
+ config.register(wifi)
161
+ }
43
162
  // Bundled files for the main thread's fetch and Image (AssetsModule).
44
163
  config.register(AssetsModule.self)
45
164
  // The full collections the runtime asks for after screens go
@@ -50,6 +169,7 @@ final class LynxViewController: UIViewController {
50
169
  config.register(ShortcutsModule.self)
51
170
  // `ng serve --platform ios`'s live reload, in the development build.
52
171
  DevServer.shared.register(in: config)
172
+ builtFontScale = textScale()
53
173
  let lynxView = LynxView { builder in
54
174
  builder.config = config
55
175
  // Lynx's engine thread, which runs the main thread's JavaScript (the
@@ -67,7 +187,10 @@ final class LynxViewController: UIViewController {
67
187
  // them on its engine thread, not the UI thread (see AngularLynxWebGL.h).
68
188
  builder.enableMTSModule = true
69
189
  builder.screenSize = screenSize
70
- builder.fontScale = 1.0
190
+ // The user's text size (see textScale()). The build tells Lynx to
191
+ // scale only `sp` lengths by it, which the page's root font size is
192
+ // written in, so every rem grows with it and a px size doesn't.
193
+ builder.fontScale = self.builtFontScale
71
194
  builder.enableGenericResourceFetcher = .true
72
195
  builder.genericResourceFetcher = fetcher
73
196
  builder.templateResourceFetcher = fetcher
@@ -77,6 +200,7 @@ final class LynxViewController: UIViewController {
77
200
  lynxView.layoutHeightMode = .exact
78
201
  view.addSubview(lynxView)
79
202
  self.lynxView = lynxView
203
+ lynxView.addLifecycleClient(self)
80
204
  // Who hears that a shortcut ran, or a link arrived, while the app is open.
81
205
  ShortcutCenter.shared.lynxView = lynxView
82
206
  LinkCenter.shared.lynxView = lynxView
@@ -115,12 +239,86 @@ final class LynxViewController: UIViewController {
115
239
  NotificationCenter.default.addObserver(
116
240
  self, selector: #selector(accessibilitySettingsDidChange), name: name, object: nil)
117
241
  }
242
+ NotificationCenter.default.addObserver(
243
+ self, selector: #selector(contentSizeCategoryDidChange),
244
+ name: UIContentSizeCategory.didChangeNotification, object: nil)
245
+
246
+ // Send the app's state again each time the scene's activation changes.
247
+ observeAppState()
118
248
  }
119
249
 
120
250
  @objc private func accessibilitySettingsDidChange() {
121
251
  lynxView?.updateGlobalProps(with: globalProps())
122
252
  }
123
253
 
254
+ /// The scene's activation changes, as the state each one leads to. Lynx
255
+ /// tells the app's code nothing when it leaves the screen or comes back,
256
+ /// so the shell sends the state itself (LynxAppState). Resigning active,
257
+ /// for Control Center, Notification Center, the app switcher or a call,
258
+ /// is "inactive", and leaving the screen is "background".
259
+ private static let appStateNotifications: [(Notification.Name, String)] = [
260
+ (UIScene.didActivateNotification, "active"),
261
+ (UIScene.willDeactivateNotification, "inactive"),
262
+ (UIScene.didEnterBackgroundNotification, "background"),
263
+ (UIScene.willEnterForegroundNotification, "inactive"),
264
+ ]
265
+
266
+ private static func appState(of state: UIApplication.State) -> String {
267
+ switch state {
268
+ case .active: return "active"
269
+ case .background: return "background"
270
+ default: return "inactive"
271
+ }
272
+ }
273
+
274
+ private func observeAppState() {
275
+ appStateObservers = Self.appStateNotifications.map { name, state in
276
+ NotificationCenter.default.addObserver(forName: name, object: nil, queue: .main) {
277
+ [weak self] _ in
278
+ guard let self, self.appState != state else { return }
279
+ self.appState = state
280
+ self.lynxView?.updateGlobalProps(with: self.globalProps())
281
+ }
282
+ }
283
+ }
284
+
285
+ /// The user chose another text size while the app was open: the page's
286
+ /// root font size, and with it every rem, takes the new scale at once, as
287
+ /// UIKit's own text does, and LynxAccessibilitySettings.textScale() hears it.
288
+ @objc private func contentSizeCategoryDidChange() {
289
+ lynxView?.updateFontScale(textScale())
290
+ lynxView?.updateGlobalProps(with: globalProps())
291
+ }
292
+
293
+ /// A load sets up a new engine, as the development build's reload does, and
294
+ /// Lynx gives it the font scale the LynxView was built with: updateFontScale
295
+ /// doesn't change that. So a size chosen since then would be lost on reload
296
+ /// while `textScale` kept it; give the new page the current scale.
297
+ func lynxView(_ view: LynxView!, didLoadFinishedWithUrl url: String!) {
298
+ let scale = textScale()
299
+ if scale != builtFontScale {
300
+ view.updateFontScale(scale)
301
+ }
302
+ }
303
+
304
+ /// How much larger than the default the user's Dynamic Type size draws body
305
+ /// text: 1 at the default (Large), about 1.24 at the largest of the
306
+ /// standard sizes and 3.1 at the largest accessibility size, and below 1 at
307
+ /// the smaller sizes. Capped at angular.json's `textScaling.max`, and 1
308
+ /// with `"textScaling": false`.
309
+ ///
310
+ /// Read from the app's content size category rather than the view's
311
+ /// traits, which may not have changed yet when the notification arrives.
312
+ private func textScale() -> CGFloat {
313
+ guard textScaling else { return 1 }
314
+ let traits = UITraitCollection(
315
+ preferredContentSizeCategory: UIApplication.shared.preferredContentSizeCategory)
316
+ let body: CGFloat = 17
317
+ let scale = UIFontMetrics(forTextStyle: .body).scaledValue(for: body, compatibleWith: traits) / body
318
+ guard let maxTextScale else { return scale }
319
+ return min(scale, CGFloat(maxTextScale))
320
+ }
321
+
124
322
  @available(iOS, deprecated: 17.0, message: "registerForTraitChanges in viewDidLoad replaces it")
125
323
  override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
126
324
  super.traitCollectionDidChange(previousTraitCollection)
@@ -175,10 +373,11 @@ final class LynxViewController: UIViewController {
175
373
  /// The global props the runtime reads: `theme` (LynxTheme), `isNotchScreen`
176
374
  /// (LynxSafeArea), `appLocale` (LynxLocale), `appTimeZone` (the `intl`
177
375
  /// build option's Intl.DateTimeFormat), the accessibility settings
178
- /// (LynxAccessibilitySettings), `osVersion` (LynxSystemInfo) and
179
- /// `initialURL` (LynxLinking and the router), plus the safe-area insets and
180
- /// `edgeToEdge`, which env(safe-area-inset-*) reads. The Android shell
181
- /// sends the same keys, and Lynx Explorer sends theme and isNotchScreen too.
376
+ /// and text scale (LynxAccessibilitySettings), `appState` (LynxAppState),
377
+ /// `osVersion` (LynxSystemInfo) and `initialURL` (LynxLinking and the
378
+ /// router), plus the safe-area insets and `edgeToEdge`, which
379
+ /// env(safe-area-inset-*) reads. The Android shell sends the same keys, and
380
+ /// Lynx Explorer sends theme and isNotchScreen too.
182
381
  private func globalProps() -> LynxTemplateData {
183
382
  let insets = view.safeAreaInsets
184
383
  var props: [String: Any] = [
@@ -201,6 +400,11 @@ final class LynxViewController: UIViewController {
201
400
  "reduceTransparency": UIAccessibility.isReduceTransparencyEnabled,
202
401
  // Increase Contrast.
203
402
  "increaseContrast": UIAccessibility.isDarkerSystemColorsEnabled,
403
+ // The text size, as the LynxView's font scale has it
404
+ // (LynxAccessibilitySettings.textScale).
405
+ "textScale": textScale(),
406
+ // Whether the app is in the foreground, taking touches.
407
+ "appState": appState,
204
408
  // Lynx builds the main thread's SystemInfo, where Angular runs, without
205
409
  // the OS version, so LynxSystemInfo reads it from here. The glass
206
410
  // components need it: blur-view draws Liquid Glass only from iOS 26.