glacia-native 0.5.2 → 0.6.1
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 +84 -17
- package/lib/module/Accordion.js +58 -0
- package/lib/module/ActionSheet.js +38 -0
- package/lib/module/Alert.js +23 -0
- package/lib/module/AlertDialog.js +47 -0
- package/lib/module/Avatar.js +48 -0
- package/lib/module/Badge.js +36 -0
- package/lib/module/Bars.js +13 -268
- package/lib/module/Button.js +57 -39
- package/lib/module/Card.js +31 -19
- package/lib/module/Checkbox.js +42 -0
- package/lib/module/Chip.js +80 -0
- package/lib/module/Collapsible.js +26 -0
- package/lib/module/ContextMenu.js +33 -0
- package/lib/module/Dialog.js +39 -123
- package/lib/module/DropdownMenu.js +33 -0
- package/lib/module/Field.js +22 -0
- package/lib/module/Glass.js +10 -3
- package/lib/module/Group.js +36 -0
- package/lib/module/IconButton.js +40 -0
- package/lib/module/Input.js +43 -38
- package/lib/module/Label.js +17 -0
- package/lib/module/MorphGroup.js +47 -0
- package/lib/module/Popover.js +29 -0
- package/lib/module/Progress.js +32 -0
- package/lib/module/RadioGroup.js +51 -0
- package/lib/module/Scrim.js +44 -0
- package/lib/module/SegmentedControl.js +70 -63
- package/lib/module/Select.js +51 -0
- package/lib/module/Separator.js +25 -0
- package/lib/module/Sheet.js +51 -0
- package/lib/module/Skeleton.js +48 -0
- package/lib/module/Slider.js +45 -34
- package/lib/module/Stepper.js +167 -0
- package/lib/module/Switch.js +45 -55
- package/lib/module/TabBar.js +50 -44
- package/lib/module/Textarea.js +18 -0
- package/lib/module/Toast.js +55 -0
- package/lib/module/Toggle.js +47 -0
- package/lib/module/ToggleGroup.js +56 -0
- package/lib/module/Toolbar.js +37 -0
- package/lib/module/Tooltip.js +31 -0
- package/lib/module/glass-provider.js +28 -0
- package/lib/module/glass-stack.js +61 -0
- package/lib/module/index.js +78 -109
- package/lib/module/internal/GlassBackdrop.js +36 -0
- package/lib/module/internal/GlassView.js +43 -11
- package/lib/module/internal/blur-community.js +20 -0
- package/lib/module/internal/blur-community.web.js +9 -0
- package/lib/module/internal/blur.js +6 -9
- package/lib/module/internal/glass-routing.js +156 -30
- package/lib/module/internal/initials.js +12 -0
- package/lib/module/internal/overlay.js +147 -0
- package/lib/module/internal/primitives.js +16 -0
- package/lib/typescript/Accordion.d.ts +22 -0
- package/lib/typescript/ActionSheet.d.ts +24 -0
- package/lib/typescript/Alert.d.ts +15 -0
- package/lib/typescript/AlertDialog.d.ts +17 -0
- package/lib/typescript/Avatar.d.ts +22 -0
- package/lib/typescript/Badge.d.ts +12 -0
- package/lib/typescript/Bars.d.ts +3 -188
- package/lib/typescript/Button.d.ts +44 -10
- package/lib/typescript/Card.d.ts +30 -3
- package/lib/typescript/Checkbox.d.ts +14 -0
- package/lib/typescript/Chip.d.ts +19 -0
- package/lib/typescript/Collapsible.d.ts +17 -0
- package/lib/typescript/ContextMenu.d.ts +23 -0
- package/lib/typescript/Dialog.d.ts +8 -68
- package/lib/typescript/DropdownMenu.d.ts +23 -0
- package/lib/typescript/Field.d.ts +19 -0
- package/lib/typescript/Glass.d.ts +11 -2
- package/lib/typescript/Group.d.ts +35 -0
- package/lib/typescript/IconButton.d.ts +21 -0
- package/lib/typescript/Input.d.ts +17 -18
- package/lib/typescript/Label.d.ts +14 -0
- package/lib/typescript/MorphGroup.d.ts +46 -0
- package/lib/typescript/Popover.d.ts +17 -0
- package/lib/typescript/Progress.d.ts +13 -0
- package/lib/typescript/RadioGroup.d.ts +21 -0
- package/lib/typescript/Scrim.d.ts +33 -0
- package/lib/typescript/SegmentedControl.d.ts +24 -13
- package/lib/typescript/Select.d.ts +19 -0
- package/lib/typescript/Separator.d.ts +10 -0
- package/lib/typescript/Sheet.d.ts +45 -0
- package/lib/typescript/Skeleton.d.ts +10 -0
- package/lib/typescript/Slider.d.ts +15 -7
- package/lib/typescript/Stepper.d.ts +49 -0
- package/lib/typescript/Switch.d.ts +19 -12
- package/lib/typescript/TabBar.d.ts +18 -6
- package/lib/typescript/Textarea.d.ts +6 -0
- package/lib/typescript/Toast.d.ts +40 -0
- package/lib/typescript/Toggle.d.ts +21 -0
- package/lib/typescript/ToggleGroup.d.ts +22 -0
- package/lib/typescript/Toolbar.d.ts +35 -0
- package/lib/typescript/Tooltip.d.ts +16 -0
- package/lib/typescript/glass-provider.d.ts +34 -0
- package/lib/typescript/glass-stack.d.ts +54 -0
- package/lib/typescript/index.d.ts +38 -17
- package/lib/typescript/internal/GlassBackdrop.d.ts +33 -0
- package/lib/typescript/internal/GlassView.d.ts +18 -2
- package/lib/typescript/internal/blur-community.d.ts +2 -0
- package/lib/typescript/internal/blur-community.web.d.ts +2 -0
- package/lib/typescript/internal/glass-routing.d.ts +83 -15
- package/lib/typescript/internal/initials.d.ts +2 -0
- package/lib/typescript/internal/overlay.d.ts +74 -0
- package/lib/typescript/internal/primitives.d.ts +11 -0
- package/package.json +12 -10
- package/src/Accordion.tsx +165 -0
- package/src/ActionSheet.tsx +149 -0
- package/src/Alert.tsx +85 -0
- package/src/AlertDialog.tsx +124 -0
- package/src/Avatar.tsx +102 -0
- package/src/Badge.tsx +80 -0
- package/src/Bars.tsx +10 -807
- package/src/Button.tsx +196 -67
- package/src/Card.tsx +105 -32
- package/src/Checkbox.tsx +98 -0
- package/src/Chip.tsx +149 -0
- package/src/Collapsible.tsx +66 -0
- package/src/ContextMenu.tsx +103 -0
- package/src/Dialog.tsx +85 -335
- package/src/DropdownMenu.tsx +103 -0
- package/src/Field.tsx +65 -0
- package/src/Glass.tsx +15 -5
- package/src/Group.tsx +98 -0
- package/src/IconButton.tsx +110 -0
- package/src/Input.tsx +139 -87
- package/src/Label.tsx +56 -0
- package/src/MorphGroup.tsx +134 -0
- package/src/Popover.tsx +81 -0
- package/src/Progress.tsx +83 -0
- package/src/RadioGroup.tsx +122 -0
- package/src/Scrim.tsx +94 -0
- package/src/SegmentedControl.tsx +132 -99
- package/src/Select.tsx +136 -0
- package/src/Separator.tsx +52 -0
- package/src/Sheet.tsx +139 -0
- package/src/Skeleton.tsx +77 -0
- package/src/Slider.tsx +84 -47
- package/src/Stepper.tsx +315 -0
- package/src/Switch.tsx +81 -73
- package/src/TabBar.tsx +106 -93
- package/src/Textarea.tsx +34 -0
- package/src/Toast.tsx +131 -0
- package/src/Toggle.tsx +113 -0
- package/src/ToggleGroup.tsx +129 -0
- package/src/Toolbar.tsx +111 -0
- package/src/Tooltip.tsx +79 -0
- package/src/engine/CHANGELOG.md +430 -0
- package/src/engine/NOTICE +54 -0
- package/src/engine/README.md +975 -0
- package/src/engine/android/build.gradle +18 -0
- package/src/engine/android/src/main/AndroidManifest.xml +2 -0
- package/src/engine/android/src/main/java/expo/modules/liquidglass/ExpoLiquidGlassModule.kt +174 -0
- package/src/engine/android/src/main/java/expo/modules/liquidglass/GlassConstants.kt +7 -0
- package/src/engine/android/src/main/java/expo/modules/liquidglass/LiquidGlassContainerView.kt +16 -0
- package/src/engine/android/src/main/java/expo/modules/liquidglass/LiquidGlassProviderView.kt +165 -0
- package/src/engine/android/src/main/java/expo/modules/liquidglass/LiquidGlassView.kt +1731 -0
- package/src/engine/android/src/main/java/expo/modules/liquidglass/enums/GlassEnums.kt +171 -0
- package/src/engine/android/src/main/java/expo/modules/liquidglass/glass/BackdropGraph.kt +146 -0
- package/src/engine/android/src/main/java/expo/modules/liquidglass/glass/BackdropSource.kt +53 -0
- package/src/engine/android/src/main/java/expo/modules/liquidglass/glass/ContinuousCorners.kt +188 -0
- package/src/engine/android/src/main/java/expo/modules/liquidglass/glass/CornerRadii.kt +62 -0
- package/src/engine/android/src/main/java/expo/modules/liquidglass/glass/GlassAppearance.kt +352 -0
- package/src/engine/android/src/main/java/expo/modules/liquidglass/glass/GlassDebug.kt +109 -0
- package/src/engine/android/src/main/java/expo/modules/liquidglass/glass/GlassEnvironment.kt +139 -0
- package/src/engine/android/src/main/java/expo/modules/liquidglass/glass/GlassHdr.kt +85 -0
- package/src/engine/android/src/main/java/expo/modules/liquidglass/glass/GlassLuminanceProbe.kt +189 -0
- package/src/engine/android/src/main/java/expo/modules/liquidglass/glass/GlassPressAnimator.kt +264 -0
- package/src/engine/android/src/main/java/expo/modules/liquidglass/glass/GlassProgressiveBlur.kt +249 -0
- package/src/engine/android/src/main/java/expo/modules/liquidglass/glass/GlassShaderCache.kt +256 -0
- package/src/engine/android/src/main/java/expo/modules/liquidglass/glass/GlassShaderSource.kt +845 -0
- package/src/engine/android/src/main/java/expo/modules/liquidglass/glass/GlassTier.kt +63 -0
- package/src/engine/android/src/main/java/expo/modules/liquidglass/glass/ProviderRegistry.kt +71 -0
- package/src/engine/android/src/main/java/expo/modules/liquidglass/records/GlassRecords.kt +288 -0
- package/src/engine/index.ts +24 -0
- package/src/engine/ios/Enums/GlassBlurDirection.swift +21 -0
- package/src/engine/ios/Enums/GlassVariant.swift +86 -0
- package/src/engine/ios/ExpoLiquidGlass.podspec +93 -0
- package/src/engine/ios/ExpoLiquidGlassModule.swift +77 -0
- package/src/engine/ios/Glass/BackdropCapturer.swift +811 -0
- package/src/engine/ios/Glass/ContinuousCorners.swift +165 -0
- package/src/engine/ios/Glass/GlassBackdrop.swift +176 -0
- package/src/engine/ios/Glass/GlassFramePhase.swift +126 -0
- package/src/engine/ios/Glass/GlassFrameScheduler.swift +261 -0
- package/src/engine/ios/Glass/GlassPressAnimator.swift +250 -0
- package/src/engine/ios/Glass/GlassRenderContext.swift +168 -0
- package/src/engine/ios/Glass/GlassRenderer.swift +186 -0
- package/src/engine/ios/Glass/GlassSurfaceView.swift +452 -0
- package/src/engine/ios/Glass/NonRenderableView.swift +54 -0
- package/src/engine/ios/Glass/StripCache.swift +545 -0
- package/src/engine/ios/Records/GlassCornerRadii.swift +79 -0
- package/src/engine/ios/Records/GlassMetalOptions.swift +180 -0
- package/src/engine/ios/Records/GlassRefractionCurve.swift +14 -0
- package/src/engine/ios/Shaders/LiquidGlass.metal +480 -0
- package/src/engine/ios/Shaders/bundle-marker.txt +6 -0
- package/src/engine/ios/Views/LiquidGlassContainerView.swift +99 -0
- package/src/engine/ios/Views/LiquidGlassView.swift +859 -0
- package/src/engine/package.json +70 -0
- package/src/engine/src/components/LiquidGlassButton/LiquidGlassButton.tsx +424 -0
- package/src/engine/src/components/LiquidGlassCard/LiquidGlassCard.tsx +98 -0
- package/src/engine/src/components/LiquidGlassChip/LiquidGlassChip.tsx +65 -0
- package/src/engine/src/components/LiquidGlassGroup/LiquidGlassGroup.tsx +350 -0
- package/src/engine/src/components/LiquidGlassIconButton/LiquidGlassIconButton.tsx +24 -0
- package/src/engine/src/components/LiquidGlassMorphGroup/LiquidGlassMorphGroup.tsx +434 -0
- package/src/engine/src/components/LiquidGlassScrim/LiquidGlassScrim.tsx +100 -0
- package/src/engine/src/components/LiquidGlassSegmentedControl/LiquidGlassSegmentedControl.tsx +213 -0
- package/src/engine/src/components/LiquidGlassSheet/LiquidGlassSheet.tsx +218 -0
- package/src/engine/src/components/LiquidGlassSlider/LiquidGlassSlider.tsx +327 -0
- package/src/engine/src/components/LiquidGlassStepper/LiquidGlassStepper.tsx +321 -0
- package/src/engine/src/components/LiquidGlassSwitch/LiquidGlassSwitch.tsx +296 -0
- package/src/engine/src/components/LiquidGlassTabBar/LiquidGlassTabBar.tsx +952 -0
- package/src/engine/src/components/LiquidGlassTextInput/LiquidGlassTextInput.tsx +151 -0
- package/src/engine/src/components/LiquidGlassToast/LiquidGlassToast.tsx +169 -0
- package/src/engine/src/components/LiquidGlassToolbar/LiquidGlassToolbar.tsx +124 -0
- package/src/engine/src/components/index.ts +16 -0
- package/src/engine/src/constants/index.ts +4 -0
- package/src/engine/src/constants/metal.constants.ts +327 -0
- package/src/engine/src/constants/metrics.constants.ts +325 -0
- package/src/engine/src/constants/springs.constants.ts +107 -0
- package/src/engine/src/constants/styles.constants.ts +12 -0
- package/src/engine/src/context/glass-group.context.ts +65 -0
- package/src/engine/src/context/index.ts +6 -0
- package/src/engine/src/core/components/LiquidGlassContainer/LiquidGlassContainer.tsx +32 -0
- package/src/engine/src/core/components/LiquidGlassContainer/index.ts +1 -0
- package/src/engine/src/core/components/LiquidGlassProvider/LiquidGlassProvider.tsx +66 -0
- package/src/engine/src/core/components/LiquidGlassProvider/index.ts +1 -0
- package/src/engine/src/core/components/LiquidGlassStack/LiquidGlassStack.tsx +184 -0
- package/src/engine/src/core/components/LiquidGlassStack/index.ts +1 -0
- package/src/engine/src/core/components/LiquidGlassView/LiquidGlassView.tsx +126 -0
- package/src/engine/src/core/components/LiquidGlassView/index.ts +1 -0
- package/src/engine/src/core/components/index.ts +4 -0
- package/src/engine/src/core/constants/glass.constants.ts +57 -0
- package/src/engine/src/core/constants/index.ts +20 -0
- package/src/engine/src/core/constants/native.constants.ts +16 -0
- package/src/engine/src/core/context/glass-stack.context.ts +30 -0
- package/src/engine/src/core/context/index.ts +4 -0
- package/src/engine/src/core/enum/index.ts +12 -0
- package/src/engine/src/core/index.ts +1 -0
- package/src/engine/src/core/interfaces/glass-hdr.interface.ts +15 -0
- package/src/engine/src/core/interfaces/glass-metal.interface.ts +248 -0
- package/src/engine/src/core/interfaces/glass-surface.interface.ts +9 -0
- package/src/engine/src/core/interfaces/index.ts +31 -0
- package/src/engine/src/core/interfaces/liquid-glass-container.interface.ts +6 -0
- package/src/engine/src/core/interfaces/liquid-glass-provider.interface.ts +14 -0
- package/src/engine/src/core/interfaces/liquid-glass-stack.interface.ts +21 -0
- package/src/engine/src/core/interfaces/liquid-glass-view.interface.ts +129 -0
- package/src/engine/src/core/interfaces/native-liquid-glass-view.interface.ts +19 -0
- package/src/engine/src/core/modules/ExpoLiquidGlassModule.ts +26 -0
- package/src/engine/src/core/modules/index.ts +2 -0
- package/src/engine/src/core/root/index.ts +51 -0
- package/src/engine/src/core/types/glass.types.ts +25 -0
- package/src/engine/src/core/types/index.ts +8 -0
- package/src/engine/src/core/utils/debug.utils.ts +17 -0
- package/src/engine/src/core/utils/dev-warn.utils.ts +17 -0
- package/src/engine/src/core/utils/hdr.utils.ts +37 -0
- package/src/engine/src/core/utils/index.ts +5 -0
- package/src/engine/src/core/utils/native-view.utils.ts +33 -0
- package/src/engine/src/core/utils/platform.utils.ts +34 -0
- package/src/engine/src/core/views/NativeGlassBackdropView.ts +24 -0
- package/src/engine/src/core/views/NativeLiquidGlassContainerView.ts +13 -0
- package/src/engine/src/core/views/NativeLiquidGlassContainerView.web.ts +10 -0
- package/src/engine/src/core/views/NativeLiquidGlassProviderView.ts +13 -0
- package/src/engine/src/core/views/NativeLiquidGlassProviderView.web.ts +10 -0
- package/src/engine/src/core/views/NativeLiquidGlassView.ts +19 -0
- package/src/engine/src/core/views/NativeLiquidGlassView.web.ts +14 -0
- package/src/engine/src/core/views/index.ts +4 -0
- package/src/engine/src/hooks/index.ts +18 -0
- package/src/engine/src/hooks/use-adaptive-glass.ts +91 -0
- package/src/engine/src/hooks/use-damped-drag.ts +332 -0
- package/src/engine/src/hooks/use-echo-filter.ts +55 -0
- package/src/engine/src/hooks/use-glass-group-member.ts +169 -0
- package/src/engine/src/hooks/use-gravity-highlight.ts +79 -0
- package/src/engine/src/hooks/use-press-progress.ts +44 -0
- package/src/engine/src/index.ts +120 -0
- package/src/engine/src/interfaces/index.ts +28 -0
- package/src/engine/src/interfaces/liquid-glass-button.interface.ts +94 -0
- package/src/engine/src/interfaces/liquid-glass-card.interface.ts +40 -0
- package/src/engine/src/interfaces/liquid-glass-chip.interface.ts +29 -0
- package/src/engine/src/interfaces/liquid-glass-group.interface.ts +32 -0
- package/src/engine/src/interfaces/liquid-glass-icon-button.interface.ts +19 -0
- package/src/engine/src/interfaces/liquid-glass-morph-group.interface.ts +59 -0
- package/src/engine/src/interfaces/liquid-glass-scrim.interface.ts +36 -0
- package/src/engine/src/interfaces/liquid-glass-segmented-control.interface.ts +32 -0
- package/src/engine/src/interfaces/liquid-glass-sheet.interface.ts +38 -0
- package/src/engine/src/interfaces/liquid-glass-slider.interface.ts +37 -0
- package/src/engine/src/interfaces/liquid-glass-stepper.interface.ts +35 -0
- package/src/engine/src/interfaces/liquid-glass-switch.interface.ts +27 -0
- package/src/engine/src/interfaces/liquid-glass-tab-bar.interface.ts +116 -0
- package/src/engine/src/interfaces/liquid-glass-text-input.interface.ts +42 -0
- package/src/engine/src/interfaces/liquid-glass-toast.interface.ts +36 -0
- package/src/engine/src/interfaces/liquid-glass-toolbar.interface.ts +33 -0
- package/src/engine/src/theme/glass-ui-theme.ts +100 -0
- package/src/engine/src/theme/index.ts +2 -0
- package/src/engine/src/utils/button-press.utils.ts +63 -0
- package/src/engine/src/utils/index.ts +3 -0
- package/src/engine/src/utils/metal.utils.ts +164 -0
- package/src/glass-provider.tsx +60 -0
- package/src/glass-stack.tsx +115 -0
- package/src/index.ts +47 -190
- package/src/internal/GlassBackdrop.tsx +60 -0
- package/src/internal/GlassView.tsx +53 -18
- package/src/internal/blur-community.ts +19 -0
- package/src/internal/blur-community.web.ts +7 -0
- package/src/internal/blur.ts +7 -8
- package/src/internal/glass-routing.ts +212 -34
- package/src/internal/initials.ts +7 -0
- package/src/internal/overlay.tsx +258 -0
- package/src/internal/primitives.ts +23 -0
- package/lib/module/Carousel.js +0 -103
- package/lib/module/Display.js +0 -318
- package/lib/module/Feedback.js +0 -395
- package/lib/module/Form.js +0 -160
- package/lib/module/Forms2.js +0 -471
- package/lib/module/Message.js +0 -84
- package/lib/module/Overlays.js +0 -344
- package/lib/module/Pickers.js +0 -243
- package/lib/module/Table.js +0 -100
- package/lib/module/ai.js +0 -283
- package/lib/module/charts/AreaChart.js +0 -32
- package/lib/module/charts/BarChart.js +0 -75
- package/lib/module/charts/FunnelChart.js +0 -50
- package/lib/module/charts/HeatmapChart.js +0 -71
- package/lib/module/charts/LineChart.js +0 -81
- package/lib/module/charts/PlotChart.js +0 -52
- package/lib/module/charts/RadarChart.js +0 -78
- package/lib/module/charts/RingChart.js +0 -52
- package/lib/module/charts/ScatterChart.js +0 -95
- package/lib/module/charts/WaterfallChart.js +0 -85
- package/lib/module/charts/advanced.js +0 -313
- package/lib/module/charts/extra.js +0 -108
- package/lib/module/charts/index.js +0 -50
- package/lib/module/charts/scales.js +0 -140
- package/lib/typescript/Carousel.d.ts +0 -47
- package/lib/typescript/Display.d.ts +0 -178
- package/lib/typescript/Feedback.d.ts +0 -196
- package/lib/typescript/Form.d.ts +0 -97
- package/lib/typescript/Forms2.d.ts +0 -209
- package/lib/typescript/Message.d.ts +0 -67
- package/lib/typescript/Overlays.d.ts +0 -146
- package/lib/typescript/Pickers.d.ts +0 -105
- package/lib/typescript/Table.d.ts +0 -64
- package/lib/typescript/ai.d.ts +0 -166
- package/lib/typescript/charts/AreaChart.d.ts +0 -44
- package/lib/typescript/charts/BarChart.d.ts +0 -19
- package/lib/typescript/charts/FunnelChart.d.ts +0 -25
- package/lib/typescript/charts/HeatmapChart.d.ts +0 -23
- package/lib/typescript/charts/LineChart.d.ts +0 -30
- package/lib/typescript/charts/PlotChart.d.ts +0 -31
- package/lib/typescript/charts/RadarChart.d.ts +0 -27
- package/lib/typescript/charts/RingChart.d.ts +0 -28
- package/lib/typescript/charts/ScatterChart.d.ts +0 -34
- package/lib/typescript/charts/WaterfallChart.d.ts +0 -22
- package/lib/typescript/charts/advanced.d.ts +0 -107
- package/lib/typescript/charts/extra.d.ts +0 -63
- package/lib/typescript/charts/index.d.ts +0 -13
- package/lib/typescript/charts/scales.d.ts +0 -35
- package/src/Carousel.tsx +0 -233
- package/src/Display.tsx +0 -781
- package/src/Feedback.tsx +0 -992
- package/src/Form.tsx +0 -445
- package/src/Forms2.tsx +0 -1055
- package/src/Message.tsx +0 -218
- package/src/Overlays.tsx +0 -704
- package/src/Pickers.tsx +0 -595
- package/src/Table.tsx +0 -232
- package/src/ai.tsx +0 -715
- package/src/charts/AreaChart.tsx +0 -73
- package/src/charts/BarChart.tsx +0 -221
- package/src/charts/FunnelChart.tsx +0 -125
- package/src/charts/HeatmapChart.tsx +0 -155
- package/src/charts/LineChart.tsx +0 -247
- package/src/charts/PlotChart.tsx +0 -168
- package/src/charts/RadarChart.tsx +0 -208
- package/src/charts/RingChart.tsx +0 -133
- package/src/charts/ScatterChart.tsx +0 -223
- package/src/charts/WaterfallChart.tsx +0 -201
- package/src/charts/advanced.tsx +0 -676
- package/src/charts/extra.tsx +0 -242
- package/src/charts/index.ts +0 -86
- package/src/charts/scales.ts +0 -163
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import type { FrameInfo, SharedValue } from "react-native-reanimated";
|
|
3
|
+
import { useFrameCallback, useSharedValue } from "react-native-reanimated";
|
|
4
|
+
|
|
5
|
+
import type { ISpringSpec } from "../constants";
|
|
6
|
+
import {
|
|
7
|
+
SCALE_X_SPEC,
|
|
8
|
+
SCALE_Y_SPEC,
|
|
9
|
+
VALUE_SPEC,
|
|
10
|
+
VELOCITY_SPEC,
|
|
11
|
+
} from "../constants";
|
|
12
|
+
|
|
13
|
+
/** The reference's jelly: velocity (already divided) times these, clamped to ±`JELLY_LIMIT`. */
|
|
14
|
+
const JELLY_STRETCH_X = 0.75;
|
|
15
|
+
const JELLY_SQUASH_Y = 0.25;
|
|
16
|
+
const JELLY_LIMIT = 0.2;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The catalog's `DampedDragAnimation`, ported whole.
|
|
20
|
+
*
|
|
21
|
+
* Five spring channels advance together every frame: the value follower, press progress, the two
|
|
22
|
+
* grab scales, and a low-passed velocity. They are integrated here rather than driven by
|
|
23
|
+
* `withSpring` for one reason — Compose's `Animatable.animateTo` **inherits the current velocity**
|
|
24
|
+
* when it is re-targeted mid-flight, and `withSpring` does not. A drag re-targets the follower on
|
|
25
|
+
* every touch move, so without inherited velocity the pill visibly notches at each event. A
|
|
26
|
+
* semi-implicit Euler integrator gets that continuity for free: retargeting only changes where the
|
|
27
|
+
* spring is pulling, never the state it carries.
|
|
28
|
+
*
|
|
29
|
+
* The frame callback stays registered and cheaply early-outs when everything is at rest, rather
|
|
30
|
+
* than being toggled with `setActive`. Toggling would route gesture start through `runOnJS`, and a
|
|
31
|
+
* busy JS thread could then delay the first frame of the animation — exactly the failure this kit
|
|
32
|
+
* exists to avoid.
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
/** Semi-implicit Euler is stable here well past this, but substepping keeps k=1000 honest. */
|
|
36
|
+
const MAX_STEP_SECONDS = 1 / 60;
|
|
37
|
+
|
|
38
|
+
/** The reference's release gate: deflate once the follower is within 2.5% of the span. */
|
|
39
|
+
const CONVERGENCE_FRACTION = 0.025;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Velocity below this is treated as zero when deciding whether the system has settled, in
|
|
43
|
+
* range-fractions per second. The channel this gates is the *smoothed* one that feeds the jelly,
|
|
44
|
+
* and it rings down on an underdamped spring for a good third of a second after the follower
|
|
45
|
+
* has already landed; at 0.01 the deflate waited out that whole ring-down (a pill sat inflated
|
|
46
|
+
* ~0.3 s after arriving, which reads as lag, not as liquid). At 0.15 the residual stretch is
|
|
47
|
+
* ~1 % — below what the eye separates from rest — and the deflate starts on arrival.
|
|
48
|
+
*/
|
|
49
|
+
const VELOCITY_REST = 0.15;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The window the follower's velocity is averaged over before it reaches its spring, matching the
|
|
53
|
+
* span a Compose `VelocityTracker` least-squares-fits. See the integrator.
|
|
54
|
+
*/
|
|
55
|
+
const VELOCITY_WINDOW_SECONDS = 0.1;
|
|
56
|
+
|
|
57
|
+
interface IDampedDragConfig {
|
|
58
|
+
/** Inclusive range the follower is clamped to, e.g. `[0, tabCount - 1]`. */
|
|
59
|
+
range: [number, number];
|
|
60
|
+
initialValue: number;
|
|
61
|
+
/** Scale at rest. The reference always uses 1. */
|
|
62
|
+
initialScale?: number;
|
|
63
|
+
/** Scale while grabbed — `78/56` for the tab pill, `1.5` for the thumbs. */
|
|
64
|
+
pressedScale: number;
|
|
65
|
+
/**
|
|
66
|
+
* Velocity is divided by this before it reaches the jelly. The reference uses 10 for
|
|
67
|
+
* full-width controls (tab pill, slider) and 50 for short-throw ones (toggle).
|
|
68
|
+
*/
|
|
69
|
+
velocityDivisor: number;
|
|
70
|
+
/**
|
|
71
|
+
* The follower's spring. Defaults to the reference's critically damped `spring(1, 1000)`,
|
|
72
|
+
* which lands dead on the value; the tab bar passes an overshooting one so the pill overruns
|
|
73
|
+
* its tab and settles back, as iOS 26's does. Press progress is not affected — the inflate
|
|
74
|
+
* always runs the reference's spring.
|
|
75
|
+
*/
|
|
76
|
+
valueSpring?: ISpringSpec;
|
|
77
|
+
/**
|
|
78
|
+
* The jelly's reach. `gain` multiplies the reference's velocity-to-stretch mapping (0.75 on
|
|
79
|
+
* X, 0.25 on Y) and `limit` caps the stretch, both defaulting to the reference's (gain 1,
|
|
80
|
+
* limit 0.2 — at most 1.25x wide). The tab bar runs gain 2 / limit 0.45 for iOS 26's hotdog.
|
|
81
|
+
*/
|
|
82
|
+
jelly?: { gain?: number; limit?: number };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
interface IDampedDrag {
|
|
86
|
+
/** The damped follower — read this for position. */
|
|
87
|
+
value: SharedValue<number>;
|
|
88
|
+
/** The spring's goal. A drag moves this; `value` chases it. */
|
|
89
|
+
targetValue: SharedValue<number>;
|
|
90
|
+
pressProgress: SharedValue<number>;
|
|
91
|
+
scaleX: SharedValue<number>;
|
|
92
|
+
scaleY: SharedValue<number>;
|
|
93
|
+
/** Smoothed follower velocity, in range-fractions per second. */
|
|
94
|
+
velocity: SharedValue<number>;
|
|
95
|
+
/** Inflate and light up. Call on touch-down, with no slop. */
|
|
96
|
+
press: () => void;
|
|
97
|
+
/** Deflate — but only once the follower has essentially arrived. */
|
|
98
|
+
release: () => void;
|
|
99
|
+
/** Add to the target, clamped to the range. */
|
|
100
|
+
dragBy: (delta: number) => void;
|
|
101
|
+
/** The full grab choreography for a programmatic move: press, fly, release on arrival. */
|
|
102
|
+
animateTo: (next: number) => void;
|
|
103
|
+
/** The velocity-driven squash/stretch, ready to spread into a transform. */
|
|
104
|
+
jelly: () => { scaleX: number; scaleY: number };
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function useDampedDrag(config: IDampedDragConfig): IDampedDrag {
|
|
108
|
+
const {
|
|
109
|
+
range,
|
|
110
|
+
initialValue,
|
|
111
|
+
initialScale = 1,
|
|
112
|
+
pressedScale,
|
|
113
|
+
velocityDivisor,
|
|
114
|
+
valueSpring,
|
|
115
|
+
jelly: jellyConfig,
|
|
116
|
+
} = config;
|
|
117
|
+
const valueSpec = valueSpring ?? VALUE_SPEC;
|
|
118
|
+
const jellyGain = jellyConfig?.gain ?? 1;
|
|
119
|
+
const jellyLimit = jellyConfig?.limit ?? JELLY_LIMIT;
|
|
120
|
+
|
|
121
|
+
const value = useSharedValue(initialValue);
|
|
122
|
+
const targetValue = useSharedValue(initialValue);
|
|
123
|
+
const pressProgress = useSharedValue(0);
|
|
124
|
+
const scaleX = useSharedValue(initialScale);
|
|
125
|
+
const scaleY = useSharedValue(initialScale);
|
|
126
|
+
const velocity = useSharedValue(0);
|
|
127
|
+
|
|
128
|
+
// Integrator state, one velocity per channel.
|
|
129
|
+
const valueRate = useSharedValue(0);
|
|
130
|
+
const pressRate = useSharedValue(0);
|
|
131
|
+
const scaleXRate = useSharedValue(0);
|
|
132
|
+
const scaleYRate = useSharedValue(0);
|
|
133
|
+
const velocityRate = useSharedValue(0);
|
|
134
|
+
|
|
135
|
+
const pressTarget = useSharedValue(0);
|
|
136
|
+
const scaleTarget = useSharedValue(initialScale);
|
|
137
|
+
const rawVelocity = useSharedValue(0);
|
|
138
|
+
const previousValue = useSharedValue(initialValue);
|
|
139
|
+
/** Set by `release()`; the integrator honours it once the follower converges. */
|
|
140
|
+
const releasePending = useSharedValue(false);
|
|
141
|
+
/** False during a programmatic snap — the reference stops sampling velocity there. */
|
|
142
|
+
const trackVelocity = useSharedValue(true);
|
|
143
|
+
|
|
144
|
+
const lower = range[0];
|
|
145
|
+
const upper = range[1];
|
|
146
|
+
const span = Math.max(upper - lower, 1e-6);
|
|
147
|
+
|
|
148
|
+
useFrameCallback((frame: FrameInfo): void => {
|
|
149
|
+
"worklet";
|
|
150
|
+
const elapsed = frame.timeSincePreviousFrame;
|
|
151
|
+
if (elapsed == null || elapsed <= 0) return;
|
|
152
|
+
|
|
153
|
+
const settled =
|
|
154
|
+
Math.abs(value.value - targetValue.value) < 1e-4 &&
|
|
155
|
+
Math.abs(valueRate.value) < 1e-3 &&
|
|
156
|
+
Math.abs(pressProgress.value - pressTarget.value) < 1e-4 &&
|
|
157
|
+
Math.abs(pressRate.value) < 1e-3 &&
|
|
158
|
+
Math.abs(scaleX.value - scaleTarget.value) < 1e-5 &&
|
|
159
|
+
Math.abs(scaleY.value - scaleTarget.value) < 1e-5 &&
|
|
160
|
+
Math.abs(velocity.value) < 1e-4 &&
|
|
161
|
+
!releasePending.value;
|
|
162
|
+
if (settled) return;
|
|
163
|
+
|
|
164
|
+
let remaining = Math.min(elapsed / 1000, 0.1);
|
|
165
|
+
while (remaining > 0) {
|
|
166
|
+
const dt = Math.min(remaining, MAX_STEP_SECONDS);
|
|
167
|
+
remaining -= dt;
|
|
168
|
+
|
|
169
|
+
// Follower. Clamped after integrating so a drag past the end dead-stops, as the reference
|
|
170
|
+
// does — the rubber band there is a separate, whole-panel affair.
|
|
171
|
+
const valueAccel =
|
|
172
|
+
valueSpec.stiffness * (targetValue.value - value.value) -
|
|
173
|
+
valueSpec.damping * valueRate.value;
|
|
174
|
+
valueRate.value += valueAccel * dt;
|
|
175
|
+
value.value = Math.min(
|
|
176
|
+
upper,
|
|
177
|
+
Math.max(lower, value.value + valueRate.value * dt)
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
const pressAccel =
|
|
181
|
+
VALUE_SPEC.stiffness * (pressTarget.value - pressProgress.value) -
|
|
182
|
+
VALUE_SPEC.damping * pressRate.value;
|
|
183
|
+
pressRate.value += pressAccel * dt;
|
|
184
|
+
pressProgress.value += pressRate.value * dt;
|
|
185
|
+
|
|
186
|
+
const scaleXAccel =
|
|
187
|
+
SCALE_X_SPEC.stiffness * (scaleTarget.value - scaleX.value) -
|
|
188
|
+
SCALE_X_SPEC.damping * scaleXRate.value;
|
|
189
|
+
scaleXRate.value += scaleXAccel * dt;
|
|
190
|
+
scaleX.value += scaleXRate.value * dt;
|
|
191
|
+
|
|
192
|
+
const scaleYAccel =
|
|
193
|
+
SCALE_Y_SPEC.stiffness * (scaleTarget.value - scaleY.value) -
|
|
194
|
+
SCALE_Y_SPEC.damping * scaleYRate.value;
|
|
195
|
+
scaleYRate.value += scaleYAccel * dt;
|
|
196
|
+
scaleY.value += scaleYRate.value * dt;
|
|
197
|
+
|
|
198
|
+
// Velocity is measured off the *follower*, not the finger, then low-passed by its own
|
|
199
|
+
// underdamped spring. That double filter is what makes the stretch wobble instead of
|
|
200
|
+
// tracking the touch instantly.
|
|
201
|
+
//
|
|
202
|
+
// The instantaneous derivative is only half of it. The reference reads a Compose
|
|
203
|
+
// `VelocityTracker`, which least-squares-fits the last ~100 ms of samples — so what reaches
|
|
204
|
+
// its spring is already a windowed average, not a per-frame difference. Feeding the raw
|
|
205
|
+
// difference straight in makes the channel far peakier than the reference's, and on a *flick*
|
|
206
|
+
// that difference is the whole story: the peak slams the jelly's +/-0.2 clamp and holds it
|
|
207
|
+
// there, so the pill wears its widest stretch on top of the grab scale for most of the
|
|
208
|
+
// throw. A tap never shows it, because `animateTo` stops sampling velocity altogether.
|
|
209
|
+
//
|
|
210
|
+
// One pole at the tracker's own window reproduces the smoothing without touching any of the
|
|
211
|
+
// reference's constants.
|
|
212
|
+
if (trackVelocity.value) {
|
|
213
|
+
const instant = (value.value - previousValue.value) / dt / span;
|
|
214
|
+
const alpha = 1 - Math.exp(-dt / VELOCITY_WINDOW_SECONDS);
|
|
215
|
+
rawVelocity.value += (instant - rawVelocity.value) * alpha;
|
|
216
|
+
}
|
|
217
|
+
previousValue.value = value.value;
|
|
218
|
+
|
|
219
|
+
const velocityAccel =
|
|
220
|
+
VELOCITY_SPEC.stiffness * (rawVelocity.value - velocity.value) -
|
|
221
|
+
VELOCITY_SPEC.damping * velocityRate.value;
|
|
222
|
+
velocityRate.value += velocityAccel * dt;
|
|
223
|
+
velocity.value += velocityRate.value * dt;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// The single most important detail of the choreography: the control stays inflated and glassy
|
|
227
|
+
// through the entire snap, deflating only once it has essentially arrived. Deflating on
|
|
228
|
+
// finger-up instead is the usual way this is got wrong.
|
|
229
|
+
if (
|
|
230
|
+
releasePending.value &&
|
|
231
|
+
Math.abs(value.value - targetValue.value) < span * CONVERGENCE_FRACTION &&
|
|
232
|
+
Math.abs(velocity.value) < VELOCITY_REST
|
|
233
|
+
) {
|
|
234
|
+
releasePending.value = false;
|
|
235
|
+
trackVelocity.value = true;
|
|
236
|
+
pressTarget.value = 0;
|
|
237
|
+
scaleTarget.value = initialScale;
|
|
238
|
+
}
|
|
239
|
+
}, true);
|
|
240
|
+
|
|
241
|
+
return useMemo<IDampedDrag>(() => {
|
|
242
|
+
const press = (): void => {
|
|
243
|
+
"worklet";
|
|
244
|
+
releasePending.value = false;
|
|
245
|
+
trackVelocity.value = true;
|
|
246
|
+
rawVelocity.value = 0;
|
|
247
|
+
previousValue.value = value.value;
|
|
248
|
+
pressTarget.value = 1;
|
|
249
|
+
scaleTarget.value = pressedScale;
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
const release = (): void => {
|
|
253
|
+
"worklet";
|
|
254
|
+
releasePending.value = true;
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
const dragBy = (delta: number): void => {
|
|
258
|
+
"worklet";
|
|
259
|
+
targetValue.value = Math.min(
|
|
260
|
+
upper,
|
|
261
|
+
Math.max(lower, targetValue.value + delta)
|
|
262
|
+
);
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
const animateTo = (next: number): void => {
|
|
266
|
+
"worklet";
|
|
267
|
+
press();
|
|
268
|
+
targetValue.value = Math.min(upper, Math.max(lower, next));
|
|
269
|
+
// The reference stops sampling velocity during a programmatic snap and springs the existing
|
|
270
|
+
// velocity to zero instead; that unwind is the settle wobble.
|
|
271
|
+
trackVelocity.value = false;
|
|
272
|
+
rawVelocity.value = 0;
|
|
273
|
+
release();
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
const jelly = (): { scaleX: number; scaleY: number } => {
|
|
277
|
+
"worklet";
|
|
278
|
+
const v = (velocity.value / velocityDivisor) * jellyGain;
|
|
279
|
+
const stretch = Math.min(
|
|
280
|
+
jellyLimit,
|
|
281
|
+
Math.max(-jellyLimit, v * JELLY_STRETCH_X)
|
|
282
|
+
);
|
|
283
|
+
const squash = Math.min(
|
|
284
|
+
jellyLimit,
|
|
285
|
+
Math.max(-jellyLimit, v * JELLY_SQUASH_Y)
|
|
286
|
+
);
|
|
287
|
+
// Division on X, multiplication on Y — volume-preserving, and signed, so it inverts on
|
|
288
|
+
// reverse motion. Do not "fix" this to abs(); it changes the character.
|
|
289
|
+
return {
|
|
290
|
+
scaleX: scaleX.value / (1 - stretch),
|
|
291
|
+
scaleY: scaleY.value * (1 - squash),
|
|
292
|
+
};
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
return {
|
|
296
|
+
value,
|
|
297
|
+
targetValue,
|
|
298
|
+
pressProgress,
|
|
299
|
+
scaleX,
|
|
300
|
+
scaleY,
|
|
301
|
+
velocity,
|
|
302
|
+
press,
|
|
303
|
+
release,
|
|
304
|
+
dragBy,
|
|
305
|
+
animateTo,
|
|
306
|
+
jelly,
|
|
307
|
+
};
|
|
308
|
+
}, [
|
|
309
|
+
value,
|
|
310
|
+
targetValue,
|
|
311
|
+
pressProgress,
|
|
312
|
+
scaleX,
|
|
313
|
+
scaleY,
|
|
314
|
+
velocity,
|
|
315
|
+
pressTarget,
|
|
316
|
+
scaleTarget,
|
|
317
|
+
rawVelocity,
|
|
318
|
+
previousValue,
|
|
319
|
+
releasePending,
|
|
320
|
+
trackVelocity,
|
|
321
|
+
lower,
|
|
322
|
+
upper,
|
|
323
|
+
initialScale,
|
|
324
|
+
pressedScale,
|
|
325
|
+
velocityDivisor,
|
|
326
|
+
jellyGain,
|
|
327
|
+
jellyLimit,
|
|
328
|
+
]);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
export { useDampedDrag };
|
|
332
|
+
export type { IDampedDrag, IDampedDragConfig };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { useCallback, useMemo, useRef } from "react";
|
|
2
|
+
|
|
3
|
+
/** How many un-echoed emits to remember before the oldest are forgotten. */
|
|
4
|
+
const ECHO_CAPACITY = 64;
|
|
5
|
+
|
|
6
|
+
interface IEchoFilter<T> {
|
|
7
|
+
/** Record a value this control just reported through its change callback. */
|
|
8
|
+
emitted: (value: T) => void;
|
|
9
|
+
/**
|
|
10
|
+
* Whether an incoming controlled `value` is merely one of our own reports coming back —
|
|
11
|
+
* in which case the control is already there (or past it) and must not re-target. Every
|
|
12
|
+
* report up to and including the matched one is forgotten; later ones stay pending for
|
|
13
|
+
* their own echoes.
|
|
14
|
+
*/
|
|
15
|
+
isEcho: (value: T) => boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Tells a controlled control's own echoes apart from a real external change.
|
|
20
|
+
*
|
|
21
|
+
* A dragged control reports many values a second through `runOnJS`. The parent stores each
|
|
22
|
+
* one and renders it back as `value`, and the control's effect must then decide: is this the
|
|
23
|
+
* app moving me, or my own report returning? Comparing against *the last* value reported is not
|
|
24
|
+
* enough — passive effects run after paint, so the effect of an earlier render can fire after
|
|
25
|
+
* several newer reports have gone out. The slider had exactly this: the effect for `0.47` ran
|
|
26
|
+
* once `0.66` had been reported, decided `0.47` was external and sprang the thumb back to it,
|
|
27
|
+
* and the drag looked like it kept bouncing to old positions.
|
|
28
|
+
*
|
|
29
|
+
* So the filter remembers every report that has not been echoed yet. An incoming value found
|
|
30
|
+
* in that list is an echo (echoes arrive in the order they were reported, so everything up to
|
|
31
|
+
* the match is done too); a value not in the list is the app's, and the control animates to it.
|
|
32
|
+
*/
|
|
33
|
+
function useEchoFilter<T>(): IEchoFilter<T> {
|
|
34
|
+
const pending = useRef<T[]>([]);
|
|
35
|
+
|
|
36
|
+
const emitted = useCallback((value: T): void => {
|
|
37
|
+
const list = pending.current;
|
|
38
|
+
list.push(value);
|
|
39
|
+
if (list.length > ECHO_CAPACITY)
|
|
40
|
+
list.splice(0, list.length - ECHO_CAPACITY);
|
|
41
|
+
}, []);
|
|
42
|
+
|
|
43
|
+
const isEcho = useCallback((value: T): boolean => {
|
|
44
|
+
const list = pending.current;
|
|
45
|
+
const index = list.indexOf(value);
|
|
46
|
+
if (index < 0) return false;
|
|
47
|
+
list.splice(0, index + 1);
|
|
48
|
+
return true;
|
|
49
|
+
}, []);
|
|
50
|
+
|
|
51
|
+
return useMemo(() => ({ emitted, isEcho }), [emitted, isEcho]);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export { useEchoFilter };
|
|
55
|
+
export type { IEchoFilter };
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import type { RefObject } from "react";
|
|
2
|
+
import { useCallback, useContext, useLayoutEffect, useRef } from "react";
|
|
3
|
+
import type { LayoutChangeEvent, View as RNView } from "react-native";
|
|
4
|
+
import type { SharedValue } from "react-native-reanimated";
|
|
5
|
+
import { useDerivedValue, useSharedValue } from "react-native-reanimated";
|
|
6
|
+
|
|
7
|
+
import { GlassGroupContext } from "../context";
|
|
8
|
+
import type { IGlassGroupMember, IGlassGroupRect } from "../context";
|
|
9
|
+
|
|
10
|
+
interface IGlassGroupMembership {
|
|
11
|
+
/** Whether a `LiquidGlassGroup` is above this control. */
|
|
12
|
+
inGroup: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Whether the pane should stay put — because the system merges natively (iOS 26), or because
|
|
15
|
+
* there is no group at all. When false the pane crossfades to the group's canvas while
|
|
16
|
+
* involved in a merge.
|
|
17
|
+
*/
|
|
18
|
+
keepsPane: boolean;
|
|
19
|
+
/** This member's slot, on the UI thread; -1 until registered. */
|
|
20
|
+
slot: SharedValue<number>;
|
|
21
|
+
/**
|
|
22
|
+
* Attach to the member's outermost, untransformed view. Pass that view's instance too (or
|
|
23
|
+
* give the hook a `frameRef`): the frame is then measured against the group's row, so a
|
|
24
|
+
* wrapper between the two does not put the canvas pane in the wrong place.
|
|
25
|
+
*/
|
|
26
|
+
onLayout: (event: LayoutChangeEvent, node?: RNView | null) => void;
|
|
27
|
+
/**
|
|
28
|
+
* Opacity for the member's own glass pane: 1 normally, `1 - activeProgress` while this member
|
|
29
|
+
* is the pressed one or its partner — the canvas is drawing both silhouettes for the duration.
|
|
30
|
+
*/
|
|
31
|
+
paneOpacity: SharedValue<number>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
type TMeasurable = {
|
|
35
|
+
measureLayout?: (
|
|
36
|
+
relativeTo: unknown,
|
|
37
|
+
onSuccess: (x: number, y: number, width: number, height: number) => void,
|
|
38
|
+
onFail?: () => void
|
|
39
|
+
) => void;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The member half of `LiquidGlassGroup`: registers the control's press channels with the group
|
|
44
|
+
* above it (if any), reports its frame, and hands back the opacity its own pane should wear.
|
|
45
|
+
*
|
|
46
|
+
* Every hook here mounts whether or not a group exists, so a control can be written once; outside
|
|
47
|
+
* a group `paneOpacity` is a constant 1 and `onLayout` is a no-op.
|
|
48
|
+
*/
|
|
49
|
+
function useGlassGroupMember(
|
|
50
|
+
member: IGlassGroupMember,
|
|
51
|
+
frameRef?: RefObject<RNView | null>
|
|
52
|
+
): IGlassGroupMembership {
|
|
53
|
+
const group = useContext(GlassGroupContext);
|
|
54
|
+
const slot = useSharedValue(-1);
|
|
55
|
+
const slotRef = useRef(-1);
|
|
56
|
+
const { progress, offsetX, offsetY, pressX, pressY, height, growth, light } =
|
|
57
|
+
member;
|
|
58
|
+
|
|
59
|
+
/** The frame measured against the group's row, with the layout event's numbers as fallback. */
|
|
60
|
+
const report = useCallback(
|
|
61
|
+
(
|
|
62
|
+
assigned: number,
|
|
63
|
+
node: RNView | null | undefined,
|
|
64
|
+
fallback?: IGlassGroupRect
|
|
65
|
+
): void => {
|
|
66
|
+
if (group == null) return;
|
|
67
|
+
const host = group.hostRef.current;
|
|
68
|
+
const measurable = node as unknown as TMeasurable | null | undefined;
|
|
69
|
+
if (host != null && measurable?.measureLayout != null) {
|
|
70
|
+
measurable.measureLayout(
|
|
71
|
+
host,
|
|
72
|
+
(mx, my, mw, mh) => {
|
|
73
|
+
if (mw > 0 && mh > 0) {
|
|
74
|
+
group.setRect(assigned, { x: mx, y: my, w: mw, h: mh });
|
|
75
|
+
} else if (fallback != null) {
|
|
76
|
+
group.setRect(assigned, fallback);
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
() => {
|
|
80
|
+
if (fallback != null) group.setRect(assigned, fallback);
|
|
81
|
+
}
|
|
82
|
+
);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if (fallback != null) group.setRect(assigned, fallback);
|
|
86
|
+
},
|
|
87
|
+
[group]
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
useLayoutEffect(() => {
|
|
91
|
+
if (group == null) return undefined;
|
|
92
|
+
const assigned = group.register({
|
|
93
|
+
progress,
|
|
94
|
+
offsetX,
|
|
95
|
+
offsetY,
|
|
96
|
+
pressX,
|
|
97
|
+
pressY,
|
|
98
|
+
height,
|
|
99
|
+
growth,
|
|
100
|
+
light,
|
|
101
|
+
});
|
|
102
|
+
slotRef.current = assigned;
|
|
103
|
+
slot.value = assigned;
|
|
104
|
+
// A re-registration (a prop in the deps changed, or a refresh) gets a new slot but no new
|
|
105
|
+
// layout event, so the frame is measured here as well; on first mount the view has no
|
|
106
|
+
// size yet and the layout event that follows fills it in.
|
|
107
|
+
report(assigned, frameRef?.current);
|
|
108
|
+
return () => {
|
|
109
|
+
group.unregister(assigned);
|
|
110
|
+
slotRef.current = -1;
|
|
111
|
+
slot.value = -1;
|
|
112
|
+
};
|
|
113
|
+
}, [
|
|
114
|
+
group,
|
|
115
|
+
progress,
|
|
116
|
+
offsetX,
|
|
117
|
+
offsetY,
|
|
118
|
+
pressX,
|
|
119
|
+
pressY,
|
|
120
|
+
height,
|
|
121
|
+
growth,
|
|
122
|
+
light,
|
|
123
|
+
slot,
|
|
124
|
+
report,
|
|
125
|
+
frameRef,
|
|
126
|
+
]);
|
|
127
|
+
|
|
128
|
+
const onLayout = useCallback(
|
|
129
|
+
(event: LayoutChangeEvent, node?: RNView | null): void => {
|
|
130
|
+
if (group == null || slotRef.current < 0) return;
|
|
131
|
+
const { x, y, width: w, height: h } = event.nativeEvent.layout;
|
|
132
|
+
report(slotRef.current, node ?? frameRef?.current, { x, y, w, h });
|
|
133
|
+
},
|
|
134
|
+
[group, report, frameRef]
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
const keepsPane = group == null || group.native;
|
|
138
|
+
const activeSlot = group?.activeSlot;
|
|
139
|
+
const targetSlot = group?.targetSlot;
|
|
140
|
+
const activeProgress = group?.activeProgress;
|
|
141
|
+
|
|
142
|
+
const paneOpacity = useDerivedValue(() => {
|
|
143
|
+
if (
|
|
144
|
+
keepsPane ||
|
|
145
|
+
activeSlot == null ||
|
|
146
|
+
targetSlot == null ||
|
|
147
|
+
activeProgress == null
|
|
148
|
+
) {
|
|
149
|
+
return 1;
|
|
150
|
+
}
|
|
151
|
+
const mine = slot.value;
|
|
152
|
+
const involved =
|
|
153
|
+
mine >= 0 && (activeSlot.value === mine || targetSlot.value === mine);
|
|
154
|
+
if (!involved) return 1;
|
|
155
|
+
// The press spring overshoots on both ends; the pane must not wrap around.
|
|
156
|
+
return Math.min(1, Math.max(0, 1 - activeProgress.value));
|
|
157
|
+
}, [keepsPane, activeSlot, targetSlot, activeProgress, slot]);
|
|
158
|
+
|
|
159
|
+
return {
|
|
160
|
+
inGroup: group != null,
|
|
161
|
+
keepsPane,
|
|
162
|
+
slot,
|
|
163
|
+
onLayout,
|
|
164
|
+
paneOpacity,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export { useGlassGroupMember };
|
|
169
|
+
export type { IGlassGroupMembership };
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { useCallback, useMemo } from "react";
|
|
2
|
+
import type { SharedValue } from "react-native-reanimated";
|
|
3
|
+
import { useSharedValue } from "react-native-reanimated";
|
|
4
|
+
|
|
5
|
+
interface IGravityHighlightOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Low-pass weight of each new sample, `0`–`1`. Kyant's demo uses `0.5` at `SENSOR_DELAY_UI`
|
|
8
|
+
* (~60 Hz); lower is steadier, higher follows the hand faster.
|
|
9
|
+
*/
|
|
10
|
+
smoothing?: number;
|
|
11
|
+
/** The angle to report before the first sample. Defaults to `180`, the vertical light axis. */
|
|
12
|
+
initialAngle?: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface IGravityHighlight {
|
|
16
|
+
/**
|
|
17
|
+
* `highlight.angle` in the base view's degrees, on the UI thread — write it into `metal` from
|
|
18
|
+
* `useAnimatedProps`.
|
|
19
|
+
*/
|
|
20
|
+
angle: SharedValue<number>;
|
|
21
|
+
/**
|
|
22
|
+
* Feed an accelerometer sample: `x` positive toward the device's right edge, `y` positive
|
|
23
|
+
* toward its top, in any unit — only the direction matters. `expo-sensors`'
|
|
24
|
+
* `Accelerometer.addListener` hands you exactly this.
|
|
25
|
+
*/
|
|
26
|
+
push: (x: number, y: number) => void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The highlight follows gravity: tilt the phone and the light on every glass edge slides with it,
|
|
31
|
+
* as if the panes sat under one fixed lamp. The AndroidLiquidGlass catalog's control-centre demo
|
|
32
|
+
* does this with the accelerometer (`UISensor`, Apache-2.0 — see NOTICE); this is the same
|
|
33
|
+
* filter, without the sensor. The kit takes no dependency on `expo-sensors` — the app subscribes
|
|
34
|
+
* and calls `push`.
|
|
35
|
+
*
|
|
36
|
+
* ```tsx
|
|
37
|
+
* const gravity = useGravityHighlight();
|
|
38
|
+
* useEffect(() => {
|
|
39
|
+
* Accelerometer.setUpdateInterval(16);
|
|
40
|
+
* const sub = Accelerometer.addListener(({ x, y }) => gravity.push(x, y));
|
|
41
|
+
* return () => sub.remove();
|
|
42
|
+
* }, [gravity]);
|
|
43
|
+
* const props = useAnimatedProps(() => ({
|
|
44
|
+
* metal: { ...GLASS_BAR_METAL, highlight: { ...GLASS_BAR_METAL.highlight, angle: gravity.angle.value } },
|
|
45
|
+
* }));
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* Axis mapping: an upright phone reads gravity along `+y`, and the light should then sit on the
|
|
49
|
+
* vertical axis — top and bottom edges lit — which in `highlight.angle`'s convention is `180`.
|
|
50
|
+
* `atan2(y, x)` puts that at `90`, so the reported angle is Kyant's plus a quarter turn.
|
|
51
|
+
*/
|
|
52
|
+
function useGravityHighlight(
|
|
53
|
+
options: IGravityHighlightOptions = {},
|
|
54
|
+
): IGravityHighlight {
|
|
55
|
+
const smoothing = Math.min(1, Math.max(0.01, options.smoothing ?? 0.5));
|
|
56
|
+
const angle = useSharedValue(options.initialAngle ?? 180);
|
|
57
|
+
const filteredX = useSharedValue(0);
|
|
58
|
+
const filteredY = useSharedValue(1);
|
|
59
|
+
|
|
60
|
+
const push = useCallback(
|
|
61
|
+
(x: number, y: number): void => {
|
|
62
|
+
const norm = Math.hypot(x, y);
|
|
63
|
+
if (!Number.isFinite(norm) || norm < 1e-3) return;
|
|
64
|
+
// Filter the vector, not the angle: averaging angles across the ±180 seam would swing the
|
|
65
|
+
// light through every other direction on the way.
|
|
66
|
+
filteredX.value += (x / norm - filteredX.value) * smoothing;
|
|
67
|
+
filteredY.value += (y / norm - filteredY.value) * smoothing;
|
|
68
|
+
const gravity =
|
|
69
|
+
(Math.atan2(filteredY.value, filteredX.value) * 180) / Math.PI;
|
|
70
|
+
angle.value = gravity + 90;
|
|
71
|
+
},
|
|
72
|
+
[angle, filteredX, filteredY, smoothing],
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
return useMemo(() => ({ angle, push }), [angle, push]);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export { useGravityHighlight };
|
|
79
|
+
export type { IGravityHighlight, IGravityHighlightOptions };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { useCallback } from "react";
|
|
2
|
+
import type { SharedValue, WithSpringConfig } from "react-native-reanimated";
|
|
3
|
+
import { useSharedValue, withSpring } from "react-native-reanimated";
|
|
4
|
+
|
|
5
|
+
import { GLOW_SPRING } from "../constants";
|
|
6
|
+
|
|
7
|
+
interface IPressProgress {
|
|
8
|
+
progress: SharedValue<number>;
|
|
9
|
+
pressIn: () => void;
|
|
10
|
+
pressOut: () => void;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A 0→1 press spring, on the reference's `InteractiveHighlight` spec by default:
|
|
15
|
+
* `spring(0.5f, 300f)`, the bouncy one.
|
|
16
|
+
*
|
|
17
|
+
* That is deliberately *not* the spec a dragged control presses with. `DampedDragAnimation` uses
|
|
18
|
+
* `spring(1f, 1000f)`, critically damped, and holds it up through the entire snap — so on the tab
|
|
19
|
+
* bar the two run side by side and disagree on purpose: the pill's lens is still fully dialled in
|
|
20
|
+
* while it flies home, and the light the bar throws under it has already begun to fade, because
|
|
21
|
+
* `InteractiveHighlight` releases on finger-up and waits for nothing.
|
|
22
|
+
*
|
|
23
|
+
* Both callbacks are worklets, so a gesture handler can drive them on the UI thread; calling them
|
|
24
|
+
* from JS still works, which is what the tap-only controls do.
|
|
25
|
+
*/
|
|
26
|
+
function usePressProgress(
|
|
27
|
+
spring: WithSpringConfig = GLOW_SPRING,
|
|
28
|
+
): IPressProgress {
|
|
29
|
+
const progress = useSharedValue(0);
|
|
30
|
+
|
|
31
|
+
const pressIn = useCallback((): void => {
|
|
32
|
+
"worklet";
|
|
33
|
+
progress.value = withSpring(1, spring);
|
|
34
|
+
}, [progress, spring]);
|
|
35
|
+
const pressOut = useCallback((): void => {
|
|
36
|
+
"worklet";
|
|
37
|
+
progress.value = withSpring(0, spring);
|
|
38
|
+
}, [progress, spring]);
|
|
39
|
+
|
|
40
|
+
return { progress, pressIn, pressOut };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export { usePressProgress };
|
|
44
|
+
export type { IPressProgress };
|