@onekeyfe/react-native-native-overlay 3.0.162-alpha.268

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.
Files changed (163) hide show
  1. package/LICENSE +21 -0
  2. package/NativeOverlay.podspec +30 -0
  3. package/README.md +35 -0
  4. package/android/build.gradle +82 -0
  5. package/android/src/main/AndroidManifest.xml +2 -0
  6. package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayAnimation.kt +176 -0
  7. package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayEntryRootView.kt +415 -0
  8. package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayEvents.kt +38 -0
  9. package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayHost.kt +174 -0
  10. package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayPackage.kt +16 -0
  11. package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayPageHostView.kt +122 -0
  12. package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayPageHostViewManager.kt +40 -0
  13. package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayView.kt +465 -0
  14. package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayViewManager.kt +156 -0
  15. package/android/src/main/jni/CMakeLists.txt +44 -0
  16. package/android/src/main/jni/RNCNativeOverlay.h +19 -0
  17. package/common/cpp/react/renderer/components/RNCNativeOverlay/NativeOverlayComponentDescriptor.h +12 -0
  18. package/common/cpp/react/renderer/components/RNCNativeOverlay/NativeOverlayShadowNode.cpp +12 -0
  19. package/common/cpp/react/renderer/components/RNCNativeOverlay/NativeOverlayShadowNode.h +41 -0
  20. package/common/cpp/react/renderer/components/RNCNativeOverlay/NativeOverlayState.h +40 -0
  21. package/docs/SPEC.md +693 -0
  22. package/ios/NativeOverlayAnimation.swift +160 -0
  23. package/ios/NativeOverlayContainerView.swift +688 -0
  24. package/ios/NativeOverlayKeyboard.swift +88 -0
  25. package/ios/NativeOverlayPageHostView.swift +98 -0
  26. package/ios/NativeOverlaySheetController.swift +391 -0
  27. package/ios/NativeOverlayWindowManager.swift +194 -0
  28. package/ios/RCTNativeOverlayComponentView.h +11 -0
  29. package/ios/RCTNativeOverlayComponentView.mm +193 -0
  30. package/ios/RCTNativeOverlayPageHostComponentView.h +11 -0
  31. package/ios/RCTNativeOverlayPageHostComponentView.mm +64 -0
  32. package/lib/module/NativeOverlayNativeComponent.ts +61 -0
  33. package/lib/module/NativeOverlayPageHostNativeComponent.ts +13 -0
  34. package/lib/module/OverlayErrors.js +6 -0
  35. package/lib/module/OverlayErrors.js.map +1 -0
  36. package/lib/module/OverlayLevelContext.js +27 -0
  37. package/lib/module/OverlayLevelContext.js.map +1 -0
  38. package/lib/module/OverlayLevels.js +33 -0
  39. package/lib/module/OverlayLevels.js.map +1 -0
  40. package/lib/module/OverlayPageHost.js +24 -0
  41. package/lib/module/OverlayPageHost.js.map +1 -0
  42. package/lib/module/OverlayPageHost.web.js +49 -0
  43. package/lib/module/OverlayPageHost.web.js.map +1 -0
  44. package/lib/module/OverlayPageScope.js +41 -0
  45. package/lib/module/OverlayPageScope.js.map +1 -0
  46. package/lib/module/OverlayStore.js +305 -0
  47. package/lib/module/OverlayStore.js.map +1 -0
  48. package/lib/module/OverlayView.js +141 -0
  49. package/lib/module/OverlayView.js.map +1 -0
  50. package/lib/module/OverlayView.web.js +290 -0
  51. package/lib/module/OverlayView.web.js.map +1 -0
  52. package/lib/module/OverlayViewTypes.js +4 -0
  53. package/lib/module/OverlayViewTypes.js.map +1 -0
  54. package/lib/module/animation/motionPresets.js +57 -0
  55. package/lib/module/animation/motionPresets.js.map +1 -0
  56. package/lib/module/animation/platformMotionPresets.js +4 -0
  57. package/lib/module/animation/platformMotionPresets.js.map +1 -0
  58. package/lib/module/animation/platformMotionPresets.web.js +4 -0
  59. package/lib/module/animation/platformMotionPresets.web.js.map +1 -0
  60. package/lib/module/animation/resolveAnimation.js +80 -0
  61. package/lib/module/animation/resolveAnimation.js.map +1 -0
  62. package/lib/module/animation/spring.js +69 -0
  63. package/lib/module/animation/spring.js.map +1 -0
  64. package/lib/module/animation/types.js +2 -0
  65. package/lib/module/animation/types.js.map +1 -0
  66. package/lib/module/index.js +16 -0
  67. package/lib/module/index.js.map +1 -0
  68. package/lib/module/package.json +1 -0
  69. package/lib/module/types.js +2 -0
  70. package/lib/module/types.js.map +1 -0
  71. package/lib/module/useOverlayController.js +127 -0
  72. package/lib/module/useOverlayController.js.map +1 -0
  73. package/lib/module/useSuspendedPageOwners.js +16 -0
  74. package/lib/module/useSuspendedPageOwners.js.map +1 -0
  75. package/lib/module/web/animateTransition.js +115 -0
  76. package/lib/module/web/animateTransition.js.map +1 -0
  77. package/lib/module/web/overlayLayers.js +147 -0
  78. package/lib/module/web/overlayLayers.js.map +1 -0
  79. package/lib/module/web/useKeyboardShift.js +110 -0
  80. package/lib/module/web/useKeyboardShift.js.map +1 -0
  81. package/lib/module/web/useSheetDrag.js +126 -0
  82. package/lib/module/web/useSheetDrag.js.map +1 -0
  83. package/lib/typescript/package.json +1 -0
  84. package/lib/typescript/src/NativeOverlayNativeComponent.d.ts +41 -0
  85. package/lib/typescript/src/NativeOverlayNativeComponent.d.ts.map +1 -0
  86. package/lib/typescript/src/NativeOverlayPageHostNativeComponent.d.ts +9 -0
  87. package/lib/typescript/src/NativeOverlayPageHostNativeComponent.d.ts.map +1 -0
  88. package/lib/typescript/src/OverlayErrors.d.ts +4 -0
  89. package/lib/typescript/src/OverlayErrors.d.ts.map +1 -0
  90. package/lib/typescript/src/OverlayLevelContext.d.ts +12 -0
  91. package/lib/typescript/src/OverlayLevelContext.d.ts.map +1 -0
  92. package/lib/typescript/src/OverlayLevels.d.ts +13 -0
  93. package/lib/typescript/src/OverlayLevels.d.ts.map +1 -0
  94. package/lib/typescript/src/OverlayPageHost.d.ts +9 -0
  95. package/lib/typescript/src/OverlayPageHost.d.ts.map +1 -0
  96. package/lib/typescript/src/OverlayPageHost.web.d.ts +11 -0
  97. package/lib/typescript/src/OverlayPageHost.web.d.ts.map +1 -0
  98. package/lib/typescript/src/OverlayPageScope.d.ts +17 -0
  99. package/lib/typescript/src/OverlayPageScope.d.ts.map +1 -0
  100. package/lib/typescript/src/OverlayStore.d.ts +72 -0
  101. package/lib/typescript/src/OverlayStore.d.ts.map +1 -0
  102. package/lib/typescript/src/OverlayView.d.ts +3 -0
  103. package/lib/typescript/src/OverlayView.d.ts.map +1 -0
  104. package/lib/typescript/src/OverlayView.web.d.ts +3 -0
  105. package/lib/typescript/src/OverlayView.web.d.ts.map +1 -0
  106. package/lib/typescript/src/OverlayViewTypes.d.ts +68 -0
  107. package/lib/typescript/src/OverlayViewTypes.d.ts.map +1 -0
  108. package/lib/typescript/src/animation/motionPresets.d.ts +13 -0
  109. package/lib/typescript/src/animation/motionPresets.d.ts.map +1 -0
  110. package/lib/typescript/src/animation/platformMotionPresets.d.ts +2 -0
  111. package/lib/typescript/src/animation/platformMotionPresets.d.ts.map +1 -0
  112. package/lib/typescript/src/animation/platformMotionPresets.web.d.ts +2 -0
  113. package/lib/typescript/src/animation/platformMotionPresets.web.d.ts.map +1 -0
  114. package/lib/typescript/src/animation/resolveAnimation.d.ts +23 -0
  115. package/lib/typescript/src/animation/resolveAnimation.d.ts.map +1 -0
  116. package/lib/typescript/src/animation/spring.d.ts +24 -0
  117. package/lib/typescript/src/animation/spring.d.ts.map +1 -0
  118. package/lib/typescript/src/animation/types.d.ts +56 -0
  119. package/lib/typescript/src/animation/types.d.ts.map +1 -0
  120. package/lib/typescript/src/index.d.ts +18 -0
  121. package/lib/typescript/src/index.d.ts.map +1 -0
  122. package/lib/typescript/src/types.d.ts +59 -0
  123. package/lib/typescript/src/types.d.ts.map +1 -0
  124. package/lib/typescript/src/useOverlayController.d.ts +29 -0
  125. package/lib/typescript/src/useOverlayController.d.ts.map +1 -0
  126. package/lib/typescript/src/useSuspendedPageOwners.d.ts +7 -0
  127. package/lib/typescript/src/useSuspendedPageOwners.d.ts.map +1 -0
  128. package/lib/typescript/src/web/animateTransition.d.ts +18 -0
  129. package/lib/typescript/src/web/animateTransition.d.ts.map +1 -0
  130. package/lib/typescript/src/web/overlayLayers.d.ts +10 -0
  131. package/lib/typescript/src/web/overlayLayers.d.ts.map +1 -0
  132. package/lib/typescript/src/web/useKeyboardShift.d.ts +29 -0
  133. package/lib/typescript/src/web/useKeyboardShift.d.ts.map +1 -0
  134. package/lib/typescript/src/web/useSheetDrag.d.ts +13 -0
  135. package/lib/typescript/src/web/useSheetDrag.d.ts.map +1 -0
  136. package/package.json +188 -0
  137. package/react-native.config.js +16 -0
  138. package/src/NativeOverlayNativeComponent.ts +61 -0
  139. package/src/NativeOverlayPageHostNativeComponent.ts +13 -0
  140. package/src/OverlayErrors.ts +3 -0
  141. package/src/OverlayLevelContext.tsx +32 -0
  142. package/src/OverlayLevels.ts +40 -0
  143. package/src/OverlayPageHost.tsx +21 -0
  144. package/src/OverlayPageHost.web.tsx +53 -0
  145. package/src/OverlayPageScope.tsx +42 -0
  146. package/src/OverlayStore.ts +401 -0
  147. package/src/OverlayView.tsx +165 -0
  148. package/src/OverlayView.web.tsx +356 -0
  149. package/src/OverlayViewTypes.ts +81 -0
  150. package/src/animation/motionPresets.ts +52 -0
  151. package/src/animation/platformMotionPresets.ts +1 -0
  152. package/src/animation/platformMotionPresets.web.ts +1 -0
  153. package/src/animation/resolveAnimation.ts +103 -0
  154. package/src/animation/spring.ts +80 -0
  155. package/src/animation/types.ts +71 -0
  156. package/src/index.ts +55 -0
  157. package/src/types.ts +79 -0
  158. package/src/useOverlayController.ts +199 -0
  159. package/src/useSuspendedPageOwners.ts +26 -0
  160. package/src/web/animateTransition.ts +137 -0
  161. package/src/web/overlayLayers.ts +182 -0
  162. package/src/web/useKeyboardShift.ts +130 -0
  163. package/src/web/useSheetDrag.ts +143 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 OneKey
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,30 @@
1
+ require "json"
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = "NativeOverlay"
7
+ s.version = package["version"].split("-").first
8
+ s.summary = package["description"]
9
+ s.homepage = "https://github.com/OneKeyHQ/app-modules"
10
+ s.license = package["license"]
11
+ s.authors = "@onekeyfe"
12
+
13
+ s.platforms = { :ios => '16.0' }
14
+ s.source = { :git => "https://github.com/OneKeyHQ/app-modules.git", :tag => "#{s.version}" }
15
+
16
+ s.source_files = [
17
+ "ios/**/*.h",
18
+ "ios/**/*.{swift}",
19
+ "ios/**/*.{m,mm}",
20
+ "common/cpp/**/*.{cpp,h}",
21
+ ]
22
+ # C++ headers stay private so the Swift module does not import them.
23
+ s.project_header_files = "common/cpp/**/*.h"
24
+ s.pod_target_xcconfig = {
25
+ "HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/common/cpp\""
26
+ }
27
+ s.exclude_files = "ios/tests/**/*"
28
+ s.swift_version = '5.0'
29
+ install_modules_dependencies(s)
30
+ end
package/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # @onekeyfe/react-native-native-overlay
2
+
3
+ Native and Web overlay hosts with ordered levels, page scope, lifecycle events,
4
+ keyboard avoidance and Fabric measurement. See [SPEC](docs/SPEC.md) for the
5
+ behavioral contract, platform differences and outstanding runtime acceptance.
6
+
7
+ ```tsx
8
+ import { OverlayView } from '@onekeyfe/react-native-native-overlay';
9
+
10
+ <OverlayView open={open} presentation="sheet" level="modal">
11
+ {content}
12
+ </OverlayView>;
13
+ ```
14
+
15
+ Global levels are ordered modal, hardware, secure, toast, lock, then debug.
16
+ React context stays attached to the original subtree while the native host
17
+ reparents its contents. Page overlays use `OverlayPageHost` and
18
+ `OverlayPageHostScope` / `OverlayPageOwnerScope`. Android and iOS require the React Native new
19
+ architecture; Web additionally requires `react-dom`.
20
+
21
+ ## Development
22
+
23
+ Run `yarn typecheck`, `yarn lint`, `yarn test --runInBand`, and `yarn prepare`.
24
+ This package was initialized from the repository view template and retains
25
+ Fabric rather than Nitro under the explicit exception recorded in the SPEC.
26
+
27
+ ## Release
28
+
29
+ Use the repository `package-publish` CI workflow. This branch's synchronized
30
+ 42-package batch is `3.0.162-alpha.268`, published under `next`; no PR merge or
31
+ stable-tag change is required. Consumers must pin the exact verified version.
32
+
33
+ ## License
34
+
35
+ MIT
@@ -0,0 +1,82 @@
1
+ buildscript {
2
+ ext.getExtOrDefault = {name ->
3
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['NativeOverlay_' + name]
4
+ }
5
+
6
+ repositories {
7
+ google()
8
+ mavenCentral()
9
+ }
10
+
11
+ dependencies {
12
+ classpath "com.android.tools.build:gradle:8.7.2"
13
+ // noinspection DifferentKotlinGradleVersion
14
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}"
15
+ }
16
+ }
17
+
18
+ apply plugin: "com.android.library"
19
+ apply plugin: "kotlin-android"
20
+ apply plugin: "com.facebook.react"
21
+
22
+ def getExtOrIntegerDefault(name) {
23
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["NativeOverlay_" + name]).toInteger()
24
+ }
25
+
26
+ android {
27
+ namespace "com.onekey.nativeoverlay"
28
+
29
+ compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
30
+
31
+ defaultConfig {
32
+ minSdkVersion getExtOrIntegerDefault("minSdkVersion")
33
+ targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
34
+ }
35
+
36
+ buildFeatures {
37
+ buildConfig true
38
+ }
39
+
40
+ buildTypes {
41
+ release {
42
+ minifyEnabled false
43
+ }
44
+ }
45
+
46
+ lintOptions {
47
+ disable "GradleCompatible"
48
+ }
49
+
50
+ compileOptions {
51
+ sourceCompatibility JavaVersion.VERSION_1_8
52
+ targetCompatibility JavaVersion.VERSION_1_8
53
+ }
54
+
55
+ sourceSets {
56
+ main {
57
+ java.srcDirs += [
58
+ "generated/java",
59
+ "generated/jni"
60
+ ]
61
+ }
62
+ }
63
+ }
64
+
65
+ repositories {
66
+ mavenCentral()
67
+ google()
68
+ }
69
+
70
+ def kotlin_version = getExtOrDefault("kotlinVersion")
71
+
72
+ dependencies {
73
+ implementation "com.facebook.react:react-android"
74
+ implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
75
+ implementation "com.google.android.material:material:1.14.0-alpha05"
76
+ }
77
+
78
+ react {
79
+ jsRootDir = file("../src/")
80
+ libraryName = "RNCNativeOverlay"
81
+ codegenJavaPackageName = "com.onekey.nativeoverlay"
82
+ }
@@ -0,0 +1,2 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ </manifest>
@@ -0,0 +1,176 @@
1
+ package com.onekey.nativeoverlay
2
+
3
+ import android.animation.TimeInterpolator
4
+ import android.view.animation.PathInterpolator
5
+ import org.json.JSONObject
6
+ import kotlin.math.abs
7
+ import kotlin.math.cos
8
+ import kotlin.math.exp
9
+ import kotlin.math.sin
10
+ import kotlin.math.sqrt
11
+
12
+ /** Mirrors `IOverlayMotion` from `src/animation/types.ts`. */
13
+ internal sealed class OverlayMotion {
14
+ data class Spring(val mass: Double, val stiffness: Double, val damping: Double) : OverlayMotion()
15
+
16
+ data class Timing(
17
+ val durationMs: Long,
18
+ val x1: Float,
19
+ val y1: Float,
20
+ val x2: Float,
21
+ val y2: Float,
22
+ ) : OverlayMotion()
23
+
24
+ fun interpolator(): TimeInterpolator = when (this) {
25
+ is Spring -> SpringInterpolator(this)
26
+ is Timing -> PathInterpolator(x1, y1, x2, y2)
27
+ }
28
+
29
+ fun durationMs(): Long = when (this) {
30
+ is Spring -> SpringInterpolator.settleTimeMs(this)
31
+ is Timing -> durationMs
32
+ }
33
+
34
+ companion object {
35
+ /** Tamagui `quick` on native. */
36
+ val QUICK = Spring(0.1, 100.0, 20.0)
37
+
38
+ fun parse(json: JSONObject?): OverlayMotion {
39
+ json ?: return QUICK
40
+ return when (json.optString("type")) {
41
+ "timing" -> {
42
+ val timing = json.optJSONObject("timing") ?: return QUICK
43
+ val easing = timing.optJSONArray("easing")
44
+ val points = if (easing != null && easing.length() == 4) {
45
+ FloatArray(4) { easing.optDouble(it).toFloat() }
46
+ } else {
47
+ floatArrayOf(0.25f, 0.1f, 0.25f, 1f)
48
+ }
49
+ Timing(
50
+ timing.optDouble("durationMs", 150.0).toLong(),
51
+ points[0],
52
+ points[1],
53
+ points[2],
54
+ points[3],
55
+ )
56
+ }
57
+ "spring" -> {
58
+ val spring = json.optJSONObject("spring") ?: return QUICK
59
+ Spring(
60
+ spring.optDouble("mass", 1.0),
61
+ spring.optDouble("stiffness", 100.0),
62
+ spring.optDouble("damping", 20.0),
63
+ )
64
+ }
65
+ else -> QUICK
66
+ }
67
+ }
68
+ }
69
+ }
70
+
71
+ /**
72
+ * Analytic step response of `m·x'' + c·x' + k·x = 0`, identical to
73
+ * Reanimated and `springProgressAt` in JS. Driving one ValueAnimator with it
74
+ * keeps alpha, translation, scale and backdrop on the same clock; androidx
75
+ * SpringAnimation would need one animation per property.
76
+ */
77
+ internal class SpringInterpolator(private val spring: OverlayMotion.Spring) : TimeInterpolator {
78
+ private val durationMs = settleTimeMs(spring)
79
+
80
+ override fun getInterpolation(input: Float): Float {
81
+ if (input >= 1f) return 1f
82
+ return progressAt(spring, input * durationMs / 1000.0).toFloat()
83
+ }
84
+
85
+ companion object {
86
+ private const val EPSILON = 0.001
87
+ private const val MAX_SETTLE_MS = 10_000L
88
+ private val settleCache = HashMap<OverlayMotion.Spring, Long>()
89
+
90
+ fun progressAt(spring: OverlayMotion.Spring, t: Double): Double {
91
+ val w0 = sqrt(spring.stiffness / spring.mass)
92
+ val zeta = spring.damping / (2 * sqrt(spring.stiffness * spring.mass))
93
+ return when {
94
+ zeta < 1 -> {
95
+ val wd = w0 * sqrt(1 - zeta * zeta)
96
+ 1 - exp(-zeta * w0 * t) * (cos(wd * t) + (zeta * w0 / wd) * sin(wd * t))
97
+ }
98
+ zeta == 1.0 -> 1 - exp(-w0 * t) * (1 + w0 * t)
99
+ else -> {
100
+ val root = sqrt(zeta * zeta - 1)
101
+ val r1 = -w0 * (zeta - root)
102
+ val r2 = -w0 * (zeta + root)
103
+ 1 - (r2 * exp(r1 * t) - r1 * exp(r2 * t)) / (r2 - r1)
104
+ }
105
+ }
106
+ }
107
+
108
+ fun settleTimeMs(spring: OverlayMotion.Spring): Long = synchronized(settleCache) {
109
+ settleCache.getOrPut(spring) {
110
+ var lastOutside = 0L
111
+ for (t in 0..MAX_SETTLE_MS) {
112
+ if (abs(1 - progressAt(spring, t / 1000.0)) >= EPSILON) lastOutside = t
113
+ }
114
+ lastOutside + 1
115
+ }
116
+ }
117
+ }
118
+ }
119
+
120
+ /** Mirrors `IResolvedOverlayTransition`. */
121
+ internal data class OverlayTransition(
122
+ val kind: String = "fade",
123
+ val edge: String = "bottom",
124
+ val distanceDp: Double? = null,
125
+ val scale: Float = 0.95f,
126
+ val offsetYDp: Double = 0.0,
127
+ val fade: Boolean = true,
128
+ val motion: OverlayMotion = OverlayMotion.QUICK,
129
+ ) {
130
+ val hidesOpacity: Boolean get() = kind == "fade" || fade
131
+
132
+ fun reduceMotionAdjusted(reduceMotion: Boolean): OverlayTransition =
133
+ if (reduceMotion && kind != "none") copy(kind = "fade", fade = true) else this
134
+
135
+ companion object {
136
+ fun parse(json: JSONObject?): OverlayTransition {
137
+ json ?: return OverlayTransition()
138
+ val kind = json.optString("type", "fade")
139
+ return OverlayTransition(
140
+ kind = kind,
141
+ edge = json.optString("edge", "bottom"),
142
+ distanceDp = if (json.has("distance")) json.optDouble("distance") else null,
143
+ scale = json.optDouble("scale", 0.95).toFloat(),
144
+ offsetYDp = json.optDouble("offsetY", 0.0),
145
+ fade = if (json.has("fade")) json.optBoolean("fade") else kind == "fade" || kind == "scale",
146
+ motion = OverlayMotion.parse(json.optJSONObject("motion")),
147
+ )
148
+ }
149
+ }
150
+ }
151
+
152
+ /** Mirrors `IResolvedOverlayAnimation`. */
153
+ internal data class OverlayAnimationConfig(
154
+ val enter: OverlayTransition = OverlayTransition(),
155
+ val exit: OverlayTransition = OverlayTransition(),
156
+ val backdropMotion: OverlayMotion = OverlayMotion.QUICK,
157
+ ) {
158
+ companion object {
159
+ fun parse(source: String?): OverlayAnimationConfig {
160
+ if (source.isNullOrEmpty()) return OverlayAnimationConfig()
161
+ return try {
162
+ val json = JSONObject(source)
163
+ val enter = OverlayTransition.parse(json.optJSONObject("enter"))
164
+ OverlayAnimationConfig(
165
+ enter = enter,
166
+ exit = json.optJSONObject("exit")?.let(OverlayTransition::parse) ?: enter,
167
+ backdropMotion = OverlayMotion.parse(
168
+ json.optJSONObject("backdrop")?.optJSONObject("motion"),
169
+ ),
170
+ )
171
+ } catch (_: Exception) {
172
+ OverlayAnimationConfig()
173
+ }
174
+ }
175
+ }
176
+ }