@blotch/angular-lynx-native 22.2.25 → 22.2.26
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 +5 -3
- package/dist/android/project.d.ts +2 -1
- package/dist/android/project.d.ts.map +1 -1
- package/dist/android/project.js +4 -1
- package/dist/generate.d.ts +1 -1
- package/dist/generate.js +8 -2
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -0
- package/dist/ios/project.d.ts +3 -2
- package/dist/ios/project.d.ts.map +1 -1
- package/dist/ios/project.js +12 -2
- package/dist/options.d.ts +57 -0
- package/dist/options.d.ts.map +1 -1
- package/dist/options.js +51 -0
- package/dist/png.d.ts +5 -0
- package/dist/png.d.ts.map +1 -1
- package/dist/png.js +19 -5
- package/dist/splash.d.ts +70 -0
- package/dist/splash.d.ts.map +1 -0
- package/dist/splash.js +239 -0
- package/package.json +1 -1
- package/templates/android/README.md +8 -1
- package/templates/android/app/build.gradle.kts +4 -0
- package/templates/android/app/src/debug/java/dev/angularlynx/shell/DevServer.kt +6 -0
- package/templates/android/app/src/main/AndroidManifest.xml +3 -1
- package/templates/android/app/src/main/java/dev/angularlynx/shell/AssetsModule.kt +2 -1
- package/templates/android/app/src/main/java/dev/angularlynx/shell/CanvasUI.kt +16 -3
- package/templates/android/app/src/main/java/dev/angularlynx/shell/MainActivity.kt +57 -1
- package/templates/android/app/src/main/java/dev/angularlynx/shell/ShellModule.kt +10 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/WebGLContext.kt +15 -4
- package/templates/android/app/src/main/java/dev/angularlynx/shell/WebGLModule.kt +10 -1
- package/templates/android/app/src/main/res/values/colors.xml +3 -2
- package/templates/android/app/src/main/res/values/splash.xml +9 -0
- package/templates/android/app/src/main/res/values/themes.xml +14 -0
- package/templates/android/app/src/release/java/dev/angularlynx/shell/DevServer.kt +2 -0
- package/templates/ios/App/AngularLynxWebGL.h +34 -6
- package/templates/ios/App/AngularLynxWebGL.m +58 -23
- package/templates/ios/App/AngularLynxWebGLContext.m +25 -21
- package/templates/ios/App/AnimationFrameRate.swift +214 -0
- package/templates/ios/App/AppDelegate.swift +2 -0
- package/templates/ios/App/AssetsModule.swift +3 -1
- package/templates/ios/App/DevServer.swift +3 -0
- package/templates/ios/App/Info.plist +12 -5
- package/templates/ios/App/LynxViewController.swift +19 -1
- package/templates/ios/App/ShellModule.swift +14 -1
- package/templates/ios/App/SplashScreen.swift +71 -0
|
@@ -16,6 +16,8 @@ final class LynxViewController: UIViewController {
|
|
|
16
16
|
|
|
17
17
|
override func viewDidLoad() {
|
|
18
18
|
super.viewDidLoad()
|
|
19
|
+
// The launch screen's color (angular.json's splash.backgroundColor),
|
|
20
|
+
// behind the LynxView, so no other color shows between the two.
|
|
19
21
|
view.backgroundColor = UIColor(named: "LaunchBackground") ?? .systemBackground
|
|
20
22
|
|
|
21
23
|
let fetcher = BundleResourceFetcher.shared
|
|
@@ -50,8 +52,19 @@ final class LynxViewController: UIViewController {
|
|
|
50
52
|
DevServer.shared.register(in: config)
|
|
51
53
|
let lynxView = LynxView { builder in
|
|
52
54
|
builder.config = config
|
|
55
|
+
// Lynx's engine thread, which runs the main thread's JavaScript (the
|
|
56
|
+
// whole Angular app), layout and Lynx's animator, gets a thread of its
|
|
57
|
+
// own. Lynx's default, AllOnUI, runs it on the UI thread, where change
|
|
58
|
+
// detection, a screen being built or a long event handler took frames
|
|
59
|
+
// from what UIKit runs itself: a scroll view's momentum, typing, a web
|
|
60
|
+
// view. Off it, the element tree reaches the screen a step later, once
|
|
61
|
+
// the flush crosses to the UI thread: the build plugin turns on Lynx's
|
|
62
|
+
// pending invokes so UI methods follow it, and the runtime sets
|
|
63
|
+
// enable-async-list on every <list>, which this strategy requires.
|
|
64
|
+
builder.setThreadStrategyForRender(.mostOnTASM)
|
|
53
65
|
// Lets main-thread code, where Angular runs, call the config's modules
|
|
54
|
-
// with lynx.module(name): WebGL needs answers synchronously.
|
|
66
|
+
// with lynx.module(name): WebGL needs answers synchronously. Lynx calls
|
|
67
|
+
// them on its engine thread, not the UI thread (see AngularLynxWebGL.h).
|
|
55
68
|
builder.enableMTSModule = true
|
|
56
69
|
builder.screenSize = screenSize
|
|
57
70
|
builder.fontScale = 1.0
|
|
@@ -73,6 +86,11 @@ final class LynxViewController: UIViewController {
|
|
|
73
86
|
// server's, which it loads again on every edit.
|
|
74
87
|
let templateURL = DevServer.shared.templateURL
|
|
75
88
|
lynxView.loadTemplate(fromURL: templateURL, initData: nil)
|
|
89
|
+
// The launch screen, over the LynxView until the app's first screen is
|
|
90
|
+
// drawn: iOS takes its own down at the first frame, which is the empty
|
|
91
|
+
// LynxView (SplashScreen.swift). The development build's messages go
|
|
92
|
+
// over it.
|
|
93
|
+
SplashScreen.shared.show(over: view)
|
|
76
94
|
DevServer.shared.attach(to: view) { [weak self] in
|
|
77
95
|
self?.lynxView?.loadTemplate(fromURL: templateURL, initData: nil)
|
|
78
96
|
}
|
|
@@ -14,11 +14,18 @@ import UIKit
|
|
|
14
14
|
/// memory pressure, so this reports a moderate one. The runtime asks once it
|
|
15
15
|
/// has released about a screen's worth of elements and the app has settled
|
|
16
16
|
/// (`collect-garbage.ts` in `packages/runtime`).
|
|
17
|
+
///
|
|
18
|
+
/// `hideSplashScreen` fades out the copy of the launch screen the shell keeps
|
|
19
|
+
/// over the app until its first screen is ready (SplashScreen.swift). The
|
|
20
|
+
/// runtime's LynxSplashScreen calls it.
|
|
17
21
|
final class ShellModule: NSObject, LynxModule {
|
|
18
22
|
static var name: String { "AngularLynxShell" }
|
|
19
23
|
|
|
20
24
|
static var methodLookup: [String: String] {
|
|
21
|
-
[
|
|
25
|
+
[
|
|
26
|
+
"collectGarbage": NSStringFromSelector(#selector(collectGarbage)),
|
|
27
|
+
"hideSplashScreen": NSStringFromSelector(#selector(hideSplashScreen)),
|
|
28
|
+
]
|
|
22
29
|
}
|
|
23
30
|
|
|
24
31
|
override init() {
|
|
@@ -39,4 +46,10 @@ final class ShellModule: NSObject, LynxModule {
|
|
|
39
46
|
LynxEnv.sharedInstance().trimMemory(.moderate)
|
|
40
47
|
}
|
|
41
48
|
}
|
|
49
|
+
|
|
50
|
+
@objc func hideSplashScreen() {
|
|
51
|
+
DispatchQueue.main.async {
|
|
52
|
+
SplashScreen.shared.hide()
|
|
53
|
+
}
|
|
54
|
+
}
|
|
42
55
|
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import UIKit
|
|
2
|
+
|
|
3
|
+
/// Keeps the launch screen up until the app's first screen is ready.
|
|
4
|
+
///
|
|
5
|
+
/// iOS takes the launch screen down as soon as the app draws its first
|
|
6
|
+
/// frame, which is the empty LynxView: the bundle hasn't run yet, and the
|
|
7
|
+
/// app's first screen may have work to finish first, such as a lazy route or
|
|
8
|
+
/// a guard. So the shell puts a copy of the launch screen over the LynxView
|
|
9
|
+
/// (UILaunchScreen's color and image, from the asset catalog, laid out as iOS
|
|
10
|
+
/// lays them out), and fades it out when the runtime says the screen under
|
|
11
|
+
/// it is drawn: `ShellModule.hideSplashScreen`, which the runtime's
|
|
12
|
+
/// LynxSplashScreen calls after the first frame Angular commits, or when the
|
|
13
|
+
/// app's `provideSplashScreen()` says.
|
|
14
|
+
///
|
|
15
|
+
/// A host the runtime can't reach never asks, so the copy also goes after
|
|
16
|
+
/// `timeout`, rather than leave the app behind its logo.
|
|
17
|
+
final class SplashScreen {
|
|
18
|
+
static let shared = SplashScreen()
|
|
19
|
+
|
|
20
|
+
/// The longest the copy stays up: enough for a slow first screen, short
|
|
21
|
+
/// enough that one that never settles doesn't look like a hung app.
|
|
22
|
+
static let timeout: TimeInterval = 5
|
|
23
|
+
/// The fade, as long as UIKit's own transitions.
|
|
24
|
+
private static let fadeDuration: TimeInterval = 0.25
|
|
25
|
+
|
|
26
|
+
private weak var overlay: UIView?
|
|
27
|
+
|
|
28
|
+
private init() {}
|
|
29
|
+
|
|
30
|
+
/// Puts the copy over everything in `view`, now and until it's hidden.
|
|
31
|
+
func show(over view: UIView) {
|
|
32
|
+
let overlay = UIView(frame: view.bounds)
|
|
33
|
+
overlay.autoresizingMask = [.flexibleWidth, .flexibleHeight]
|
|
34
|
+
// The same names Info.plist's UILaunchScreen reads, so the two match.
|
|
35
|
+
// Both follow dark mode, as the launch screen does.
|
|
36
|
+
overlay.backgroundColor = UIColor(named: "LaunchBackground") ?? .systemBackground
|
|
37
|
+
// An app without angular.json's splash.image has none: the color alone.
|
|
38
|
+
if let image = UIImage(named: "LaunchImage") {
|
|
39
|
+
let imageView = UIImageView(image: image)
|
|
40
|
+
// At its natural size, centered on the whole screen, as the launch
|
|
41
|
+
// screen draws it (UIImageRespectsSafeAreaInsets is false).
|
|
42
|
+
imageView.center = CGPoint(x: overlay.bounds.midX, y: overlay.bounds.midY)
|
|
43
|
+
imageView.autoresizingMask = [
|
|
44
|
+
.flexibleLeftMargin, .flexibleRightMargin, .flexibleTopMargin, .flexibleBottomMargin,
|
|
45
|
+
]
|
|
46
|
+
overlay.addSubview(imageView)
|
|
47
|
+
}
|
|
48
|
+
// VoiceOver has nothing to read until the app is there.
|
|
49
|
+
overlay.isAccessibilityElement = false
|
|
50
|
+
view.addSubview(overlay)
|
|
51
|
+
self.overlay = overlay
|
|
52
|
+
|
|
53
|
+
DispatchQueue.main.asyncAfter(deadline: .now() + Self.timeout) { [weak self] in
|
|
54
|
+
self?.hide()
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/// Fades the copy out. Main thread only. Once it's gone, does nothing: the
|
|
59
|
+
/// development build loads the app again on every edit, and each load
|
|
60
|
+
/// asks.
|
|
61
|
+
func hide() {
|
|
62
|
+
guard let overlay else { return }
|
|
63
|
+
self.overlay = nil
|
|
64
|
+
// Reduce Motion keeps the fade, as UIKit's cross-dissolves do: it moves
|
|
65
|
+
// nothing.
|
|
66
|
+
UIView.animate(
|
|
67
|
+
withDuration: Self.fadeDuration, delay: 0, options: [.curveEaseOut],
|
|
68
|
+
animations: { overlay.alpha = 0 },
|
|
69
|
+
completion: { _ in overlay.removeFromSuperview() })
|
|
70
|
+
}
|
|
71
|
+
}
|