@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.
- package/lib/commonjs/Input/Input.js +14 -0
- package/lib/commonjs/Input/Input.js.map +1 -1
- package/lib/commonjs/Input/Input.native.js +13 -1
- package/lib/commonjs/Input/Input.native.js.map +1 -1
- package/lib/commonjs/Input/shared.js +42 -1
- package/lib/commonjs/Input/shared.js.map +1 -1
- package/lib/commonjs/NativeSelect/NativeSelect.js +11 -0
- package/lib/commonjs/NativeSelect/NativeSelect.js.map +1 -1
- package/lib/commonjs/PinInput/PinInput.js +45 -6
- package/lib/commonjs/PinInput/PinInput.js.map +1 -1
- package/lib/commonjs/Transition/Transition.native.js +33 -16
- package/lib/commonjs/Transition/Transition.native.js.map +1 -1
- package/lib/module/Input/Input.js +15 -1
- package/lib/module/Input/Input.js.map +1 -1
- package/lib/module/Input/Input.native.js +14 -2
- package/lib/module/Input/Input.native.js.map +1 -1
- package/lib/module/Input/shared.js +40 -0
- package/lib/module/Input/shared.js.map +1 -1
- package/lib/module/NativeSelect/NativeSelect.js +12 -1
- package/lib/module/NativeSelect/NativeSelect.js.map +1 -1
- package/lib/module/PinInput/PinInput.js +46 -7
- package/lib/module/PinInput/PinInput.js.map +1 -1
- package/lib/module/Transition/Transition.native.js +33 -16
- package/lib/module/Transition/Transition.native.js.map +1 -1
- package/lib/typescript/Input/Input.d.ts.map +1 -1
- package/lib/typescript/Input/Input.native.d.ts.map +1 -1
- package/lib/typescript/Input/shared.d.ts +15 -0
- package/lib/typescript/Input/shared.d.ts.map +1 -1
- package/lib/typescript/NativeSelect/NativeSelect.d.ts.map +1 -1
- package/lib/typescript/PinInput/PinInput.d.ts.map +1 -1
- package/lib/typescript/Transition/Transition.native.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/Input/Input.native.tsx +13 -0
- package/src/Input/Input.tsx +15 -0
- package/src/Input/shared.tsx +49 -0
- package/src/NativeSelect/NativeSelect.tsx +12 -0
- package/src/PinInput/PinInput.tsx +49 -6
- 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
|
-
|
|
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
|
}
|