@knitui/components 0.12.1 → 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 (38) hide show
  1. package/lib/commonjs/Input/Input.js +14 -0
  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/Transition/Transition.native.js +33 -16
  12. package/lib/commonjs/Transition/Transition.native.js.map +1 -1
  13. package/lib/module/Input/Input.js +15 -1
  14. package/lib/module/Input/Input.js.map +1 -1
  15. package/lib/module/Input/Input.native.js +14 -2
  16. package/lib/module/Input/Input.native.js.map +1 -1
  17. package/lib/module/Input/shared.js +40 -0
  18. package/lib/module/Input/shared.js.map +1 -1
  19. package/lib/module/NativeSelect/NativeSelect.js +12 -1
  20. package/lib/module/NativeSelect/NativeSelect.js.map +1 -1
  21. package/lib/module/PinInput/PinInput.js +46 -7
  22. package/lib/module/PinInput/PinInput.js.map +1 -1
  23. package/lib/module/Transition/Transition.native.js +33 -16
  24. package/lib/module/Transition/Transition.native.js.map +1 -1
  25. package/lib/typescript/Input/Input.d.ts.map +1 -1
  26. package/lib/typescript/Input/Input.native.d.ts.map +1 -1
  27. package/lib/typescript/Input/shared.d.ts +15 -0
  28. package/lib/typescript/Input/shared.d.ts.map +1 -1
  29. package/lib/typescript/NativeSelect/NativeSelect.d.ts.map +1 -1
  30. package/lib/typescript/PinInput/PinInput.d.ts.map +1 -1
  31. package/lib/typescript/Transition/Transition.native.d.ts.map +1 -1
  32. package/package.json +4 -4
  33. package/src/Input/Input.native.tsx +13 -0
  34. package/src/Input/Input.tsx +15 -0
  35. package/src/Input/shared.tsx +49 -0
  36. package/src/NativeSelect/NativeSelect.tsx +12 -0
  37. package/src/PinInput/PinInput.tsx +49 -6
  38. package/src/Transition/Transition.native.tsx +36 -20
@@ -38,6 +38,37 @@ export interface TransitionProps {
38
38
  exitDelay?: number;
39
39
  }
40
40
 
41
+ /** The style keys every native transition animates; the hidden frame names them all. */
42
+ const ALL_ANIMATED_KEYS = ["transform", "opacity"];
43
+
44
+ /**
45
+ * Hand `child` the Tamagui `transition` prop (and what it animates).
46
+ *
47
+ * EVERY element this component returns goes through here, the hidden
48
+ * `keepMounted` frame and the reduced-motion frames included, with `null` when
49
+ * there is nothing to animate. Tamagui decides whether a view is animated by the
50
+ * PRESENCE of the `transition` key, and runs extra hooks (`usePresence`, the
51
+ * driver's) for an animated one. A child that mounted without the key and got it
52
+ * a render later — `keepMounted` with `mounted={false}`, then `mounted` — changed
53
+ * its hook order: React threw "Rendered more hooks than during the previous
54
+ * render" on native. With the key always there the hooks never change.
55
+ */
56
+ const withTransition = (
57
+ child: React.ReactElement,
58
+ value: unknown,
59
+ keys: string[] = ALL_ANIMATED_KEYS,
60
+ ): React.ReactElement => {
61
+ if (!React.isValidElement(child) || child.type === React.Fragment) return child;
62
+ const childProps = child.props as {
63
+ transition?: unknown;
64
+ animateOnly?: string[];
65
+ };
66
+ return React.cloneElement(child, {
67
+ transition: "transition" in childProps ? childProps.transition : value,
68
+ animateOnly: childProps.animateOnly ?? keys,
69
+ } as Partial<typeof childProps>);
70
+ };
71
+
41
72
  /**
42
73
  * Native counterpart to the web Transition. It keeps the render-prop contract,
43
74
  * but injects Tamagui's `transition` prop into the child so RN animates the
@@ -72,14 +103,15 @@ export function Transition({
72
103
  });
73
104
 
74
105
  if (transitionDuration === 0) {
75
- if (mounted) return children({});
76
- return keepMounted ? children({ display: "none" }) : null;
106
+ if (mounted) return withTransition(children({}), null);
107
+ return keepMounted ? withTransition(children({ display: "none" }), null) : null;
77
108
  }
78
109
 
110
+ const timed = [resolveTransition(transitionTimingFunction), { duration: transitionDuration }];
79
111
  const isExited = transitionStatus === "exited";
80
112
 
81
113
  if (isExited && !mounted) {
82
- return keepMounted ? children({ display: "none" }) : null;
114
+ return keepMounted ? withTransition(children({ display: "none" }), timed) : null;
83
115
  }
84
116
 
85
117
  const styles = getTransitionStyles({
@@ -88,23 +120,7 @@ export function Transition({
88
120
  state: transitionStatus,
89
121
  timingFunction: transitionTimingFunction,
90
122
  });
91
- const child = children(styles);
92
123
  const keys = animatedKeys(styles);
93
124
 
94
- if (!React.isValidElement(child) || child.type === React.Fragment || keys.length === 0) {
95
- return child;
96
- }
97
-
98
- const childProps = child.props as {
99
- transition?: unknown;
100
- animateOnly?: string[];
101
- };
102
-
103
- return React.cloneElement(child, {
104
- transition: childProps.transition ?? [
105
- resolveTransition(transitionTimingFunction),
106
- { duration: transitionDuration },
107
- ],
108
- animateOnly: childProps.animateOnly ?? keys,
109
- } as Partial<typeof childProps>);
125
+ return withTransition(children(styles), timed, keys.length > 0 ? keys : ALL_ANIMATED_KEYS);
110
126
  }