@blotch/angular-lynx-native 22.3.0 → 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.
- package/README.md +41 -15
- package/dist/android/project.d.ts +90 -1
- package/dist/android/project.d.ts.map +1 -1
- package/dist/android/project.js +369 -5
- package/dist/eject.d.ts +15 -1
- package/dist/eject.d.ts.map +1 -1
- package/dist/eject.js +13 -2
- package/dist/features.d.ts +70 -0
- package/dist/features.d.ts.map +1 -0
- package/dist/features.js +115 -0
- package/dist/generate.d.ts +17 -1
- package/dist/generate.d.ts.map +1 -1
- package/dist/generate.js +12 -4
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -1
- 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 +173 -11
- package/dist/ios/project.d.ts.map +1 -1
- package/dist/ios/project.js +767 -33
- package/dist/options.d.ts +143 -2
- package/dist/options.d.ts.map +1 -1
- package/dist/options.js +127 -0
- package/dist/permissions.d.ts +18 -1
- package/dist/permissions.d.ts.map +1 -1
- package/dist/permissions.js +63 -3
- package/package.json +1 -1
- package/templates/android/README.md +37 -2
- package/templates/android/angular-lynx.properties +2 -0
- package/templates/android/app/build.gradle.kts +70 -1
- package/templates/android/app/src/main/AndroidManifest.xml +24 -3
- 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/FilePickerModule.kt +263 -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/MainActivity.kt +376 -6
- 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/NfcModule.kt +274 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/PermissionRequests.kt +25 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/PhotoLibraryModule.kt +168 -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 +6 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/ShellModule.kt +47 -3
- 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/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/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/AppDelegate.swift +34 -2
- package/templates/ios/App/AppleSignInButton.swift +106 -0
- package/templates/ios/App/AppleSignInModule.swift +222 -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/HapticsModule.swift +90 -0
- package/templates/ios/App/Info.plist +2 -0
- package/templates/ios/App/LynxViewController.swift +210 -6
- package/templates/ios/App/MotionModule.swift +430 -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
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
package dev.angularlynx.shell
|
|
2
|
+
|
|
3
|
+
import android.graphics.Bitmap
|
|
4
|
+
import android.graphics.Canvas
|
|
5
|
+
import android.graphics.Color
|
|
6
|
+
import com.lynx.react.bridge.ReadableMap
|
|
7
|
+
import com.lynx.react.bridge.ReadableType
|
|
8
|
+
import java.io.ByteArrayOutputStream
|
|
9
|
+
import java.nio.ByteBuffer
|
|
10
|
+
import java.nio.ByteOrder
|
|
11
|
+
import kotlin.math.max
|
|
12
|
+
import kotlin.math.roundToInt
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* `<canvas>`'s bitmaprenderer context for the AngularLynx runtime
|
|
16
|
+
* (packages/runtime/src/lib/canvas/bitmap-renderer-context.ts):
|
|
17
|
+
* ImageBitmapRenderingContext, which shows an ImageBitmap in the canvas.
|
|
18
|
+
*
|
|
19
|
+
* An ImageBitmap's pixels live in the shell, as a decoded image WebGLModule
|
|
20
|
+
* keeps by id (`decodeImage`, `imageFromCanvas`). transferFromImageBitmap()
|
|
21
|
+
* detaches the bitmap and hands its id to the context, which takes the image
|
|
22
|
+
* from the module, keeps it as a Bitmap, and shows it in the canvas's view as
|
|
23
|
+
* a 2D context shows its bitmap (BitmapPresenter). The canvas reads as what
|
|
24
|
+
* it shows: drawImage(), texImage2D(), createImageBitmap() and the encoders
|
|
25
|
+
* take its snapshot.
|
|
26
|
+
*
|
|
27
|
+
* Lynx calls the module on its engine thread; the view's surface comes and
|
|
28
|
+
* goes on the UI thread, which shows the bitmap again then. The context's
|
|
29
|
+
* lock keeps the two apart.
|
|
30
|
+
*/
|
|
31
|
+
class BitmapRendererContext(override val canvasId: String, attributes: ReadableMap?) : CanvasContext {
|
|
32
|
+
private val alpha = !(attributes != null && attributes.hasKey("alpha") &&
|
|
33
|
+
attributes.getType("alpha") == ReadableType.Boolean && !attributes.getBoolean("alpha"))
|
|
34
|
+
|
|
35
|
+
/** What the canvas shows, premultiplied, or null while it's blank. */
|
|
36
|
+
private var bitmap: Bitmap? = null
|
|
37
|
+
|
|
38
|
+
/** The blank's size: the canvas's, as the runtime last said. */
|
|
39
|
+
private var blankWidth = attributes.pixelSide("width", 300)
|
|
40
|
+
private var blankHeight = attributes.pixelSide("height", 150)
|
|
41
|
+
private var destroyed = false
|
|
42
|
+
private val presenter = BitmapPresenter(TAG)
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Shows [image], which the context owns from then on: as a Bitmap, which
|
|
46
|
+
* is what Android draws, composited over black for a context without
|
|
47
|
+
* alpha, as the spec shows one.
|
|
48
|
+
*/
|
|
49
|
+
@Synchronized
|
|
50
|
+
fun show(image: DecodedImage) {
|
|
51
|
+
if (destroyed) return
|
|
52
|
+
var shown = bitmapOf(image)
|
|
53
|
+
if (!alpha) {
|
|
54
|
+
val opaque = Bitmap.createBitmap(shown.width, shown.height, Bitmap.Config.ARGB_8888)
|
|
55
|
+
opaque.eraseColor(Color.BLACK)
|
|
56
|
+
Canvas(opaque).drawBitmap(shown, 0f, 0f, null)
|
|
57
|
+
opaque.setHasAlpha(false)
|
|
58
|
+
shown.recycle()
|
|
59
|
+
shown = opaque
|
|
60
|
+
}
|
|
61
|
+
// The bitmap it replaces isn't recycled: the frame last posted to the
|
|
62
|
+
// surface may still draw it. The collector frees it.
|
|
63
|
+
bitmap = shown
|
|
64
|
+
present()
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Shows a blank canvas of [width] by [height]. */
|
|
68
|
+
@Synchronized
|
|
69
|
+
fun showBlank(width: Int, height: Int) {
|
|
70
|
+
if (destroyed) return
|
|
71
|
+
bitmap = null
|
|
72
|
+
blankWidth = max(0, width)
|
|
73
|
+
blankHeight = max(0, height)
|
|
74
|
+
present()
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
@Synchronized
|
|
78
|
+
fun destroy() {
|
|
79
|
+
if (destroyed) return
|
|
80
|
+
destroyed = true
|
|
81
|
+
presenter.release()
|
|
82
|
+
bitmap?.recycle()
|
|
83
|
+
bitmap = null
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// --- Showing it ----------------------------------------------------------
|
|
87
|
+
|
|
88
|
+
@Synchronized
|
|
89
|
+
override fun attachView(canvas: CanvasUI?) {
|
|
90
|
+
if (presenter.attach(canvas, !alpha)) surfaceChanged()
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
@Synchronized
|
|
94
|
+
override fun surfaceChanged() {
|
|
95
|
+
if (destroyed) return
|
|
96
|
+
if (presenter.surfaceChanged()) present()
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** A blank canvas without alpha is opaque black; with alpha, nothing. */
|
|
100
|
+
private fun present() =
|
|
101
|
+
presenter.present(bitmap, if (bitmap == null && !alpha) Color.BLACK else Color.TRANSPARENT)
|
|
102
|
+
|
|
103
|
+
// --- Reading it ----------------------------------------------------------
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* A copy of what the canvas shows, rows top to bottom: readers change
|
|
107
|
+
* the pixels they're given (createImageBitmap's options do).
|
|
108
|
+
*/
|
|
109
|
+
@Synchronized
|
|
110
|
+
override fun snapshot(): DecodedImage? {
|
|
111
|
+
val source = bitmap
|
|
112
|
+
if (source == null) {
|
|
113
|
+
val bytes = rgbaByteCount(blankWidth, blankHeight) ?: return null
|
|
114
|
+
if (bytes == 0) return null
|
|
115
|
+
val pixels = ByteBuffer.allocateDirect(bytes).order(ByteOrder.nativeOrder())
|
|
116
|
+
if (!alpha) for (i in 3 until bytes step 4) pixels.put(i, 0xff.toByte())
|
|
117
|
+
return DecodedImage(pixels, blankWidth, blankHeight, true)
|
|
118
|
+
}
|
|
119
|
+
val pixels = ByteBuffer.allocateDirect(source.width * source.height * 4).order(ByteOrder.nativeOrder())
|
|
120
|
+
// ARGB_8888 is R, G, B, A in memory, premultiplied.
|
|
121
|
+
source.copyPixelsToBuffer(pixels)
|
|
122
|
+
pixels.rewind()
|
|
123
|
+
return DecodedImage(pixels, source.width, source.height, true)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* After OffscreenCanvas.transferToImageBitmap() took the bitmap: the
|
|
128
|
+
* canvas is blank, as the runtime then says again with the size of the bitmap taken.
|
|
129
|
+
*/
|
|
130
|
+
@Synchronized
|
|
131
|
+
override fun clearForTransfer() {
|
|
132
|
+
bitmap = null
|
|
133
|
+
if (presenter.view != null) present()
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** What the canvas shows as a PNG or JPEG file, or null when it has no pixels. */
|
|
137
|
+
@Synchronized
|
|
138
|
+
fun encode(jpeg: Boolean, quality: Double): ByteArray? {
|
|
139
|
+
val shown = bitmap
|
|
140
|
+
val image = if (shown == null) {
|
|
141
|
+
if (blankWidth == 0 || blankHeight == 0) return null
|
|
142
|
+
Bitmap.createBitmap(blankWidth, blankHeight, Bitmap.Config.ARGB_8888).apply {
|
|
143
|
+
eraseColor(if (alpha && !jpeg) Color.TRANSPARENT else Color.BLACK)
|
|
144
|
+
}
|
|
145
|
+
} else if (jpeg && alpha) {
|
|
146
|
+
// A JPEG has no transparency: transparent pixels come out black,
|
|
147
|
+
// as in browsers.
|
|
148
|
+
Bitmap.createBitmap(shown.width, shown.height, Bitmap.Config.ARGB_8888).apply {
|
|
149
|
+
eraseColor(Color.BLACK)
|
|
150
|
+
Canvas(this).drawBitmap(shown, 0f, 0f, null)
|
|
151
|
+
}
|
|
152
|
+
} else {
|
|
153
|
+
shown
|
|
154
|
+
}
|
|
155
|
+
try {
|
|
156
|
+
return ByteArrayOutputStream().use { output ->
|
|
157
|
+
val written = image.compress(
|
|
158
|
+
if (jpeg) Bitmap.CompressFormat.JPEG else Bitmap.CompressFormat.PNG,
|
|
159
|
+
(quality.coerceIn(0.0, 1.0) * 100).roundToInt(),
|
|
160
|
+
output,
|
|
161
|
+
)
|
|
162
|
+
if (written) output.toByteArray() else null
|
|
163
|
+
}
|
|
164
|
+
} finally {
|
|
165
|
+
if (image !== shown) image.recycle()
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
private companion object {
|
|
170
|
+
const val TAG = "AngularLynxBitmapRenderer"
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
private fun ReadableMap?.pixelSide(key: String, default: Int): Int =
|
|
175
|
+
if (this != null && hasKey(key) && getType(key) in NUMBER_TYPES) max(0, getDouble(key).toInt()) else default
|