@luckylca/react-native-liquid-glass 0.2.0 → 0.3.0
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 +20 -33
- package/README.zh-CN.md +20 -33
- package/THIRD_PARTY_NOTICES.md +1 -1
- package/android/build.gradle +4 -4
- package/android/src/main/java/expo/modules/{newhuliquidglass → liquidglass}/EffectiveScrollInputBridge.kt +2 -2
- package/android/src/main/java/expo/modules/{newhuliquidglass/ExpoGlassProviderCoreView.kt → liquidglass/GlassCaptureView.kt} +39 -39
- package/android/src/main/java/expo/modules/{newhuliquidglass/CoreLiquidGlassRegistry.kt → liquidglass/GlassRegistry.kt} +7 -7
- package/android/src/main/java/expo/modules/{newhuliquidglass/ExpoGlassSurfaceCoreView.kt → liquidglass/GlassSurfaceView.kt} +17 -17
- package/android/src/main/java/expo/modules/liquidglass/LiquidGlassModule.kt +205 -0
- package/android/src/main/java/expo/modules/{localglass/ExpoLocalGlassEngineModule.kt → liquidglass/LocalMaterialView.kt} +24 -27
- package/android/src/main/java/expo/modules/{newhuliquidglass → liquidglass}/PassSurfaceSuppression.kt +1 -1
- package/android/src/main/java/expo/modules/{newhuliquidglass → liquidglass}/SharedGlassPassProbeLog.kt +1 -1
- package/android/src/main/java/expo/modules/{newhuliquidglass → liquidglass}/SharedGlassPassWiring.kt +3 -3
- package/android-core/build.gradle +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/backdrop/BackdropRecorder.kt +4 -4
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/backdrop/FrozenBackdrop.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/backdrop/GlassBackdropCoordinator.kt +5 -5
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/backdrop/GlassBackdropSourceHandle.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/backdrop/GlassScrollSource.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/backdrop/GlassViewController.kt +119 -722
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/backdrop/LiquidGlassProviderLayout.kt +2 -2
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/backdrop/LiquidGlassView.kt +2 -2
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/backdrop/ReferenceSourceWindowPolicy.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/backdrop/StableSceneTexturePolicy.kt +1 -1
- package/android-core/src/main/java/io/github/luckylca/liquidglass/backdrop/SurfaceFrameBuilder.kt +278 -0
- package/android-core/src/main/java/io/github/luckylca/liquidglass/backdrop/SurfaceInteraction.kt +359 -0
- package/android-core/src/main/java/io/github/luckylca/liquidglass/backdrop/internal/GlassFrame.kt +110 -0
- package/android-core/src/main/java/io/github/luckylca/liquidglass/backdrop/internal/GlassViewRenderer.kt +728 -0
- package/android-core/src/main/java/io/github/luckylca/liquidglass/backdrop/internal/ReferenceParityPasses.kt +705 -0
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/backdrop/internal/ReferenceTabSampling.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/backdrop/internal/SharedSceneCapture.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/core/GlassCapabilities.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/core/GlassEngine.kt +7 -7
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/core/GlassMaterial.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/core/GlassMath.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/core/GlassOpticalInsets.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/core/GlassRenderTier.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/core/GlassShapePacker.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/core/GlassSurfaceState.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/core/GlassUniforms.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/core/LiquidGlassShaders.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/core/SharedGlassPass.kt +6 -6
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/core/geometry/G2RoundedRectangle.kt +2 -2
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/core/geometry/ReferenceG2MaskTexture.kt +1 -1
- package/android-core/src/main/java/io/github/luckylca/liquidglass/core/shader/HeightFieldGlassShader.kt +7 -0
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/core/shader/ReferenceBackdropBlurShader.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/core/shader/ReferenceGaussianDiscBackdropBlur.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/core/shader/ReferenceGlassUniforms.kt +4 -4
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/core/shader/ReferenceParityGlassShader.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/core/shader/ReferenceParityMultiShapeShader.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/core/shader/SdfScaleLensShader.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/local/LocalGlassHardwareLayerExperiment.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/local/LocalGlassMaterial.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/local/LocalGlassRenderer.kt +2 -2
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/local/LocalGlassRuntimeShader.kt +2 -2
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/local/LocalGlassShader.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/local/LocalGlassView.kt +2 -2
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/motion/GlassMotionDriver.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/motion/GlassMotionState.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/motion/PointerVelocityTracker.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/motion/SpringSpec.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/optics/G2Corner.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/optics/GlassMaterial.kt +3 -3
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/optics/GlassOpticsShader.kt +3 -3
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/optics/GlassParityProbe.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/optics/GlassShapeGeometry.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/optics/GlassUniformBinder.kt +2 -2
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/optics/PixelDiff.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/optics/ReferenceOptics.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/rendering/GlassSurfaceHost.kt +17 -17
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/rendering/GlassSurfaceRenderer.kt +9 -9
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/rendering/RetainedBackdropLayer.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/scheduler/GlassFrameScheduler.kt +2 -2
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/telemetry/EffectiveScrollFpsProbe.kt +13 -13
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/telemetry/GlassTelemetry.kt +1 -1
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/telemetry/LiquidGlassPerfTelemetry.kt +13 -13
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/telemetry/LiquidGlassTrace.kt +3 -3
- package/android-core/src/main/java/{com/newhu → io/github/luckylca}/liquidglass/telemetry/LocalGlassTelemetry.kt +1 -1
- package/docs/architecture.md +61 -0
- package/docs/migration-0.3.md +19 -0
- package/docs/publishing.md +29 -7
- package/expo-module.config.json +4 -4
- package/lib/commonjs/GlassSurface.js +157 -585
- package/lib/commonjs/GlassSurface.js.map +1 -1
- package/lib/commonjs/GlassTabBar.js +18 -957
- package/lib/commonjs/GlassTabBar.js.map +1 -1
- package/lib/commonjs/LocalGlassMaterial.js +3 -9
- package/lib/commonjs/LocalGlassMaterial.js.map +1 -1
- package/lib/commonjs/glassController.js +3 -7
- package/lib/commonjs/glassController.js.map +1 -1
- package/lib/commonjs/glassRuntime.js +7 -19
- package/lib/commonjs/glassRuntime.js.map +1 -1
- package/lib/commonjs/localGlassTelemetry.js +4 -13
- package/lib/commonjs/localGlassTelemetry.js.map +1 -1
- package/lib/commonjs/nativeGlassViews.js +8 -11
- package/lib/commonjs/nativeGlassViews.js.map +1 -1
- package/lib/commonjs/performanceTelemetry.js +2 -6
- package/lib/commonjs/performanceTelemetry.js.map +1 -1
- package/lib/commonjs/surface/InlineSurface.js +134 -0
- package/lib/commonjs/surface/InlineSurface.js.map +1 -0
- package/lib/commonjs/surface/MaterialProvider.js +78 -0
- package/lib/commonjs/surface/MaterialProvider.js.map +1 -0
- package/lib/commonjs/surface/NativeSurface.js +55 -0
- package/lib/commonjs/surface/NativeSurface.js.map +1 -0
- package/lib/commonjs/surface/PortalLayers.js +331 -0
- package/lib/commonjs/surface/PortalLayers.js.map +1 -0
- package/lib/commonjs/surface/contexts.js +108 -0
- package/lib/commonjs/surface/contexts.js.map +1 -0
- package/lib/commonjs/surface/registry.js +113 -0
- package/lib/commonjs/surface/registry.js.map +1 -0
- package/lib/commonjs/surface/styles.js +34 -0
- package/lib/commonjs/surface/styles.js.map +1 -0
- package/lib/commonjs/surface/types.js +3 -0
- package/lib/commonjs/surface/types.js.map +1 -0
- package/lib/commonjs/tabs/GlassTabItem.js +66 -0
- package/lib/commonjs/tabs/GlassTabItem.js.map +1 -0
- package/lib/commonjs/tabs/InlineTabBar.js +867 -0
- package/lib/commonjs/tabs/InlineTabBar.js.map +1 -0
- package/lib/commonjs/tabs/tabConstants.js +22 -0
- package/lib/commonjs/tabs/tabConstants.js.map +1 -0
- package/lib/commonjs/tabs/tabDebug.js +50 -0
- package/lib/commonjs/tabs/tabDebug.js.map +1 -0
- package/lib/commonjs/tabs/tabStyles.js +107 -0
- package/lib/commonjs/tabs/tabStyles.js.map +1 -0
- package/lib/commonjs/tabs/useInlineTabGesture.js +227 -0
- package/lib/commonjs/tabs/useInlineTabGesture.js.map +1 -0
- package/lib/commonjs/theme/buildTheme.js +1 -1
- package/lib/commonjs/theme/buildTheme.js.map +1 -1
- package/lib/module/GlassSurface.js +135 -563
- package/lib/module/GlassSurface.js.map +1 -1
- package/lib/module/GlassTabBar.js +18 -925
- package/lib/module/GlassTabBar.js.map +1 -1
- package/lib/module/LocalGlassMaterial.js +5 -11
- package/lib/module/LocalGlassMaterial.js.map +1 -1
- package/lib/module/glassController.js +3 -7
- package/lib/module/glassController.js.map +1 -1
- package/lib/module/glassRuntime.js +7 -19
- package/lib/module/glassRuntime.js.map +1 -1
- package/lib/module/localGlassTelemetry.js +4 -13
- package/lib/module/localGlassTelemetry.js.map +1 -1
- package/lib/module/nativeGlassViews.js +7 -10
- package/lib/module/nativeGlassViews.js.map +1 -1
- package/lib/module/performanceTelemetry.js +2 -6
- package/lib/module/performanceTelemetry.js.map +1 -1
- package/lib/module/surface/InlineSurface.js +97 -0
- package/lib/module/surface/InlineSurface.js.map +1 -0
- package/lib/module/surface/MaterialProvider.js +74 -0
- package/lib/module/surface/MaterialProvider.js.map +1 -0
- package/lib/module/surface/NativeSurface.js +47 -0
- package/lib/module/surface/NativeSurface.js.map +1 -0
- package/lib/module/surface/PortalLayers.js +292 -0
- package/lib/module/surface/PortalLayers.js.map +1 -0
- package/lib/module/surface/contexts.js +96 -0
- package/lib/module/surface/contexts.js.map +1 -0
- package/lib/module/surface/registry.js +103 -0
- package/lib/module/surface/registry.js.map +1 -0
- package/lib/module/surface/styles.js +31 -0
- package/lib/module/surface/styles.js.map +1 -0
- package/lib/module/surface/types.js +2 -0
- package/lib/module/surface/types.js.map +1 -0
- package/lib/module/tabs/GlassTabItem.js +30 -0
- package/lib/module/tabs/GlassTabItem.js.map +1 -0
- package/lib/module/tabs/InlineTabBar.js +829 -0
- package/lib/module/tabs/InlineTabBar.js.map +1 -0
- package/lib/module/tabs/tabConstants.js +19 -0
- package/lib/module/tabs/tabConstants.js.map +1 -0
- package/lib/module/tabs/tabDebug.js +13 -0
- package/lib/module/tabs/tabDebug.js.map +1 -0
- package/lib/module/tabs/tabStyles.js +104 -0
- package/lib/module/tabs/tabStyles.js.map +1 -0
- package/lib/module/tabs/useInlineTabGesture.js +221 -0
- package/lib/module/tabs/useInlineTabGesture.js.map +1 -0
- package/lib/module/theme/buildTheme.js +1 -1
- package/lib/module/theme/buildTheme.js.map +1 -1
- package/lib/types/GlassSurface.d.ts +17 -86
- package/lib/types/GlassTabBar.d.ts +1 -0
- package/lib/types/glassNativeEngine.d.ts +1 -1
- package/lib/types/glassRuntime.d.ts +5 -2
- package/lib/types/localGlassTelemetry.d.ts +2 -2
- package/lib/types/nativeGlassViews.d.ts +2 -4
- package/lib/types/surface/InlineSurface.d.ts +42 -0
- package/lib/types/surface/MaterialProvider.d.ts +46 -0
- package/lib/types/surface/NativeSurface.d.ts +11 -0
- package/lib/types/surface/PortalLayers.d.ts +33 -0
- package/lib/types/surface/contexts.d.ts +66 -0
- package/lib/types/surface/registry.d.ts +6 -0
- package/lib/types/surface/styles.d.ts +74 -0
- package/lib/types/surface/types.d.ts +118 -0
- package/lib/types/tabs/GlassTabItem.d.ts +20 -0
- package/lib/types/tabs/InlineTabBar.d.ts +5 -0
- package/lib/types/tabs/tabConstants.d.ts +34 -0
- package/lib/types/tabs/tabDebug.d.ts +15 -0
- package/lib/types/tabs/tabStyles.d.ts +119 -0
- package/lib/types/tabs/useInlineTabGesture.d.ts +34 -0
- package/package.json +6 -14
- package/src/GlassSurface.tsx +227 -1337
- package/src/GlassTabBar.tsx +43 -1241
- package/src/LocalGlassMaterial.tsx +5 -11
- package/src/glassController.ts +3 -7
- package/src/glassRuntime.ts +9 -26
- package/src/localGlassTelemetry.ts +6 -15
- package/src/nativeGlassViews.ts +7 -10
- package/src/performanceTelemetry.ts +2 -6
- package/src/surface/InlineSurface.tsx +299 -0
- package/src/surface/MaterialProvider.tsx +235 -0
- package/src/surface/NativeSurface.tsx +115 -0
- package/src/surface/PortalLayers.tsx +574 -0
- package/src/surface/contexts.tsx +188 -0
- package/src/surface/registry.ts +109 -0
- package/src/surface/styles.ts +31 -0
- package/src/surface/types.ts +139 -0
- package/src/tabs/GlassTabItem.tsx +100 -0
- package/src/tabs/InlineTabBar.tsx +1193 -0
- package/src/tabs/tabConstants.ts +35 -0
- package/src/tabs/tabDebug.ts +29 -0
- package/src/tabs/tabStyles.ts +104 -0
- package/src/tabs/useInlineTabGesture.ts +306 -0
- package/src/theme/buildTheme.ts +1 -1
- package/android/src/main/java/expo/modules/localglass/ExpoLocalGlassModule.kt +0 -341
- package/android/src/main/java/expo/modules/localglass/LocalGlassShader.kt +0 -59
- package/android/src/main/java/expo/modules/newhuliquidglass/ExpoGlassCoreModule.kt +0 -226
- package/android-core/src/main/java/com/newhu/liquidglass/backdrop/internal/GlassViewRenderer.kt +0 -1459
- package/android-core/src/main/java/com/newhu/liquidglass/core/shader/HeightFieldGlassShader.kt +0 -7
- package/android-core/src/main/java/com/newhu/liquidglass/rendering/GlassEngineSelection.kt +0 -30
- package/patches/liquid-glass-kit+1.0.0.patch +0 -2015
- package/patches/liquid-glass-kit-invalidation-coalescing.diff +0 -249
- package/patches/liquid-glass-kit-native-infra.diff +0 -624
- package/scripts/apply-legacy-patches.mjs +0 -116
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
package
|
|
1
|
+
package io.github.luckylca.liquidglass.backdrop
|
|
2
2
|
|
|
3
3
|
import android.content.Context
|
|
4
4
|
import android.graphics.Canvas
|
|
@@ -10,7 +10,7 @@ import android.view.View
|
|
|
10
10
|
import android.view.MotionEvent
|
|
11
11
|
import android.widget.FrameLayout
|
|
12
12
|
import androidx.annotation.RequiresApi
|
|
13
|
-
import
|
|
13
|
+
import io.github.luckylca.liquidglass.telemetry.LiquidGlassPerfTelemetry
|
|
14
14
|
import java.util.IdentityHashMap
|
|
15
15
|
|
|
16
16
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
package
|
|
1
|
+
package io.github.luckylca.liquidglass.backdrop
|
|
2
2
|
|
|
3
3
|
import android.content.Context
|
|
4
4
|
import android.graphics.Canvas
|
|
@@ -6,7 +6,7 @@ import android.util.AttributeSet
|
|
|
6
6
|
import android.view.MotionEvent
|
|
7
7
|
import android.widget.FrameLayout
|
|
8
8
|
import androidx.annotation.ColorInt
|
|
9
|
-
import
|
|
9
|
+
import io.github.luckylca.liquidglass.core.GlassRenderTier
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Liquid Glass for the classic View system: a [FrameLayout] whose background is
|
package/android-core/src/main/java/io/github/luckylca/liquidglass/backdrop/SurfaceFrameBuilder.kt
ADDED
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
package io.github.luckylca.liquidglass.backdrop
|
|
2
|
+
import io.github.luckylca.liquidglass.backdrop.GlassViewController.Companion.REFERENCE_PROFILE_BUTTON
|
|
3
|
+
|
|
4
|
+
import android.graphics.Canvas
|
|
5
|
+
import android.graphics.Color
|
|
6
|
+
import android.graphics.Matrix
|
|
7
|
+
import android.graphics.RenderNode
|
|
8
|
+
import android.os.Build
|
|
9
|
+
import android.view.MotionEvent
|
|
10
|
+
import android.view.View
|
|
11
|
+
import androidx.annotation.ColorInt
|
|
12
|
+
import io.github.luckylca.liquidglass.core.GlassRenderTier
|
|
13
|
+
import io.github.luckylca.liquidglass.core.GlassOpticsModel
|
|
14
|
+
import io.github.luckylca.liquidglass.core.SdfScaleLensConfig
|
|
15
|
+
import io.github.luckylca.liquidglass.backdrop.internal.GlassFrame
|
|
16
|
+
import io.github.luckylca.liquidglass.backdrop.internal.GlassViewRenderer
|
|
17
|
+
import io.github.luckylca.liquidglass.telemetry.LiquidGlassPerfTelemetry
|
|
18
|
+
import io.github.luckylca.liquidglass.telemetry.LiquidGlassTrace
|
|
19
|
+
import kotlin.math.abs
|
|
20
|
+
import kotlin.math.cos
|
|
21
|
+
import kotlin.math.exp
|
|
22
|
+
import kotlin.math.min
|
|
23
|
+
import kotlin.math.sin
|
|
24
|
+
import kotlin.math.sqrt
|
|
25
|
+
|
|
26
|
+
/** Package-internal frame sampling helpers; state remains owned by the host. */
|
|
27
|
+
internal fun GlassViewController.buildFrame(): GlassFrame {
|
|
28
|
+
val density = host.resources.displayMetrics.density
|
|
29
|
+
val width = host.width.toFloat()
|
|
30
|
+
val height = host.height.toFloat()
|
|
31
|
+
val maxRadius = min(width, height) / 2f
|
|
32
|
+
val cornerRadiusPx = if (cornerRadiusDp < 0f) {
|
|
33
|
+
maxRadius
|
|
34
|
+
} else {
|
|
35
|
+
min(cornerRadiusDp * density, maxRadius)
|
|
36
|
+
}
|
|
37
|
+
val relative = relativeToProvider()
|
|
38
|
+
updateMotion(relative)
|
|
39
|
+
val backdrop = provider
|
|
40
|
+
val recordedOriginX = backdrop?.recordedOriginXFor(host) ?: 0
|
|
41
|
+
val recordedOriginY = backdrop?.recordedOriginYFor(host) ?: 0
|
|
42
|
+
frame.widthPx = width
|
|
43
|
+
frame.heightPx = height
|
|
44
|
+
frame.cornerRadiusPx = cornerRadiusPx
|
|
45
|
+
frame.shapeMaskText = shapeMaskText
|
|
46
|
+
frame.shapeMaskFontSizePx = shapeMaskFontSizeDp * density
|
|
47
|
+
frame.shapeMaskFontWeight = shapeMaskFontWeight
|
|
48
|
+
frame.progressiveBlurIntensity = progressiveBlurIntensity
|
|
49
|
+
frame.densityScale = density
|
|
50
|
+
frame.opticsModel = opticsModel
|
|
51
|
+
frame.dispersion = chromaticAberration
|
|
52
|
+
frame.sdfScaleLens = sdfScaleLens
|
|
53
|
+
frame.blurRadiusPx = blurRadiusDp * density
|
|
54
|
+
frame.backdropAlreadyBlurred = false
|
|
55
|
+
frame.refractionHeightPx = refractionHeightDp * density
|
|
56
|
+
frame.refractionAmountPx = refractionAmountDp * density
|
|
57
|
+
frame.referenceDepthEffect = referenceDepthEffect
|
|
58
|
+
frame.bodyRefractionAmountPx = bodyRefractionAmountDp * density
|
|
59
|
+
frame.contentScaleX = referenceContentScaleX
|
|
60
|
+
frame.contentScaleY = referenceContentScaleY
|
|
61
|
+
frame.contentOffsetXPx = referenceSampleOffsetXDp * density
|
|
62
|
+
frame.contentOffsetYPx = referenceSampleOffsetYDp * density
|
|
63
|
+
// For a value-driven control the press belongs to the motion driver, which
|
|
64
|
+
// integrates it alongside the value. Reading the controller's own press
|
|
65
|
+
// spring here as well would give the same quantity two authors and make the
|
|
66
|
+
// thumb's scale disagree with the rail it magnifies.
|
|
67
|
+
val driverOwnsPress = supportsNativeOptics &&
|
|
68
|
+
(Build.VERSION.SDK_INT >= 33) &&
|
|
69
|
+
referenceInteractionProfile != 0 && engine.motion.hasInput
|
|
70
|
+
frame.interactionProgress = if (driverOwnsPress) {
|
|
71
|
+
engine.motion.state.pressProgress
|
|
72
|
+
} else {
|
|
73
|
+
maxOf(interactionProgress, pressAmount)
|
|
74
|
+
}
|
|
75
|
+
val buttonDriverOwnsMotion = hasReferenceButtonMotion()
|
|
76
|
+
val interactionScale = if (buttonDriverOwnsMotion) {
|
|
77
|
+
Pair(engine.motion.state.deformationScaleX, engine.motion.state.deformationScaleY)
|
|
78
|
+
} else {
|
|
79
|
+
interactionScale()
|
|
80
|
+
}
|
|
81
|
+
if (buttonDriverOwnsMotion) applyInteractionTransform()
|
|
82
|
+
frame.layerScaleX = interactionScale.first
|
|
83
|
+
frame.layerScaleY = interactionScale.second
|
|
84
|
+
// A travelling knob's offset belongs to the motion state, which is the single
|
|
85
|
+
// writer of the value. Reading it here rather than trusting host.translationX
|
|
86
|
+
// means a knob that was never touched still opens at its value: a controlled
|
|
87
|
+
// slider publishes a value during layout, before any gesture exists.
|
|
88
|
+
val motionKind = engine.motion.kindOf()
|
|
89
|
+
// TAB_LENS belongs here with the other travelling knobs: its View moves by the
|
|
90
|
+
// same motion state, and leaving it out pinned the tab lens to the first tab
|
|
91
|
+
// forever — measured on device, native received travel=820.5 while the lens
|
|
92
|
+
// stayed put and the accent copy showed through a glass parked at tab 0.
|
|
93
|
+
val travels = motionKind == io.github.luckylca.liquidglass.motion.GlassInteractionKind.SLIDER_KNOB ||
|
|
94
|
+
motionKind == io.github.luckylca.liquidglass.motion.GlassInteractionKind.TOGGLE_KNOB ||
|
|
95
|
+
motionKind == io.github.luckylca.liquidglass.motion.GlassInteractionKind.TAB_LENS
|
|
96
|
+
if (travels && supportsNativeOptics) {
|
|
97
|
+
host.translationX = engine.motion.state.translationX
|
|
98
|
+
host.translationY = engine.motion.state.translationY
|
|
99
|
+
}
|
|
100
|
+
frame.layerTranslationXPx = host.translationX
|
|
101
|
+
frame.layerTranslationYPx = host.translationY
|
|
102
|
+
frame.saturation = saturation
|
|
103
|
+
frame.brightness = brightness
|
|
104
|
+
frame.contrast = contrast
|
|
105
|
+
frame.tintColor = glassTintColor
|
|
106
|
+
frame.tintAlpha = tintAlpha
|
|
107
|
+
frame.surfaceColor = glassSurfaceColor
|
|
108
|
+
frame.referenceHighlightStyle = referenceHighlightStyle
|
|
109
|
+
frame.referenceHighlightFalloff = referenceHighlightFalloff
|
|
110
|
+
frame.referenceHighlightColor = referenceHighlightColor
|
|
111
|
+
frame.referenceInteractionProfile = referenceInteractionProfile
|
|
112
|
+
// The rail's colour, the thumb's offset and the magnified track all read this
|
|
113
|
+
// one fraction. Taking it from the motion driver keeps them on the same spring
|
|
114
|
+
// as the press: previously the fraction came from a JS shared value and the
|
|
115
|
+
// press from a native spring, so a release animated the two independently and
|
|
116
|
+
// the colour arrived before the thumb.
|
|
117
|
+
frame.referenceToggleFraction = if (supportsNativeOptics &&
|
|
118
|
+
(Build.VERSION.SDK_INT >= 33) &&
|
|
119
|
+
referenceInteractionProfile != 0 && engine.motion.hasInput
|
|
120
|
+
) {
|
|
121
|
+
engine.motion.state.selectionProgress
|
|
122
|
+
} else {
|
|
123
|
+
referenceToggleFraction
|
|
124
|
+
}
|
|
125
|
+
frame.referenceToggleTrackColorOff = referenceToggleTrackColorOff ?: Color.TRANSPARENT
|
|
126
|
+
frame.referenceToggleTrackColorOn = referenceToggleTrackColorOn ?: Color.TRANSPARENT
|
|
127
|
+
frame.referenceToggleTrackWidthPx = referenceToggleTrackWidthDp * density
|
|
128
|
+
frame.referenceToggleTrackHeightPx = referenceToggleTrackHeightDp * density
|
|
129
|
+
frame.referenceToggleUseSolidBackdropColor = referenceToggleSolidBackdropColor != null
|
|
130
|
+
frame.referenceToggleSolidBackdropColor = referenceToggleSolidBackdropColor ?: Color.TRANSPARENT
|
|
131
|
+
frame.referenceToggleBackdropEnabled = referenceInteractionProfile == 1 &&
|
|
132
|
+
referenceToggleTrackColorOff != null && referenceToggleTrackColorOn != null &&
|
|
133
|
+
referenceToggleTrackWidthDp > 0f && referenceToggleTrackHeightDp > 0f
|
|
134
|
+
frame.referenceOverlayColor = Color.TRANSPARENT
|
|
135
|
+
frame.referenceOverlayAlpha = 0f
|
|
136
|
+
frame.referenceOverlayBlackAlpha = 0f
|
|
137
|
+
frame.chromaticAberration = chromaticAberration
|
|
138
|
+
frame.noiseAlpha = noiseAlpha
|
|
139
|
+
frame.highlightAlpha = if (referenceInteractionProfile == REFERENCE_PROFILE_BUTTON) {
|
|
140
|
+
highlightAlpha
|
|
141
|
+
} else {
|
|
142
|
+
highlightAlpha * (1f + pressAmount * 0.4f)
|
|
143
|
+
}
|
|
144
|
+
frame.specularStrength = specularStrength
|
|
145
|
+
frame.fresnelStrength = fresnelStrength
|
|
146
|
+
frame.innerShadowStrength = innerShadowStrength
|
|
147
|
+
frame.outerShadowAlpha = referenceOuterShadowAlpha
|
|
148
|
+
frame.outerShadowRadiusPx = referenceOuterShadowRadiusDp * density
|
|
149
|
+
frame.outerShadowOffsetYPx = referenceOuterShadowOffsetYDp * density
|
|
150
|
+
frame.highlightWidthPx = highlightWidthDp * density
|
|
151
|
+
if (opticsModel == GlassOpticsModel.REFERENCE_PARITY) {
|
|
152
|
+
val progress = frame.interactionProgress.coerceIn(0f, 1f)
|
|
153
|
+
when (referenceInteractionProfile) {
|
|
154
|
+
1, 2 -> {
|
|
155
|
+
// Toggle and slider backdrops remain at scene coordinates;
|
|
156
|
+
// the reference shader composites their optional scaled
|
|
157
|
+
// track layer independently around the current thumb.
|
|
158
|
+
frame.contentScaleX = 1f
|
|
159
|
+
frame.contentScaleY = 1f
|
|
160
|
+
frame.blurRadiusPx = blurRadiusDp * density * (1f - progress)
|
|
161
|
+
frame.refractionHeightPx *= progress
|
|
162
|
+
frame.refractionAmountPx *= progress
|
|
163
|
+
frame.highlightAlpha = highlightAlpha * progress
|
|
164
|
+
frame.innerShadowStrength *= progress
|
|
165
|
+
// The reference body has surfaceAlpha=0. Its solid white
|
|
166
|
+
// idle pebble is a POST-body SrcOver overlay, fading to
|
|
167
|
+
// zero while pressed, after any backdrop/inner shadow.
|
|
168
|
+
frame.referenceOverlayColor = Color.WHITE
|
|
169
|
+
frame.referenceOverlayAlpha = 1f - progress
|
|
170
|
+
frame.surfaceColor = Color.TRANSPARENT
|
|
171
|
+
}
|
|
172
|
+
3 -> {
|
|
173
|
+
// Both pinned references multiply lens depth/amount by
|
|
174
|
+
// press progress. Full refraction at rest pulled a second
|
|
175
|
+
// copy of the selected glyph into the capsule's top edge.
|
|
176
|
+
frame.blurRadiusPx = 0f
|
|
177
|
+
frame.refractionHeightPx *= progress
|
|
178
|
+
frame.refractionAmountPx *= progress
|
|
179
|
+
frame.highlightAlpha = highlightAlpha * progress
|
|
180
|
+
frame.innerShadowStrength *= progress
|
|
181
|
+
frame.outerShadowAlpha *= progress
|
|
182
|
+
// Reference indicator: 10% theme-aware idle dim overlay
|
|
183
|
+
// fades out, with a 3% black wash fading in on press.
|
|
184
|
+
frame.referenceOverlayColor = glassSurfaceColor
|
|
185
|
+
frame.referenceOverlayAlpha = Color.alpha(glassSurfaceColor) / 255f * (1f - progress)
|
|
186
|
+
frame.referenceOverlayBlackAlpha = 0.03f * progress
|
|
187
|
+
frame.surfaceColor = Color.TRANSPARENT
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
frame.displacementOnlyDebug = displacementOnlyDebug
|
|
192
|
+
frame.sdfDisplacementMapDebug = sdfDisplacementMapDebug
|
|
193
|
+
frame.lightAngleDegrees = lightAngleDegrees
|
|
194
|
+
frame.pressAmount = if (buttonDriverOwnsMotion) engine.motion.state.pressProgress else pressAmount
|
|
195
|
+
frame.pressX = if (referenceInteractionProfile == REFERENCE_PROFILE_BUTTON) forwardedPointerX else pressX
|
|
196
|
+
frame.pressY = if (referenceInteractionProfile == REFERENCE_PROFILE_BUTTON) forwardedPointerY else pressY
|
|
197
|
+
frame.relativeX = relative[0] - recordedOriginX
|
|
198
|
+
frame.relativeY = relative[1] - recordedOriginY
|
|
199
|
+
frame.motionX = motionX ?: derivedMotionX
|
|
200
|
+
frame.motionY = motionY ?: derivedMotionY
|
|
201
|
+
return frame
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
internal fun GlassViewController.updateMotion(relative: FloatArray) {
|
|
205
|
+
val now = System.nanoTime()
|
|
206
|
+
val previousX = previousRelativeX
|
|
207
|
+
val previousY = previousRelativeY
|
|
208
|
+
val elapsedSeconds = (now - previousMotionAtNanos) / 1_000_000_000f
|
|
209
|
+
if (previousX != null && previousY != null &&
|
|
210
|
+
(abs(relative[0] - previousX) > 0.5f || abs(relative[1] - previousY) > 0.5f)
|
|
211
|
+
) {
|
|
212
|
+
// Cropped providers need a new recording when the consumer moves.
|
|
213
|
+
// Full-scene providers (the Expo/RN host) only need new sampling
|
|
214
|
+
// coordinates, so avoid an otherwise redundant full-page re-record.
|
|
215
|
+
val backdrop = provider
|
|
216
|
+
if (!continuousBackdrop && backdrop?.requiresCaptureOnConsumerMovement == true) {
|
|
217
|
+
backdrop.requestCaptureFrame()
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
if (previousX != null && previousY != null && elapsedSeconds in 0.004f..0.12f) {
|
|
221
|
+
val density = host.resources.displayMetrics.density.coerceAtLeast(1f)
|
|
222
|
+
val targetX = (((relative[0] - previousX) / density) / elapsedSeconds / 1800f).coerceIn(-1f, 1f)
|
|
223
|
+
val targetY = (((relative[1] - previousY) / density) / elapsedSeconds / 1800f).coerceIn(-1f, 1f)
|
|
224
|
+
derivedMotionX = derivedMotionX * 0.62f + targetX * 0.38f
|
|
225
|
+
derivedMotionY = derivedMotionY * 0.62f + targetY * 0.38f
|
|
226
|
+
} else if (elapsedSeconds > 0.12f || previousX == null) {
|
|
227
|
+
derivedMotionX = 0f
|
|
228
|
+
derivedMotionY = 0f
|
|
229
|
+
}
|
|
230
|
+
previousRelativeX = relative[0]
|
|
231
|
+
previousRelativeY = relative[1]
|
|
232
|
+
previousMotionAtNanos = now
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
internal fun GlassViewController.relativeToProvider(): FloatArray {
|
|
236
|
+
val backdrop = provider
|
|
237
|
+
if (backdrop == null) {
|
|
238
|
+
relativePosition[0] = 0f
|
|
239
|
+
relativePosition[1] = 0f
|
|
240
|
+
return relativePosition
|
|
241
|
+
}
|
|
242
|
+
val previousX = relativePosition[0]
|
|
243
|
+
val previousY = relativePosition[1]
|
|
244
|
+
LiquidGlassPerfTelemetry.geometryLookup()
|
|
245
|
+
// Keep the consumer's layout origin separate from its own optical
|
|
246
|
+
// press matrix. The shader maps samples through that matrix itself so
|
|
247
|
+
// the sampled scene stays fixed while the glass layer grows.
|
|
248
|
+
locationInWindowWithoutHostTransform(host, locationSelf)
|
|
249
|
+
LiquidGlassPerfTelemetry.geometryLookup()
|
|
250
|
+
backdrop.getCachedSourceWindowOrigin(locationProvider)
|
|
251
|
+
relativePosition[0] = (locationSelf[0] - locationProvider[0]).toFloat()
|
|
252
|
+
relativePosition[1] = (locationSelf[1] - locationProvider[1]).toFloat()
|
|
253
|
+
if (previousX != relativePosition[0] || previousY != relativePosition[1]) {
|
|
254
|
+
if (!continuousBackdrop) {
|
|
255
|
+
backdrop.onConsumerGeometryChanged(
|
|
256
|
+
host,
|
|
257
|
+
relativePosition[0].toInt(),
|
|
258
|
+
relativePosition[1].toInt(),
|
|
259
|
+
)
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return relativePosition
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
internal fun GlassViewController.locationInWindowWithoutHostTransform(view: View, out: IntArray) {
|
|
266
|
+
val parent = view.parent as? View
|
|
267
|
+
if (parent == null) {
|
|
268
|
+
view.getLocationInWindow(out)
|
|
269
|
+
return
|
|
270
|
+
}
|
|
271
|
+
parentToWindow.reset()
|
|
272
|
+
parent.transformMatrixToGlobal(parentToWindow)
|
|
273
|
+
layoutOriginInWindow[0] = (view.left - parent.scrollX).toFloat()
|
|
274
|
+
layoutOriginInWindow[1] = (view.top - parent.scrollY).toFloat()
|
|
275
|
+
parentToWindow.mapPoints(layoutOriginInWindow)
|
|
276
|
+
out[0] = kotlin.math.round(layoutOriginInWindow[0]).toInt()
|
|
277
|
+
out[1] = kotlin.math.round(layoutOriginInWindow[1]).toInt()
|
|
278
|
+
}
|
package/android-core/src/main/java/io/github/luckylca/liquidglass/backdrop/SurfaceInteraction.kt
ADDED
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
package io.github.luckylca.liquidglass.backdrop
|
|
2
|
+
import io.github.luckylca.liquidglass.backdrop.GlassViewController.Companion.REFERENCE_PROFILE_BUTTON
|
|
3
|
+
import io.github.luckylca.liquidglass.backdrop.GlassViewController.Companion.BUTTON_SPRING_STIFFNESS
|
|
4
|
+
import io.github.luckylca.liquidglass.backdrop.GlassViewController.Companion.BUTTON_SPRING_DAMPING
|
|
5
|
+
import io.github.luckylca.liquidglass.backdrop.GlassViewController.Companion.CONTROL_SPRING_STIFFNESS
|
|
6
|
+
import io.github.luckylca.liquidglass.backdrop.GlassViewController.Companion.SPRING_SETTLE_THRESHOLD
|
|
7
|
+
|
|
8
|
+
import android.graphics.Canvas
|
|
9
|
+
import android.graphics.Color
|
|
10
|
+
import android.graphics.Matrix
|
|
11
|
+
import android.graphics.RenderNode
|
|
12
|
+
import android.os.Build
|
|
13
|
+
import android.view.MotionEvent
|
|
14
|
+
import android.view.View
|
|
15
|
+
import androidx.annotation.ColorInt
|
|
16
|
+
import io.github.luckylca.liquidglass.core.GlassRenderTier
|
|
17
|
+
import io.github.luckylca.liquidglass.core.GlassOpticsModel
|
|
18
|
+
import io.github.luckylca.liquidglass.core.SdfScaleLensConfig
|
|
19
|
+
import io.github.luckylca.liquidglass.backdrop.internal.GlassFrame
|
|
20
|
+
import io.github.luckylca.liquidglass.backdrop.internal.GlassViewRenderer
|
|
21
|
+
import io.github.luckylca.liquidglass.telemetry.LiquidGlassPerfTelemetry
|
|
22
|
+
import io.github.luckylca.liquidglass.telemetry.LiquidGlassTrace
|
|
23
|
+
import kotlin.math.abs
|
|
24
|
+
import kotlin.math.cos
|
|
25
|
+
import kotlin.math.exp
|
|
26
|
+
import kotlin.math.min
|
|
27
|
+
import kotlin.math.sin
|
|
28
|
+
import kotlin.math.sqrt
|
|
29
|
+
|
|
30
|
+
/** Package-internal interaction and rendering helpers; state remains owned by the host. */
|
|
31
|
+
internal fun GlassViewController.resetNativePress() {
|
|
32
|
+
host.removeCallbacks(pressAnimationFrame)
|
|
33
|
+
host.removeCallbacks(externalPressPointerBaselineFrame)
|
|
34
|
+
externalPressAwaitingPointerBaseline = false
|
|
35
|
+
pressStartedAtNanos = 0L
|
|
36
|
+
pointerDown = false
|
|
37
|
+
externalButtonProgress = 0f
|
|
38
|
+
pressAmount = 0f
|
|
39
|
+
pressVelocity = 0f
|
|
40
|
+
pressTarget = 0f
|
|
41
|
+
pressStartValue = 0f
|
|
42
|
+
pressStartVelocity = 0f
|
|
43
|
+
dragX = 0f
|
|
44
|
+
dragY = 0f
|
|
45
|
+
dragTargetX = 0f
|
|
46
|
+
dragTargetY = 0f
|
|
47
|
+
dragStartValueX = 0f
|
|
48
|
+
dragStartValueY = 0f
|
|
49
|
+
dragStartVelocityX = 0f
|
|
50
|
+
dragStartVelocityY = 0f
|
|
51
|
+
dragVelocityX = 0f
|
|
52
|
+
dragVelocityY = 0f
|
|
53
|
+
pointerVelocityXDpPerSecond = 0f
|
|
54
|
+
pointerVelocityYDpPerSecond = 0f
|
|
55
|
+
applyInteractionTransform()
|
|
56
|
+
host.invalidate()
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
internal fun GlassViewController.beginExternalButtonPress() {
|
|
60
|
+
host.removeCallbacks(externalPressPointerBaselineFrame)
|
|
61
|
+
externalPressAwaitingPointerBaseline = true
|
|
62
|
+
dragX = 0f
|
|
63
|
+
dragY = 0f
|
|
64
|
+
dragTargetX = 0f
|
|
65
|
+
dragTargetY = 0f
|
|
66
|
+
dragVelocityX = 0f
|
|
67
|
+
dragVelocityY = 0f
|
|
68
|
+
pointerVelocityXDpPerSecond = 0f
|
|
69
|
+
pointerVelocityYDpPerSecond = 0f
|
|
70
|
+
pointerDown = true
|
|
71
|
+
// Keep the initial press stationary until the current Reanimated
|
|
72
|
+
// coordinates have both had a chance to reach the native view.
|
|
73
|
+
pressX = 0f
|
|
74
|
+
pressY = 0f
|
|
75
|
+
host.postOnAnimation(externalPressPointerBaselineFrame)
|
|
76
|
+
animatePress(1f)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
internal fun GlassViewController.captureExternalPressPointerBaseline() {
|
|
80
|
+
externalPressAwaitingPointerBaseline = false
|
|
81
|
+
val density = host.resources.displayMetrics.density
|
|
82
|
+
pressX = interactionPointXDp * density
|
|
83
|
+
pressY = interactionPointYDp * density
|
|
84
|
+
dragStartX = pressX
|
|
85
|
+
dragStartY = pressY
|
|
86
|
+
dragX = 0f
|
|
87
|
+
dragY = 0f
|
|
88
|
+
dragTargetX = 0f
|
|
89
|
+
dragTargetY = 0f
|
|
90
|
+
dragVelocityX = 0f
|
|
91
|
+
dragVelocityY = 0f
|
|
92
|
+
pointerVelocityXDpPerSecond = 0f
|
|
93
|
+
pointerVelocityYDpPerSecond = 0f
|
|
94
|
+
applyInteractionTransform()
|
|
95
|
+
reportConsumerDirty(GlassBackdropDirtyReason.OPTICS)
|
|
96
|
+
host.invalidate()
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
internal fun GlassViewController.endExternalButtonPress() {
|
|
100
|
+
if (!pointerDown) return
|
|
101
|
+
if (externalPressAwaitingPointerBaseline) {
|
|
102
|
+
host.removeCallbacks(externalPressPointerBaselineFrame)
|
|
103
|
+
captureExternalPressPointerBaseline()
|
|
104
|
+
}
|
|
105
|
+
pointerDown = false
|
|
106
|
+
// The pinned reference snaps the pointer position during movement and
|
|
107
|
+
// releases it to a 300/0.5 spring with zero inherited pointer speed.
|
|
108
|
+
animatePress(target = 0f)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
internal fun GlassViewController.updateExternalButtonPointer() {
|
|
112
|
+
if (!pointerDown || referenceInteractionProfile != 0) return
|
|
113
|
+
if (externalPressAwaitingPointerBaseline) return
|
|
114
|
+
val density = host.resources.displayMetrics.density
|
|
115
|
+
pressX = interactionPointXDp * density
|
|
116
|
+
pressY = interactionPointYDp * density
|
|
117
|
+
dragX = pressX - dragStartX
|
|
118
|
+
dragY = pressY - dragStartY
|
|
119
|
+
dragTargetX = dragX
|
|
120
|
+
dragTargetY = dragY
|
|
121
|
+
applyInteractionTransform()
|
|
122
|
+
reportConsumerDirty(GlassBackdropDirtyReason.OPTICS)
|
|
123
|
+
host.invalidate()
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
internal fun GlassViewController.animatePress(target: Float, releaseDragVelocityX: Float? = null, releaseDragVelocityY: Float? = null) {
|
|
127
|
+
val now = System.nanoTime()
|
|
128
|
+
advancePressAnimation(now)
|
|
129
|
+
host.removeCallbacks(pressAnimationFrame)
|
|
130
|
+
pressTarget = target
|
|
131
|
+
pressStartValue = pressAmount
|
|
132
|
+
pressStartVelocity = pressVelocity
|
|
133
|
+
pressStartedAtNanos = now
|
|
134
|
+
if (referenceInteractionProfile == 0 && !pointerDown) {
|
|
135
|
+
dragTargetX = 0f
|
|
136
|
+
dragTargetY = 0f
|
|
137
|
+
}
|
|
138
|
+
dragStartValueX = dragX
|
|
139
|
+
dragStartValueY = dragY
|
|
140
|
+
dragStartVelocityX = releaseDragVelocityX ?: dragVelocityX
|
|
141
|
+
dragStartVelocityY = releaseDragVelocityY ?: dragVelocityY
|
|
142
|
+
dragVelocityX = dragStartVelocityX
|
|
143
|
+
dragVelocityY = dragStartVelocityY
|
|
144
|
+
val pressSettled = abs(pressStartValue - target) < SPRING_SETTLE_THRESHOLD && abs(pressVelocity) < SPRING_SETTLE_THRESHOLD
|
|
145
|
+
val dragSettled = referenceInteractionProfile != 0 || (
|
|
146
|
+
abs(dragStartValueX - dragTargetX) < SPRING_SETTLE_THRESHOLD &&
|
|
147
|
+
abs(dragStartValueY - dragTargetY) < SPRING_SETTLE_THRESHOLD &&
|
|
148
|
+
abs(dragVelocityX) < SPRING_SETTLE_THRESHOLD &&
|
|
149
|
+
abs(dragVelocityY) < SPRING_SETTLE_THRESHOLD
|
|
150
|
+
)
|
|
151
|
+
if (pressSettled && dragSettled) {
|
|
152
|
+
pressAmount = target
|
|
153
|
+
pressVelocity = 0f
|
|
154
|
+
pressStartedAtNanos = 0L
|
|
155
|
+
if (referenceInteractionProfile == 0 && !pointerDown) {
|
|
156
|
+
dragX = dragTargetX
|
|
157
|
+
dragY = dragTargetY
|
|
158
|
+
dragVelocityX = 0f
|
|
159
|
+
dragVelocityY = 0f
|
|
160
|
+
}
|
|
161
|
+
applyInteractionTransform()
|
|
162
|
+
reportConsumerDirty(GlassBackdropDirtyReason.OPTICS)
|
|
163
|
+
host.invalidate()
|
|
164
|
+
return
|
|
165
|
+
}
|
|
166
|
+
host.postOnAnimation(pressAnimationFrame)
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
internal fun GlassViewController.advancePressAnimation(nowNanos: Long): Boolean {
|
|
170
|
+
if (pressStartedAtNanos == 0L) return false
|
|
171
|
+
val elapsed = ((nowNanos - pressStartedAtNanos).coerceAtLeast(0L) / 1_000_000_000.0).toFloat()
|
|
172
|
+
val (stiffness, damping) = when (referenceInteractionProfile) {
|
|
173
|
+
1, 2, 3 -> Pair(CONTROL_SPRING_STIFFNESS, 1f)
|
|
174
|
+
else -> Pair(BUTTON_SPRING_STIFFNESS, BUTTON_SPRING_DAMPING)
|
|
175
|
+
}
|
|
176
|
+
val omega = sqrt(stiffness)
|
|
177
|
+
val x0 = pressStartValue - pressTarget
|
|
178
|
+
val v0 = pressStartVelocity
|
|
179
|
+
val offset: Float
|
|
180
|
+
val velocity: Float
|
|
181
|
+
if (damping >= 1f) {
|
|
182
|
+
val decay = exp(-omega * elapsed)
|
|
183
|
+
offset = x0 * decay + (v0 + omega * x0) * elapsed * decay
|
|
184
|
+
velocity = -omega * x0 * decay + (v0 + omega * x0) * (decay - omega * elapsed * decay)
|
|
185
|
+
} else {
|
|
186
|
+
val omegaD = omega * sqrt(1f - damping * damping)
|
|
187
|
+
val decay = exp(-damping * omega * elapsed)
|
|
188
|
+
val cosWd = cos(omegaD * elapsed)
|
|
189
|
+
val sinWd = sin(omegaD * elapsed)
|
|
190
|
+
val b0 = (v0 + damping * omega * x0) / omegaD
|
|
191
|
+
offset = x0 * decay * cosWd + b0 * decay * sinWd
|
|
192
|
+
velocity = -damping * omega * offset + decay * (-x0 * omegaD * sinWd + b0 * omegaD * cosWd)
|
|
193
|
+
}
|
|
194
|
+
pressAmount = pressTarget + offset
|
|
195
|
+
pressVelocity = velocity
|
|
196
|
+
var dragXSettled = true
|
|
197
|
+
var dragYSettled = true
|
|
198
|
+
if (referenceInteractionProfile == 0) {
|
|
199
|
+
if (pointerDown) {
|
|
200
|
+
// The reference snaps both axes to the active pointer. Do not
|
|
201
|
+
// let the press spring's clock pull the drag point back toward
|
|
202
|
+
// the stale down position while the finger is moving.
|
|
203
|
+
dragX = dragTargetX
|
|
204
|
+
dragY = dragTargetY
|
|
205
|
+
dragVelocityX = 0f
|
|
206
|
+
dragVelocityY = 0f
|
|
207
|
+
} else {
|
|
208
|
+
val dragXResult = springValue(
|
|
209
|
+
dragStartValueX,
|
|
210
|
+
dragStartVelocityX,
|
|
211
|
+
dragTargetX,
|
|
212
|
+
elapsed,
|
|
213
|
+
BUTTON_SPRING_DAMPING,
|
|
214
|
+
)
|
|
215
|
+
dragX = dragXResult.first
|
|
216
|
+
dragVelocityX = dragXResult.second
|
|
217
|
+
val dragYResult = springValue(
|
|
218
|
+
dragStartValueY,
|
|
219
|
+
dragStartVelocityY,
|
|
220
|
+
dragTargetY,
|
|
221
|
+
elapsed,
|
|
222
|
+
BUTTON_SPRING_DAMPING,
|
|
223
|
+
)
|
|
224
|
+
dragY = dragYResult.first
|
|
225
|
+
dragVelocityY = dragYResult.second
|
|
226
|
+
dragXSettled = abs(dragX - dragTargetX) < SPRING_SETTLE_THRESHOLD && abs(dragVelocityX) < SPRING_SETTLE_THRESHOLD
|
|
227
|
+
dragYSettled = abs(dragY - dragTargetY) < SPRING_SETTLE_THRESHOLD && abs(dragVelocityY) < SPRING_SETTLE_THRESHOLD
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
val pressSettled = abs(offset) < SPRING_SETTLE_THRESHOLD && abs(velocity) < SPRING_SETTLE_THRESHOLD
|
|
231
|
+
if (pressSettled && dragXSettled && dragYSettled) {
|
|
232
|
+
pressAmount = pressTarget
|
|
233
|
+
pressVelocity = 0f
|
|
234
|
+
if (referenceInteractionProfile == 0) {
|
|
235
|
+
dragX = dragTargetX
|
|
236
|
+
dragY = dragTargetY
|
|
237
|
+
dragVelocityX = 0f
|
|
238
|
+
dragVelocityY = 0f
|
|
239
|
+
}
|
|
240
|
+
pressStartedAtNanos = 0L
|
|
241
|
+
return false
|
|
242
|
+
}
|
|
243
|
+
return true
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
internal fun GlassViewController.applyInteractionTransform() {
|
|
247
|
+
if (hasReferenceButtonMotion()) {
|
|
248
|
+
val motion = engine.motion.state
|
|
249
|
+
host.translationX = motion.translationX
|
|
250
|
+
host.translationY = motion.translationY
|
|
251
|
+
host.scaleX = motion.deformationScaleX
|
|
252
|
+
host.scaleY = motion.deformationScaleY
|
|
253
|
+
onInteractionTransformUpdated?.invoke(
|
|
254
|
+
host.translationX,
|
|
255
|
+
host.translationY,
|
|
256
|
+
host.scaleX,
|
|
257
|
+
host.scaleY,
|
|
258
|
+
)
|
|
259
|
+
return
|
|
260
|
+
}
|
|
261
|
+
val interactionScale = interactionScale()
|
|
262
|
+
if (referenceInteractionProfile == 0) {
|
|
263
|
+
val width = host.width.toFloat().coerceAtLeast(1f)
|
|
264
|
+
val height = host.height.toFloat().coerceAtLeast(1f)
|
|
265
|
+
val minDimension = min(width, height)
|
|
266
|
+
val safeDimension = minDimension.coerceAtLeast(1f)
|
|
267
|
+
host.translationX = minDimension * kotlin.math.tanh(0.05f * dragX / safeDimension)
|
|
268
|
+
host.translationY = minDimension * kotlin.math.tanh(0.05f * dragY / safeDimension)
|
|
269
|
+
host.scaleX = interactionScale.first
|
|
270
|
+
host.scaleY = interactionScale.second
|
|
271
|
+
} else {
|
|
272
|
+
// A knob's position is the motion state's, not a fixed zero. This branch
|
|
273
|
+
// used to clear the translation every frame, which is correct for a glass
|
|
274
|
+
// that stays where layout put it and wrong for one that travels: the value,
|
|
275
|
+
// the rail fill and the label all advanced while the lens stayed at the
|
|
276
|
+
// rail's start, because this line rewrote what the spring had produced.
|
|
277
|
+
val kindNow = engine.motion.kindOf()
|
|
278
|
+
val travelling = kindNow == io.github.luckylca.liquidglass.motion.GlassInteractionKind.SLIDER_KNOB ||
|
|
279
|
+
kindNow == io.github.luckylca.liquidglass.motion.GlassInteractionKind.TOGGLE_KNOB ||
|
|
280
|
+
kindNow == io.github.luckylca.liquidglass.motion.GlassInteractionKind.TAB_LENS
|
|
281
|
+
if (travelling && supportsNativeOptics) {
|
|
282
|
+
host.translationX = engine.motion.state.translationX
|
|
283
|
+
host.translationY = engine.motion.state.translationY
|
|
284
|
+
} else {
|
|
285
|
+
host.translationX = 0f
|
|
286
|
+
host.translationY = 0f
|
|
287
|
+
}
|
|
288
|
+
host.scaleX = interactionScale.first
|
|
289
|
+
host.scaleY = interactionScale.second
|
|
290
|
+
}
|
|
291
|
+
onInteractionTransformUpdated?.invoke(
|
|
292
|
+
host.translationX,
|
|
293
|
+
host.translationY,
|
|
294
|
+
host.scaleX,
|
|
295
|
+
host.scaleY,
|
|
296
|
+
)
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
internal fun GlassViewController.hasReferenceButtonMotion(): Boolean =
|
|
300
|
+
referenceInteractionProfile == REFERENCE_PROFILE_BUTTON &&
|
|
301
|
+
supportsNativeOptics &&
|
|
302
|
+
(Build.VERSION.SDK_INT >= 33) &&
|
|
303
|
+
engine.motion.hasInput
|
|
304
|
+
|
|
305
|
+
/** Matches the View graphics-layer transform in applyInteractionTransform(). */
|
|
306
|
+
|
|
307
|
+
internal fun GlassViewController.interactionScale(): Pair<Float, Float> {
|
|
308
|
+
if (referenceInteractionProfile in 1..3) {
|
|
309
|
+
// Toggle/slider (pressedScale = 1.5) and tab lens (78/56) share the
|
|
310
|
+
// native DampedDragAnimation / VelocityTracker deformation spring.
|
|
311
|
+
// Reading it keeps both the View layer and the shader sample map in sync.
|
|
312
|
+
if (supportsNativeOptics &&
|
|
313
|
+
(Build.VERSION.SDK_INT >= 33) &&
|
|
314
|
+
engine.motion.hasInput
|
|
315
|
+
) {
|
|
316
|
+
return Pair(engine.motion.state.deformationScaleX, engine.motion.state.deformationScaleY)
|
|
317
|
+
}
|
|
318
|
+
val progress = maxOf(interactionProgress, pressAmount).coerceIn(0f, 1f)
|
|
319
|
+
val maxScale = if (referenceInteractionProfile == 3) 78f / 56f else 1.5f
|
|
320
|
+
val scale = 1f + (maxScale - 1f) * progress
|
|
321
|
+
return Pair(scale, scale)
|
|
322
|
+
}
|
|
323
|
+
if (referenceInteractionProfile != 0) {
|
|
324
|
+
val scale = 1f + 0.025f * pressAmount
|
|
325
|
+
return Pair(scale, scale)
|
|
326
|
+
}
|
|
327
|
+
val width = host.width.toFloat().coerceAtLeast(1f)
|
|
328
|
+
val height = host.height.toFloat().coerceAtLeast(1f)
|
|
329
|
+
val maxDimension = maxOf(width, height)
|
|
330
|
+
val pressScaleRatio = 4f / 48f
|
|
331
|
+
val scale = 1f + pressScaleRatio * pressAmount
|
|
332
|
+
val distance = sqrt(dragX * dragX + dragY * dragY)
|
|
333
|
+
val angle = kotlin.math.atan2(dragY, dragX)
|
|
334
|
+
val widthHeightCap = min(width / height, 1f)
|
|
335
|
+
val heightWidthCap = min(height / width, 1f)
|
|
336
|
+
return Pair(
|
|
337
|
+
scale + pressScaleRatio * abs(kotlin.math.cos(angle) * distance / maxDimension) * widthHeightCap,
|
|
338
|
+
scale + pressScaleRatio * abs(kotlin.math.sin(angle) * distance / maxDimension) * heightWidthCap,
|
|
339
|
+
)
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
internal fun GlassViewController.springValue(
|
|
343
|
+
start: Float,
|
|
344
|
+
startVelocity: Float,
|
|
345
|
+
target: Float,
|
|
346
|
+
elapsed: Float,
|
|
347
|
+
damping: Float,
|
|
348
|
+
): Pair<Float, Float> {
|
|
349
|
+
val omega = sqrt(BUTTON_SPRING_STIFFNESS)
|
|
350
|
+
val omegaD = omega * sqrt(1f - damping * damping)
|
|
351
|
+
val decay = exp(-damping * omega * elapsed)
|
|
352
|
+
val cosWd = cos(omegaD * elapsed)
|
|
353
|
+
val sinWd = sin(omegaD * elapsed)
|
|
354
|
+
val x0 = start - target
|
|
355
|
+
val b0 = (startVelocity + damping * omega * x0) / omegaD
|
|
356
|
+
val offset = x0 * decay * cosWd + b0 * decay * sinWd
|
|
357
|
+
val velocity = -damping * omega * offset + decay * (-x0 * omegaD * sinWd + b0 * omegaD * cosWd)
|
|
358
|
+
return Pair(target + offset, velocity)
|
|
359
|
+
}
|