@oxy.so/bloom 7.19.2 → 7.21.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/docs/adoption-matrix.mdx +10 -9
- package/docs/bottom-sheet.mdx +15 -0
- package/docs/dialog.mdx +51 -0
- package/docs/overlay.mdx +18 -0
- package/docs/rating.mdx +2 -0
- package/docs/stat-bar.mdx +10 -0
- package/docs/viewport.mdx +47 -0
- package/lib/commonjs/bottom-sheet/BottomSheetBase.js +27 -10
- package/lib/commonjs/bottom-sheet/BottomSheetBase.js.map +1 -1
- package/lib/commonjs/dialog/Dialog.js +21 -8
- package/lib/commonjs/dialog/Dialog.js.map +1 -1
- package/lib/commonjs/dialog/Dialog.web.js +37 -18
- package/lib/commonjs/dialog/Dialog.web.js.map +1 -1
- package/lib/commonjs/dialog/DialogBottomSheet.js +4 -0
- package/lib/commonjs/dialog/DialogBottomSheet.js.map +1 -1
- package/lib/commonjs/dialog/placement.js +8 -1
- package/lib/commonjs/dialog/placement.js.map +1 -1
- package/lib/commonjs/index.js +12 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/index.web.js +12 -0
- package/lib/commonjs/index.web.js.map +1 -1
- package/lib/commonjs/motion/surface-transition.js +18 -0
- package/lib/commonjs/motion/surface-transition.js.map +1 -0
- package/lib/commonjs/motion/use-surface-transition.js +24 -0
- package/lib/commonjs/motion/use-surface-transition.js.map +1 -0
- package/lib/commonjs/overlay/Overlay.js +11 -11
- package/lib/commonjs/overlay/Overlay.js.map +1 -1
- package/lib/commonjs/overlay/backdrop-paint.js +34 -0
- package/lib/commonjs/overlay/backdrop-paint.js.map +1 -0
- package/lib/commonjs/rating/RatingBar.js +2 -0
- package/lib/commonjs/rating/RatingBar.js.map +1 -1
- package/lib/commonjs/rating/RatingBar.web.js +2 -0
- package/lib/commonjs/rating/RatingBar.web.js.map +1 -1
- package/lib/commonjs/stat-bar/Meter.js +7 -4
- package/lib/commonjs/stat-bar/Meter.js.map +1 -1
- package/lib/commonjs/stat-bar/Meter.web.js +11 -4
- package/lib/commonjs/stat-bar/Meter.web.js.map +1 -1
- package/lib/commonjs/stat-bar/use-meter-reveal-policy.js +29 -0
- package/lib/commonjs/stat-bar/use-meter-reveal-policy.js.map +1 -0
- package/lib/commonjs/stat-bar/use-meter-reveal.js +39 -0
- package/lib/commonjs/stat-bar/use-meter-reveal.js.map +1 -0
- package/lib/commonjs/stat-bar/use-meter-reveal.web.js +38 -0
- package/lib/commonjs/stat-bar/use-meter-reveal.web.js.map +1 -0
- package/lib/commonjs/viewport/ViewportProvider.js +28 -0
- package/lib/commonjs/viewport/ViewportProvider.js.map +1 -0
- package/lib/commonjs/viewport/context.js +9 -0
- package/lib/commonjs/viewport/context.js.map +1 -0
- package/lib/commonjs/viewport/geometry.js +31 -0
- package/lib/commonjs/viewport/geometry.js.map +1 -0
- package/lib/commonjs/viewport/index.js +27 -0
- package/lib/commonjs/viewport/index.js.map +1 -0
- package/lib/commonjs/viewport/index.web.js +27 -0
- package/lib/commonjs/viewport/index.web.js.map +1 -0
- package/lib/commonjs/viewport/types.js +6 -0
- package/lib/commonjs/viewport/types.js.map +1 -0
- package/lib/commonjs/viewport/use-in-view.js +106 -0
- package/lib/commonjs/viewport/use-in-view.js.map +1 -0
- package/lib/commonjs/viewport/use-in-view.web.js +49 -0
- package/lib/commonjs/viewport/use-in-view.web.js.map +1 -0
- package/lib/commonjs/viewport/use-viewport-binding.js +55 -0
- package/lib/commonjs/viewport/use-viewport-binding.js.map +1 -0
- package/lib/module/bottom-sheet/BottomSheetBase.js +27 -10
- package/lib/module/bottom-sheet/BottomSheetBase.js.map +1 -1
- package/lib/module/dialog/Dialog.js +22 -9
- package/lib/module/dialog/Dialog.js.map +1 -1
- package/lib/module/dialog/Dialog.web.js +38 -19
- package/lib/module/dialog/Dialog.web.js.map +1 -1
- package/lib/module/dialog/DialogBottomSheet.js +4 -0
- package/lib/module/dialog/DialogBottomSheet.js.map +1 -1
- package/lib/module/dialog/placement.js +7 -1
- package/lib/module/dialog/placement.js.map +1 -1
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/index.web.js +1 -0
- package/lib/module/index.web.js.map +1 -1
- package/lib/module/motion/surface-transition.js +14 -0
- package/lib/module/motion/surface-transition.js.map +1 -0
- package/lib/module/motion/use-surface-transition.js +20 -0
- package/lib/module/motion/use-surface-transition.js.map +1 -0
- package/lib/module/overlay/Overlay.js +11 -11
- package/lib/module/overlay/Overlay.js.map +1 -1
- package/lib/module/overlay/backdrop-paint.js +29 -0
- package/lib/module/overlay/backdrop-paint.js.map +1 -0
- package/lib/module/rating/RatingBar.js +2 -0
- package/lib/module/rating/RatingBar.js.map +1 -1
- package/lib/module/rating/RatingBar.web.js +2 -0
- package/lib/module/rating/RatingBar.web.js.map +1 -1
- package/lib/module/stat-bar/Meter.js +9 -4
- package/lib/module/stat-bar/Meter.js.map +1 -1
- package/lib/module/stat-bar/Meter.web.js +11 -4
- package/lib/module/stat-bar/Meter.web.js.map +1 -1
- package/lib/module/stat-bar/use-meter-reveal-policy.js +25 -0
- package/lib/module/stat-bar/use-meter-reveal-policy.js.map +1 -0
- package/lib/module/stat-bar/use-meter-reveal.js +35 -0
- package/lib/module/stat-bar/use-meter-reveal.js.map +1 -0
- package/lib/module/stat-bar/use-meter-reveal.web.js +34 -0
- package/lib/module/stat-bar/use-meter-reveal.web.js.map +1 -0
- package/lib/module/viewport/ViewportProvider.js +23 -0
- package/lib/module/viewport/ViewportProvider.js.map +1 -0
- package/lib/module/viewport/context.js +5 -0
- package/lib/module/viewport/context.js.map +1 -0
- package/lib/module/viewport/geometry.js +25 -0
- package/lib/module/viewport/geometry.js.map +1 -0
- package/lib/module/viewport/index.js +6 -0
- package/lib/module/viewport/index.js.map +1 -0
- package/lib/module/viewport/index.web.js +11 -0
- package/lib/module/viewport/index.web.js.map +1 -0
- package/lib/module/viewport/types.js +4 -0
- package/lib/module/viewport/types.js.map +1 -0
- package/lib/module/viewport/use-in-view.js +102 -0
- package/lib/module/viewport/use-in-view.js.map +1 -0
- package/lib/module/viewport/use-in-view.web.js +45 -0
- package/lib/module/viewport/use-in-view.web.js.map +1 -0
- package/lib/module/viewport/use-viewport-binding.js +51 -0
- package/lib/module/viewport/use-viewport-binding.js.map +1 -0
- package/lib/typescript/commonjs/bottom-sheet/BottomSheetBase.d.ts.map +1 -1
- package/lib/typescript/commonjs/bottom-sheet/types.d.ts +6 -0
- package/lib/typescript/commonjs/bottom-sheet/types.d.ts.map +1 -1
- package/lib/typescript/commonjs/dialog/Dialog.d.ts.map +1 -1
- package/lib/typescript/commonjs/dialog/Dialog.web.d.ts.map +1 -1
- package/lib/typescript/commonjs/dialog/DialogBottomSheet.d.ts +2 -2
- package/lib/typescript/commonjs/dialog/DialogBottomSheet.d.ts.map +1 -1
- package/lib/typescript/commonjs/dialog/placement.d.ts +3 -1
- package/lib/typescript/commonjs/dialog/placement.d.ts.map +1 -1
- package/lib/typescript/commonjs/dialog/types.d.ts +8 -0
- package/lib/typescript/commonjs/dialog/types.d.ts.map +1 -1
- package/lib/typescript/commonjs/index.d.ts +1 -0
- package/lib/typescript/commonjs/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/index.web.d.ts +1 -0
- package/lib/typescript/commonjs/index.web.d.ts.map +1 -1
- package/lib/typescript/commonjs/motion/index.d.ts +1 -1
- package/lib/typescript/commonjs/motion/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/motion/index.web.d.ts +1 -1
- package/lib/typescript/commonjs/motion/index.web.d.ts.map +1 -1
- package/lib/typescript/commonjs/motion/surface-transition.d.ts +8 -0
- package/lib/typescript/commonjs/motion/surface-transition.d.ts.map +1 -0
- package/lib/typescript/commonjs/motion/types.d.ts +7 -0
- package/lib/typescript/commonjs/motion/types.d.ts.map +1 -1
- package/lib/typescript/commonjs/motion/use-surface-transition.d.ts +9 -0
- package/lib/typescript/commonjs/motion/use-surface-transition.d.ts.map +1 -0
- package/lib/typescript/commonjs/overlay/Overlay.d.ts.map +1 -1
- package/lib/typescript/commonjs/overlay/backdrop-paint.d.ts +7 -0
- package/lib/typescript/commonjs/overlay/backdrop-paint.d.ts.map +1 -0
- package/lib/typescript/commonjs/overlay/index.d.ts +1 -1
- package/lib/typescript/commonjs/overlay/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/overlay/types.d.ts +23 -9
- package/lib/typescript/commonjs/overlay/types.d.ts.map +1 -1
- package/lib/typescript/commonjs/rating/RatingBar.d.ts.map +1 -1
- package/lib/typescript/commonjs/rating/types.d.ts +3 -0
- package/lib/typescript/commonjs/rating/types.d.ts.map +1 -1
- package/lib/typescript/commonjs/stat-bar/Meter.d.ts.map +1 -1
- package/lib/typescript/commonjs/stat-bar/Meter.web.d.ts.map +1 -1
- package/lib/typescript/commonjs/stat-bar/index.d.ts +1 -0
- package/lib/typescript/commonjs/stat-bar/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/stat-bar/index.web.d.ts +1 -0
- package/lib/typescript/commonjs/stat-bar/index.web.d.ts.map +1 -1
- package/lib/typescript/commonjs/stat-bar/types.d.ts +14 -0
- package/lib/typescript/commonjs/stat-bar/types.d.ts.map +1 -1
- package/lib/typescript/commonjs/stat-bar/use-meter-reveal-policy.d.ts +10 -0
- package/lib/typescript/commonjs/stat-bar/use-meter-reveal-policy.d.ts.map +1 -0
- package/lib/typescript/commonjs/stat-bar/use-meter-reveal.d.ts +5 -0
- package/lib/typescript/commonjs/stat-bar/use-meter-reveal.d.ts.map +1 -0
- package/lib/typescript/commonjs/stat-bar/use-meter-reveal.web.d.ts +9 -0
- package/lib/typescript/commonjs/stat-bar/use-meter-reveal.web.d.ts.map +1 -0
- package/lib/typescript/commonjs/viewport/ViewportProvider.d.ts +4 -0
- package/lib/typescript/commonjs/viewport/ViewportProvider.d.ts.map +1 -0
- package/lib/typescript/commonjs/viewport/context.d.ts +8 -0
- package/lib/typescript/commonjs/viewport/context.d.ts.map +1 -0
- package/lib/typescript/commonjs/viewport/geometry.d.ts +10 -0
- package/lib/typescript/commonjs/viewport/geometry.d.ts.map +1 -0
- package/lib/typescript/commonjs/viewport/index.d.ts +5 -0
- package/lib/typescript/commonjs/viewport/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/viewport/index.web.d.ts +5 -0
- package/lib/typescript/commonjs/viewport/index.web.d.ts.map +1 -0
- package/lib/typescript/commonjs/viewport/types.d.ts +25 -0
- package/lib/typescript/commonjs/viewport/types.d.ts.map +1 -0
- package/lib/typescript/commonjs/viewport/use-in-view.d.ts +11 -0
- package/lib/typescript/commonjs/viewport/use-in-view.d.ts.map +1 -0
- package/lib/typescript/commonjs/viewport/use-in-view.web.d.ts +10 -0
- package/lib/typescript/commonjs/viewport/use-in-view.web.d.ts.map +1 -0
- package/lib/typescript/commonjs/viewport/use-viewport-binding.d.ts +9 -0
- package/lib/typescript/commonjs/viewport/use-viewport-binding.d.ts.map +1 -0
- package/lib/typescript/module/bottom-sheet/BottomSheetBase.d.ts.map +1 -1
- package/lib/typescript/module/bottom-sheet/types.d.ts +6 -0
- package/lib/typescript/module/bottom-sheet/types.d.ts.map +1 -1
- package/lib/typescript/module/dialog/Dialog.d.ts.map +1 -1
- package/lib/typescript/module/dialog/Dialog.web.d.ts.map +1 -1
- package/lib/typescript/module/dialog/DialogBottomSheet.d.ts +2 -2
- package/lib/typescript/module/dialog/DialogBottomSheet.d.ts.map +1 -1
- package/lib/typescript/module/dialog/placement.d.ts +3 -1
- package/lib/typescript/module/dialog/placement.d.ts.map +1 -1
- package/lib/typescript/module/dialog/types.d.ts +8 -0
- package/lib/typescript/module/dialog/types.d.ts.map +1 -1
- package/lib/typescript/module/index.d.ts +1 -0
- package/lib/typescript/module/index.d.ts.map +1 -1
- package/lib/typescript/module/index.web.d.ts +1 -0
- package/lib/typescript/module/index.web.d.ts.map +1 -1
- package/lib/typescript/module/motion/index.d.ts +1 -1
- package/lib/typescript/module/motion/index.d.ts.map +1 -1
- package/lib/typescript/module/motion/index.web.d.ts +1 -1
- package/lib/typescript/module/motion/index.web.d.ts.map +1 -1
- package/lib/typescript/module/motion/surface-transition.d.ts +8 -0
- package/lib/typescript/module/motion/surface-transition.d.ts.map +1 -0
- package/lib/typescript/module/motion/types.d.ts +7 -0
- package/lib/typescript/module/motion/types.d.ts.map +1 -1
- package/lib/typescript/module/motion/use-surface-transition.d.ts +9 -0
- package/lib/typescript/module/motion/use-surface-transition.d.ts.map +1 -0
- package/lib/typescript/module/overlay/Overlay.d.ts.map +1 -1
- package/lib/typescript/module/overlay/backdrop-paint.d.ts +7 -0
- package/lib/typescript/module/overlay/backdrop-paint.d.ts.map +1 -0
- package/lib/typescript/module/overlay/index.d.ts +1 -1
- package/lib/typescript/module/overlay/index.d.ts.map +1 -1
- package/lib/typescript/module/overlay/types.d.ts +23 -9
- package/lib/typescript/module/overlay/types.d.ts.map +1 -1
- package/lib/typescript/module/rating/RatingBar.d.ts.map +1 -1
- package/lib/typescript/module/rating/types.d.ts +3 -0
- package/lib/typescript/module/rating/types.d.ts.map +1 -1
- package/lib/typescript/module/stat-bar/Meter.d.ts.map +1 -1
- package/lib/typescript/module/stat-bar/Meter.web.d.ts.map +1 -1
- package/lib/typescript/module/stat-bar/index.d.ts +1 -0
- package/lib/typescript/module/stat-bar/index.d.ts.map +1 -1
- package/lib/typescript/module/stat-bar/index.web.d.ts +1 -0
- package/lib/typescript/module/stat-bar/index.web.d.ts.map +1 -1
- package/lib/typescript/module/stat-bar/types.d.ts +14 -0
- package/lib/typescript/module/stat-bar/types.d.ts.map +1 -1
- package/lib/typescript/module/stat-bar/use-meter-reveal-policy.d.ts +10 -0
- package/lib/typescript/module/stat-bar/use-meter-reveal-policy.d.ts.map +1 -0
- package/lib/typescript/module/stat-bar/use-meter-reveal.d.ts +5 -0
- package/lib/typescript/module/stat-bar/use-meter-reveal.d.ts.map +1 -0
- package/lib/typescript/module/stat-bar/use-meter-reveal.web.d.ts +9 -0
- package/lib/typescript/module/stat-bar/use-meter-reveal.web.d.ts.map +1 -0
- package/lib/typescript/module/viewport/ViewportProvider.d.ts +4 -0
- package/lib/typescript/module/viewport/ViewportProvider.d.ts.map +1 -0
- package/lib/typescript/module/viewport/context.d.ts +8 -0
- package/lib/typescript/module/viewport/context.d.ts.map +1 -0
- package/lib/typescript/module/viewport/geometry.d.ts +10 -0
- package/lib/typescript/module/viewport/geometry.d.ts.map +1 -0
- package/lib/typescript/module/viewport/index.d.ts +5 -0
- package/lib/typescript/module/viewport/index.d.ts.map +1 -0
- package/lib/typescript/module/viewport/index.web.d.ts +5 -0
- package/lib/typescript/module/viewport/index.web.d.ts.map +1 -0
- package/lib/typescript/module/viewport/types.d.ts +25 -0
- package/lib/typescript/module/viewport/types.d.ts.map +1 -0
- package/lib/typescript/module/viewport/use-in-view.d.ts +11 -0
- package/lib/typescript/module/viewport/use-in-view.d.ts.map +1 -0
- package/lib/typescript/module/viewport/use-in-view.web.d.ts +10 -0
- package/lib/typescript/module/viewport/use-in-view.web.d.ts.map +1 -0
- package/lib/typescript/module/viewport/use-viewport-binding.d.ts +9 -0
- package/lib/typescript/module/viewport/use-viewport-binding.d.ts.map +1 -0
- package/package.json +23 -1
- package/src/bottom-sheet/BottomSheetBase.tsx +18 -8
- package/src/bottom-sheet/types.ts +6 -0
- package/src/dialog/Dialog.tsx +24 -8
- package/src/dialog/Dialog.web.tsx +40 -16
- package/src/dialog/DialogBottomSheet.tsx +6 -0
- package/src/dialog/placement.ts +9 -1
- package/src/dialog/types.ts +8 -0
- package/src/index.ts +2 -0
- package/src/index.web.ts +2 -0
- package/src/motion/index.ts +1 -1
- package/src/motion/index.web.ts +1 -1
- package/src/motion/surface-transition.ts +15 -0
- package/src/motion/types.ts +8 -0
- package/src/motion/use-surface-transition.ts +14 -0
- package/src/overlay/Overlay.tsx +12 -8
- package/src/overlay/backdrop-paint.ts +25 -0
- package/src/overlay/index.ts +1 -1
- package/src/overlay/types.ts +22 -9
- package/src/rating/RatingBar.tsx +2 -1
- package/src/rating/RatingBar.web.tsx +2 -2
- package/src/rating/types.ts +3 -0
- package/src/stat-bar/Meter.tsx +7 -3
- package/src/stat-bar/Meter.web.tsx +7 -4
- package/src/stat-bar/index.ts +2 -0
- package/src/stat-bar/index.web.ts +2 -0
- package/src/stat-bar/types.ts +15 -0
- package/src/stat-bar/use-meter-reveal-policy.ts +19 -0
- package/src/stat-bar/use-meter-reveal.ts +21 -0
- package/src/stat-bar/use-meter-reveal.web.ts +24 -0
- package/src/viewport/ViewportProvider.tsx +11 -0
- package/src/viewport/context.ts +9 -0
- package/src/viewport/geometry.ts +18 -0
- package/src/viewport/index.ts +4 -0
- package/src/viewport/index.web.ts +9 -0
- package/src/viewport/types.ts +23 -0
- package/src/viewport/use-in-view.ts +69 -0
- package/src/viewport/use-in-view.web.ts +33 -0
- package/src/viewport/use-viewport-binding.ts +34 -0
package/src/motion/types.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { type StyleProp, type ViewStyle } from 'react-native';
|
|
3
3
|
|
|
4
|
+
/** Opt-in timing for a surface's panel and backdrop. Defaults remain owner-specific when omitted. */
|
|
5
|
+
export interface SurfaceTransition {
|
|
6
|
+
/** Milliseconds, clamped to zero. Non-finite values fall back to 300. */
|
|
7
|
+
duration: number;
|
|
8
|
+
/** CSS cubic-bezier coordinates. Invalid curves fall back to ease. */
|
|
9
|
+
easing?: readonly [number, number, number, number];
|
|
10
|
+
}
|
|
11
|
+
|
|
4
12
|
/** Direction the incoming screen travels. */
|
|
5
13
|
export type ScreenTransitionDirection = 'forward' | 'backward';
|
|
6
14
|
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { Easing } from 'react-native-reanimated';
|
|
3
|
+
import { usePrefersReducedMotion } from '../hooks/use-prefers-reduced-motion';
|
|
4
|
+
import { resolveSurfaceTransition } from './surface-transition';
|
|
5
|
+
import type { SurfaceTransition } from './types';
|
|
6
|
+
|
|
7
|
+
/** Stable timing values keep unrelated surface renders from restarting motion. */
|
|
8
|
+
export function useSurfaceTransition(transition: SurfaceTransition | undefined) {
|
|
9
|
+
const reducedMotion = usePrefersReducedMotion();
|
|
10
|
+
const resolved = resolveSurfaceTransition(transition);
|
|
11
|
+
const [x1, y1, x2, y2] = resolved.easing;
|
|
12
|
+
const easing = useMemo(() => Easing.bezier(x1, y1, x2, y2), [x1, y1, x2, y2]);
|
|
13
|
+
return { ...resolved, easing, reducedMotion, duration: reducedMotion ? 0 : transition ? resolved.duration : undefined };
|
|
14
|
+
}
|
package/src/overlay/Overlay.tsx
CHANGED
|
@@ -43,6 +43,8 @@ import { ScreenScope } from '../layout/screen-scope';
|
|
|
43
43
|
import { createContext, memo, useContext, useMemo } from 'react';
|
|
44
44
|
import { BlurView } from 'expo-blur';
|
|
45
45
|
|
|
46
|
+
import { useIsRtl } from '../hooks/use-is-rtl';
|
|
47
|
+
import { backdropDimStyle, clampBackdropNumber } from './backdrop-paint';
|
|
46
48
|
import { useWindowedBlurTarget } from '../glass/blur-target';
|
|
47
49
|
import {
|
|
48
50
|
Platform,
|
|
@@ -247,7 +249,7 @@ interface BackdropLayerProps {
|
|
|
247
249
|
blurTarget?: ReturnType<typeof useWindowedBlurTarget>;
|
|
248
250
|
blurIntensity: number;
|
|
249
251
|
blurTint: 'light' | 'dark' | 'default';
|
|
250
|
-
|
|
252
|
+
dimStyle: ViewStyle;
|
|
251
253
|
dimOpacity: number;
|
|
252
254
|
/** Opacity the caller asked for, already lifted off the press target. */
|
|
253
255
|
staticOpacity: number;
|
|
@@ -264,7 +266,7 @@ function AnimatedBackdropLayers({
|
|
|
264
266
|
progress,
|
|
265
267
|
blurIntensity,
|
|
266
268
|
blurTint,
|
|
267
|
-
|
|
269
|
+
dimStyle,
|
|
268
270
|
dimOpacity,
|
|
269
271
|
staticOpacity,
|
|
270
272
|
layerStyle,
|
|
@@ -299,7 +301,7 @@ function AnimatedBackdropLayers({
|
|
|
299
301
|
) : null}
|
|
300
302
|
<Animated.View
|
|
301
303
|
pointerEvents="none"
|
|
302
|
-
style={[StyleSheet.absoluteFill,
|
|
304
|
+
style={[StyleSheet.absoluteFill, dimStyle, layerStyle, dimFade]}
|
|
303
305
|
/>
|
|
304
306
|
</>
|
|
305
307
|
);
|
|
@@ -325,7 +327,7 @@ function StaticBackdropLayers({
|
|
|
325
327
|
blurTarget,
|
|
326
328
|
blurIntensity,
|
|
327
329
|
blurTint,
|
|
328
|
-
|
|
330
|
+
dimStyle,
|
|
329
331
|
dimOpacity,
|
|
330
332
|
staticOpacity,
|
|
331
333
|
layerStyle,
|
|
@@ -350,7 +352,7 @@ function StaticBackdropLayers({
|
|
|
350
352
|
pointerEvents="none"
|
|
351
353
|
style={[
|
|
352
354
|
StyleSheet.absoluteFill,
|
|
353
|
-
|
|
355
|
+
dimStyle,
|
|
354
356
|
layerStyle,
|
|
355
357
|
{ opacity: staticOpacity * dimOpacity },
|
|
356
358
|
]}
|
|
@@ -383,6 +385,7 @@ export const Backdrop = memo(function Backdrop({
|
|
|
383
385
|
blurIntensity = BACKDROP_BLUR_INTENSITY,
|
|
384
386
|
blurTint = 'dark',
|
|
385
387
|
dimColor = '#000',
|
|
388
|
+
dimGradient,
|
|
386
389
|
dimOpacity = BACKDROP_DIM_OPACITY,
|
|
387
390
|
style,
|
|
388
391
|
layerStyle,
|
|
@@ -390,6 +393,7 @@ export const Backdrop = memo(function Backdrop({
|
|
|
390
393
|
accessibilityLabel: accessibilityLabelProp,
|
|
391
394
|
testID,
|
|
392
395
|
}: BackdropProps) {
|
|
396
|
+
const rtl = useIsRtl();
|
|
393
397
|
const common = useCommonMessages();
|
|
394
398
|
const accessibilityLabel = accessibilityLabelProp ?? common.dismiss;
|
|
395
399
|
const inert = disabled || !onPress;
|
|
@@ -412,10 +416,10 @@ export const Backdrop = memo(function Backdrop({
|
|
|
412
416
|
|
|
413
417
|
const layerProps: BackdropLayerProps = {
|
|
414
418
|
blurTarget,
|
|
415
|
-
blurIntensity,
|
|
419
|
+
blurIntensity: clampBackdropNumber(blurIntensity, BACKDROP_BLUR_INTENSITY, 100),
|
|
416
420
|
blurTint,
|
|
417
|
-
|
|
418
|
-
dimOpacity,
|
|
421
|
+
dimStyle: backdropDimStyle(resolvedDimColor, dimGradient, rtl),
|
|
422
|
+
dimOpacity: clampBackdropNumber(dimOpacity, BACKDROP_DIM_OPACITY, 1),
|
|
419
423
|
staticOpacity,
|
|
420
424
|
layerStyle,
|
|
421
425
|
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Platform } from 'react-native';
|
|
2
|
+
import type { WebCssStyle } from '../styles/web-view-style';
|
|
3
|
+
import type { BackdropGradient } from './types';
|
|
4
|
+
|
|
5
|
+
/** Invalid/non-finite numbers preserve the owner's default; valid numbers clamp. */
|
|
6
|
+
export function clampBackdropNumber(value: number, fallback: number, max: number): number {
|
|
7
|
+
return Number.isFinite(value) ? Math.max(0, Math.min(max, value)) : fallback;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** The gradient lives on the dim layer, never the interactive backdrop host. */
|
|
11
|
+
export function backdropDimStyle(color: string, gradient: BackdropGradient | undefined, rtl: boolean): WebCssStyle {
|
|
12
|
+
if (!gradient || !['start-to-end', 'end-to-start', 'top-to-bottom', 'bottom-to-top'].includes(gradient.direction) || !Array.isArray(gradient.stops) || gradient.stops.length < 2 || gradient.stops.some(stop => !Number.isFinite(stop.offset) || typeof stop.color !== 'string' || !stop.color.trim())) {
|
|
13
|
+
return { backgroundColor: color };
|
|
14
|
+
}
|
|
15
|
+
const angle = gradient.direction === 'top-to-bottom' ? 180
|
|
16
|
+
: gradient.direction === 'bottom-to-top' ? 0
|
|
17
|
+
: (gradient.direction === 'start-to-end') !== rtl ? 90 : 270;
|
|
18
|
+
let previous = 0;
|
|
19
|
+
const stops = gradient.stops.map(stop => {
|
|
20
|
+
previous = Math.max(previous, Math.min(1, Math.max(0, stop.offset)));
|
|
21
|
+
return `${stop.color} ${previous * 100}%`;
|
|
22
|
+
}).join(', ');
|
|
23
|
+
const image = `linear-gradient(${angle}deg, ${stops})`;
|
|
24
|
+
return Platform.OS === 'web' ? { backgroundImage: image } : { experimental_backgroundImage: image };
|
|
25
|
+
}
|
package/src/overlay/index.ts
CHANGED
|
@@ -16,4 +16,4 @@ export {
|
|
|
16
16
|
OverlayRoot,
|
|
17
17
|
Backdrop,
|
|
18
18
|
} from './Overlay';
|
|
19
|
-
export type { OverlayRootProps, BackdropProps, OverlayInertBoundaryProps } from './types';
|
|
19
|
+
export type { OverlayRootProps, BackdropProps, BackdropAppearance, BackdropGradient, OverlayInertBoundaryProps } from './types';
|
package/src/overlay/types.ts
CHANGED
|
@@ -62,7 +62,28 @@ export interface OverlayInertBoundaryProps {
|
|
|
62
62
|
testID?: string;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
|
|
65
|
+
/** A logical linear gradient replacing the uniform dim fill. */
|
|
66
|
+
export interface BackdropGradient {
|
|
67
|
+
direction: 'start-to-end' | 'end-to-start' | 'top-to-bottom' | 'bottom-to-top';
|
|
68
|
+
/** At least two stops. Offsets clamp to 0..1 and cannot precede the previous stop. */
|
|
69
|
+
stops: readonly { offset: number; color: string }[];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Paint only; the owning surface retains hit testing, layering and animation. */
|
|
73
|
+
export interface BackdropAppearance {
|
|
74
|
+
/** Blur radius behind the dim. `0` renders the dim alone. */
|
|
75
|
+
blurIntensity?: number;
|
|
76
|
+
/** Blur tint. Backdrops dim the app, so `dark` is the default on every theme. */
|
|
77
|
+
blurTint?: 'light' | 'dark' | 'default';
|
|
78
|
+
/** Dim colour over the blur. */
|
|
79
|
+
dimColor?: string;
|
|
80
|
+
/** Dim opacity, 0–1. */
|
|
81
|
+
dimOpacity?: number;
|
|
82
|
+
/** Replaces dimColor; dimOpacity still multiplies the gradient. Invalid stops fall back to dimColor. */
|
|
83
|
+
dimGradient?: BackdropGradient;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export interface BackdropProps extends BackdropAppearance {
|
|
66
87
|
/** Dismiss handler. Omit (or pass `disabled`) for a backdrop that only dims. */
|
|
67
88
|
onPress?: () => void;
|
|
68
89
|
/**
|
|
@@ -73,14 +94,6 @@ export interface BackdropProps {
|
|
|
73
94
|
progress?: SharedValue<number>;
|
|
74
95
|
/** `true` keeps the dim but makes it inert — a blocking dialog, a busy state. */
|
|
75
96
|
disabled?: boolean;
|
|
76
|
-
/** Blur radius behind the dim. `0` renders the dim alone. */
|
|
77
|
-
blurIntensity?: number;
|
|
78
|
-
/** Blur tint. Backdrops dim the app, so `dark` is the default on every theme. */
|
|
79
|
-
blurTint?: 'light' | 'dark' | 'default';
|
|
80
|
-
/** Dim colour over the blur. */
|
|
81
|
-
dimColor?: string;
|
|
82
|
-
/** Dim opacity, 0–1. */
|
|
83
|
-
dimOpacity?: number;
|
|
84
97
|
/**
|
|
85
98
|
* Geometry for the press target: insets, layout. NOT a z-index — where this
|
|
86
99
|
* surface sits relative to others is `OverlayRoot`'s call (see `./stack.ts`),
|
package/src/rating/RatingBar.tsx
CHANGED
|
@@ -29,7 +29,7 @@ import type { RatingBarProps } from './types';
|
|
|
29
29
|
|
|
30
30
|
const BAR_WIDTH = 96;
|
|
31
31
|
|
|
32
|
-
function RatingBarComponent({ label, value, max = 5, display, labelWidth, style, testID, labelStyle, displayStyle, trackStyle, fillClassName }: RatingBarProps & {
|
|
32
|
+
function RatingBarComponent({ label, value, reveal, max = 5, display, labelWidth, style, testID, labelStyle, displayStyle, trackStyle, fillClassName }: RatingBarProps & {
|
|
33
33
|
labelStyle?: StyleProp<TextStyle>; displayStyle?: StyleProp<TextStyle>; trackStyle?: StyleProp<ViewStyle>;
|
|
34
34
|
}) {
|
|
35
35
|
const theme = useTheme();
|
|
@@ -54,6 +54,7 @@ function RatingBarComponent({ label, value, max = 5, display, labelWidth, style,
|
|
|
54
54
|
{label}
|
|
55
55
|
</Text>
|
|
56
56
|
<Meter
|
|
57
|
+
reveal={reveal}
|
|
57
58
|
value={value}
|
|
58
59
|
max={safeMax}
|
|
59
60
|
height={4}
|
|
@@ -14,14 +14,14 @@ const CSS = `@layer base {
|
|
|
14
14
|
.bloom-rating-track-flex { flex:1; min-width:0; }
|
|
15
15
|
.bloom-rating-display { min-width:28px; text-align:right; font-family:var(--bloom-font-sans); font-size:${semibold.fontSize}px; line-height:${semibold.lineHeight}px; font-weight:${semibold.fontWeight}; font-variant-numeric:tabular-nums; }
|
|
16
16
|
}`;
|
|
17
|
-
export const RatingBar = memo(function RatingBar({ label, value, max = 5, display, labelWidth, style, testID,
|
|
17
|
+
export const RatingBar = memo(function RatingBar({ label, value, reveal, max = 5, display, labelWidth, style, testID,
|
|
18
18
|
className, labelClassName, displayClassName, trackClassName, fillClassName }: RatingBarProps) {
|
|
19
19
|
useInteractiveWebCss('bloom-rating-bar', CSS);
|
|
20
20
|
const theme = useTheme();
|
|
21
21
|
const vars = { '--bloom-rating-text': theme.colors.text, '--bloom-rating-label-width': `${labelWidth ?? 0}px` } as React.CSSProperties;
|
|
22
22
|
return <div className={['bloom-rating-bar', className].filter(Boolean).join(' ')} style={{ ...vars, ...resolveNativeWebStyle(style) }} data-testid={testID}>
|
|
23
23
|
<span className={['bloom-rating-label', labelClassName].filter(Boolean).join(' ')} data-fixed={labelWidth !== undefined ? '' : undefined} aria-hidden>{label}</span>
|
|
24
|
-
<Meter value={value} max={max > 0 ? max : 1} height={4} width={labelWidth === undefined ? 96 : undefined} accessibilityLabel={label} valueText={display}
|
|
24
|
+
<Meter reveal={reveal} value={value} max={max > 0 ? max : 1} height={4} width={labelWidth === undefined ? 96 : undefined} accessibilityLabel={label} valueText={display}
|
|
25
25
|
testID={testID ? `${testID}-bar` : undefined} fillTestID={testID ? `${testID}-fill` : undefined}
|
|
26
26
|
className={['bloom-rating-track', labelWidth !== undefined ? 'bloom-rating-track-flex' : '', trackClassName].filter(Boolean).join(' ')} fillClassName={fillClassName} />
|
|
27
27
|
{display != null && <span className={['bloom-rating-display', displayClassName].filter(Boolean).join(' ')} aria-hidden>{display}</span>}
|
package/src/rating/types.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { MeterReveal } from '../stat-bar/types';
|
|
1
2
|
import type { StyleProp, ViewStyle } from 'react-native';
|
|
2
3
|
|
|
3
4
|
/** `small` is body-2 text with a 14px star; `medium` (default) body text with a 16px star. */
|
|
@@ -103,6 +104,8 @@ export interface RatingInputProps {
|
|
|
103
104
|
}
|
|
104
105
|
|
|
105
106
|
export interface RatingBarProps {
|
|
107
|
+
/** Forwarded to Meter; never changes the accessible measurement. */
|
|
108
|
+
reveal?: MeterReveal;
|
|
106
109
|
className?: string;
|
|
107
110
|
labelClassName?: string;
|
|
108
111
|
displayClassName?: string;
|
package/src/stat-bar/Meter.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { memo, useEffect, useMemo } from 'react';
|
|
2
2
|
import { styled } from 'react-native-css';
|
|
3
|
-
import { Platform, View, type StyleProp, type ViewStyle } from 'react-native';
|
|
3
|
+
import { Animated, Platform, View, type StyleProp, type ViewStyle } from 'react-native';
|
|
4
4
|
|
|
5
5
|
import { webDataSet } from '../styles/web-data';
|
|
6
6
|
import type { WebCssStyle } from '../styles/web-view-style';
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
resolveMeterColors,
|
|
14
14
|
} from './shared';
|
|
15
15
|
import type { AnyMeterProps } from './types';
|
|
16
|
+
import { useMeterReveal } from './use-meter-reveal';
|
|
16
17
|
|
|
17
18
|
/**
|
|
18
19
|
* ONE determinate bar. Every progress bar in Bloom is this one.
|
|
@@ -41,6 +42,7 @@ function MeterComponent(props: AnyMeterProps & { fillStyle?: StyleProp<ViewStyle
|
|
|
41
42
|
const defaults = useMemo(() => resolveMeterColors(theme), [theme]);
|
|
42
43
|
const {
|
|
43
44
|
value,
|
|
45
|
+
reveal,
|
|
44
46
|
max = 1,
|
|
45
47
|
height = 6,
|
|
46
48
|
radius = height / 2,
|
|
@@ -59,6 +61,8 @@ function MeterComponent(props: AnyMeterProps & { fillStyle?: StyleProp<ViewStyle
|
|
|
59
61
|
}, [transitionMs]);
|
|
60
62
|
|
|
61
63
|
const fraction = meterFraction(value, max);
|
|
64
|
+
const revealedWidth = useMeterReveal(fraction, reveal);
|
|
65
|
+
const Fill = reveal ? Animated.View : View;
|
|
62
66
|
|
|
63
67
|
const fillStyle: WebCssStyle = {
|
|
64
68
|
width: `${fraction * 100}%`,
|
|
@@ -69,10 +73,10 @@ function MeterComponent(props: AnyMeterProps & { fillStyle?: StyleProp<ViewStyle
|
|
|
69
73
|
};
|
|
70
74
|
|
|
71
75
|
const bar = (
|
|
72
|
-
<
|
|
76
|
+
<Fill
|
|
73
77
|
{...(transitionMs > 0 ? webDataSet({ bloomMeterFill: '' }) : null)}
|
|
74
78
|
testID={fillTestID}
|
|
75
|
-
style={[fillStyle, callerFillStyle, { width: fillStyle.width }]}
|
|
79
|
+
style={[fillStyle, callerFillStyle, { width: reveal ? revealedWidth : fillStyle.width }]}
|
|
76
80
|
/>
|
|
77
81
|
);
|
|
78
82
|
|
|
@@ -4,11 +4,12 @@ import { useInteractiveWebCss } from '../styles/interactive-web-css';
|
|
|
4
4
|
import { useTheme } from '../theme/use-theme';
|
|
5
5
|
import { meterFraction, meterValue, resolveMeterColors } from './shared';
|
|
6
6
|
import type { AnyMeterProps } from './types';
|
|
7
|
+
import { useMeterReveal } from './use-meter-reveal.web';
|
|
7
8
|
|
|
8
9
|
const CSS = `@layer base {
|
|
9
10
|
.bloom-meter-track { display:block; flex-shrink:0; box-sizing:border-box; width:var(--bloom-meter-width,100%); height:var(--bloom-meter-height); border-radius:var(--bloom-meter-radius); background:var(--bloom-meter-track); overflow:hidden; }
|
|
10
11
|
.bloom-meter-fill { display:block; box-sizing:border-box; height:100%; border-radius:var(--bloom-meter-radius); background:var(--bloom-meter-fill); }
|
|
11
|
-
.bloom-meter-fill[data-transition] { transition:width var(--bloom-meter-ms,0ms) ease-out; }
|
|
12
|
+
.bloom-meter-fill[data-transition] { transition:width var(--bloom-meter-ms,0ms) var(--bloom-meter-easing,ease-out) var(--bloom-meter-delay,0ms); }
|
|
12
13
|
@media(prefers-reduced-motion:reduce) { .bloom-meter-fill[data-transition] { transition:none; } }
|
|
13
14
|
}`;
|
|
14
15
|
|
|
@@ -16,15 +17,17 @@ export const Meter = memo(function Meter(props: AnyMeterProps) {
|
|
|
16
17
|
useInteractiveWebCss('bloom-meter-classes', CSS);
|
|
17
18
|
const theme = useTheme();
|
|
18
19
|
const colors = resolveMeterColors(theme);
|
|
19
|
-
const { value, max = 1, height = 6, radius = height / 2, width, fill = colors.fill, track = colors.track,
|
|
20
|
+
const { value, reveal, max = 1, height = 6, radius = height / 2, width, fill = colors.fill, track = colors.track,
|
|
20
21
|
transitionMs = 0, style, testID, fillTestID = testID ? `${testID}-fill` : undefined, className, fillClassName } = props;
|
|
22
|
+
const motion = useMeterReveal(meterFraction(value, max), reveal);
|
|
21
23
|
const vars = {
|
|
22
24
|
'--bloom-meter-width': width == null ? '100%' : `${width}px`,
|
|
23
25
|
'--bloom-meter-height': `${height}px`, '--bloom-meter-radius': `${radius}px`,
|
|
24
|
-
'--bloom-meter-track': track, '--bloom-meter-fill': fill, '--bloom-meter-ms': `${transitionMs}ms`,
|
|
26
|
+
'--bloom-meter-track': track, '--bloom-meter-fill': fill, '--bloom-meter-ms': `${reveal ? motion.duration : transitionMs}ms`,
|
|
27
|
+
...(reveal ? { '--bloom-meter-delay': `${motion.delay}ms`, '--bloom-meter-easing': motion.easing } : {}),
|
|
25
28
|
} as React.CSSProperties;
|
|
26
29
|
const contents = <div className={['bloom-meter-fill', fillClassName].filter(Boolean).join(' ')}
|
|
27
|
-
data-transition={transitionMs > 0 ? '' : undefined} data-testid={fillTestID} style={{ width: `${meterFraction(value, max) * 100}%` }} />;
|
|
30
|
+
data-transition={(reveal ? motion.duration : transitionMs) > 0 ? '' : undefined} data-testid={fillTestID} style={{ width: `${reveal ? motion.fraction * 100 : meterFraction(value, max) * 100}%` }} />;
|
|
28
31
|
const root = { className: ['bloom-meter-track', className].filter(Boolean).join(' '), style: { ...vars, ...resolveNativeWebStyle(style) }, 'data-testid': testID };
|
|
29
32
|
if (props.decorative) return <div {...root} aria-hidden>{contents}</div>;
|
|
30
33
|
return <div {...root} role="progressbar" aria-label={props.accessibilityLabel} aria-valuemin={0} aria-valuemax={max}
|
package/src/stat-bar/index.ts
CHANGED
package/src/stat-bar/types.ts
CHANGED
|
@@ -68,7 +68,22 @@ export type StatBarProps = StatBarProgressProps | StatBarSplitProps;
|
|
|
68
68
|
// Meter — the bare determinate bar every progress bar in Bloom is built from
|
|
69
69
|
// ---------------------------------------------------------------------------
|
|
70
70
|
|
|
71
|
+
/** Visual-only entrance; the accessible value always remains the real measurement. */
|
|
72
|
+
export interface MeterReveal {
|
|
73
|
+
visible: boolean;
|
|
74
|
+
/** Retain the revealed state after the first visible observation. Default false. */
|
|
75
|
+
once?: boolean;
|
|
76
|
+
/** Non-negative milliseconds. Default 300. */
|
|
77
|
+
duration?: number;
|
|
78
|
+
/** Non-negative milliseconds before motion begins. Default 0. */
|
|
79
|
+
delay?: number;
|
|
80
|
+
/** CSS cubic-bezier control points. Default ease. */
|
|
81
|
+
easing?: readonly [number, number, number, number];
|
|
82
|
+
}
|
|
83
|
+
|
|
71
84
|
interface MeterGeometryProps {
|
|
85
|
+
/** Animate only the fill from empty when visible; reduced motion displays the real value immediately. */
|
|
86
|
+
reveal?: MeterReveal;
|
|
72
87
|
/** Classes on the track. Unclaimed properties retain the normal Meter defaults. */
|
|
73
88
|
className?: string;
|
|
74
89
|
/** Classes on the fill. Width continues to represent value/max. */
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { usePrefersReducedMotion } from '../hooks/use-prefers-reduced-motion';
|
|
3
|
+
import type { MeterReveal } from './types';
|
|
4
|
+
|
|
5
|
+
/** Shared reveal policy. Visibility never replaces the public data value. */
|
|
6
|
+
export function useMeterRevealPolicy(fraction: number, reveal?: MeterReveal) {
|
|
7
|
+
const reduced = usePrefersReducedMotion();
|
|
8
|
+
const [entered, setEntered] = useState(false);
|
|
9
|
+
if (reveal?.visible && !entered) setEntered(true);
|
|
10
|
+
const visible = !reveal || reduced || reveal.visible || (!!reveal.once && entered);
|
|
11
|
+
const duration = Math.max(0, Number.isFinite(reveal?.duration) ? reveal!.duration! : 300);
|
|
12
|
+
const delay = Math.max(0, Number.isFinite(reveal?.delay) ? reveal!.delay! : 0);
|
|
13
|
+
const easing = reveal?.easing ?? [.25, .1, .25, 1] as const;
|
|
14
|
+
if (easing.some((value) => !Number.isFinite(value)) || easing[0] < 0 || easing[0] > 1 || easing[2] < 0 || easing[2] > 1) {
|
|
15
|
+
throw new Error('Bloom Meter reveal easing requires finite cubic-bezier coordinates with x values in 0..1.');
|
|
16
|
+
}
|
|
17
|
+
return { fraction: visible ? fraction : 0, animate: !!reveal && visible && !reduced && duration > 0, duration, delay, easing };
|
|
18
|
+
}
|
|
19
|
+
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useLayoutEffect, useMemo, useRef } from 'react';
|
|
2
|
+
import { Animated, Easing } from 'react-native';
|
|
3
|
+
import { useMeterRevealPolicy } from './use-meter-reveal-policy';
|
|
4
|
+
import type { MeterReveal } from './types';
|
|
5
|
+
|
|
6
|
+
/** Width animation on the native JS driver; layout properties cannot use the native driver. */
|
|
7
|
+
export function useMeterReveal(fraction: number, reveal?: MeterReveal) {
|
|
8
|
+
const policy = useMeterRevealPolicy(fraction, reveal);
|
|
9
|
+
const progress = useRef(new Animated.Value(reveal && policy.animate ? 0 : policy.fraction)).current;
|
|
10
|
+
const [x1, y1, x2, y2] = policy.easing;
|
|
11
|
+
const easing = useMemo(() => Easing.bezier(x1, y1, x2, y2), [x1, y1, x2, y2]);
|
|
12
|
+
useLayoutEffect(() => {
|
|
13
|
+
progress.stopAnimation();
|
|
14
|
+
if (!policy.animate) { progress.setValue(policy.fraction); return; }
|
|
15
|
+
const animation = Animated.timing(progress, { toValue: policy.fraction, duration: policy.duration,
|
|
16
|
+
delay: policy.delay, easing, useNativeDriver: false, isInteraction: false });
|
|
17
|
+
animation.start();
|
|
18
|
+
return () => animation.stop();
|
|
19
|
+
}, [progress, policy.fraction, policy.animate, policy.duration, policy.delay, easing]);
|
|
20
|
+
return progress.interpolate({ inputRange: [0, 1], outputRange: ['0%', '100%'], extrapolate: 'clamp' });
|
|
21
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useLayoutEffect, useRef, useState } from 'react';
|
|
2
|
+
import { useMeterRevealPolicy } from './use-meter-reveal-policy';
|
|
3
|
+
import type { MeterReveal } from './types';
|
|
4
|
+
|
|
5
|
+
/** Stage an initial empty paint before the CSS transition, including visible-on-mount. */
|
|
6
|
+
export function useMeterReveal(fraction: number, reveal?: MeterReveal) {
|
|
7
|
+
const policy = useMeterRevealPolicy(fraction, reveal);
|
|
8
|
+
const [painted, setPainted] = useState(reveal && policy.animate ? 0 : policy.fraction);
|
|
9
|
+
const staged = useRef(false);
|
|
10
|
+
useLayoutEffect(() => {
|
|
11
|
+
if (!policy.animate || staged.current) { setPainted(policy.fraction); return; }
|
|
12
|
+
let next = 0;
|
|
13
|
+
const frame = requestAnimationFrame(() => {
|
|
14
|
+
next = requestAnimationFrame(() => { staged.current = true; setPainted(policy.fraction); });
|
|
15
|
+
});
|
|
16
|
+
return () => { cancelAnimationFrame(frame); if (next) cancelAnimationFrame(next); };
|
|
17
|
+
}, [policy.fraction, policy.animate]);
|
|
18
|
+
return {
|
|
19
|
+
fraction: policy.animate ? painted : policy.fraction,
|
|
20
|
+
duration: policy.animate ? policy.duration : 0,
|
|
21
|
+
delay: policy.animate ? policy.delay : 0,
|
|
22
|
+
easing: `cubic-bezier(${policy.easing.join(',')})`,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React, { useContext, useMemo } from 'react';
|
|
2
|
+
import { ViewportContext, type ViewportScope } from './context';
|
|
3
|
+
import type { ViewportProviderProps } from './types';
|
|
4
|
+
|
|
5
|
+
/** Scope native clipping geometry without inserting a layout wrapper. */
|
|
6
|
+
export function ViewportProvider({ children, root = false }: ViewportProviderProps) {
|
|
7
|
+
const inherited = useContext(ViewportContext);
|
|
8
|
+
const parent = root ? null : inherited;
|
|
9
|
+
const scope = useMemo<ViewportScope>(() => ({ parent, getNode: null, listeners: new Set() }), [parent]);
|
|
10
|
+
return <ViewportContext.Provider value={scope}>{children}</ViewportContext.Provider>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { createContext } from 'react';
|
|
2
|
+
import type { ViewportHandle } from './types';
|
|
3
|
+
|
|
4
|
+
export interface ViewportScope {
|
|
5
|
+
parent: ViewportScope | null;
|
|
6
|
+
getNode: (() => ViewportHandle | null) | null;
|
|
7
|
+
listeners: Set<() => void>;
|
|
8
|
+
}
|
|
9
|
+
export const ViewportContext = createContext<ViewportScope | null>(null);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface VisibilityRect { x: number; y: number; width: number; height: number }
|
|
2
|
+
export function validVisibilityRect(rect: VisibilityRect): boolean {
|
|
3
|
+
return Object.values(rect).every(Number.isFinite) && rect.width > 0 && rect.height > 0;
|
|
4
|
+
}
|
|
5
|
+
export function intersectionRatio(target: VisibilityRect, clips: readonly VisibilityRect[]): number {
|
|
6
|
+
if (!validVisibilityRect(target) || clips.some((clip) => !validVisibilityRect(clip))) return 0;
|
|
7
|
+
let left = target.x, top = target.y, right = left + target.width, bottom = top + target.height;
|
|
8
|
+
for (const clip of clips) {
|
|
9
|
+
left = Math.max(left, clip.x); top = Math.max(top, clip.y);
|
|
10
|
+
right = Math.min(right, clip.x + clip.width); bottom = Math.min(bottom, clip.y + clip.height);
|
|
11
|
+
}
|
|
12
|
+
if (left === target.x && top === target.y && right === target.x + target.width && bottom === target.y + target.height) return 1;
|
|
13
|
+
return Math.max(0, right - left) * Math.max(0, bottom - top) / (target.width * target.height);
|
|
14
|
+
}
|
|
15
|
+
export function visibilityThreshold(value = 0): number {
|
|
16
|
+
if (!Number.isFinite(value) || value < 0 || value > 1) throw new Error('Bloom visibility threshold must be between 0 and 1.');
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { ViewportProvider } from './ViewportProvider';
|
|
2
|
+
export { useViewportBinding } from './use-viewport-binding';
|
|
3
|
+
export { useInView } from './use-in-view';
|
|
4
|
+
export type { ViewportProviderProps, ViewportBindingOptions, InViewOptions, VisibilityHandle, ViewportHandle } from './types';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// AUTO-GENERATED by scripts/generate-platform-exports.mjs — DO NOT EDIT.
|
|
2
|
+
// Source of truth: src/viewport/index.ts.
|
|
3
|
+
// Re-run `bun run generate:exports` (or any `bun run build`) after
|
|
4
|
+
// changing that barrel or the set of web-forked subpaths.
|
|
5
|
+
|
|
6
|
+
export { ViewportProvider } from './ViewportProvider';
|
|
7
|
+
export { useViewportBinding } from './use-viewport-binding';
|
|
8
|
+
export { useInView } from './use-in-view.web';
|
|
9
|
+
export type { ViewportProviderProps, ViewportBindingOptions, InViewOptions, VisibilityHandle, ViewportHandle } from './types';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { PropsWithChildren, RefObject } from 'react';
|
|
2
|
+
import type { ScrollViewProps } from 'react-native';
|
|
3
|
+
|
|
4
|
+
/** A mounted native viewport or target supporting window-space measurement. */
|
|
5
|
+
export interface VisibilityHandle {
|
|
6
|
+
measureInWindow(callback: (x: number, y: number, width: number, height: number) => void): void;
|
|
7
|
+
}
|
|
8
|
+
/** ScrollView exposes measurement through its native scroll host. */
|
|
9
|
+
export type ViewportHandle = VisibilityHandle | { getNativeScrollRef(): VisibilityHandle | null };
|
|
10
|
+
export interface ViewportProviderProps extends PropsWithChildren {
|
|
11
|
+
/** Start a separate clipping chain, e.g. in a portaled dialog. */
|
|
12
|
+
root?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface ViewportBindingOptions extends Pick<ScrollViewProps, 'onScroll' | 'onLayout' | 'onContentSizeChange'> {
|
|
15
|
+
/** The actual scrolling/clipping host. Keep its ref on the ScrollView. */
|
|
16
|
+
viewportRef: RefObject<ViewportHandle | null>;
|
|
17
|
+
}
|
|
18
|
+
export interface InViewOptions {
|
|
19
|
+
/** Required visible area fraction, from 0 to 1. Defaults to 0. */
|
|
20
|
+
threshold?: number;
|
|
21
|
+
/** Stop observing after the threshold is first reached. Defaults to false. */
|
|
22
|
+
once?: boolean;
|
|
23
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { useCallback, useContext, useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { Dimensions } from 'react-native';
|
|
3
|
+
import { ViewportContext, type ViewportScope } from './context';
|
|
4
|
+
import { intersectionRatio, visibilityThreshold, type VisibilityRect } from './geometry';
|
|
5
|
+
import type { InViewOptions, VisibilityHandle, ViewportHandle } from './types';
|
|
6
|
+
|
|
7
|
+
/** Native visibility is measured against every bound ancestor viewport. */
|
|
8
|
+
export function useInView({ threshold: requestedThreshold, once = false }: InViewOptions = {}) {
|
|
9
|
+
const threshold = visibilityThreshold(requestedThreshold);
|
|
10
|
+
const scope = useContext(ViewportContext);
|
|
11
|
+
if (!scope) throw new Error('Bloom useInView requires a bound ViewportProvider on native.');
|
|
12
|
+
const [node, setNode] = useState<VisibilityHandle | null>(null);
|
|
13
|
+
const [inView, setInView] = useState(false);
|
|
14
|
+
const entered = useRef(false);
|
|
15
|
+
const scheduleRef = useRef<() => void>(() => {});
|
|
16
|
+
const ref = useCallback((value: unknown) => {
|
|
17
|
+
const target = value as VisibilityHandle | null;
|
|
18
|
+
if (target && typeof target.measureInWindow !== 'function') throw new Error('Bloom useInView ref must point to a native View with measureInWindow.');
|
|
19
|
+
setNode(target);
|
|
20
|
+
}, []);
|
|
21
|
+
const onLayout = useCallback(() => scheduleRef.current(), []);
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
if (!node || (once && entered.current)) return;
|
|
24
|
+
let disposed = false, frame: ReturnType<typeof requestAnimationFrame> | null = null, generation = 0;
|
|
25
|
+
const scopes: ViewportScope[] = [];
|
|
26
|
+
for (let current: ViewportScope | null = scope; current; current = current.parent) scopes.push(current);
|
|
27
|
+
const measure = (source: ViewportHandle | null, complete: (rect: VisibilityRect | null) => void) => {
|
|
28
|
+
const handle = source && 'getNativeScrollRef' in source ? source.getNativeScrollRef() : source;
|
|
29
|
+
if (!handle) { complete(null); return; }
|
|
30
|
+
handle.measureInWindow((x, y, width, height) => complete({ x, y, width, height }));
|
|
31
|
+
};
|
|
32
|
+
const read = () => {
|
|
33
|
+
frame = null;
|
|
34
|
+
const ticket = ++generation;
|
|
35
|
+
const window = Dimensions.get('window');
|
|
36
|
+
const clips: VisibilityRect[] = [{ x: 0, y: 0, width: window.width, height: window.height }];
|
|
37
|
+
let pending = scopes.length + 1, target: VisibilityRect | null = null, missing = false;
|
|
38
|
+
const finish = () => {
|
|
39
|
+
if (--pending || disposed || ticket !== generation) return;
|
|
40
|
+
const ratio = !missing && target ? intersectionRatio(target, clips) : 0;
|
|
41
|
+
const visible = ratio > 0 && ratio >= threshold;
|
|
42
|
+
if (visible) entered.current = true;
|
|
43
|
+
setInView(visible);
|
|
44
|
+
};
|
|
45
|
+
measure(node, (rect) => { target = rect; finish(); });
|
|
46
|
+
scopes.forEach((owner) => measure(owner.getNode?.() ?? null, (rect) => {
|
|
47
|
+
if (rect) clips.push(rect); else missing = true;
|
|
48
|
+
finish();
|
|
49
|
+
}));
|
|
50
|
+
};
|
|
51
|
+
const schedule = () => {
|
|
52
|
+
if (disposed || frame !== null) return;
|
|
53
|
+
// A newer event invalidates asynchronous native measurements immediately.
|
|
54
|
+
generation++;
|
|
55
|
+
frame = requestAnimationFrame(read);
|
|
56
|
+
};
|
|
57
|
+
scheduleRef.current = schedule;
|
|
58
|
+
scopes.forEach((owner) => owner.listeners.add(schedule));
|
|
59
|
+
const subscription = Dimensions.addEventListener('change', schedule);
|
|
60
|
+
schedule();
|
|
61
|
+
return () => {
|
|
62
|
+
disposed = true; generation++;
|
|
63
|
+
if (frame !== null) cancelAnimationFrame(frame);
|
|
64
|
+
scopes.forEach((owner) => owner.listeners.delete(schedule));
|
|
65
|
+
subscription.remove(); scheduleRef.current = () => {};
|
|
66
|
+
};
|
|
67
|
+
}, [node, scope, threshold, once, inView]);
|
|
68
|
+
return { inView, targetProps: { ref, onLayout, collapsable: false as const } };
|
|
69
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { visibilityThreshold } from './geometry';
|
|
3
|
+
import type { InViewOptions } from './types';
|
|
4
|
+
|
|
5
|
+
/** The browser owns ancestor clipping, scrolling and resize observation. */
|
|
6
|
+
export function useInView({ threshold: requestedThreshold, once = false }: InViewOptions = {}) {
|
|
7
|
+
const threshold = visibilityThreshold(requestedThreshold);
|
|
8
|
+
const [node, setNode] = useState<Element | null>(null);
|
|
9
|
+
const [inView, setInView] = useState(false);
|
|
10
|
+
const entered = useRef(false);
|
|
11
|
+
const ref = useCallback((value: unknown) => {
|
|
12
|
+
if (value != null && !(value instanceof Element)) throw new Error('Bloom useInView ref must point to a web host element.');
|
|
13
|
+
setNode(value as Element | null);
|
|
14
|
+
}, []);
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
if (!node || (once && entered.current)) return;
|
|
17
|
+
// Unsupported environments remain unobserved, never pretend mount is visible.
|
|
18
|
+
if (typeof IntersectionObserver === 'undefined') return;
|
|
19
|
+
const observer = new IntersectionObserver((entries) => {
|
|
20
|
+
for (const entry of entries) {
|
|
21
|
+
if (entry.target !== node || (once && entered.current)) continue;
|
|
22
|
+
const visible = entry.boundingClientRect.width > 0 && entry.boundingClientRect.height > 0 && entry.isIntersecting && entry.intersectionRatio > 0 && entry.intersectionRatio >= threshold;
|
|
23
|
+
if (visible) entered.current = true;
|
|
24
|
+
setInView(visible);
|
|
25
|
+
if (visible && once) observer.disconnect();
|
|
26
|
+
}
|
|
27
|
+
}, { threshold });
|
|
28
|
+
observer.observe(node);
|
|
29
|
+
return () => observer.disconnect();
|
|
30
|
+
}, [node, threshold, once]);
|
|
31
|
+
const onLayout = useCallback(() => {}, []);
|
|
32
|
+
return { inView, targetProps: { ref, onLayout } };
|
|
33
|
+
}
|