peachsim 0.1.1655 → 0.1.1660
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/cli/app-config.ts +4 -0
- package/cli/app-stubs.ts +43 -6
- package/cli/commands/inspect/shared.ts +5 -2
- package/cli/commands/inspect/url.ts +2 -1
- package/cli/commands/screenshot.ts +5 -5
- package/cli/commands/state.ts +9 -6
- package/cli/outbound-endpoints.ts +9 -1
- package/cli/output-redaction.ts +49 -0
- package/detox/index.ts +0 -1
- package/dist-lib/agent-daemon-client.cjs +1 -1
- package/dist-lib/agent-events.cjs +1 -1
- package/dist-lib/attached-projects.cjs +1 -1
- package/dist-lib/auth/shared-session.cjs +1 -1
- package/dist-lib/backend-origin.cjs +1 -1
- package/dist-lib/beta.cjs +1 -1
- package/dist-lib/beta.mjs +1 -1
- package/dist-lib/bridge-constants.cjs +1 -1
- package/dist-lib/bridge-contract-input.cjs +1 -1
- package/dist-lib/bridge-contract-input.mjs +1 -1
- package/dist-lib/bridge-contract.cjs +1 -1
- package/dist-lib/bridge-contract.mjs +1 -1
- package/dist-lib/bundle-channel.cjs +12772 -1132
- package/dist-lib/capture-contract.cjs +1 -1
- package/dist-lib/capture-contract.mjs +1 -1
- package/dist-lib/cloud-contract.cjs +1 -1
- package/dist-lib/cloud-contract.mjs +1 -1
- package/dist-lib/cloud-test-args.cjs +1 -1
- package/dist-lib/cloud-test-args.mjs +1 -1
- package/dist-lib/cloud.cjs +1 -1
- package/dist-lib/cloud.mjs +1 -1
- package/dist-lib/config.cjs +29 -5
- package/dist-lib/config.mjs +29 -5
- package/dist-lib/detox/index.cjs +19 -6
- package/dist-lib/dev-bundle-resolution.cjs +1 -1
- package/dist-lib/expo-swift-bundle.cjs +10411 -73
- package/dist-lib/expo-swift-metadata.cjs +1 -1
- package/dist-lib/expo-swift-metadata.mjs +1 -1
- package/dist-lib/home-paths.cjs +1 -1
- package/dist-lib/host/bridge-host.cjs +11220 -670
- package/dist-lib/host/fetch-proxy-handler.cjs +260 -197
- package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
- package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
- package/dist-lib/host/replacement-module-handler.cjs +1 -1
- package/dist-lib/host/websocket-proxy.cjs +1 -1
- package/dist-lib/index.cjs +653 -338
- package/dist-lib/jump-to-source-babel.cjs +1 -1
- package/dist-lib/jump-to-source-native.cjs +1 -1
- package/dist-lib/kotlin-host.cjs +443 -312
- package/dist-lib/menu.cjs +1 -1
- package/dist-lib/menu.mjs +1 -1
- package/dist-lib/metro-fingerprint-registry.cjs +1 -1
- package/dist-lib/metro-fingerprint-registry.mjs +1 -1
- package/dist-lib/metro-production-bundle.cjs +1 -1
- package/dist-lib/metro-production-bundle.mjs +1 -1
- package/dist-lib/metro.cjs +548 -163
- package/dist-lib/native-app-identity-project.cjs +179 -33
- package/dist-lib/native-app-identity-project.mjs +179 -33
- package/dist-lib/native-app-identity.cjs +1 -1
- package/dist-lib/native-app-identity.mjs +1 -1
- package/dist-lib/native-firebase-metadata.cjs +1 -1
- package/dist-lib/native-firebase-metadata.mjs +1 -1
- package/dist-lib/plist.cjs +1 -1
- package/dist-lib/plist.mjs +1 -1
- package/dist-lib/profiles.cjs +1 -1
- package/dist-lib/public-brand.cjs +1 -1
- package/dist-lib/public-origins-lib-esm.json +23 -23
- package/dist-lib/public-origins-lib.json +96 -63
- package/dist-lib/react-native-host-modules.cjs +1 -1
- package/dist-lib/react-native-host-modules.mjs +1 -1
- package/dist-lib/scripts/dev-server-scanner.cjs +2 -2
- package/dist-lib/sdk.cjs +1 -1
- package/dist-lib/sdk.mjs +1 -1
- package/dist-lib/skills.cjs +12193 -1448
- package/dist-lib/swift-compile.cjs +10348 -172
- package/dist-lib/swift-compile.mjs +10348 -172
- package/dist-lib/swift-package.cjs +1 -1
- package/dist-lib/swift-package.mjs +1 -1
- package/dist-lib/swift-submit.cjs +1 -1
- package/dist-lib/swift-submit.mjs +1 -1
- package/dist-lib/swift-toolchain.cjs +1 -1
- package/dist-lib/swift.cjs +1 -1
- package/dist-lib/vite-swift.cjs +10411 -73
- package/dist-lib/vite.cjs +149 -163
- package/dist-lib/worklet-executable.cjs +1 -1
- package/dist-lib/worklet-executable.mjs +1 -1
- package/dist-types/packages/peach-compat/src/stubs/native-seams/react-native-gesture-handler.d.ts +2 -0
- package/dist-types/packages/peach-engine/src/engine/app-font-registry.d.ts +14 -0
- package/dist-types/packages/peach-engine/src/engine/image-loader.d.ts +8 -0
- package/dist-types/packages/peach-engine/src/engine/node.d.ts +3 -0
- package/dist-types/packages/peach-engine/src/render-worker/compositor-protocol.d.ts +21 -0
- package/dist-types/packages/peach-engine/src/render-worker/gesture-seam-protocol.d.ts +2 -1
- package/dist-types/packages/peach-engine/src/render-worker/test-bridge-protocol.d.ts +1 -1
- package/dist-types/packages/peach-engine/src/rolldown-bundle-inventory.d.ts +1 -0
- package/dist-types/packages/peach-globals/src/index.d.ts +34 -0
- package/kotlin/README.md +38 -23
- package/kotlin/sdk.tar.gz +0 -0
- package/package.json +2 -12
- package/runtime-companion.json +1 -1
- package/src/bundleGlobalFooter.ts +0 -2
- package/src/config.ts +54 -2
- package/src/configured-bundle-producer.ts +7 -1
- package/src/host/fetch-proxy-handler.ts +14 -50
- package/src/host/rolldown-bundle-forward.ts +71 -0
- package/src/installed-package-versions.ts +54 -2
- package/src/kotlin-host.ts +138 -285
- package/src/kotlin-module.ts +4 -7
- package/src/kotlin-sdk.ts +81 -0
- package/src/kotlin-toolchain.ts +152 -0
- package/src/kotlin-view-models.ts +1 -1
- package/src/kotlinSdkContract.ts +113 -0
- package/src/nitro-adapter.lock.json +3 -3
- package/src/nitro-bundle.ts +18 -4
- package/src/nitro-compile.ts +5 -1
- package/src/nitro-source.ts +112 -28
- package/src/nitroContract.ts +16 -4
- package/src/stub-pattern-matcher.ts +4 -0
- package/src/swift-compile.ts +44 -14
- package/src/swift-host.ts +2 -1
- package/src/swift-objc-compile.ts +117 -4
- package/src/swift-objc-sdk.ts +10215 -59
- package/src/swift-objc-standin.ts +5 -2
- package/src/vite-plugin-one.ts +73 -134
- package/src/worker-system-chunks.ts +14 -4
- package/src/xcode-project.ts +261 -34
- package/kotlin/AndroidViewSources/android/content/Context.kt +0 -22
- package/kotlin/AndroidViewSources/android/content/res/Configuration.kt +0 -25
- package/kotlin/AndroidViewSources/android/content/res/Resources.kt +0 -72
- package/kotlin/AndroidViewSources/android/graphics/Canvas.kt +0 -22
- package/kotlin/AndroidViewSources/android/graphics/Color.kt +0 -13
- package/kotlin/AndroidViewSources/android/graphics/Paint.kt +0 -18
- package/kotlin/AndroidViewSources/android/util/DisplayMetrics.kt +0 -12
- package/kotlin/AndroidViewSources/android/view/View.kt +0 -211
- package/kotlin/AndroidViewSources/android/widget/FrameLayout.kt +0 -61
- package/kotlin/AndroidViewSources/android/widget/LinearLayout.kt +0 -49
- package/kotlin/AndroidViewSources/dev/peach/app/JavaFormat.kt +0 -272
- package/kotlin/AppSources/android/app/Activity.kt +0 -174
- package/kotlin/AppSources/android/app/Application.kt +0 -11
- package/kotlin/AppSources/android/app/UiModeManager.kt +0 -9
- package/kotlin/AppSources/android/content/Intent.kt +0 -16
- package/kotlin/AppSources/android/os/Bundle.kt +0 -11
- package/kotlin/AppSources/android/util/SuperNotCalledException.kt +0 -3
- package/kotlin/AppSources/android/view/Window.kt +0 -182
- package/kotlin/AppSources/android/view/WindowInsets.kt +0 -9
- package/kotlin/AppSources/android/view/WindowInsetsController.kt +0 -17
- package/kotlin/AppSources/android/view/WindowManager.kt +0 -16
- package/kotlin/AppSources/android/window/BackEvent.kt +0 -24
- package/kotlin/AppSources/android/window/OnBackAnimationCallback.kt +0 -7
- package/kotlin/AppSources/android/window/OnBackInvokedDispatcher.kt +0 -84
- package/kotlin/AppSources/androidx/activity/ActivityFlags.kt +0 -9
- package/kotlin/AppSources/androidx/activity/ActivityViewModelLazy.kt +0 -21
- package/kotlin/AppSources/androidx/activity/BackEventCompat.kt +0 -43
- package/kotlin/AppSources/androidx/activity/ComponentActivity.kt +0 -122
- package/kotlin/AppSources/androidx/activity/EdgeToEdge.kt +0 -75
- package/kotlin/AppSources/androidx/activity/ExperimentalActivityApi.kt +0 -6
- package/kotlin/AppSources/androidx/activity/OnBackPressedCallback.kt +0 -69
- package/kotlin/AppSources/androidx/activity/OnBackPressedDispatcher.kt +0 -144
- package/kotlin/AppSources/androidx/activity/OnBackPressedDispatcherOwner.kt +0 -7
- package/kotlin/AppSources/androidx/activity/compose/BackHandler.kt +0 -86
- package/kotlin/AppSources/androidx/activity/compose/ComponentActivity.kt +0 -29
- package/kotlin/AppSources/androidx/activity/compose/internal/BackHandlerCompat.kt +0 -38
- package/kotlin/AppSources/androidx/activity/compose/internal/BackHandlerDispatcherCompat.kt +0 -27
- package/kotlin/AppSources/androidx/compose/foundation/layout/WindowInsets.kt +0 -15
- package/kotlin/AppSources/androidx/compose/ui/platform/AndroidCompositionLocals.kt +0 -27
- package/kotlin/AppSources/androidx/compose/ui/platform/ComposeView.kt +0 -68
- package/kotlin/AppSources/androidx/compose/ui/res/ColorResources.kt +0 -16
- package/kotlin/AppSources/androidx/compose/ui/res/PainterResources.kt +0 -70
- package/kotlin/AppSources/androidx/compose/ui/res/StringResources.kt +0 -38
- package/kotlin/AppSources/androidx/core/view/WindowCompat.kt +0 -32
- package/kotlin/AppSources/androidx/lifecycle/AndroidViewModel.kt +0 -10
- package/kotlin/AppSources/dev/peach/app/PeachApp.kt +0 -388
- package/kotlin/AppSources/dev/peach/app/PeachDrawable.kt +0 -102
- package/kotlin/AppSources/dev/peach/app/PeachWindowHost.kt +0 -14
- package/kotlin/CompilerSources/META-INF/services/org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar +0 -1
- package/kotlin/CompilerSources/PeachJniIncoming.kt +0 -243
- package/kotlin/CompilerSources/PeachJniPlugin.kt +0 -116
- package/kotlin/ComposeSources/PeachComposeHost.kt +0 -724
- package/kotlin/ComposeSources/PeachMagnifier.kt +0 -185
- package/kotlin/ComposeSources/PeachSemantics.kt +0 -127
- package/kotlin/ExpoComposeSources/PeachAndroidView.kt +0 -103
- package/kotlin/ExpoComposeSources/PeachExpoViewMount.kt +0 -24
- package/kotlin/ExpoComposeSources/dev/peach/expo/PeachExpoCompose.kt +0 -28
- package/kotlin/ExpoComposeSources/expo/modules/kotlin/views/ExpoComposeView.kt +0 -70
- package/kotlin/ExpoSources/dev/peach/expo/PeachExpoRuntime.kt +0 -516
- package/kotlin/ExpoSources/dev/peach/expo/PeachExpoTypes.kt +0 -173
- package/kotlin/ExpoSources/expo/modules/kotlin/AppContext.kt +0 -20
- package/kotlin/ExpoSources/expo/modules/kotlin/Promise.kt +0 -19
- package/kotlin/ExpoSources/expo/modules/kotlin/classcomponent/ClassComponentBuilder.kt +0 -198
- package/kotlin/ExpoSources/expo/modules/kotlin/exception/CodedException.kt +0 -126
- package/kotlin/ExpoSources/expo/modules/kotlin/functions/Functions.kt +0 -132
- package/kotlin/ExpoSources/expo/modules/kotlin/jni/JavaScriptTypedArray.kt +0 -81
- package/kotlin/ExpoSources/expo/modules/kotlin/modules/Module.kt +0 -98
- package/kotlin/ExpoSources/expo/modules/kotlin/objects/ObjectDefinitionBuilder.kt +0 -236
- package/kotlin/ExpoSources/expo/modules/kotlin/records/Record.kt +0 -12
- package/kotlin/ExpoSources/expo/modules/kotlin/runtime/Runtime.kt +0 -9
- package/kotlin/ExpoSources/expo/modules/kotlin/sharedobjects/SharedObject.kt +0 -50
- package/kotlin/ExpoSources/expo/modules/kotlin/sharedobjects/SharedObjectRegistry.kt +0 -57
- package/kotlin/ExpoSources/expo/modules/kotlin/sharedobjects/SharedRef.kt +0 -19
- package/kotlin/ExpoSources/expo/modules/kotlin/typedarray/ConcreteTypedArrays.kt +0 -158
- package/kotlin/ExpoSources/expo/modules/kotlin/typedarray/GenericTypedArray.kt +0 -8
- package/kotlin/ExpoSources/expo/modules/kotlin/typedarray/TypedArray.kt +0 -29
- package/kotlin/ExpoSources/expo/modules/kotlin/typedarray/TypedArrayIterator.kt +0 -9
- package/kotlin/ExpoSources/expo/modules/kotlin/types/AnyType.kt +0 -155
- package/kotlin/ExpoSources/expo/modules/kotlin/types/Either.kt +0 -91
- package/kotlin/ExpoSources/expo/modules/kotlin/types/Enumerable.kt +0 -6
- package/kotlin/ExpoSources/expo/modules/kotlin/viewevent/ViewEvent.kt +0 -68
- package/kotlin/ExpoSources/expo/modules/kotlin/views/ExpoView.kt +0 -20
- package/kotlin/ExpoSources/expo/modules/kotlin/views/ViewDefinitionBuilder.kt +0 -72
- package/kotlin/ExpoSources/expo/modules/kotlin/views/ViewProps.kt +0 -36
- package/kotlin/JniPlatformSources/androidx/annotation/CallSuper.kt +0 -5
- package/kotlin/JniPlatformSources/com/facebook/proguard/annotations/DoNotStrip.kt +0 -5
- package/kotlin/JniPlatformSources/dalvik/annotation/optimization/FastNative.kt +0 -5
- package/kotlin/JniPlatformSources/kotlin/Synchronized.kt +0 -6
- package/kotlin/JniPlatformSources/kotlin/jvm/JvmField.kt +0 -5
- package/kotlin/JniPlatformSources/kotlin/jvm/JvmStatic.kt +0 -5
- package/kotlin/JniSources/com/facebook/jni/HybridData.kt +0 -66
- package/kotlin/JniSources/dev/peach/jni/IncomingBindings.kt +0 -157
- package/kotlin/JniSources/dev/peach/jni/NativeBindings.kt +0 -77
- package/kotlin/JniTransportSources/dev/peach/jni/integration/JniTransport.kt +0 -89
- package/kotlin/Sources/android/os/Build.kt +0 -17
- package/kotlin/Sources/android/os/Handler.kt +0 -35
- package/kotlin/Sources/android/os/Looper.kt +0 -17
- package/kotlin/Sources/android/os/MessageQueue.kt +0 -56
- package/kotlin/Sources/android/os/SystemClock.kt +0 -14
- package/kotlin/Sources/android/util/Log.kt +0 -64
- package/kotlin/Sources/androidx/annotation/DrawableRes.kt +0 -14
- package/kotlin/Sources/androidx/annotation/Keep.kt +0 -4
- package/kotlin/Sources/dev/onejs/one/OneNativeSourceDispatch.kt +0 -7
- package/kotlin/Sources/dev/onejs/one/OneNativeSourceViewDispatch.kt +0 -13
- package/kotlin/Sources/dev/onejs/one/source/OneModule.kt +0 -4
- package/kotlin/Sources/java/lang/Runnable.kt +0 -6
- package/kotlin/Sources/java/security/MessageDigest.kt +0 -114
- package/kotlin/Sources/java/util/IllegalFormatCodePointException.kt +0 -10
- package/kotlin/Sources/java/util/IllegalFormatException.kt +0 -5
- package/kotlin/Sources/kotlin/text/StringFormat.kt +0 -9
- package/kotlin/Sources/org/json/JSON.kt +0 -307
- package/kotlin/tools/abi-classes.main.kts +0 -41
- package/kotlin/tools/expo-types.main.kts +0 -127
|
@@ -1,724 +0,0 @@
|
|
|
1
|
-
@file:OptIn(androidx.compose.ui.ExperimentalComposeUiApi::class, androidx.compose.ui.InternalComposeUiApi::class, androidx.compose.ui.text.ExperimentalTextApi::class, kotlin.js.ExperimentalJsExport::class, org.jetbrains.skiko.InternalSkikoApi::class)
|
|
2
|
-
|
|
3
|
-
import androidx.compose.foundation.LocalPlatformMagnifierFactory
|
|
4
|
-
import androidx.compose.runtime.Composable
|
|
5
|
-
import androidx.compose.runtime.CompositionLocalProvider
|
|
6
|
-
import androidx.compose.runtime.getValue
|
|
7
|
-
import androidx.compose.runtime.mutableStateOf
|
|
8
|
-
import androidx.compose.runtime.remember
|
|
9
|
-
import androidx.compose.runtime.setValue
|
|
10
|
-
import androidx.compose.runtime.snapshots.Snapshot
|
|
11
|
-
import androidx.compose.ui.LocalSystemTheme
|
|
12
|
-
import androidx.compose.ui.geometry.Offset
|
|
13
|
-
import androidx.compose.ui.geometry.Rect
|
|
14
|
-
import androidx.compose.ui.graphics.asComposeCanvas
|
|
15
|
-
import androidx.compose.ui.input.InputMode
|
|
16
|
-
import androidx.compose.ui.input.InputModeManager
|
|
17
|
-
import androidx.compose.ui.input.key.Key
|
|
18
|
-
import androidx.compose.ui.input.key.KeyEvent
|
|
19
|
-
import androidx.compose.ui.input.key.KeyEventType
|
|
20
|
-
import androidx.compose.ui.input.pointer.PointerEventType
|
|
21
|
-
import androidx.compose.ui.input.pointer.PointerType
|
|
22
|
-
import androidx.compose.ui.layout.Layout
|
|
23
|
-
import androidx.compose.ui.layout.Remeasurement
|
|
24
|
-
import androidx.compose.ui.layout.RemeasurementModifier
|
|
25
|
-
import androidx.compose.ui.platform.FrameRecomposer
|
|
26
|
-
import androidx.compose.ui.platform.LocalFontFamilyResolver
|
|
27
|
-
import androidx.compose.ui.platform.PlatformArchitectureComponentsOwner
|
|
28
|
-
import androidx.compose.ui.platform.PlatformInsets
|
|
29
|
-
import androidx.compose.ui.platform.PlatformWindowInsets
|
|
30
|
-
import androidx.compose.ui.platform.PlatformContext
|
|
31
|
-
import androidx.compose.ui.platform.PlatformTextInputMethodRequest
|
|
32
|
-
import androidx.compose.ui.platform.ViewConfiguration
|
|
33
|
-
import androidx.compose.ui.platform.WindowInfo
|
|
34
|
-
import androidx.compose.ui.platform.registerSkikoComposeImplementation
|
|
35
|
-
import androidx.compose.ui.scene.CanvasLayersComposeScene
|
|
36
|
-
import androidx.compose.ui.scene.hasInvalidations
|
|
37
|
-
import androidx.compose.ui.semantics.SemanticsOwner
|
|
38
|
-
import androidx.compose.ui.text.font.FontFamily
|
|
39
|
-
import androidx.compose.ui.text.font.FontStyle
|
|
40
|
-
import androidx.compose.ui.text.font.FontSynthesis
|
|
41
|
-
import androidx.compose.ui.text.font.FontVariation
|
|
42
|
-
import androidx.compose.ui.text.font.FontWeight
|
|
43
|
-
import androidx.compose.ui.text.font.PlatformTypefacesLoader
|
|
44
|
-
import androidx.compose.ui.text.font.createPlatformFontFamilyResolver
|
|
45
|
-
import androidx.compose.ui.text.font.platformTypefacesLoader
|
|
46
|
-
import androidx.compose.ui.text.input.BackspaceCommand
|
|
47
|
-
import androidx.compose.ui.text.input.CommitTextCommand
|
|
48
|
-
import androidx.compose.ui.text.input.EditCommand
|
|
49
|
-
import androidx.compose.ui.text.input.FinishComposingTextCommand
|
|
50
|
-
import androidx.compose.ui.text.input.ImeAction
|
|
51
|
-
import androidx.compose.ui.text.input.ImeOptions
|
|
52
|
-
import androidx.compose.ui.text.input.KeyboardCapitalization
|
|
53
|
-
import androidx.compose.ui.text.input.KeyboardType
|
|
54
|
-
import androidx.compose.ui.text.input.PlatformTextInputService
|
|
55
|
-
import androidx.compose.ui.text.input.SetComposingRegionCommand
|
|
56
|
-
import androidx.compose.ui.text.input.SetComposingTextCommand
|
|
57
|
-
import androidx.compose.ui.text.input.SetSelectionCommand
|
|
58
|
-
import androidx.compose.ui.text.input.TextFieldValue
|
|
59
|
-
import androidx.compose.ui.text.intl.LocaleList
|
|
60
|
-
import androidx.compose.ui.text.intl.setPlatformLocaleProvider
|
|
61
|
-
import androidx.compose.ui.text.platform.Font
|
|
62
|
-
import androidx.compose.ui.unit.Constraints
|
|
63
|
-
import androidx.compose.ui.unit.Density
|
|
64
|
-
import androidx.compose.ui.unit.DpSize
|
|
65
|
-
import androidx.compose.ui.unit.IntSize
|
|
66
|
-
import androidx.compose.ui.unit.LayoutDirection
|
|
67
|
-
import androidx.compose.ui.unit.constrainHeight
|
|
68
|
-
import androidx.compose.ui.unit.constrainWidth
|
|
69
|
-
import androidx.navigationevent.NavigationEventDispatcher
|
|
70
|
-
import androidx.navigationevent.NavigationEventInput
|
|
71
|
-
import androidx.navigationevent.NavigationEventDispatcherOwner
|
|
72
|
-
import androidx.navigationevent.compose.LocalNavigationEventDispatcherOwner
|
|
73
|
-
import dev.onejs.one.OneNativeSourceViewDispatch
|
|
74
|
-
import kotlin.io.encoding.Base64
|
|
75
|
-
import kotlinx.coroutines.Dispatchers
|
|
76
|
-
import kotlinx.coroutines.Job
|
|
77
|
-
import kotlinx.coroutines.awaitCancellation
|
|
78
|
-
import kotlinx.coroutines.currentCoroutineContext
|
|
79
|
-
import kotlinx.coroutines.job
|
|
80
|
-
import org.jetbrains.skiko.SystemTheme
|
|
81
|
-
import org.jetbrains.skia.Color
|
|
82
|
-
import org.jetbrains.skia.Picture
|
|
83
|
-
import org.jetbrains.skia.PictureRecorder
|
|
84
|
-
import org.jetbrains.skia.Rect as SkRect
|
|
85
|
-
import org.jetbrains.skia.impl.getPtr
|
|
86
|
-
import org.jetbrains.skiko.OS
|
|
87
|
-
import org.jetbrains.skiko.setHostOsProvider
|
|
88
|
-
import org.json.JSONArray
|
|
89
|
-
import org.json.JSONObject
|
|
90
|
-
|
|
91
|
-
internal fun readPeachWindowInsets(insets: String) = insets.split(',').map { it.toInt() }.also {
|
|
92
|
-
require(it.size == 24 && it.all { pixel -> pixel >= 0 })
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// the window delivers inset types to its compose views; a fitting decor consumes them.
|
|
96
|
-
internal class PeachWindowInsets(
|
|
97
|
-
private val pixels: () -> List<Int>,
|
|
98
|
-
imeBottom: () -> Int,
|
|
99
|
-
private val consumesInsets: () -> Boolean,
|
|
100
|
-
) : PlatformWindowInsets {
|
|
101
|
-
private fun type(index: Int): PlatformInsets {
|
|
102
|
-
fun side(offset: Int) = { if (consumesInsets()) 0 else pixels()[index * 4 + offset] }
|
|
103
|
-
return PlatformInsets(side(0), side(1), side(2), side(3))
|
|
104
|
-
}
|
|
105
|
-
override val statusBars = type(0)
|
|
106
|
-
override val navigationBars = type(1)
|
|
107
|
-
override val displayCutout = type(2)
|
|
108
|
-
override val systemGestures = type(3)
|
|
109
|
-
override val mandatorySystemGestures = type(4)
|
|
110
|
-
override val tappableElement = type(5)
|
|
111
|
-
override val ime = PlatformInsets({ 0 }, { 0 }, { 0 }, { if (consumesInsets()) 0 else imeBottom() })
|
|
112
|
-
override val systemBars = PlatformInsets(
|
|
113
|
-
{ maxOf(statusBars.left, navigationBars.left) },
|
|
114
|
-
{ maxOf(statusBars.top, navigationBars.top) },
|
|
115
|
-
{ maxOf(statusBars.right, navigationBars.right) },
|
|
116
|
-
{ maxOf(statusBars.bottom, navigationBars.bottom) },
|
|
117
|
-
)
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// the values android.view.ViewConfiguration gives a window: config.xml's dp
|
|
121
|
-
// dimensions resolved as getDimensionPixelSize does, rounding half up
|
|
122
|
-
internal class AndroidViewConfiguration(private val density: Float) : ViewConfiguration {
|
|
123
|
-
private fun pixels(dp: Float) = (dp * density + 0.5f).toInt().toFloat()
|
|
124
|
-
override val longPressTimeoutMillis: Long = 400
|
|
125
|
-
override val doubleTapTimeoutMillis: Long = 300
|
|
126
|
-
override val doubleTapMinTimeMillis: Long = 40
|
|
127
|
-
override val touchSlop: Float = pixels(8f)
|
|
128
|
-
override val handwritingSlop: Float = pixels(2f)
|
|
129
|
-
override val maximumFlingVelocity: Float = pixels(8000f)
|
|
130
|
-
override val minimumFlingVelocity: Float = pixels(50f)
|
|
131
|
-
override val handwritingGestureLineMargin: Float = pixels(16f)
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
internal class PeachComposePlatform(
|
|
135
|
-
val density: Density,
|
|
136
|
-
override val localeList: LocaleList,
|
|
137
|
-
var size: IntSize,
|
|
138
|
-
owners: PlatformArchitectureComponentsOwner?,
|
|
139
|
-
insets: PlatformWindowInsets?,
|
|
140
|
-
base: PlatformContext = PlatformContext.Empty(),
|
|
141
|
-
) : PlatformContext by base, PlatformContext.SemanticsOwnerListener {
|
|
142
|
-
override val architectureComponentsOwner: PlatformArchitectureComponentsOwner = owners ?: base.architectureComponentsOwner
|
|
143
|
-
override val windowInsets: PlatformWindowInsets = insets ?: base.windowInsets
|
|
144
|
-
val owners = mutableSetOf<SemanticsOwner>()
|
|
145
|
-
override val windowInfo: WindowInfo = object : WindowInfo {
|
|
146
|
-
override val isWindowFocused: Boolean get() = true
|
|
147
|
-
override val containerSize: IntSize get() = size
|
|
148
|
-
override val containerDpSize: DpSize get() = with(density) { DpSize(size.width.toDp(), size.height.toDp()) }
|
|
149
|
-
}
|
|
150
|
-
// android's ViewConfiguration: AOSP's dp defaults as the device's pixels,
|
|
151
|
-
// where the skiko default is a desktop's
|
|
152
|
-
override val viewConfiguration: ViewConfiguration = AndroidViewConfiguration(density.density)
|
|
153
|
-
override val inputModeManager: InputModeManager = object : InputModeManager {
|
|
154
|
-
override var inputMode: InputMode by mutableStateOf(InputMode.Touch)
|
|
155
|
-
override fun requestInputMode(inputMode: InputMode): Boolean {
|
|
156
|
-
this.inputMode = inputMode
|
|
157
|
-
return true
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
override val semanticsOwnerListener: PlatformContext.SemanticsOwnerListener get() = this
|
|
161
|
-
override fun onSemanticsOwnerAppended(semanticsOwner: SemanticsOwner) { owners.add(semanticsOwner) }
|
|
162
|
-
override fun onSemanticsOwnerRemoved(semanticsOwner: SemanticsOwner) { owners.remove(semanticsOwner) }
|
|
163
|
-
override fun onSemanticsChange(semanticsOwner: SemanticsOwner) = Unit
|
|
164
|
-
override fun onLayoutChange(semanticsOwner: SemanticsOwner, semanticsNodeId: Int) = Unit
|
|
165
|
-
|
|
166
|
-
// the input method session the focused text field holds, android's
|
|
167
|
-
// InputConnection. each session gets a new token, so the host can tell a
|
|
168
|
-
// late close from the session that replaced it. a field that detaches
|
|
169
|
-
// cancels its session at once, though the cancelled coroutine finishes
|
|
170
|
-
// later; from the cancel on the session is closed, as compose web only
|
|
171
|
-
// reads a request inside the session's own coroutines
|
|
172
|
-
private var session: PeachInputSession? = null
|
|
173
|
-
val input get() = session?.takeIf { it.job.isActive }
|
|
174
|
-
var onInputChange: () -> Unit = {}
|
|
175
|
-
var onDialogChange: () -> Unit = {}
|
|
176
|
-
private val dialogs = mutableListOf<PeachDialogWindow>()
|
|
177
|
-
private var nextDialog = 0
|
|
178
|
-
|
|
179
|
-
override fun attachDialogWindow(dispatcher: NavigationEventDispatcher): AutoCloseable {
|
|
180
|
-
val window = PeachDialogWindow(++nextDialog, dispatcher, onDialogChange)
|
|
181
|
-
dialogs.add(window)
|
|
182
|
-
onDialogChange()
|
|
183
|
-
return AutoCloseable { dialogs.remove(window); window.dispose(); onDialogChange() }
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
fun dialogState(): JSONArray = JSONArray().also { state -> dialogs.forEach { state.put(it.describe()) } }
|
|
187
|
-
fun dialogBack(): Boolean {
|
|
188
|
-
val window = dialogs.lastOrNull() ?: return false
|
|
189
|
-
window.back()
|
|
190
|
-
return true
|
|
191
|
-
}
|
|
192
|
-
fun dialogBackPhase(id: Int, phase: String, registration: Int, event: android.window.BackEvent) {
|
|
193
|
-
dialogs.firstOrNull { it.id == id }?.phase(phase, registration, event)
|
|
194
|
-
}
|
|
195
|
-
fun cancelDialogBackGestures() { dialogs.forEach { it.cancelGesture() } }
|
|
196
|
-
private var nextInput = 1
|
|
197
|
-
|
|
198
|
-
override suspend fun startInputMethod(request: PlatformTextInputMethodRequest): Nothing {
|
|
199
|
-
val opened = PeachInputSession(nextInput++, request, currentCoroutineContext().job)
|
|
200
|
-
session = opened
|
|
201
|
-
onInputChange()
|
|
202
|
-
try { awaitCancellation() }
|
|
203
|
-
finally {
|
|
204
|
-
if (session === opened) session = null
|
|
205
|
-
onInputChange()
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
// compose's keyboard controller: show and hide move the keyboard and keep
|
|
210
|
-
// the session, as Done does on android. a session opens with the keyboard
|
|
211
|
-
// up, as android's legacy text input service shows it on startInput
|
|
212
|
-
@Suppress("DEPRECATION")
|
|
213
|
-
override val textInputService: PlatformTextInputService = object : PlatformTextInputService {
|
|
214
|
-
override fun startInput(value: TextFieldValue, imeOptions: ImeOptions,
|
|
215
|
-
onEditCommand: (List<EditCommand>) -> Unit, onImeActionPerformed: (ImeAction) -> Unit) = Unit
|
|
216
|
-
override fun stopInput() = Unit
|
|
217
|
-
override fun showSoftwareKeyboard() { input?.request(true); onInputChange() }
|
|
218
|
-
override fun hideSoftwareKeyboard() { input?.request(false); onInputChange() }
|
|
219
|
-
override fun updateState(oldValue: TextFieldValue?, newValue: TextFieldValue) = Unit
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
// each dialog has its own window dispatch. scoped AndroidX inputs observe
|
|
224
|
-
// default and overlay handlers; registration ids change only on re-registration.
|
|
225
|
-
private class PeachDialogWindow(
|
|
226
|
-
val id: Int,
|
|
227
|
-
dispatcher: NavigationEventDispatcher,
|
|
228
|
-
private val changed: () -> Unit,
|
|
229
|
-
) {
|
|
230
|
-
private val backDispatcher = android.window.WindowOnBackInvokedDispatcher(changed)
|
|
231
|
-
private inner class BackInput(private val priority: Int) : NavigationEventInput() {
|
|
232
|
-
private val callback = object : android.window.OnBackAnimationCallback {
|
|
233
|
-
override fun onBackStarted(backEvent: android.window.BackEvent) =
|
|
234
|
-
dispatchOnBackStarted(androidx.activity.BackEventCompat(backEvent).toNavigationEvent())
|
|
235
|
-
override fun onBackProgressed(backEvent: android.window.BackEvent) =
|
|
236
|
-
dispatchOnBackProgressed(androidx.activity.BackEventCompat(backEvent).toNavigationEvent())
|
|
237
|
-
override fun onBackCancelled() = dispatchOnBackCancelled()
|
|
238
|
-
override fun onBackInvoked() = dispatchOnBackCompleted()
|
|
239
|
-
}
|
|
240
|
-
override fun onHasEnabledHandlersChanged(hasEnabledHandlers: Boolean) {
|
|
241
|
-
if (hasEnabledHandlers) backDispatcher.registerOnBackInvokedCallback(priority, callback)
|
|
242
|
-
else backDispatcher.unregisterOnBackInvokedCallback(callback)
|
|
243
|
-
}
|
|
244
|
-
override fun onRemoved() { backDispatcher.unregisterOnBackInvokedCallback(callback) }
|
|
245
|
-
}
|
|
246
|
-
private val default = BackInput(0)
|
|
247
|
-
private val overlay = BackInput(1000000)
|
|
248
|
-
init {
|
|
249
|
-
dispatcher.addInput(default, NavigationEventDispatcher.PRIORITY_DEFAULT)
|
|
250
|
-
dispatcher.addInput(overlay, NavigationEventDispatcher.PRIORITY_OVERLAY)
|
|
251
|
-
}
|
|
252
|
-
fun back(): Boolean = backDispatcher.invoke()
|
|
253
|
-
fun phase(phase: String, registration: Int, event: android.window.BackEvent) =
|
|
254
|
-
backDispatcher.phase(phase, registration, event)
|
|
255
|
-
fun cancelGesture() = backDispatcher.cancelGesture()
|
|
256
|
-
fun dispose() = backDispatcher.clear()
|
|
257
|
-
fun describe(): JSONObject = JSONObject().put("id", id).put("callbacks", backDispatcher.registrations())
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
internal class PeachInputSession(val token: Int, val request: PlatformTextInputMethodRequest, val job: Job) {
|
|
261
|
-
var keyboard = true
|
|
262
|
-
private set
|
|
263
|
-
// each show or hide compose asks for, so a repeat still reaches the keyboard
|
|
264
|
-
private var keyboardRequest = 0
|
|
265
|
-
private val options get() = request.imeOptions
|
|
266
|
-
|
|
267
|
-
// EditorInfo.android.kt: a single line field's default action is Done; a
|
|
268
|
-
// multi line field's default has no enter action, so enter types a newline
|
|
269
|
-
private val action: ImeAction? get() = when (options.imeAction) {
|
|
270
|
-
ImeAction.Default -> if (options.singleLine) ImeAction.Done else null
|
|
271
|
-
ImeAction.None -> null
|
|
272
|
-
else -> options.imeAction
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
fun request(visible: Boolean) {
|
|
276
|
-
keyboard = visible
|
|
277
|
-
keyboardRequest++
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
private fun rect(rect: Rect?) = rect?.let { JSONArray().put(it.left).put(it.top).put(it.right).put(it.bottom) }
|
|
281
|
-
|
|
282
|
-
fun state(): JSONObject {
|
|
283
|
-
val value = request.value()
|
|
284
|
-
return JSONObject().put("token", token).put("keyboard", keyboard).put("keyboardRequest", keyboardRequest)
|
|
285
|
-
.put("value", value.text).put("selectionStart", value.selection.start).put("selectionEnd", value.selection.end)
|
|
286
|
-
.put("singleLine", options.singleLine).put("enterInsertsNewline", action == null && !options.singleLine)
|
|
287
|
-
.put("keyboardType", when (options.keyboardType) {
|
|
288
|
-
KeyboardType.Number -> "number"
|
|
289
|
-
KeyboardType.Phone -> "phone"
|
|
290
|
-
KeyboardType.Uri -> "uri"
|
|
291
|
-
KeyboardType.Email -> "email"
|
|
292
|
-
KeyboardType.Password -> "password"
|
|
293
|
-
KeyboardType.NumberPassword -> "number-password"
|
|
294
|
-
KeyboardType.Decimal -> "decimal"
|
|
295
|
-
KeyboardType.Ascii -> "ascii"
|
|
296
|
-
else -> "text"
|
|
297
|
-
})
|
|
298
|
-
.put("imeAction", when (action) {
|
|
299
|
-
ImeAction.Done -> "done"
|
|
300
|
-
ImeAction.Go -> "go"
|
|
301
|
-
ImeAction.Search -> "search"
|
|
302
|
-
ImeAction.Send -> "send"
|
|
303
|
-
ImeAction.Next -> "next"
|
|
304
|
-
ImeAction.Previous -> "previous"
|
|
305
|
-
else -> "default"
|
|
306
|
-
})
|
|
307
|
-
.put("capitalization", when (options.capitalization) {
|
|
308
|
-
KeyboardCapitalization.Characters -> "characters"
|
|
309
|
-
KeyboardCapitalization.Words -> "words"
|
|
310
|
-
KeyboardCapitalization.Sentences -> "sentences"
|
|
311
|
-
else -> "none"
|
|
312
|
-
})
|
|
313
|
-
.put("autoCorrect", options.autoCorrect)
|
|
314
|
-
.put("field", rect(request.textFieldRectInRoot()))
|
|
315
|
-
.put("caret", rect(request.focusedRectInRoot()))
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
// one keyboard edit, applied as one batch the way RecordingInputConnection
|
|
319
|
-
// ends a batch edit. typed text commits as an IME's commitText does; a
|
|
320
|
-
// composition replaces its own region, else the edit's range
|
|
321
|
-
fun edit(command: JSONObject): Boolean {
|
|
322
|
-
val value = request.value()
|
|
323
|
-
val start = command.optInt("start")
|
|
324
|
-
val end = command.optInt("end")
|
|
325
|
-
val composing = value.composition?.let { it.start == start && it.end == end } == true
|
|
326
|
-
val commands: List<EditCommand> = when (command.getString("kind")) {
|
|
327
|
-
"text" -> listOf(CommitTextCommand(command.getString("text"), 1))
|
|
328
|
-
"backspace" -> listOf(BackspaceCommand())
|
|
329
|
-
"enter" -> {
|
|
330
|
-
val performed = action
|
|
331
|
-
if (performed != null) {
|
|
332
|
-
request.onImeAction?.invoke(performed)
|
|
333
|
-
return true
|
|
334
|
-
}
|
|
335
|
-
if (options.singleLine) return false
|
|
336
|
-
listOf(CommitTextCommand("\n", 1))
|
|
337
|
-
}
|
|
338
|
-
"compositionStart" -> if (start == end) return true else listOf(SetComposingRegionCommand(start, end))
|
|
339
|
-
"replace" -> {
|
|
340
|
-
val text = command.getString("text")
|
|
341
|
-
val place = if (composing) emptyList() else listOf(FinishComposingTextCommand(), SetSelectionCommand(start, end))
|
|
342
|
-
place + if (command.getString("composition") == "update") SetComposingTextCommand(text, 1) else CommitTextCommand(text, 1)
|
|
343
|
-
}
|
|
344
|
-
else -> error("unknown input edit ${command.getString("kind")}")
|
|
345
|
-
}
|
|
346
|
-
request.onEditCommand(commands)
|
|
347
|
-
return true
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
// android's default and sans-serif families use the same device font bytes as
|
|
352
|
-
// peach's react native renderer. compose owns shaping and all other families.
|
|
353
|
-
@Composable
|
|
354
|
-
internal fun PeachAndroidFonts(roboto: FontFamily, content: @Composable () -> Unit) {
|
|
355
|
-
val parent = LocalFontFamilyResolver.current
|
|
356
|
-
val resolver = remember(parent, roboto) {
|
|
357
|
-
val backend = checkNotNull(parent.platformTypefacesLoader())
|
|
358
|
-
createPlatformFontFamilyResolver(object : PlatformTypefacesLoader by backend {
|
|
359
|
-
override val cacheKey: Any get() = this
|
|
360
|
-
override fun loadPlatformTypes(fontFamily: FontFamily, fontWeight: FontWeight, fontStyle: FontStyle): Any =
|
|
361
|
-
if (fontFamily == FontFamily.Default || fontFamily == FontFamily.SansSerif)
|
|
362
|
-
parent.resolve(roboto, fontWeight, fontStyle, FontSynthesis.All).value
|
|
363
|
-
else backend.loadPlatformTypes(fontFamily, fontWeight, fontStyle)
|
|
364
|
-
})
|
|
365
|
-
}
|
|
366
|
-
CompositionLocalProvider(LocalFontFamilyResolver provides resolver, content = content)
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
// one compose scene presented by the tenant canvas. the frame clock runs only
|
|
370
|
-
// while clockRunning answers true, as Android's window recomposer pauses its
|
|
371
|
-
// clock below STARTED.
|
|
372
|
-
internal class PeachComposeMount(
|
|
373
|
-
density: Float,
|
|
374
|
-
fontScale: Float,
|
|
375
|
-
locale: String,
|
|
376
|
-
private val fonts: FontFamily,
|
|
377
|
-
val invalidate: (Boolean) -> Unit,
|
|
378
|
-
night: Boolean,
|
|
379
|
-
owners: PlatformArchitectureComponentsOwner? = null,
|
|
380
|
-
insets: PlatformWindowInsets? = null,
|
|
381
|
-
private val clockRunning: () -> Boolean = { true },
|
|
382
|
-
) : AutoCloseable {
|
|
383
|
-
var props by mutableStateOf("")
|
|
384
|
-
// the configuration's night mode, which isSystemInDarkTheme reads
|
|
385
|
-
var night by mutableStateOf(night)
|
|
386
|
-
// the bounds the host last measured or laid the view out in. like a
|
|
387
|
-
// ComposeView before its parent measures it, the content has none and
|
|
388
|
-
// lays out nothing until the first arrive
|
|
389
|
-
var constraints: Constraints? = null
|
|
390
|
-
set(value) {
|
|
391
|
-
if (field != value) {
|
|
392
|
-
field = value
|
|
393
|
-
needsMeasure = true
|
|
394
|
-
rootNeedsMeasure = true
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
private val events = mutableListOf<JSONObject>()
|
|
398
|
-
// state reported once a frame, read when the frame draws: like the decor,
|
|
399
|
-
// the device sees the state a frame ends with, not each step to it
|
|
400
|
-
private val frameState = linkedMapOf<String, () -> Any?>()
|
|
401
|
-
private var importedInsets by mutableStateOf(List(24) { 0 })
|
|
402
|
-
private var importedIme by mutableStateOf(0)
|
|
403
|
-
private val platform = PeachComposePlatform(Density(density, fontScale), LocaleList(locale), IntSize.Zero, owners,
|
|
404
|
-
insets ?: PeachWindowInsets({ importedInsets }, { importedIme }, { false }))
|
|
405
|
-
// imported views own a dispatcher instead of sharing the empty platform owner's.
|
|
406
|
-
private val importedNavigation = if (owners == null) object : NavigationEventDispatcherOwner {
|
|
407
|
-
override val navigationEventDispatcher = NavigationEventDispatcher()
|
|
408
|
-
} else null
|
|
409
|
-
private val importedBack = importedNavigation?.let {
|
|
410
|
-
PeachDialogWindow(0, it.navigationEventDispatcher) {}
|
|
411
|
-
}
|
|
412
|
-
private val recomposer = FrameRecomposer(Dispatchers.Main) { invalidate(false) }
|
|
413
|
-
private var needsMeasure = true
|
|
414
|
-
private var measuredSize = IntSize.Zero
|
|
415
|
-
private var rootSize = IntSize.Zero
|
|
416
|
-
private var rootNeedsMeasure = true
|
|
417
|
-
private var rootRemeasurement: Remeasurement? = null
|
|
418
|
-
private val rootMeasureModifier = object : RemeasurementModifier {
|
|
419
|
-
override fun onRemeasurementAvailable(remeasurement: Remeasurement) {
|
|
420
|
-
rootRemeasurement = remeasurement
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
private var baseDirty = true
|
|
424
|
-
private val magnifiers = PeachMagnifierFactory(platform.windowInsets) { invalidate(false) }
|
|
425
|
-
private val scene = CanvasLayersComposeScene(
|
|
426
|
-
recomposer, platform.density, LayoutDirection.Ltr, null, platform,
|
|
427
|
-
invalidateLayout = { needsMeasure = true; baseDirty = true; invalidate(true) },
|
|
428
|
-
invalidateDraw = { baseDirty = true; invalidate(false) },
|
|
429
|
-
)
|
|
430
|
-
// the session's state as last reported; a change reports it again
|
|
431
|
-
private var reportedInput: String? = null
|
|
432
|
-
// overlay-only draws reuse the immutable scene, so updateContent cannot feed a draw loop.
|
|
433
|
-
private var basePicture: Picture? = null
|
|
434
|
-
private var picture: Picture? = null
|
|
435
|
-
|
|
436
|
-
init {
|
|
437
|
-
platform.onInputChange = { invalidate(false) }
|
|
438
|
-
platform.onDialogChange = { emitAtFrame("dialogs") { platform.dialogState().toString() } }
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
fun dialogState(): JSONArray = platform.dialogState()
|
|
442
|
-
fun dialogBack(): Boolean = platform.dialogBack()
|
|
443
|
-
fun dialogBackPhase(id: Int, phase: String, registration: Int, event: android.window.BackEvent) =
|
|
444
|
-
platform.dialogBackPhase(id, phase, registration, event)
|
|
445
|
-
fun cancelDialogBackGestures() = platform.cancelDialogBackGestures()
|
|
446
|
-
fun back(): Boolean {
|
|
447
|
-
// app activities dispatch their own back; imported views have no activity owner.
|
|
448
|
-
val receivingWindow = importedBack ?: return false
|
|
449
|
-
return platform.dialogBack() || receivingWindow.back()
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
fun setContent(content: @Composable () -> Unit) {
|
|
453
|
-
try {
|
|
454
|
-
scene.setContent {
|
|
455
|
-
// the parent measures the imported root; popup windows keep their own minimums.
|
|
456
|
-
Layout(modifier = rootMeasureModifier, content = {
|
|
457
|
-
CompositionLocalProvider(
|
|
458
|
-
LocalPlatformMagnifierFactory provides magnifiers,
|
|
459
|
-
LocalSystemTheme provides if (night) SystemTheme.DARK else SystemTheme.LIGHT,
|
|
460
|
-
LocalNavigationEventDispatcherOwner provides
|
|
461
|
-
checkNotNull(importedNavigation ?: LocalNavigationEventDispatcherOwner.current),
|
|
462
|
-
) {
|
|
463
|
-
PeachAndroidFonts(fonts, content)
|
|
464
|
-
}
|
|
465
|
-
}) { measurables, _ ->
|
|
466
|
-
val rootConstraints = constraints
|
|
467
|
-
if (rootConstraints == null) {
|
|
468
|
-
// an attached view has no measured children until its parent supplies bounds.
|
|
469
|
-
rootSize = IntSize.Zero
|
|
470
|
-
layout(0, 0) {}
|
|
471
|
-
} else {
|
|
472
|
-
val placeables = measurables.map { it.measure(rootConstraints) }
|
|
473
|
-
rootSize = IntSize(
|
|
474
|
-
rootConstraints.constrainWidth(placeables.maxOfOrNull { it.width } ?: 0),
|
|
475
|
-
rootConstraints.constrainHeight(placeables.maxOfOrNull { it.height } ?: 0),
|
|
476
|
-
)
|
|
477
|
-
layout(rootSize.width, rootSize.height) { placeables.forEach { it.place(0, 0) } }
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
} catch (failure: Throwable) {
|
|
482
|
-
close()
|
|
483
|
-
throw failure
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
fun emit(name: String, args: Any?) {
|
|
488
|
-
events.add(JSONObject().put("name", name).put("args", args))
|
|
489
|
-
invalidate(false)
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
fun windowInsets(insets: String, imeBottom: Int) {
|
|
493
|
-
require(imeBottom >= 0)
|
|
494
|
-
val next = readPeachWindowInsets(insets)
|
|
495
|
-
if (next == importedInsets && imeBottom == importedIme) return
|
|
496
|
-
importedInsets = next
|
|
497
|
-
importedIme = imeBottom
|
|
498
|
-
needsMeasure = true
|
|
499
|
-
invalidate(true)
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
fun emitAtFrame(name: String, args: () -> Any?) {
|
|
503
|
-
frameState[name] = args
|
|
504
|
-
invalidate(false)
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
fun measure(): IntSize {
|
|
508
|
-
// host bounds can change while the scene's popup bounds remain the same.
|
|
509
|
-
if (rootNeedsMeasure) {
|
|
510
|
-
rootRemeasurement?.forceRemeasure()
|
|
511
|
-
rootNeedsMeasure = false
|
|
512
|
-
}
|
|
513
|
-
// intrinsic root constraints can be unbounded; popup windows measure within the laid-out view.
|
|
514
|
-
scene.measureContent(Constraints(maxWidth = measuredSize.width, maxHeight = measuredSize.height))
|
|
515
|
-
val measured = rootSize
|
|
516
|
-
scene.size = measured
|
|
517
|
-
platform.size = measured
|
|
518
|
-
measuredSize = measured
|
|
519
|
-
needsMeasure = false
|
|
520
|
-
return measured
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
fun frame(nanos: Long): String {
|
|
524
|
-
releaseFrame()
|
|
525
|
-
try {
|
|
526
|
-
Snapshot.sendApplyNotifications()
|
|
527
|
-
if (clockRunning()) recomposer.performFrame(nanos)
|
|
528
|
-
val measured = if (needsMeasure && constraints != null) measure() else measuredSize
|
|
529
|
-
platform.size = measured
|
|
530
|
-
scene.size = measured
|
|
531
|
-
scene.measureAndLayout()
|
|
532
|
-
if (baseDirty || basePicture == null) {
|
|
533
|
-
val recorder = PictureRecorder()
|
|
534
|
-
try {
|
|
535
|
-
val canvas = recorder.beginRecording(SkRect.makeWH(
|
|
536
|
-
measured.width.coerceAtLeast(1).toFloat(), measured.height.coerceAtLeast(1).toFloat(),
|
|
537
|
-
))
|
|
538
|
-
canvas.clear(Color.TRANSPARENT)
|
|
539
|
-
baseDirty = false
|
|
540
|
-
scene.draw(canvas.asComposeCanvas())
|
|
541
|
-
val next = recorder.finishRecordingAsPicture()
|
|
542
|
-
basePicture?.close()
|
|
543
|
-
basePicture = next
|
|
544
|
-
} finally { recorder.close() }
|
|
545
|
-
}
|
|
546
|
-
val base = checkNotNull(basePicture)
|
|
547
|
-
picture = if (magnifiers.hasOverlays) magnifiers.compose(base, measured) else base
|
|
548
|
-
val reply = JSONObject().put("width", measured.width).put("height", measured.height)
|
|
549
|
-
.put("pending", recomposer.hasPendingWork() || scene.hasInvalidations())
|
|
550
|
-
for ((name, args) in frameState) events.add(JSONObject().put("name", name).put("args", args()))
|
|
551
|
-
frameState.clear()
|
|
552
|
-
reply.put("events", JSONArray(events))
|
|
553
|
-
val input = platform.input?.state()?.toString()
|
|
554
|
-
if (input != reportedInput) {
|
|
555
|
-
reportedInput = input
|
|
556
|
-
reply.put("input", input?.let { JSONObject(it) } ?: JSONObject.NULL)
|
|
557
|
-
}
|
|
558
|
-
events.clear()
|
|
559
|
-
reply.put("picture", getPtr(checkNotNull(picture)))
|
|
560
|
-
return reply.toString()
|
|
561
|
-
} catch (failure: Throwable) {
|
|
562
|
-
releaseFrame()
|
|
563
|
-
throw failure
|
|
564
|
-
}
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
fun pointer(phase: String, x: Float, y: Float, millis: Long) {
|
|
568
|
-
if (phase == "cancel") scene.cancelPointerInput()
|
|
569
|
-
else scene.sendPointerEvent(
|
|
570
|
-
when (phase) {
|
|
571
|
-
"press" -> PointerEventType.Press
|
|
572
|
-
"release" -> PointerEventType.Release
|
|
573
|
-
"move" -> PointerEventType.Move
|
|
574
|
-
else -> error("unknown pointer phase $phase")
|
|
575
|
-
}, Offset(x, y), timeMillis = millis, type = PointerType.Touch,
|
|
576
|
-
)
|
|
577
|
-
invalidate(false)
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
private fun session(token: Int) = platform.input?.takeIf { it.token == token }
|
|
581
|
-
|
|
582
|
-
fun inputEdit(token: Int, command: String): Boolean {
|
|
583
|
-
val session = session(token) ?: return false
|
|
584
|
-
return session.edit(JSONObject(command)).also { invalidate(false) }
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
// a hardware key, pressed and released, through compose's key input as an
|
|
588
|
-
// android view dispatches it; true when compose consumed the press
|
|
589
|
-
fun inputKey(token: Int, name: String, ctrl: Boolean, shift: Boolean, alt: Boolean): Boolean {
|
|
590
|
-
if (session(token) == null) return false
|
|
591
|
-
val key = hardwareKeys[name] ?: name.singleOrNull()?.lowercaseChar()?.let { letterKeys["$it"] } ?: return false
|
|
592
|
-
val codePoint = name.singleOrNull()?.code ?: 0
|
|
593
|
-
fun send(type: KeyEventType) = scene.sendKeyEvent(KeyEvent(key, type, codePoint,
|
|
594
|
-
isCtrlPressed = ctrl, isAltPressed = alt, isShiftPressed = shift))
|
|
595
|
-
val consumed = send(KeyEventType.KeyDown)
|
|
596
|
-
send(KeyEventType.KeyUp)
|
|
597
|
-
invalidate(false)
|
|
598
|
-
return consumed
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
fun inputState(token: Int): String = session(token)?.state()?.toString() ?: ""
|
|
602
|
-
|
|
603
|
-
// the host gave focus to another input: the view loses focus, as
|
|
604
|
-
// View.clearFocus does, and compose closes the session itself
|
|
605
|
-
fun inputBlur(token: Int) {
|
|
606
|
-
if (session(token) == null) return
|
|
607
|
-
scene.focusManager.releaseFocus()
|
|
608
|
-
invalidate(false)
|
|
609
|
-
}
|
|
610
|
-
|
|
611
|
-
// each owner's accessibility node tree, as android's delegate builds it
|
|
612
|
-
fun semantics(): String {
|
|
613
|
-
val nodes = JSONArray()
|
|
614
|
-
platform.owners.forEach { accessibilityNodes(it, nodes) }
|
|
615
|
-
return nodes.toString()
|
|
616
|
-
}
|
|
617
|
-
|
|
618
|
-
fun releaseFrame() {
|
|
619
|
-
if (picture !== basePicture) picture?.close()
|
|
620
|
-
picture = null
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
override fun close() {
|
|
624
|
-
try { scene.close() }
|
|
625
|
-
finally {
|
|
626
|
-
importedNavigation?.navigationEventDispatcher?.dispose()
|
|
627
|
-
try { recomposer.close() }
|
|
628
|
-
finally {
|
|
629
|
-
magnifiers.close()
|
|
630
|
-
releaseFrame()
|
|
631
|
-
basePicture?.close()
|
|
632
|
-
basePicture = null
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
// the keys a hardware keyboard sends, by their DOM names
|
|
639
|
-
private val hardwareKeys = mapOf(
|
|
640
|
-
"ArrowLeft" to Key.DirectionLeft, "ArrowRight" to Key.DirectionRight,
|
|
641
|
-
"ArrowUp" to Key.DirectionUp, "ArrowDown" to Key.DirectionDown,
|
|
642
|
-
"Home" to Key.MoveHome, "End" to Key.MoveEnd, "PageUp" to Key.PageUp, "PageDown" to Key.PageDown,
|
|
643
|
-
"Tab" to Key.Tab, "Delete" to Key.Delete, "Backspace" to Key.Backspace,
|
|
644
|
-
"Enter" to Key.Enter, "Escape" to Key.Escape,
|
|
645
|
-
)
|
|
646
|
-
private val letterKeys = listOf(
|
|
647
|
-
Key.A, Key.B, Key.C, Key.D, Key.E, Key.F, Key.G, Key.H, Key.I, Key.J, Key.K, Key.L, Key.M,
|
|
648
|
-
Key.N, Key.O, Key.P, Key.Q, Key.R, Key.S, Key.T, Key.U, Key.V, Key.W, Key.X, Key.Y, Key.Z,
|
|
649
|
-
).mapIndexed { index, key -> "${'a' + index}" to key }.toMap()
|
|
650
|
-
|
|
651
|
-
internal val mounts = mutableMapOf<Int, PeachComposeMount>()
|
|
652
|
-
private var nextMount = 1
|
|
653
|
-
private var deviceLocale: String? = null
|
|
654
|
-
|
|
655
|
-
internal fun addMount(mount: PeachComposeMount): Int = nextMount++.also { mounts[it] = mount }
|
|
656
|
-
|
|
657
|
-
// the process-wide device setup every scene shares: skiko's platform, the
|
|
658
|
-
// host OS and the device locale, fixed for the life of the process.
|
|
659
|
-
internal fun preparePeachDevice(locale: String) {
|
|
660
|
-
registerSkikoComposeImplementation()
|
|
661
|
-
if (deviceLocale == null) {
|
|
662
|
-
setHostOsProvider { OS.Android }
|
|
663
|
-
val locales = LocaleList(locale)
|
|
664
|
-
setPlatformLocaleProvider { locales }
|
|
665
|
-
deviceLocale = locale
|
|
666
|
-
}
|
|
667
|
-
require(deviceLocale == locale) { "device locale changes require a new Kotlin process" }
|
|
668
|
-
}
|
|
669
|
-
|
|
670
|
-
internal fun robotoFamily(font: String): FontFamily {
|
|
671
|
-
val data = Base64.decode(font)
|
|
672
|
-
return FontFamily(listOf(FontWeight.Normal, FontWeight.Medium, FontWeight.Bold).map { weight ->
|
|
673
|
-
Font("Roboto-${weight.weight}", getData = { data }, weight = weight,
|
|
674
|
-
variationSettings = FontVariation.Settings(weight, FontStyle.Normal))
|
|
675
|
-
})
|
|
676
|
-
}
|
|
677
|
-
|
|
678
|
-
@JsExport
|
|
679
|
-
fun peachViewMount(source: String, view: String, hash: String, props: String,
|
|
680
|
-
density: Float, fontScale: Float, locale: String, night: Boolean,
|
|
681
|
-
font: String, invalidate: (Boolean) -> Unit): String {
|
|
682
|
-
try {
|
|
683
|
-
val dispatch = peachViewDispatcher(source)
|
|
684
|
-
if (dispatch.contractHash != hash) return JSONObject().put("ok", false).put("code", "E_NATIVE_SOURCE_REBUILD")
|
|
685
|
-
.put("error", "composable source $source changed; rebuild the app").toString()
|
|
686
|
-
preparePeachDevice(locale)
|
|
687
|
-
val mount = PeachComposeMount(density, fontScale, locale, robotoFamily(font), invalidate, night)
|
|
688
|
-
mount.props = props
|
|
689
|
-
mount.setContent { dispatch.Content(view, mount.props, mount::emit) }
|
|
690
|
-
return JSONObject().put("ok", true).put("id", addMount(mount)).toString()
|
|
691
|
-
} catch (error: Throwable) {
|
|
692
|
-
return JSONObject().put("ok", false).put("code", "E_NATIVE_SOURCE").put("error", "$source.$view: ${error.message}").toString()
|
|
693
|
-
}
|
|
694
|
-
}
|
|
695
|
-
|
|
696
|
-
@JsExport fun peachViewUpdate(id: Int, props: String) { checkNotNull(mounts[id]).props = props }
|
|
697
|
-
// a host activity that handles uiMode itself, as React Native's does, keeps
|
|
698
|
-
// its views and hands them the new configuration
|
|
699
|
-
@JsExport fun peachViewNight(id: Int, night: Boolean) { checkNotNull(mounts[id]).night = night }
|
|
700
|
-
@JsExport fun peachViewInsets(id: Int, insets: String, imeBottom: Int) { checkNotNull(mounts[id]).windowInsets(insets, imeBottom) }
|
|
701
|
-
@JsExport fun peachViewConstraints(id: Int, minWidth: Int, maxWidth: Int, minHeight: Int, maxHeight: Int) {
|
|
702
|
-
checkNotNull(mounts[id]).also {
|
|
703
|
-
it.constraints = Constraints(minWidth, maxWidth, minHeight, maxHeight)
|
|
704
|
-
it.invalidate(false)
|
|
705
|
-
}
|
|
706
|
-
}
|
|
707
|
-
@JsExport fun peachViewFrame(id: Int, millis: Double): String = checkNotNull(mounts[id]).frame((millis * 1_000_000).toLong())
|
|
708
|
-
@JsExport fun peachViewReleaseFrame(id: Int) { checkNotNull(mounts[id]).releaseFrame() }
|
|
709
|
-
@JsExport fun peachViewBack(id: Int): Boolean = checkNotNull(mounts[id]).back()
|
|
710
|
-
@JsExport fun peachViewPointer(id: Int, phase: String, x: Float, y: Float, millis: Double) = checkNotNull(mounts[id]).pointer(phase, x, y, millis.toLong())
|
|
711
|
-
@JsExport fun peachViewInputEdit(id: Int, token: Int, command: String): Boolean = checkNotNull(mounts[id]).inputEdit(token, command)
|
|
712
|
-
@JsExport fun peachViewInputKey(id: Int, token: Int, key: String, ctrl: Boolean, shift: Boolean, alt: Boolean): Boolean =
|
|
713
|
-
checkNotNull(mounts[id]).inputKey(token, key, ctrl, shift, alt)
|
|
714
|
-
@JsExport fun peachViewInputState(id: Int, token: Int): String = checkNotNull(mounts[id]).inputState(token)
|
|
715
|
-
@JsExport fun peachViewInputBlur(id: Int, token: Int) = checkNotNull(mounts[id]).inputBlur(token)
|
|
716
|
-
@JsExport fun peachViewSemantics(id: Int): String = checkNotNull(mounts[id]).semantics()
|
|
717
|
-
@JsExport fun peachViewDispose(id: Int) { mounts.remove(id)?.close() }
|
|
718
|
-
|
|
719
|
-
@JsExport fun peachViewMeasure(id: Int, minWidth: Int, maxWidth: Int, minHeight: Int, maxHeight: Int): String {
|
|
720
|
-
val mount = checkNotNull(mounts[id])
|
|
721
|
-
mount.constraints = Constraints(minWidth, maxWidth, minHeight, maxHeight)
|
|
722
|
-
val size = mount.measure()
|
|
723
|
-
return JSONObject().put("width", size.width).put("height", size.height).toString()
|
|
724
|
-
}
|