@knitui/components 0.11.0 → 0.12.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/lib/commonjs/Input/Input.js +18 -1
  2. package/lib/commonjs/Input/Input.js.map +1 -1
  3. package/lib/commonjs/Input/Input.native.js +13 -1
  4. package/lib/commonjs/Input/Input.native.js.map +1 -1
  5. package/lib/commonjs/Input/shared.js +42 -1
  6. package/lib/commonjs/Input/shared.js.map +1 -1
  7. package/lib/commonjs/NativeSelect/NativeSelect.js +11 -0
  8. package/lib/commonjs/NativeSelect/NativeSelect.js.map +1 -1
  9. package/lib/commonjs/PinInput/PinInput.js +45 -6
  10. package/lib/commonjs/PinInput/PinInput.js.map +1 -1
  11. package/lib/commonjs/Skeleton/Skeleton.js +72 -3
  12. package/lib/commonjs/Skeleton/Skeleton.js.map +1 -1
  13. package/lib/commonjs/Transition/Transition.native.js +33 -16
  14. package/lib/commonjs/Transition/Transition.native.js.map +1 -1
  15. package/lib/commonjs/index.js +6 -0
  16. package/lib/commonjs/index.js.map +1 -1
  17. package/lib/commonjs/internal/use-reveal-pulse.js +77 -0
  18. package/lib/commonjs/internal/use-reveal-pulse.js.map +1 -0
  19. package/lib/commonjs/internal/use-reveal-pulse.native.js +69 -0
  20. package/lib/commonjs/internal/use-reveal-pulse.native.js.map +1 -0
  21. package/lib/commonjs/internal/use-reveal-pulse.shared.js +52 -0
  22. package/lib/commonjs/internal/use-reveal-pulse.shared.js.map +1 -0
  23. package/lib/module/Input/Input.js +19 -2
  24. package/lib/module/Input/Input.js.map +1 -1
  25. package/lib/module/Input/Input.native.js +14 -2
  26. package/lib/module/Input/Input.native.js.map +1 -1
  27. package/lib/module/Input/shared.js +40 -0
  28. package/lib/module/Input/shared.js.map +1 -1
  29. package/lib/module/NativeSelect/NativeSelect.js +12 -1
  30. package/lib/module/NativeSelect/NativeSelect.js.map +1 -1
  31. package/lib/module/PinInput/PinInput.js +46 -7
  32. package/lib/module/PinInput/PinInput.js.map +1 -1
  33. package/lib/module/Skeleton/Skeleton.js +71 -2
  34. package/lib/module/Skeleton/Skeleton.js.map +1 -1
  35. package/lib/module/Transition/Transition.native.js +33 -16
  36. package/lib/module/Transition/Transition.native.js.map +1 -1
  37. package/lib/module/index.js +1 -1
  38. package/lib/module/index.js.map +1 -1
  39. package/lib/module/internal/use-reveal-pulse.js +71 -0
  40. package/lib/module/internal/use-reveal-pulse.js.map +1 -0
  41. package/lib/module/internal/use-reveal-pulse.native.js +63 -0
  42. package/lib/module/internal/use-reveal-pulse.native.js.map +1 -0
  43. package/lib/module/internal/use-reveal-pulse.shared.js +48 -0
  44. package/lib/module/internal/use-reveal-pulse.shared.js.map +1 -0
  45. package/lib/typescript/Input/Input.d.ts.map +1 -1
  46. package/lib/typescript/Input/Input.native.d.ts.map +1 -1
  47. package/lib/typescript/Input/shared.d.ts +15 -0
  48. package/lib/typescript/Input/shared.d.ts.map +1 -1
  49. package/lib/typescript/NativeSelect/NativeSelect.d.ts.map +1 -1
  50. package/lib/typescript/PinInput/PinInput.d.ts.map +1 -1
  51. package/lib/typescript/Skeleton/Skeleton.d.ts +29 -0
  52. package/lib/typescript/Skeleton/Skeleton.d.ts.map +1 -1
  53. package/lib/typescript/Transition/Transition.native.d.ts.map +1 -1
  54. package/lib/typescript/index.d.ts +1 -1
  55. package/lib/typescript/index.d.ts.map +1 -1
  56. package/lib/typescript/internal/use-reveal-pulse.d.ts +31 -0
  57. package/lib/typescript/internal/use-reveal-pulse.d.ts.map +1 -0
  58. package/lib/typescript/internal/use-reveal-pulse.native.d.ts +22 -0
  59. package/lib/typescript/internal/use-reveal-pulse.native.d.ts.map +1 -0
  60. package/lib/typescript/internal/use-reveal-pulse.shared.d.ts +31 -0
  61. package/lib/typescript/internal/use-reveal-pulse.shared.d.ts.map +1 -0
  62. package/package.json +4 -4
  63. package/src/Input/Input.native.tsx +13 -0
  64. package/src/Input/Input.tsx +23 -1
  65. package/src/Input/shared.tsx +49 -0
  66. package/src/NativeSelect/NativeSelect.tsx +12 -0
  67. package/src/PinInput/PinInput.tsx +49 -6
  68. package/src/Skeleton/Skeleton.tsx +73 -2
  69. package/src/Transition/Transition.native.tsx +36 -20
  70. package/src/index.ts +1 -1
  71. package/src/internal/use-reveal-pulse.native.tsx +72 -0
  72. package/src/internal/use-reveal-pulse.shared.ts +57 -0
  73. package/src/internal/use-reveal-pulse.tsx +79 -0
@@ -0,0 +1,72 @@
1
+ import * as React from "react";
2
+ import Animated, {
3
+ Easing,
4
+ useAnimatedStyle,
5
+ useSharedValue,
6
+ withDelay,
7
+ withRepeat,
8
+ withSequence,
9
+ withTiming,
10
+ } from "react-native-reanimated";
11
+
12
+ import { useReducedMotion } from "@knitui/hooks";
13
+
14
+ import { resolveRevealPulse, type RevealPulseMotion } from "./use-reveal-pulse.shared";
15
+
16
+ export type { RevealPulseMotion } from "./use-reveal-pulse.shared";
17
+
18
+ /** The reanimated animated style returned by {@link useRevealPulse}. */
19
+ export interface RevealPulseStyle {
20
+ style: ReturnType<typeof useAnimatedStyle>;
21
+ }
22
+
23
+ /**
24
+ * Promote a frame so a {@link useRevealPulse} style can ride on it (native): an
25
+ * animated style may only land on an `Animated.*` host — same move as
26
+ * `asLoopHost`. Web sibling is the identity.
27
+ */
28
+ export const asRevealHost = <C extends React.ComponentType<any>>(Component: C): C =>
29
+ Animated.createAnimatedComponent(Component as React.ComponentClass<unknown>) as unknown as C;
30
+
31
+ const PULSE_EASING = Easing.bezier(0.42, 0, 0.58, 1);
32
+ const FADE_EASING = Easing.out(Easing.quad);
33
+
34
+ /**
35
+ * Reveal-then-pulse (native): ONE shared value on the UI thread runs the whole
36
+ * timeline — `withDelay(hold, withSequence(fade, withRepeat(pulse)))` — so a
37
+ * silhouette of any number of blocks costs one animated node and no JS frames.
38
+ * See `use-reveal-pulse.shared.ts` for the timeline.
39
+ */
40
+ export function useRevealPulse(motion?: RevealPulseMotion): RevealPulseStyle {
41
+ const reduced = useReducedMotion();
42
+ const { delayMs, fadeMs, durationMs, minOpacity, pulse } = resolveRevealPulse(motion);
43
+ const pulsing = pulse && !reduced && durationMs > 0 && minOpacity < 1;
44
+ const opacity = useSharedValue(0);
45
+
46
+ React.useEffect(() => {
47
+ const fadeIn = withTiming(1, { duration: reduced ? 0 : fadeMs, easing: FADE_EASING });
48
+ const timeline = pulsing
49
+ ? withSequence(
50
+ fadeIn,
51
+ withRepeat(
52
+ withTiming(minOpacity, { duration: durationMs, easing: PULSE_EASING }),
53
+ -1,
54
+ true,
55
+ ),
56
+ )
57
+ : fadeIn;
58
+ opacity.value = 0;
59
+ opacity.value = delayMs > 0 ? withDelay(delayMs, timeline) : timeline;
60
+ return () => {
61
+ // Assigning cancels the running animation; a re-run starts clean.
62
+ opacity.value = 0;
63
+ };
64
+ }, [opacity, reduced, pulsing, delayMs, fadeMs, durationMs, minOpacity]);
65
+
66
+ const style = useAnimatedStyle(() => {
67
+ "worklet";
68
+ return { opacity: opacity.value };
69
+ });
70
+
71
+ return { style };
72
+ }
@@ -0,0 +1,57 @@
1
+ import { DURATIONS } from "@knitui/core";
2
+
3
+ /**
4
+ * Shared types + defaults for the reveal-then-pulse primitive
5
+ * (`use-reveal-pulse` web / `.native`) behind `SkeletonGroup`. One element, one
6
+ * animation timeline:
7
+ *
8
+ * 1. HOLD at opacity 0 for `delayMs` — content that arrives inside it swaps in
9
+ * without a placeholder ever painting (no grey strobe on a fast load);
10
+ * 2. FADE to 1 over `fadeMs`;
11
+ * 3. PULSE between 1 and `minOpacity` forever, `durationMs` per half-cycle.
12
+ *
13
+ * Reduced motion keeps the hold (it is about flashing, not motion) and snaps in
14
+ * with no fade and no pulse. Both platform files read these defaults so the
15
+ * web and native silhouettes keep the same clock.
16
+ */
17
+ export interface RevealPulseMotion {
18
+ /** Hold invisible before revealing, ms. @default 150 */
19
+ delayMs?: number;
20
+ /** Fade-in once the hold ends, ms. @default 200 (`DURATIONS.base`) */
21
+ fadeMs?: number;
22
+ /** One pulse half-cycle, ms. @default 1200 (2 × `DURATIONS.ambient`) */
23
+ durationMs?: number;
24
+ /** Dimmest opacity at the pulse's trough. @default 0.5 */
25
+ minOpacity?: number;
26
+ /** Pulse after revealing. `false` → hold, fade in, stay solid. @default true */
27
+ pulse?: boolean;
28
+ }
29
+
30
+ export type ResolvedRevealPulse = Required<RevealPulseMotion>;
31
+
32
+ export const REVEAL_PULSE_DEFAULTS: ResolvedRevealPulse = {
33
+ delayMs: DURATIONS.fast,
34
+ fadeMs: DURATIONS.base,
35
+ durationMs: DURATIONS.ambient * 2,
36
+ minOpacity: 0.5,
37
+ pulse: true,
38
+ };
39
+
40
+ /** Apply the documented defaults; negative times clamp to 0. */
41
+ export function resolveRevealPulse(motion: RevealPulseMotion = {}): ResolvedRevealPulse {
42
+ const m = { ...REVEAL_PULSE_DEFAULTS, ...stripUndefined(motion) };
43
+ return {
44
+ ...m,
45
+ delayMs: Math.max(0, m.delayMs),
46
+ fadeMs: Math.max(0, m.fadeMs),
47
+ durationMs: Math.max(0, m.durationMs),
48
+ };
49
+ }
50
+
51
+ function stripUndefined<T extends object>(o: T): Partial<T> {
52
+ const out: Partial<T> = {};
53
+ for (const k of Object.keys(o) as Array<keyof T>) {
54
+ if (o[k] !== undefined) out[k] = o[k];
55
+ }
56
+ return out;
57
+ }
@@ -0,0 +1,79 @@
1
+ import * as React from "react";
2
+
3
+ import { useReducedMotion } from "@knitui/hooks";
4
+
5
+ import { injectKeyframes } from "./keyframes-web";
6
+ import { resolveRevealPulse, type RevealPulseMotion } from "./use-reveal-pulse.shared";
7
+
8
+ export type { RevealPulseMotion } from "./use-reveal-pulse.shared";
9
+
10
+ /**
11
+ * Inline `animation*` longhands for the reveal-then-pulse timeline (web). Spread
12
+ * through the host `style` prop for the same reason as `useLoopingAnimation`'s:
13
+ * the `animation*` keys are not modeled Tamagui style props, and Tamagui forwards
14
+ * an inline `style` object straight to the DOM node.
15
+ */
16
+ export interface RevealPulseStyle {
17
+ style: {
18
+ animationName: string;
19
+ animationDuration: string;
20
+ animationTimingFunction: string;
21
+ animationDelay: string;
22
+ animationIterationCount: string;
23
+ animationDirection: string;
24
+ animationFillMode: string;
25
+ };
26
+ }
27
+
28
+ /** The element a reveal pulse mounts on — identity on web (CSS needs no host). */
29
+ export const asRevealHost = <C extends React.ComponentType<any>>(Component: C): C => Component;
30
+
31
+ const FADE = "knitui-reveal-in";
32
+
33
+ /**
34
+ * Reveal-then-pulse (web): ONE element runs two CSS animations — a one-shot fade
35
+ * (`fill-mode: both`, so it holds at 0 through its delay and at 1 after) and the
36
+ * infinite pulse, listed LAST so it wins the `opacity` cascade once it starts
37
+ * (no fill on the pulse, so it doesn't apply until its own delay elapses). All
38
+ * on the compositor: no timers, no re-render. See `use-reveal-pulse.shared.ts`.
39
+ */
40
+ export function useRevealPulse(motion?: RevealPulseMotion): RevealPulseStyle {
41
+ const reduced = useReducedMotion();
42
+ const { delayMs, fadeMs, durationMs, minOpacity, pulse } = resolveRevealPulse(motion);
43
+ const pulsing = pulse && !reduced && durationMs > 0 && minOpacity < 1;
44
+ const pulseName = `knitui-reveal-pulse-${String(minOpacity).replace(".", "_")}`;
45
+
46
+ // Inject during render (idempotent) so the rules exist before first paint.
47
+ injectKeyframes(FADE, "from{opacity:0}to{opacity:1}");
48
+ if (pulsing) injectKeyframes(pulseName, `from{opacity:1}to{opacity:${minOpacity}}`);
49
+
50
+ return React.useMemo<RevealPulseStyle>(() => {
51
+ // Reduced motion: keep the hold, snap in (a 1ms fade, not 0 — a zero-length
52
+ // animation with a delay is dropped by some engines before it applies).
53
+ const fade = reduced ? 1 : Math.max(1, fadeMs);
54
+ if (!pulsing) {
55
+ return {
56
+ style: {
57
+ animationName: FADE,
58
+ animationDuration: `${fade}ms`,
59
+ animationTimingFunction: "ease-out",
60
+ animationDelay: `${delayMs}ms`,
61
+ animationIterationCount: "1",
62
+ animationDirection: "normal",
63
+ animationFillMode: "both",
64
+ },
65
+ };
66
+ }
67
+ return {
68
+ style: {
69
+ animationName: `${FADE}, ${pulseName}`,
70
+ animationDuration: `${fade}ms, ${durationMs}ms`,
71
+ animationTimingFunction: "ease-out, ease-in-out",
72
+ animationDelay: `${delayMs}ms, ${delayMs + fade}ms`,
73
+ animationIterationCount: "1, infinite",
74
+ animationDirection: "normal, alternate",
75
+ animationFillMode: "both, none",
76
+ },
77
+ };
78
+ }, [reduced, pulsing, pulseName, delayMs, fadeMs, durationMs]);
79
+ }