@blotch/angular-lynx-native 22.2.7 → 22.2.9
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 +2 -0
- package/package.json +2 -1
- package/templates/android/README.md +6 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/AssetsModule.kt +41 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/CanvasUI.kt +76 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/MainActivity.kt +9 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/WebGLContext.kt +1442 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/WebGLModule.kt +220 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/WebGLOps.kt +211 -0
- package/templates/ios/App/AngularLynxWebGL.h +80 -0
- package/templates/ios/App/AngularLynxWebGL.m +338 -0
- package/templates/ios/App/AngularLynxWebGLContext.m +2220 -0
- package/templates/ios/App/AngularLynxWebGLOps.h +209 -0
- package/templates/ios/App/AssetsModule.swift +53 -0
- package/templates/ios/App/LynxViewController.swift +11 -0
- package/templates/ios/App/XElementRegistry.swift +6 -1
package/README.md
CHANGED
|
@@ -23,6 +23,8 @@ Both register the native modules the runtime's services call, which Lynx Explore
|
|
|
23
23
|
|
|
24
24
|
Both link Lynx's XElement library, which holds `<input>`, `<textarea>`, `<overlay>`, `<svg>`, `<blur-view>`, `<viewpager>`, `<refresh>`, the `<scroll-coordinator>` family, `<webview>` and `<video>`. Lynx's core doesn't include these, and a host that doesn't register them renders nothing for those tags (on Android, nothing after them either). XElement's AnimaX and Markdown elements are left out: the runtime doesn't support them. On iOS, `<blur-view>` is XElement's with more of UIKit in it (`App/BlurView.swift`): a `blur-material` attribute for UIKit's adaptive blur materials, which the glass components draw their design before iOS 26 on (Lynx's blur-view has only the styles from before iOS 13); Liquid Glass that materializes, dissolves and eases between effects inside a `glass-container`, where Lynx's sets its effect at once; and a `glass-effect-id` attribute that pairs two glass shapes across a change so one morphs into the other (`App/GlassTransitions.swift`).
|
|
25
25
|
|
|
26
|
+
Both have `<canvas>` with WebGL2 (issue #211), which Lynx doesn't: a `canvas` element (`App/AngularLynxWebGL.m`'s `AngularLynxCanvas`, a `CAEAGLLayer` view; `CanvasUI.kt`, a `TextureView`) and the `AngularLynxWebGL` module the runtime's WebGL2 context sends its calls to, which runs them on OpenGL ES 3.0 (`App/AngularLynxWebGLContext.m`, `WebGLContext.kt`). The runtime runs on Lynx's main thread and WebGL needs answers synchronously, so both turn on main-thread modules (`enableMTSModule`): the config's modules are then callable from main-thread JavaScript as `lynx.module(name)`. `AngularLynxAssets` (`App/AssetsModule.swift`, `AssetsModule.kt`) reads a file the app bundles for the main thread's `fetch`, which has no page URL to resolve `/static/...` against. The command numbers the WebGL module reads (`App/AngularLynxWebGLOps.h`, `WebGLOps.kt`) are generated from the runtime's `canvas/webgl-ops.ts` with `npm run generate:webgl-ops -w packages/native`; `scripts/webgl-ops.test.ts` fails when they're stale. OpenGL ES is deprecated on iOS but still in the SDK; `GLES_SILENCE_DEPRECATION` keeps each call from warning.
|
|
27
|
+
|
|
26
28
|
| | iOS | Android |
|
|
27
29
|
| ---------------- | ---------------------------------------------------- | -------------------------------------------------------- |
|
|
28
30
|
| Language | Swift, scene lifecycle | Kotlin |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blotch/angular-lynx-native",
|
|
3
|
-
"version": "22.2.
|
|
3
|
+
"version": "22.2.9",
|
|
4
4
|
"description": "Builds AngularLynx apps into iOS and Android binaries",
|
|
5
5
|
"homepage": "https://github.com/Blotch-Smart-Frames/AngularLynx#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
"format:check": "oxfmt --check .",
|
|
39
39
|
"cspell": "cspell .",
|
|
40
40
|
"generate:ios-project": "vite build",
|
|
41
|
+
"generate:webgl-ops": "node scripts/webgl-ops.ts",
|
|
41
42
|
"build:lynx-ios-frameworks": "scripts/build-lynx-ios-frameworks.sh",
|
|
42
43
|
"publish:local": "yalc publish --push"
|
|
43
44
|
},
|
|
@@ -47,6 +47,12 @@ Back is off by default, so it leaves the app like any root screen. The runtime t
|
|
|
47
47
|
|
|
48
48
|
iOS's `LocalStorageModule.swift` uses a `UserDefaults` suite and `SecureStorageModule.swift` the Keychain, readable after the first unlock and never moved to another device.
|
|
49
49
|
|
|
50
|
+
## Canvas and WebGL
|
|
51
|
+
|
|
52
|
+
`<canvas>` (issue #211) is the shell's: `CanvasUI.kt`, a `TextureView` registered as the `canvas` element (`addBehavior(CanvasUI.behavior())`), and `WebGLModule.kt`, the `AngularLynxWebGL` module the runtime's WebGL2 context sends its calls to. `MainActivity` turns on main-thread modules (`setEnableMTSModule(true)`), so the runtime, which runs on Lynx's main thread, calls the module synchronously with `lynx.module(name)`, on the UI thread. Each context (`WebGLContext.kt`) is an EGL context with OpenGL ES 3.0 and an offscreen default framebuffer, which `present` copies into the canvas's surface; `WebGLOps.kt` is generated from the runtime's opcodes (`npm run generate:webgl-ops -w packages/native`). `AssetsModule.kt` (`AngularLynxAssets`) reads a file the app bundles for the main thread's `fetch`, which has no page URL to resolve `/static/...` against.
|
|
53
|
+
|
|
54
|
+
Android's GLES has no 2D uploads from a `PIXEL_UNPACK_BUFFER` and no `glGetVertexAttribPointerv`, so those log a warning and answer 0.
|
|
55
|
+
|
|
50
56
|
## Global props
|
|
51
57
|
|
|
52
58
|
`MainActivity.globalProps()` sends what the runtime reads and Lynx has no API for (see the package README), again on every configuration change and accessibility setting change.
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
package dev.angularlynx.shell
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import com.lynx.jsbridge.LynxMethod
|
|
5
|
+
import com.lynx.jsbridge.LynxModule
|
|
6
|
+
import com.lynx.react.bridge.JavaOnlyArray
|
|
7
|
+
import java.io.IOException
|
|
8
|
+
import java.nio.ByteBuffer
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The `AngularLynxAssets` module: a file the app bundles (`/static/...`),
|
|
12
|
+
* read for the runtime's main-thread `fetch` and `Image`, which load a
|
|
13
|
+
* texture or a glTF model the app imports. The app's `dist/` is in the APK's
|
|
14
|
+
* assets, not on a server, so a URL relative to it has nowhere to be fetched
|
|
15
|
+
* from; BundleAssets maps it to the asset, as it does for Lynx's own
|
|
16
|
+
* `<image>`.
|
|
17
|
+
*
|
|
18
|
+
* Called from the main thread, synchronously (`lynx.module(name)`), like the
|
|
19
|
+
* WebGL module: the runtime turns the answer into a Response.
|
|
20
|
+
*/
|
|
21
|
+
class AssetsModule(context: Context, param: Any?) : LynxModule(context, param) {
|
|
22
|
+
/**
|
|
23
|
+
* The file's bytes as 32-bit words with the byte count last (see toWords
|
|
24
|
+
* in the runtime's webgl-bridge.ts: Lynx's bridge carries no binary), or
|
|
25
|
+
* null when the app doesn't bundle it.
|
|
26
|
+
*/
|
|
27
|
+
@LynxMethod
|
|
28
|
+
fun read(url: String): JavaOnlyArray? {
|
|
29
|
+
val path = BundleAssets.assetPath(url) ?: return null
|
|
30
|
+
return try {
|
|
31
|
+
val bytes = BundleAssets.read(mContext, path)
|
|
32
|
+
wordsFromBytes(ByteBuffer.wrap(bytes), bytes.size)
|
|
33
|
+
} catch (_: IOException) {
|
|
34
|
+
null
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
companion object {
|
|
39
|
+
const val NAME = "AngularLynxAssets"
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
package dev.angularlynx.shell
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.graphics.SurfaceTexture
|
|
5
|
+
import android.view.TextureView
|
|
6
|
+
import com.lynx.tasm.behavior.Behavior
|
|
7
|
+
import com.lynx.tasm.behavior.LynxContext
|
|
8
|
+
import com.lynx.tasm.behavior.LynxProp
|
|
9
|
+
import com.lynx.tasm.behavior.ui.LynxUI
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The `canvas` element: a TextureView its WebGL context (WebGLContext) copies
|
|
13
|
+
* each finished frame into. Its `canvas-id` attribute, which the runtime
|
|
14
|
+
* sets, pairs it with the context the runtime made for it.
|
|
15
|
+
*
|
|
16
|
+
* A TextureView composites with the views around it, so a canvas can sit
|
|
17
|
+
* under or over other elements and take their rounded corners and opacity.
|
|
18
|
+
*/
|
|
19
|
+
class CanvasUI(context: LynxContext) : LynxUI<TextureView>(context) {
|
|
20
|
+
private var canvasId: String? = null
|
|
21
|
+
|
|
22
|
+
/** The view's surface, while it has one. */
|
|
23
|
+
var surface: SurfaceTexture? = null
|
|
24
|
+
private set
|
|
25
|
+
|
|
26
|
+
override fun createView(context: Context): TextureView =
|
|
27
|
+
TextureView(context).apply {
|
|
28
|
+
isOpaque = false
|
|
29
|
+
surfaceTextureListener = object : TextureView.SurfaceTextureListener {
|
|
30
|
+
override fun onSurfaceTextureAvailable(texture: SurfaceTexture, width: Int, height: Int) {
|
|
31
|
+
surface = texture
|
|
32
|
+
contextOrNull()?.surfaceChanged()
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
override fun onSurfaceTextureSizeChanged(texture: SurfaceTexture, width: Int, height: Int) {
|
|
36
|
+
contextOrNull()?.surfaceChanged()
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
override fun onSurfaceTextureDestroyed(texture: SurfaceTexture): Boolean {
|
|
40
|
+
// The context lets go of its EGL surface first.
|
|
41
|
+
surface = null
|
|
42
|
+
contextOrNull()?.surfaceChanged()
|
|
43
|
+
return true
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
override fun onSurfaceTextureUpdated(texture: SurfaceTexture) {}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
private fun contextOrNull(): WebGLContext? = canvasId?.let { CanvasRegistry.context(it) }
|
|
51
|
+
|
|
52
|
+
/** Whether the frames can be shown see-through, as the context's `alpha` asks. */
|
|
53
|
+
fun setOpaque(opaque: Boolean) {
|
|
54
|
+
view.isOpaque = opaque
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@LynxProp(name = "canvas-id")
|
|
58
|
+
fun setCanvasId(value: String?) {
|
|
59
|
+
if (value == canvasId) return
|
|
60
|
+
canvasId?.let { old -> if (CanvasRegistry.view(old) === this) CanvasRegistry.setView(old, null) }
|
|
61
|
+
canvasId = value
|
|
62
|
+
value?.let { CanvasRegistry.setView(it, this) }
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
override fun destroy() {
|
|
66
|
+
canvasId?.let { id -> if (CanvasRegistry.view(id) === this) CanvasRegistry.setView(id, null) }
|
|
67
|
+
super.destroy()
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
companion object {
|
|
71
|
+
/** Registers the element under `canvas`, which Lynx's core doesn't have. */
|
|
72
|
+
fun behavior(): Behavior = object : Behavior("canvas") {
|
|
73
|
+
override fun createUI(context: LynxContext): LynxUI<*> = CanvasUI(context)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -84,10 +84,19 @@ class MainActivity : ComponentActivity(), ShellModule.Host, WebAuthModule.Host {
|
|
|
84
84
|
registerModule(WebAuthModule.NAME, WebAuthModule::class.java, this@MainActivity)
|
|
85
85
|
registerModule(LocalStorageModule.NAME, LocalStorageModule::class.java, null)
|
|
86
86
|
registerModule(SecureStorageModule.NAME, SecureStorageModule::class.java, null)
|
|
87
|
+
// <canvas>'s WebGL (WebGLModule.kt), which the runtime calls from
|
|
88
|
+
// the main thread, where Angular runs: main-thread modules let
|
|
89
|
+
// it get its answers synchronously, with lynx.module(name).
|
|
90
|
+
registerModule(WebGLModule.NAME, WebGLModule::class.java, null)
|
|
91
|
+
// Bundled files for the main thread's fetch and Image (AssetsModule.kt).
|
|
92
|
+
registerModule(AssetsModule.NAME, AssetsModule::class.java, null)
|
|
93
|
+
setEnableMTSModule(true)
|
|
87
94
|
// Lynx's core has no <input>, <overlay>, <svg>, <blur-view> etc.;
|
|
88
95
|
// these come from XElement (see app/build.gradle.kts). Lynx
|
|
89
96
|
// Explorer registers them the same way.
|
|
90
97
|
addBehaviors(XElementBehaviors().create())
|
|
98
|
+
// The shell's own <canvas> (CanvasUI.kt): Lynx has none.
|
|
99
|
+
addBehavior(CanvasUI.behavior())
|
|
91
100
|
}.build(this)
|
|
92
101
|
lynxView.addLynxViewClient(object : LynxViewClient() {
|
|
93
102
|
override fun onReceivedError(error: LynxError?) {
|