@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
|
@@ -13,9 +13,12 @@ import android.os.Handler
|
|
|
13
13
|
import android.os.Looper
|
|
14
14
|
import android.provider.Settings
|
|
15
15
|
import android.util.Log
|
|
16
|
+
import android.util.Size
|
|
17
|
+
import android.view.MotionEvent
|
|
18
|
+
import android.view.View.MeasureSpec
|
|
16
19
|
import android.view.accessibility.AccessibilityManager
|
|
17
20
|
import android.widget.FrameLayout
|
|
18
|
-
import androidx.activity.
|
|
21
|
+
import androidx.activity.BackEventCompat
|
|
19
22
|
import androidx.activity.OnBackPressedCallback
|
|
20
23
|
import androidx.activity.result.PickVisualMediaRequest
|
|
21
24
|
import androidx.activity.result.contract.ActivityResultContracts
|
|
@@ -26,7 +29,10 @@ import androidx.core.os.ConfigurationCompat
|
|
|
26
29
|
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
|
|
27
30
|
import androidx.core.view.ViewCompat
|
|
28
31
|
import androidx.core.view.WindowInsetsCompat
|
|
32
|
+
import androidx.fragment.app.FragmentActivity
|
|
33
|
+
import com.lynx.jsbridge.LynxModule
|
|
29
34
|
import com.lynx.react.bridge.JavaOnlyArray
|
|
35
|
+
import com.lynx.react.bridge.JavaOnlyMap
|
|
30
36
|
import com.lynx.tasm.LynxBooleanOption
|
|
31
37
|
import com.lynx.tasm.LynxError
|
|
32
38
|
import com.lynx.tasm.LynxView
|
|
@@ -38,20 +44,67 @@ import com.lynx.xelement.XElementBehaviors
|
|
|
38
44
|
/**
|
|
39
45
|
* The whole app: one full-screen LynxView running the Angular app. Angular
|
|
40
46
|
* Router navigates inside it, so there is no native navigation stack.
|
|
47
|
+
*
|
|
48
|
+
* A FragmentActivity, which is a ComponentActivity, because AndroidX's
|
|
49
|
+
* BiometricPrompt (BiometricsModule) shows as a fragment over one. AppCompat,
|
|
50
|
+
* which XElement needs, brings the fragment library to every app anyway.
|
|
41
51
|
*/
|
|
42
|
-
class MainActivity :
|
|
52
|
+
class MainActivity : FragmentActivity(), ShellModule.Host, WebAuthModule.Host {
|
|
43
53
|
private lateinit var lynxView: LynxView
|
|
44
54
|
|
|
55
|
+
// Android's hint that Lynx's engine thread has work coming, given at
|
|
56
|
+
// every touch (EngineThreadHint.kt). Android 12 and later.
|
|
57
|
+
private var engineThreadHint: EngineThreadHint? = null
|
|
58
|
+
|
|
45
59
|
// Whether the page draws under the system bars and the cutout:
|
|
46
60
|
// angular.json's edgeToEdge, which app/build.gradle.kts writes as a
|
|
47
61
|
// resource.
|
|
48
62
|
private val edgeToEdge by lazy { resources.getBoolean(R.bool.edge_to_edge) }
|
|
49
63
|
|
|
64
|
+
// Whether the app's text follows the system's font size, and the largest
|
|
65
|
+
// scale it takes (0 for no cap): angular.json's textScaling, which
|
|
66
|
+
// app/build.gradle.kts writes as resources.
|
|
67
|
+
private val textScaling by lazy { resources.getBoolean(R.bool.text_scaling) }
|
|
68
|
+
private val maxTextScale by lazy {
|
|
69
|
+
resources.getString(R.string.max_text_scale).toFloatOrNull() ?: 0f
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// The font scale the LynxView was built with, which Lynx gives each engine
|
|
73
|
+
// it sets up (see onLoadSuccess below).
|
|
74
|
+
private var builtFontScale = 1f
|
|
75
|
+
|
|
50
76
|
// The safe-area insets, and whether the screen has a cutout, as the
|
|
51
77
|
// window last reported them. Sent in the global props.
|
|
52
78
|
private var safeArea = Insets.NONE
|
|
53
79
|
private var hasCutout = false
|
|
54
80
|
|
|
81
|
+
// The window's size and the LynxView's, in px, as the container was last
|
|
82
|
+
// measured (see updateSizes). Null until the first measure.
|
|
83
|
+
private var windowSize: Size? = null
|
|
84
|
+
private var viewportSize: Size? = null
|
|
85
|
+
|
|
86
|
+
// Where the app is, for LynxAppState, sent in the global props and again
|
|
87
|
+
// as the activity's lifecycle moves: "active" from onResume, "inactive"
|
|
88
|
+
// from onPause and onStart, and "background" from onStop. It starts
|
|
89
|
+
// "inactive": the first props go out from onCreate, on the way onto the
|
|
90
|
+
// screen. From Android 10, both apps in split screen stay resumed, so
|
|
91
|
+
// onPause doesn't run when the other one takes the focus: a resumed
|
|
92
|
+
// activity is "inactive" too while it isn't the top resumed one
|
|
93
|
+
// (onTopResumedActivityChanged, which older Androids never call).
|
|
94
|
+
private var appState = "inactive"
|
|
95
|
+
private var resumed = false
|
|
96
|
+
|
|
97
|
+
// Whether this is the top resumed activity. Android 10 and later call
|
|
98
|
+
// onTopResumedActivityChanged(true) after onResume once it is, but never
|
|
99
|
+
// say false first, so it starts false there: an activity started without
|
|
100
|
+
// the focus in split screen stays "inactive". Older Androids never call
|
|
101
|
+
// it, so a resumed activity is the one with the focus.
|
|
102
|
+
private var topResumed = Build.VERSION.SDK_INT < Build.VERSION_CODES.Q
|
|
103
|
+
|
|
104
|
+
// Whether the phone is online, for LynxNetwork: sent in the global props,
|
|
105
|
+
// and again each time it changes. Closed in onDestroy.
|
|
106
|
+
private var networkStatus: NetworkStatus? = null
|
|
107
|
+
|
|
55
108
|
// Sends the accessibility settings again when the user changes one while
|
|
56
109
|
// the app is open: Remove animations (the animator duration scale), the
|
|
57
110
|
// contrast level (Android 14) and high contrast text (Android 16). The
|
|
@@ -71,12 +124,52 @@ class MainActivity : ComponentActivity(), ShellModule.Host, WebAuthModule.Host {
|
|
|
71
124
|
|
|
72
125
|
// Disabled until the Angular app enables it (see ShellModule), so by
|
|
73
126
|
// default back leaves the app like any other root screen.
|
|
127
|
+
//
|
|
128
|
+
// While it's enabled, Android's predictive back gesture reaches the app
|
|
129
|
+
// as it goes, not only once it's done: a stack in the app moves its top
|
|
130
|
+
// page with the finger, as Android's own screens do, and brings it back
|
|
131
|
+
// if the gesture is canceled. Android sends these only for the gesture,
|
|
132
|
+
// on Android 14 and later; a press of the 3-button bar's back, or of a
|
|
133
|
+
// key, calls handleOnBackPressed() alone.
|
|
74
134
|
private val backHandler = object : OnBackPressedCallback(false) {
|
|
135
|
+
override fun handleOnBackStarted(backEvent: BackEventCompat) {
|
|
136
|
+
sendBackGesture("started", backEvent)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
override fun handleOnBackProgressed(backEvent: BackEventCompat) {
|
|
140
|
+
sendBackGesture("progressed", backEvent)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
override fun handleOnBackCancelled() {
|
|
144
|
+
sendBackGesture("canceled", null)
|
|
145
|
+
}
|
|
146
|
+
|
|
75
147
|
override fun handleOnBackPressed() {
|
|
76
148
|
lynxView.sendGlobalEvent(ShellModule.BACK_EVENT, JavaOnlyArray())
|
|
77
149
|
}
|
|
78
150
|
}
|
|
79
151
|
|
|
152
|
+
/**
|
|
153
|
+
* Sends a step of the back gesture as an `angularLynxBackGesture` global
|
|
154
|
+
* event: its phase, how far it's gone (0 to 1, eased by Android as its
|
|
155
|
+
* own screens use it) and the edge it came from.
|
|
156
|
+
*/
|
|
157
|
+
private fun sendBackGesture(phase: String, backEvent: BackEventCompat?) {
|
|
158
|
+
val event = JavaOnlyMap()
|
|
159
|
+
event.putString("phase", phase)
|
|
160
|
+
if (backEvent != null) {
|
|
161
|
+
event.putDouble("progress", backEvent.progress.toDouble())
|
|
162
|
+
event.putString(
|
|
163
|
+
"edge",
|
|
164
|
+
if (backEvent.swipeEdge == BackEventCompat.EDGE_RIGHT) "right" else "left",
|
|
165
|
+
)
|
|
166
|
+
}
|
|
167
|
+
lynxView.sendGlobalEvent(
|
|
168
|
+
ShellModule.BACK_GESTURE_EVENT,
|
|
169
|
+
JavaOnlyArray().apply { pushMap(event) },
|
|
170
|
+
)
|
|
171
|
+
}
|
|
172
|
+
|
|
80
173
|
// The open sign-in (see WebAuthModule): the scheme its page returns to,
|
|
81
174
|
// who to tell, and whether the app has gone behind the Custom Tab yet.
|
|
82
175
|
private class WebAuthSession(val scheme: String, val done: (WebAuthModule.Result) -> Unit) {
|
|
@@ -99,13 +192,127 @@ class MainActivity : ComponentActivity(), ShellModule.Host, WebAuthModule.Host {
|
|
|
99
192
|
imagePicked = null
|
|
100
193
|
done(uri)
|
|
101
194
|
}
|
|
195
|
+
// angular-lynx:image-picker-camera
|
|
196
|
+
// The camera app behind LynxImagePicker's source: 'camera', registered as
|
|
197
|
+
// the Photo Picker is. Only an app with permissions.camera keeps these
|
|
198
|
+
// lines (@blotch/angular-lynx-native's android/project.ts).
|
|
199
|
+
private var photoTaken: ((Boolean) -> Unit)? = null
|
|
200
|
+
private val camera = registerForActivityResult(ActivityResultContracts.TakePicture()) { taken ->
|
|
201
|
+
val done = photoTaken ?: return@registerForActivityResult
|
|
202
|
+
photoTaken = null
|
|
203
|
+
done(taken)
|
|
204
|
+
}
|
|
205
|
+
// /angular-lynx:image-picker-camera
|
|
102
206
|
private val imagePickerHost = object : ImagePickerModule.Host {
|
|
103
207
|
override fun pickImage(done: (Uri?) -> Unit): Boolean {
|
|
104
208
|
if (imagePicked != null) return false
|
|
209
|
+
// angular-lynx:image-picker-camera
|
|
210
|
+
// One of the two at a time, as takePicture checks the other way.
|
|
211
|
+
if (photoTaken != null) return false
|
|
212
|
+
// /angular-lynx:image-picker-camera
|
|
105
213
|
imagePicked = done
|
|
106
214
|
imagePicker.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly))
|
|
107
215
|
return true
|
|
108
216
|
}
|
|
217
|
+
|
|
218
|
+
// angular-lynx:image-picker-camera
|
|
219
|
+
override fun takePicture(output: Uri, done: (Boolean) -> Unit): Boolean {
|
|
220
|
+
if (photoTaken != null || imagePicked != null) return false
|
|
221
|
+
// Throws ActivityNotFoundException before anything is kept, so a
|
|
222
|
+
// phone without a camera app can try again.
|
|
223
|
+
camera.launch(output)
|
|
224
|
+
photoTaken = done
|
|
225
|
+
return true
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
override val permissions: PermissionHost get() = permissionHost
|
|
229
|
+
// /angular-lynx:image-picker-camera
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// Android's permission prompt, which the modules that need a runtime
|
|
233
|
+
// permission show through PermissionHost (PermissionRequests.kt), and who
|
|
234
|
+
// to tell what the person chose. Registered as the activity is created,
|
|
235
|
+
// as the Photo Picker's launcher is, and for the same reason.
|
|
236
|
+
private var permissionsAnswered: ((Map<String, Boolean>) -> Unit)? = null
|
|
237
|
+
private val permissionPrompt =
|
|
238
|
+
registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { results ->
|
|
239
|
+
val done = permissionsAnswered ?: return@registerForActivityResult
|
|
240
|
+
permissionsAnswered = null
|
|
241
|
+
done(results)
|
|
242
|
+
}
|
|
243
|
+
private val permissionHost = object : PermissionHost {
|
|
244
|
+
override fun requestPermissions(names: Array<String>, done: (Map<String, Boolean>) -> Unit): Boolean {
|
|
245
|
+
if (permissionsAnswered != null) return false
|
|
246
|
+
permissionsAnswered = done
|
|
247
|
+
permissionPrompt.launch(names)
|
|
248
|
+
return true
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
override fun canAskAgain(name: String): Boolean = shouldShowRequestPermissionRationale(name)
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// The document picker and save screen behind LynxFilePicker (see
|
|
255
|
+
// FilePickerModule), and who to tell what came back. Registered as the
|
|
256
|
+
// activity is created, as the Photo Picker is above. Only an app with
|
|
257
|
+
// angular.json's filePicker keeps these lines (@blotch/angular-lynx-native's
|
|
258
|
+
// android/project.ts).
|
|
259
|
+
// angular-lynx:file-picker
|
|
260
|
+
private var documentDone: ((Int, Intent?) -> Unit)? = null
|
|
261
|
+
private val documentLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
|
262
|
+
val done = documentDone ?: return@registerForActivityResult
|
|
263
|
+
documentDone = null
|
|
264
|
+
done(result.resultCode, result.data)
|
|
265
|
+
}
|
|
266
|
+
private val filePickerHost = object : FilePickerModule.Host {
|
|
267
|
+
override fun startDocumentActivity(intent: Intent, done: (Int, Intent?) -> Unit): Boolean {
|
|
268
|
+
if (documentDone != null) return false
|
|
269
|
+
documentDone = done
|
|
270
|
+
try {
|
|
271
|
+
documentLauncher.launch(intent)
|
|
272
|
+
} catch (error: ActivityNotFoundException) {
|
|
273
|
+
documentDone = null
|
|
274
|
+
throw error
|
|
275
|
+
}
|
|
276
|
+
return true
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
// /angular-lynx:file-picker
|
|
280
|
+
|
|
281
|
+
// angular-lynx:calendar
|
|
282
|
+
// The calendar app's editor (see CalendarModule), and who to tell how it
|
|
283
|
+
// closed. Registered as the activity is created, as the image picker's
|
|
284
|
+
// launcher is. Only an app whose angular.json sets calendar keeps these
|
|
285
|
+
// lines and the module (@blotch/angular-lynx-native's android/project.ts).
|
|
286
|
+
private var calendarEditorClosed: ((Int) -> Unit)? = null
|
|
287
|
+
private val calendarEditor = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
|
288
|
+
val done = calendarEditorClosed ?: return@registerForActivityResult
|
|
289
|
+
calendarEditorClosed = null
|
|
290
|
+
done(result.resultCode)
|
|
291
|
+
}
|
|
292
|
+
private val calendarHost = object : CalendarModule.Host {
|
|
293
|
+
override fun openCalendarEditor(intent: Intent, done: (Int) -> Unit): Boolean {
|
|
294
|
+
if (calendarEditorClosed != null) return false
|
|
295
|
+
// Throws ActivityNotFoundException before anything is kept, so a
|
|
296
|
+
// phone without a calendar app can try again.
|
|
297
|
+
calendarEditor.launch(intent)
|
|
298
|
+
calendarEditorClosed = done
|
|
299
|
+
return true
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
// /angular-lynx:calendar
|
|
303
|
+
|
|
304
|
+
// angular-lynx:share-target
|
|
305
|
+
// Tells the runtime's LynxShareTarget a share is waiting (see onCreate).
|
|
306
|
+
private val shareArrived: () -> Unit = {
|
|
307
|
+
lynxView.sendGlobalEvent(ShareTargetModule.EVENT, JavaOnlyArray())
|
|
308
|
+
}
|
|
309
|
+
// /angular-lynx:share-target
|
|
310
|
+
|
|
311
|
+
override fun dispatchTouchEvent(event: MotionEvent): Boolean {
|
|
312
|
+
// Before the touch reaches Lynx, so the engine thread is on its way
|
|
313
|
+
// to a faster core by the time the page's handler runs.
|
|
314
|
+
engineThreadHint?.touched(event)
|
|
315
|
+
return super.dispatchTouchEvent(event)
|
|
109
316
|
}
|
|
110
317
|
|
|
111
318
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
@@ -142,7 +349,18 @@ class MainActivity : ComponentActivity(), ShellModule.Host, WebAuthModule.Host {
|
|
|
142
349
|
intent.flags and Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY == 0
|
|
143
350
|
) {
|
|
144
351
|
ShortcutsModule.run(intent)
|
|
352
|
+
// angular-lynx:share-target
|
|
353
|
+
// A share that started the app, from another app's share sheet,
|
|
354
|
+
// waits for the runtime's LynxShareTarget to take it.
|
|
355
|
+
ShareTargetModule.receive(this, intent)
|
|
356
|
+
// /angular-lynx:share-target
|
|
145
357
|
}
|
|
358
|
+
// angular-lynx:share-target
|
|
359
|
+
// Reading a share's files takes a moment, and Android may recreate
|
|
360
|
+
// the activity meanwhile, so the event goes through whichever
|
|
361
|
+
// activity is current once they're read (ShareTargetModule.arrived).
|
|
362
|
+
ShareTargetModule.arrived = shareArrived
|
|
363
|
+
// /angular-lynx:share-target
|
|
146
364
|
// A link that started the app, which the router starts at. Unlike a
|
|
147
365
|
// shortcut it's read again when Android recreates the activity: the
|
|
148
366
|
// app starts again then, and a link tapped after Android ended the
|
|
@@ -158,6 +376,10 @@ class MainActivity : ComponentActivity(), ShellModule.Host, WebAuthModule.Host {
|
|
|
158
376
|
// The bundle in the app's assets, or in the debug build `ng serve
|
|
159
377
|
// --platform android` runs, the dev server's (DevServer.kt).
|
|
160
378
|
val bundleUrl = DevServer.bundleUrl(this) ?: BundleAssets.MAIN_BUNDLE
|
|
379
|
+
builtFontScale = textScale(resources.configuration)
|
|
380
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
|
381
|
+
engineThreadHint = EngineThreadHint(this)
|
|
382
|
+
}
|
|
161
383
|
lynxView = LynxViewBuilder().apply {
|
|
162
384
|
// Lynx's engine thread, which runs the main thread's JavaScript
|
|
163
385
|
// (the whole Angular app), layout and Lynx's animator, gets a
|
|
@@ -171,6 +393,10 @@ class MainActivity : ComponentActivity(), ShellModule.Host, WebAuthModule.Host {
|
|
|
171
393
|
// on every <list>, which this strategy requires. The iOS shell
|
|
172
394
|
// does the same.
|
|
173
395
|
setThreadStrategyForRendering(ThreadStrategyForRendering.MOST_ON_TASM)
|
|
396
|
+
// The user's font size (see textScale()). The build tells Lynx to
|
|
397
|
+
// scale only `sp` lengths by it, which the page's root font size
|
|
398
|
+
// is written in, so every rem grows with it and a px size doesn't.
|
|
399
|
+
setFontScale(builtFontScale)
|
|
174
400
|
setTemplateProvider(AssetTemplateProvider(this@MainActivity))
|
|
175
401
|
setTemplateResourceFetcher(AssetTemplateResourceFetcher(this@MainActivity))
|
|
176
402
|
setMediaResourceFetcher(AssetMediaResourceFetcher())
|
|
@@ -182,23 +408,143 @@ class MainActivity : ComponentActivity(), ShellModule.Host, WebAuthModule.Host {
|
|
|
182
408
|
registerModule(SecureStorageModule.NAME, SecureStorageModule::class.java, null)
|
|
183
409
|
// LynxClipboard's text (ClipboardModule.kt).
|
|
184
410
|
registerModule(ClipboardModule.NAME, ClipboardModule::class.java, null)
|
|
411
|
+
// LynxHaptics' taps (HapticsModule.kt), which play on this
|
|
412
|
+
// activity's window.
|
|
413
|
+
registerModule(HapticsModule.NAME, HapticsModule::class.java, this@MainActivity)
|
|
185
414
|
// Links out of the app (LinkingModule.kt), which it opens from this
|
|
186
415
|
// activity.
|
|
187
416
|
registerModule(LinkingModule.NAME, LinkingModule::class.java, this@MainActivity)
|
|
188
417
|
// The photo picker behind LynxImagePicker (ImagePickerModule.kt), which
|
|
189
418
|
// this activity launches.
|
|
190
419
|
registerModule(ImagePickerModule.NAME, ImagePickerModule::class.java, imagePickerHost)
|
|
420
|
+
// The document picker behind LynxFilePicker (FilePickerModule.kt),
|
|
421
|
+
// which this activity launches. Only an app with filePicker keeps
|
|
422
|
+
// these lines and the module.
|
|
423
|
+
// angular-lynx:file-picker
|
|
424
|
+
registerModule(FilePickerModule.NAME, FilePickerModule::class.java, filePickerHost)
|
|
425
|
+
// /angular-lynx:file-picker
|
|
191
426
|
// The share sheet behind LynxShare (ShareModule.kt), which it opens
|
|
192
427
|
// from this activity.
|
|
193
428
|
registerModule(ShareModule.NAME, ShareModule::class.java, this@MainActivity)
|
|
429
|
+
// Biometrics behind LynxBiometrics and LynxSecureStorage's
|
|
430
|
+
// requireBiometrics (BiometricsModule.kt), whose prompt shows over
|
|
431
|
+
// this activity. Only an app with permissions.biometrics keeps
|
|
432
|
+
// these lines and the module (@blotch/angular-lynx-native's
|
|
433
|
+
// android/project.ts).
|
|
434
|
+
// angular-lynx:biometrics
|
|
435
|
+
registerModule(BiometricsModule.NAME, BiometricsModule::class.java, this@MainActivity)
|
|
436
|
+
// /angular-lynx:biometrics
|
|
437
|
+
// Saving to the photo library behind LynxPhotoLibrary
|
|
438
|
+
// (PhotoLibraryModule.kt), which asks for the storage permission
|
|
439
|
+
// through this activity on Android 7 to 9. Only an app with
|
|
440
|
+
// permissions.savePhotos keeps these lines and the module
|
|
441
|
+
// (@blotch/angular-lynx-native's android/project.ts).
|
|
442
|
+
// angular-lynx:photo-library
|
|
443
|
+
registerModule(PhotoLibraryModule.NAME, PhotoLibraryModule::class.java, permissionHost)
|
|
444
|
+
// /angular-lynx:photo-library
|
|
445
|
+
// The code scanner behind LynxBarcodeScanner
|
|
446
|
+
// (BarcodeScannerModule.kt), which opens over this activity. Only
|
|
447
|
+
// an app whose angular.json sets permissions.camera has it: the
|
|
448
|
+
// generator deletes the file, and the Play services library it
|
|
449
|
+
// needs, from every other app (as the iOS shell leaves its module
|
|
450
|
+
// out, since App Store Connect flags an app whose code uses the
|
|
451
|
+
// camera without saying why). So it's looked up by name, which
|
|
452
|
+
// compiles either way, and nothing else may name the class.
|
|
453
|
+
// Lynx's own R8 rules keep every LynxModule's name, so a release
|
|
454
|
+
// build finds it too.
|
|
455
|
+
optionalModule(BARCODE_SCANNER_MODULE_CLASS)?.let {
|
|
456
|
+
registerModule(BARCODE_SCANNER_MODULE, it, this@MainActivity)
|
|
457
|
+
}
|
|
458
|
+
// Google Play's rating prompt behind LynxStoreReview
|
|
459
|
+
// (StoreReviewModule.kt), which it shows over this activity. An
|
|
460
|
+
// app whose angular.json doesn't set storeReview is built without
|
|
461
|
+
// the module, these lines and Play's review library
|
|
462
|
+
// (@blotch/angular-lynx-native's android/project.ts).
|
|
463
|
+
// angular-lynx:store-review
|
|
464
|
+
registerModule(StoreReviewModule.NAME, StoreReviewModule::class.java, this@MainActivity)
|
|
465
|
+
// /angular-lynx:store-review
|
|
466
|
+
// angular-lynx:calendar
|
|
467
|
+
// The calendar app's editor behind LynxCalendar (CalendarModule.kt),
|
|
468
|
+
// which this activity opens. An app whose angular.json doesn't set
|
|
469
|
+
// calendar is built without the module and these lines.
|
|
470
|
+
registerModule(CalendarModule.NAME, CalendarModule::class.java, calendarHost)
|
|
471
|
+
// /angular-lynx:calendar
|
|
472
|
+
// angular-lynx:tracking
|
|
473
|
+
// The advertising ID's opt-out behind LynxTracking
|
|
474
|
+
// (TrackingModule.kt). An app whose angular.json doesn't set
|
|
475
|
+
// permissions.tracking is built without the module, these lines
|
|
476
|
+
// and Play's advertising ID library.
|
|
477
|
+
registerModule(TrackingModule.NAME, TrackingModule::class.java, null)
|
|
478
|
+
// /angular-lynx:tracking
|
|
479
|
+
// angular-lynx:audio-recorder
|
|
480
|
+
// The microphone's recorder behind LynxAudioRecorder
|
|
481
|
+
// (AudioRecorderModule.kt), which asks for RECORD_AUDIO through
|
|
482
|
+
// this activity's prompt. An app whose angular.json doesn't set
|
|
483
|
+
// permissions.microphone is built without the module and these
|
|
484
|
+
// lines.
|
|
485
|
+
registerModule(AudioRecorderModule.NAME, AudioRecorderModule::class.java, permissionHost)
|
|
486
|
+
// /angular-lynx:audio-recorder
|
|
487
|
+
// angular-lynx:nfc
|
|
488
|
+
// NFC reader mode behind LynxNfc (NfcModule.kt), in this activity.
|
|
489
|
+
// An app whose angular.json doesn't set permissions.nfc is built
|
|
490
|
+
// without the module and these lines.
|
|
491
|
+
registerModule(NfcModule.NAME, NfcModule::class.java, this@MainActivity)
|
|
492
|
+
// /angular-lynx:nfc
|
|
493
|
+
// angular-lynx:wifi
|
|
494
|
+
// The Wi-Fi network reads and joins behind LynxWifi
|
|
495
|
+
// (WifiModule.kt), which asks for the location a read needs
|
|
496
|
+
// through this activity's prompt. An app whose angular.json
|
|
497
|
+
// doesn't set wifi is built without the module and these lines.
|
|
498
|
+
registerModule(WifiModule.NAME, WifiModule::class.java, permissionHost)
|
|
499
|
+
// /angular-lynx:wifi
|
|
500
|
+
// The motion sensors, the compass and shakes behind LynxMotion
|
|
501
|
+
// (MotionModule.kt), which stop while this activity is paused. An
|
|
502
|
+
// app whose angular.json doesn't set motion is built without the
|
|
503
|
+
// module and these lines (@blotch/angular-lynx-native's
|
|
504
|
+
// android/project.ts).
|
|
505
|
+
// angular-lynx:motion
|
|
506
|
+
registerModule(MotionModule.NAME, MotionModule::class.java, this@MainActivity)
|
|
507
|
+
// /angular-lynx:motion
|
|
194
508
|
// The shortcuts the person runs from the app icon's menu, which
|
|
195
509
|
// LynxShortcuts takes (ShortcutsModule.kt).
|
|
196
510
|
registerModule(ShortcutsModule.NAME, ShortcutsModule::class.java, null)
|
|
511
|
+
// angular-lynx:share-target
|
|
512
|
+
// What other apps share to this one, which LynxShareTarget takes
|
|
513
|
+
// (ShareTargetModule.kt). An app whose angular.json has no
|
|
514
|
+
// shareTarget is built without the module, its intent filters and
|
|
515
|
+
// these lines.
|
|
516
|
+
registerModule(ShareTargetModule.NAME, ShareTargetModule::class.java, null)
|
|
517
|
+
// /angular-lynx:share-target
|
|
518
|
+
// Bluetooth LE behind LynxBluetooth (BluetoothModule.kt), which
|
|
519
|
+
// asks for its permissions through this activity. Only an app
|
|
520
|
+
// whose angular.json sets permissions.bluetooth has it: the
|
|
521
|
+
// generator deletes the file from every other app, which then
|
|
522
|
+
// ships no Bluetooth code and its manifest declares no Bluetooth
|
|
523
|
+
// permission (the iOS shell does the same, since App Store Connect
|
|
524
|
+
// flags an app whose code uses CoreBluetooth without saying why).
|
|
525
|
+
// So it's looked up by name, which compiles either way, and
|
|
526
|
+
// nothing else may name the class. Lynx's own R8 rules keep every
|
|
527
|
+
// LynxModule's name, so a release build finds it too.
|
|
528
|
+
optionalModule(BLUETOOTH_MODULE_CLASS)?.let {
|
|
529
|
+
registerModule(BLUETOOTH_MODULE, it, permissionHost)
|
|
530
|
+
}
|
|
531
|
+
// angular-lynx:geolocation
|
|
532
|
+
// Where the phone is, behind LynxGeolocation
|
|
533
|
+
// (GeolocationModule.kt), which asks for the location
|
|
534
|
+
// permissions through this activity. An app whose angular.json
|
|
535
|
+
// doesn't set permissions.location is built without the module
|
|
536
|
+
// and these lines.
|
|
537
|
+
registerModule(GeolocationModule.NAME, GeolocationModule::class.java, permissionHost)
|
|
538
|
+
// /angular-lynx:geolocation
|
|
197
539
|
// <canvas>'s WebGL (WebGLModule.kt), which the runtime calls from
|
|
198
540
|
// the main thread, where Angular runs: main-thread modules let
|
|
199
541
|
// it get its answers synchronously, with lynx.module(name). Lynx
|
|
200
|
-
// calls them on its engine thread, not the UI thread.
|
|
542
|
+
// calls them on its engine thread, not the UI thread. An app
|
|
543
|
+
// that never draws on a canvas is built without the canvas code
|
|
544
|
+
// and these lines (@blotch/angular-lynx-native's features.ts).
|
|
545
|
+
// angular-lynx:canvas
|
|
201
546
|
registerModule(WebGLModule.NAME, WebGLModule::class.java, null)
|
|
547
|
+
// /angular-lynx:canvas
|
|
202
548
|
// Bundled files for the main thread's fetch and Image (AssetsModule.kt).
|
|
203
549
|
registerModule(AssetsModule.NAME, AssetsModule::class.java, null)
|
|
204
550
|
setEnableMTSModule(true)
|
|
@@ -209,11 +555,21 @@ class MainActivity : ComponentActivity(), ShellModule.Host, WebAuthModule.Host {
|
|
|
209
555
|
// In an edge-to-edge app an <overlay>'s window fills the screen as
|
|
210
556
|
// the page does, under the navigation bar too (EdgeToEdgeOverlay.kt).
|
|
211
557
|
if (edgeToEdge) addBehavior(EdgeToEdgeOverlay.behavior())
|
|
558
|
+
// angular-lynx:canvas
|
|
212
559
|
// The shell's own <canvas> (CanvasUI.kt): Lynx has none.
|
|
213
560
|
addBehavior(CanvasUI.behavior())
|
|
561
|
+
// XElement's <video>, with frames a canvas can read (VideoUI.kt).
|
|
562
|
+
// Without the canvas, XElementBehaviors' own <video> plays.
|
|
563
|
+
addBehavior(VideoUI.behavior())
|
|
564
|
+
// /angular-lynx:canvas
|
|
214
565
|
// Live reload, in the debug build: it renders the bundle again
|
|
215
566
|
// after every edit.
|
|
216
567
|
DevServer.register(this) { lynxView.renderTemplateUrl(bundleUrl, "") }
|
|
568
|
+
// The app's native plugins' modules and elements (angular.json's
|
|
569
|
+
// `nativePlugins`), after the shell's own and the dev server's,
|
|
570
|
+
// as on iOS. A module gets this activity as its param, as the
|
|
571
|
+
// shell's own modules that need one do.
|
|
572
|
+
AngularLynxPlugins.register(this, this@MainActivity)
|
|
217
573
|
}.build(this)
|
|
218
574
|
// The LynxView is focusable, so it takes focus whenever the window
|
|
219
575
|
// isn't in touch mode: after any key press, from a hardware keyboard,
|
|
@@ -232,6 +588,16 @@ class MainActivity : ComponentActivity(), ShellModule.Host, WebAuthModule.Host {
|
|
|
232
588
|
override fun onReceivedError(error: LynxError?) {
|
|
233
589
|
Log.e(TAG, "Lynx error: ${error?.msg}")
|
|
234
590
|
}
|
|
591
|
+
|
|
592
|
+
// A load sets up a new engine, as the debug build's reload does,
|
|
593
|
+
// and Lynx gives it the font scale the LynxView was built with:
|
|
594
|
+
// updateFontScale doesn't change that. So a size chosen since then
|
|
595
|
+
// would be lost on reload while textScale kept it; give the new
|
|
596
|
+
// page the current scale.
|
|
597
|
+
override fun onLoadSuccess() {
|
|
598
|
+
val scale = textScale(resources.configuration)
|
|
599
|
+
if (scale != builtFontScale) lynxView.updateFontScale(scale)
|
|
600
|
+
}
|
|
235
601
|
})
|
|
236
602
|
|
|
237
603
|
// Draw the page under the status bar, the navigation bar and the
|
|
@@ -242,7 +608,25 @@ class MainActivity : ComponentActivity(), ShellModule.Host, WebAuthModule.Host {
|
|
|
242
608
|
// variables on the page. With "edgeToEdge": false in angular.json
|
|
243
609
|
// the page sits inside the safe area, and the runtime keeps env() at
|
|
244
610
|
// 0. The iOS shell matches.
|
|
245
|
-
|
|
611
|
+
// The container fills the window, edge to edge, so each measure brings
|
|
612
|
+
// the window's size, and the LynxView's, before the LynxView is
|
|
613
|
+
// measured: a phone folding or unfolding, a rotation, or split screen
|
|
614
|
+
// resizing the window (see updateSizes).
|
|
615
|
+
val container = object : FrameLayout(this) {
|
|
616
|
+
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
|
|
617
|
+
if (MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.EXACTLY &&
|
|
618
|
+
MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.EXACTLY
|
|
619
|
+
) {
|
|
620
|
+
val width = MeasureSpec.getSize(widthMeasureSpec)
|
|
621
|
+
val height = MeasureSpec.getSize(heightMeasureSpec)
|
|
622
|
+
updateSizes(
|
|
623
|
+
Size(width, height),
|
|
624
|
+
Size(width - paddingLeft - paddingRight, height - paddingTop - paddingBottom),
|
|
625
|
+
)
|
|
626
|
+
}
|
|
627
|
+
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
|
|
628
|
+
}
|
|
629
|
+
}
|
|
246
630
|
container.addView(lynxView, FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT)
|
|
247
631
|
ViewCompat.setOnApplyWindowInsetsListener(container) { view, insets ->
|
|
248
632
|
val bars = insets.getInsets(
|
|
@@ -292,6 +676,9 @@ class MainActivity : ComponentActivity(), ShellModule.Host, WebAuthModule.Host {
|
|
|
292
676
|
highContrastTextListener = listener
|
|
293
677
|
}
|
|
294
678
|
|
|
679
|
+
// Before the first props, which it reads synchronously.
|
|
680
|
+
networkStatus = NetworkStatus(this) { sendGlobalProps() }
|
|
681
|
+
|
|
295
682
|
onBackPressedDispatcher.addCallback(this, backHandler)
|
|
296
683
|
// Sent before the bundle loads, so the app starts with the theme and
|
|
297
684
|
// the language. The insets follow once the window reports them.
|
|
@@ -341,6 +728,10 @@ class MainActivity : ComponentActivity(), ShellModule.Host, WebAuthModule.Host {
|
|
|
341
728
|
lynxView.sendGlobalEvent(ShortcutsModule.EVENT, JavaOnlyArray())
|
|
342
729
|
return
|
|
343
730
|
}
|
|
731
|
+
// angular-lynx:share-target
|
|
732
|
+
// A share from another app's share sheet while the app is open.
|
|
733
|
+
if (ShareTargetModule.receive(this, intent)) return
|
|
734
|
+
// /angular-lynx:share-target
|
|
344
735
|
if (intent.action != Intent.ACTION_VIEW) return
|
|
345
736
|
val url = intent.data ?: return
|
|
346
737
|
// The sign-in page's redirect to the callback scheme: the deep link
|
|
@@ -364,12 +755,57 @@ class MainActivity : ComponentActivity(), ShellModule.Host, WebAuthModule.Host {
|
|
|
364
755
|
// language change still restarts the activity, which sends the new
|
|
365
756
|
// appLocale: Angular reads LOCALE_ID only once. A new wallpaper arrives
|
|
366
757
|
// here too, without a restart, and globalProps() reads its colors again.
|
|
758
|
+
//
|
|
759
|
+
// A new font size arrives here too (the manifest lists fontScale), and the
|
|
760
|
+
// page's root font size, with every rem, takes the new scale at once.
|
|
761
|
+
//
|
|
762
|
+
// So does a phone folding or unfolding, or rotating, but the new size is
|
|
763
|
+
// sent from the container's measure instead (updateSizes), which follows
|
|
764
|
+
// every change in the window's size, including split screen's, and comes
|
|
765
|
+
// before the LynxView is measured at it.
|
|
367
766
|
override fun onConfigurationChanged(newConfig: Configuration) {
|
|
368
767
|
super.onConfigurationChanged(newConfig)
|
|
369
768
|
updateWindowAppearance()
|
|
769
|
+
lynxView.updateFontScale(textScale(newConfig))
|
|
370
770
|
lynxView.updateGlobalProps(globalProps(newConfig))
|
|
371
771
|
}
|
|
372
772
|
|
|
773
|
+
// Lynx 4 lays the page out again at a new size by itself, once the host
|
|
774
|
+
// tells it, in Lynx's foldable guide's order: the window's size, which
|
|
775
|
+
// rpx lengths are a 750th of, then the LynxView's, which %, vw, vh and
|
|
776
|
+
// @media measure against, then the global props LynxViewport reads. The
|
|
777
|
+
// window's is in px: LynxView.updateScreenMetrics divides it by the
|
|
778
|
+
// density itself. It's the window's rather than the display's, as on iOS,
|
|
779
|
+
// so a window sharing the screen in split screen is the one measured.
|
|
780
|
+
//
|
|
781
|
+
// Measuring gives a new size before the LynxView's onMeasure, which
|
|
782
|
+
// updates the viewport by itself, so the page is laid out once at its new
|
|
783
|
+
// size. A new window size alone doesn't lay the page out again (Lynx
|
|
784
|
+
// only takes note of it), so the viewport is updated here too: with the
|
|
785
|
+
// size it already has, that's what applies the new rpx.
|
|
786
|
+
private fun updateSizes(window: Size, viewport: Size) {
|
|
787
|
+
if (window == windowSize && viewport == viewportSize) return
|
|
788
|
+
if (window != windowSize) lynxView.updateScreenMetrics(window.width, window.height)
|
|
789
|
+
windowSize = window
|
|
790
|
+
viewportSize = viewport
|
|
791
|
+
lynxView.updateViewport(
|
|
792
|
+
MeasureSpec.makeMeasureSpec(viewport.width, MeasureSpec.EXACTLY),
|
|
793
|
+
MeasureSpec.makeMeasureSpec(viewport.height, MeasureSpec.EXACTLY),
|
|
794
|
+
)
|
|
795
|
+
sendGlobalProps()
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
// How much larger than the default the user's font size is (Settings >
|
|
799
|
+
// Display > Font size): 1 at the default, up to 2 on Android 14 and
|
|
800
|
+
// later. Capped at angular.json's textScaling.max, and 1 with
|
|
801
|
+
// "textScaling": false. Android 14 scales large sp text less than small
|
|
802
|
+
// (nonlinear font scaling); Lynx applies the one factor to everything.
|
|
803
|
+
private fun textScale(config: Configuration): Float {
|
|
804
|
+
if (!textScaling) return 1f
|
|
805
|
+
val scale = config.fontScale.takeIf { it > 0f } ?: 1f
|
|
806
|
+
return if (maxTextScale > 0f) minOf(scale, maxTextScale) else scale
|
|
807
|
+
}
|
|
808
|
+
|
|
373
809
|
// Kept through a dark mode switch, the window keeps the theme it started
|
|
374
810
|
// with: its background, which shows behind the system bars, and the
|
|
375
811
|
// bars' icons, which enableEdgeToEdge() picked for the old mode. Both are
|
|
@@ -386,11 +822,12 @@ class MainActivity : ComponentActivity(), ShellModule.Host, WebAuthModule.Host {
|
|
|
386
822
|
/**
|
|
387
823
|
* The global props the runtime reads: `theme` (LynxTheme), `isNotchScreen`
|
|
388
824
|
* (LynxSafeArea), `appLocale` (LynxLocale), `appTimeZone` (the `intl`
|
|
389
|
-
* build option's Intl.DateTimeFormat), the accessibility settings
|
|
390
|
-
* (LynxAccessibilitySettings), `
|
|
391
|
-
* `
|
|
392
|
-
*
|
|
393
|
-
*
|
|
825
|
+
* build option's Intl.DateTimeFormat), the accessibility settings and
|
|
826
|
+
* text scale (LynxAccessibilitySettings), `appState` (LynxAppState),
|
|
827
|
+
* `online` (LynxNetwork), `osVersion` (LynxSystemInfo), `initialURL`
|
|
828
|
+
* (LynxLinking and the router) and the window's and the LynxView's sizes in dp (LynxViewport),
|
|
829
|
+
* plus the safe-area insets in dp and `edgeToEdge`, which
|
|
830
|
+
* env(safe-area-inset-*) reads. The iOS shell sends the same keys, and Lynx Explorer sends theme
|
|
394
831
|
* and isNotchScreen too. Android 12 and later also send the wallpaper's
|
|
395
832
|
* colors, `dynamicColors` (LynxTheme.dynamicColors), which iOS has no
|
|
396
833
|
* equivalent of.
|
|
@@ -415,6 +852,12 @@ class MainActivity : ComponentActivity(), ShellModule.Host, WebAuthModule.Host {
|
|
|
415
852
|
// Lynx has no API for these. Android has no Reduce Transparency.
|
|
416
853
|
"reduceMotion" to reduceMotion(),
|
|
417
854
|
"increaseContrast" to increaseContrast(),
|
|
855
|
+
// The font size, as the LynxView's font scale has it
|
|
856
|
+
// (LynxAccessibilitySettings.textScale).
|
|
857
|
+
"textScale" to textScale(config),
|
|
858
|
+
"appState" to appState,
|
|
859
|
+
// Whether the phone has a connection to the internet.
|
|
860
|
+
"online" to (networkStatus?.online ?: true),
|
|
418
861
|
)
|
|
419
862
|
// The user's language as a BCP 47 tag, such as "fr-FR".
|
|
420
863
|
ConfigurationCompat.getLocales(config)[0]?.let { props["appLocale"] = it.toLanguageTag() }
|
|
@@ -422,6 +865,17 @@ class MainActivity : ComponentActivity(), ShellModule.Host, WebAuthModule.Host {
|
|
|
422
865
|
// option's Intl.DateTimeFormat formats in the device's zone by default,
|
|
423
866
|
// which it reads from the engine's local time, and names it with this.
|
|
424
867
|
props["appTimeZone"] = java.util.TimeZone.getDefault().id
|
|
868
|
+
// The sizes Lynx's foldable guide names, in dp, once the container has
|
|
869
|
+
// been measured: the window's, and the LynxView's, which is smaller
|
|
870
|
+
// with "edgeToEdge": false and while the keyboard is open.
|
|
871
|
+
windowSize?.let {
|
|
872
|
+
props["screenWidth"] = it.width / density
|
|
873
|
+
props["screenHeight"] = it.height / density
|
|
874
|
+
}
|
|
875
|
+
viewportSize?.let {
|
|
876
|
+
props["viewportWidth"] = it.width / density
|
|
877
|
+
props["viewportHeight"] = it.height / density
|
|
878
|
+
}
|
|
425
879
|
DynamicColors.read(this)?.let { props["dynamicColors"] = it }
|
|
426
880
|
// The link that started the app, which the router starts at. In
|
|
427
881
|
// every update, since each sends the whole set.
|
|
@@ -443,11 +897,27 @@ class MainActivity : ComponentActivity(), ShellModule.Host, WebAuthModule.Host {
|
|
|
443
897
|
(Build.VERSION.SDK_INT >= Build.VERSION_CODES.BAKLAVA &&
|
|
444
898
|
getSystemService(AccessibilityManager::class.java).isHighContrastTextEnabled)
|
|
445
899
|
|
|
900
|
+
// Tells the app where it is now (LynxAppState). Lynx itself tells the
|
|
901
|
+
// app's code nothing when it leaves the screen or comes back.
|
|
902
|
+
private fun sendAppState(state: String) {
|
|
903
|
+
if (appState == state) return
|
|
904
|
+
appState = state
|
|
905
|
+
sendGlobalProps()
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
override fun onStart() {
|
|
909
|
+
super.onStart()
|
|
910
|
+
sendAppState("inactive")
|
|
911
|
+
}
|
|
912
|
+
|
|
446
913
|
// Lynx pauses timers and animations in the background and fires the
|
|
447
914
|
// page's visibility events from these.
|
|
448
915
|
override fun onResume() {
|
|
449
916
|
super.onResume()
|
|
450
917
|
lynxView.onEnterForeground()
|
|
918
|
+
resumed = true
|
|
919
|
+
// After the timers resume, so what the app starts on its return runs.
|
|
920
|
+
sendAppState(if (topResumed) "active" else "inactive")
|
|
451
921
|
// Back from a Custom Tab without its redirect: the person closed it.
|
|
452
922
|
// Android says nothing else when a Custom Tab closes.
|
|
453
923
|
webAuthSession?.takeIf { it.opened }?.let {
|
|
@@ -456,13 +926,37 @@ class MainActivity : ComponentActivity(), ShellModule.Host, WebAuthModule.Host {
|
|
|
456
926
|
}
|
|
457
927
|
}
|
|
458
928
|
|
|
929
|
+
// Android 10 and later: whether this is the resumed activity that has the
|
|
930
|
+
// focus, which changes without a pause in split screen. Called after
|
|
931
|
+
// onResume and before onPause, so it only moves a resumed activity
|
|
932
|
+
// between "active" and "inactive".
|
|
933
|
+
override fun onTopResumedActivityChanged(isTopResumedActivity: Boolean) {
|
|
934
|
+
super.onTopResumedActivityChanged(isTopResumedActivity)
|
|
935
|
+
topResumed = isTopResumedActivity
|
|
936
|
+
if (resumed) sendAppState(if (isTopResumedActivity) "active" else "inactive")
|
|
937
|
+
}
|
|
938
|
+
|
|
459
939
|
override fun onPause() {
|
|
940
|
+
resumed = false
|
|
941
|
+
// Before Lynx pauses the timers, so the app hears it on its way out.
|
|
942
|
+
sendAppState("inactive")
|
|
460
943
|
lynxView.onEnterBackground()
|
|
461
944
|
webAuthSession?.opened = true
|
|
462
945
|
super.onPause()
|
|
463
946
|
}
|
|
464
947
|
|
|
948
|
+
override fun onStop() {
|
|
949
|
+
sendAppState("background")
|
|
950
|
+
super.onStop()
|
|
951
|
+
}
|
|
952
|
+
|
|
465
953
|
override fun onDestroy() {
|
|
954
|
+
// angular-lynx:share-target
|
|
955
|
+
// Only this activity's own: a recreated one has set its own already.
|
|
956
|
+
if (ShareTargetModule.arrived === shareArrived) ShareTargetModule.arrived = null
|
|
957
|
+
// /angular-lynx:share-target
|
|
958
|
+
engineThreadHint?.close()
|
|
959
|
+
networkStatus?.close()
|
|
466
960
|
contentResolver.unregisterContentObserver(animationScaleObserver)
|
|
467
961
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
|
|
468
962
|
(contrastListener as UiModeManager.ContrastChangeListener?)?.let {
|
|
@@ -482,6 +976,26 @@ class MainActivity : ComponentActivity(), ShellModule.Host, WebAuthModule.Host {
|
|
|
482
976
|
private companion object {
|
|
483
977
|
const val TAG = "AngularLynxShell"
|
|
484
978
|
|
|
979
|
+
// BarcodeScannerModule and BluetoothModule, and their NAMEs, which
|
|
980
|
+
// this file can't refer to (see onCreate). The classes are in the
|
|
981
|
+
// shell's own package, which is fixed whatever the app's
|
|
982
|
+
// applicationId.
|
|
983
|
+
const val BARCODE_SCANNER_MODULE_CLASS = "dev.angularlynx.shell.BarcodeScannerModule"
|
|
984
|
+
const val BARCODE_SCANNER_MODULE = "AngularLynxBarcodeScanner"
|
|
985
|
+
const val BLUETOOTH_MODULE_CLASS = "dev.angularlynx.shell.BluetoothModule"
|
|
986
|
+
const val BLUETOOTH_MODULE = "AngularLynxBluetooth"
|
|
987
|
+
|
|
988
|
+
/**
|
|
989
|
+
* The module class named [className], or null when the generator
|
|
990
|
+
* left it out of this app.
|
|
991
|
+
*/
|
|
992
|
+
fun optionalModule(className: String): Class<out LynxModule>? =
|
|
993
|
+
try {
|
|
994
|
+
Class.forName(className).asSubclass(LynxModule::class.java)
|
|
995
|
+
} catch (_: ClassNotFoundException) {
|
|
996
|
+
null
|
|
997
|
+
}
|
|
998
|
+
|
|
485
999
|
// The longest the splash screen waits for the app (see onCreate),
|
|
486
1000
|
// and its fade, as long as the iOS shell's.
|
|
487
1001
|
const val SPLASH_TIMEOUT_MS = 5_000L
|