@gryt/ui-native 0.3.0 → 0.3.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/dist/motion/easing.d.ts +28 -0
- package/dist/motion/easing.d.ts.map +1 -0
- package/dist/motion/easing.js +51 -0
- package/dist/motion/index.d.ts +2 -1
- package/dist/motion/index.d.ts.map +1 -1
- package/dist/motion/index.js +2 -1
- package/dist/motion/motion.d.ts +3 -5
- package/dist/motion/motion.d.ts.map +1 -1
- package/dist/motion/motion.js +3 -20
- package/package.json +1 -1
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** Same shape as Reanimated's `EasingFunction`, without importing it. */
|
|
2
|
+
export type Easing = (t: number) => number;
|
|
3
|
+
/**
|
|
4
|
+
* Turn a sample list into an easing.
|
|
5
|
+
*
|
|
6
|
+
* The body is a worklet so it runs on the UI thread — an easing evaluated on
|
|
7
|
+
* the JS thread would drop frames under exactly the load this exists to
|
|
8
|
+
* survive. `points` is a plain array, which worklets capture by value.
|
|
9
|
+
*
|
|
10
|
+
* The interpolation is written out rather than calling `sampleCurve` from
|
|
11
|
+
* @gryt/theme, and that is not a style choice. A worklet cannot synchronously
|
|
12
|
+
* call a JS-thread function: doing so throws
|
|
13
|
+
*
|
|
14
|
+
* [Worklets] Tried to synchronously call a Remote Function
|
|
15
|
+
*
|
|
16
|
+
* on the first frame of every animation. That shipped in 0.3.0, because the
|
|
17
|
+
* only thing exercising the UI thread in testing used React Native's own
|
|
18
|
+
* easing rather than this one.
|
|
19
|
+
*
|
|
20
|
+
* easing.test.ts asserts this stays identical to `sampleCurve`, so the
|
|
21
|
+
* duplication cannot drift from the definition the web renders from.
|
|
22
|
+
*/
|
|
23
|
+
export declare function easingFromSamples(samples: readonly number[]): Easing;
|
|
24
|
+
/** Overshoots ~12%. For things that scale in place. */
|
|
25
|
+
export declare const easeSpring: Easing;
|
|
26
|
+
/** Critically damped, no overshoot. For things that travel inside bounds. */
|
|
27
|
+
export declare const easeSpringTight: Easing;
|
|
28
|
+
//# sourceMappingURL=easing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"easing.d.ts","sourceRoot":"","sources":["../../src/motion/easing.ts"],"names":[],"mappings":"AASA,yEAAyE;AACzE,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;AAE3C;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAkBpE;AAED,uDAAuD;AACvD,eAAO,MAAM,UAAU,QAAmC,CAAC;AAE3D,6EAA6E;AAC7E,eAAO,MAAM,eAAe,QAAwC,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/* The sampled-spring easings, with no Reanimated import.
|
|
2
|
+
*
|
|
3
|
+
* Split from motion.ts for the same reason sliderValue.ts is split from
|
|
4
|
+
* Slider.tsx: this is arithmetic, it is where a bug hid, and importing
|
|
5
|
+
* react-native-reanimated drags in react-native-worklets, which cannot resolve
|
|
6
|
+
* under vitest. A file that cannot be imported cannot be tested.
|
|
7
|
+
*/
|
|
8
|
+
import { springSamples, springTightSamples } from "@gryt/theme";
|
|
9
|
+
/**
|
|
10
|
+
* Turn a sample list into an easing.
|
|
11
|
+
*
|
|
12
|
+
* The body is a worklet so it runs on the UI thread — an easing evaluated on
|
|
13
|
+
* the JS thread would drop frames under exactly the load this exists to
|
|
14
|
+
* survive. `points` is a plain array, which worklets capture by value.
|
|
15
|
+
*
|
|
16
|
+
* The interpolation is written out rather than calling `sampleCurve` from
|
|
17
|
+
* @gryt/theme, and that is not a style choice. A worklet cannot synchronously
|
|
18
|
+
* call a JS-thread function: doing so throws
|
|
19
|
+
*
|
|
20
|
+
* [Worklets] Tried to synchronously call a Remote Function
|
|
21
|
+
*
|
|
22
|
+
* on the first frame of every animation. That shipped in 0.3.0, because the
|
|
23
|
+
* only thing exercising the UI thread in testing used React Native's own
|
|
24
|
+
* easing rather than this one.
|
|
25
|
+
*
|
|
26
|
+
* easing.test.ts asserts this stays identical to `sampleCurve`, so the
|
|
27
|
+
* duplication cannot drift from the definition the web renders from.
|
|
28
|
+
*/
|
|
29
|
+
export function easingFromSamples(samples) {
|
|
30
|
+
const points = [...samples];
|
|
31
|
+
return (t) => {
|
|
32
|
+
"worklet";
|
|
33
|
+
const count = points.length;
|
|
34
|
+
if (count === 0)
|
|
35
|
+
return t;
|
|
36
|
+
if (t <= 0)
|
|
37
|
+
return points[0];
|
|
38
|
+
if (t >= 1)
|
|
39
|
+
return points[count - 1];
|
|
40
|
+
const span = (count - 1) * t;
|
|
41
|
+
const index = Math.floor(span);
|
|
42
|
+
const rest = span - index;
|
|
43
|
+
const from = points[index];
|
|
44
|
+
const to = points[index + 1] ?? from;
|
|
45
|
+
return from + (to - from) * rest;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/** Overshoots ~12%. For things that scale in place. */
|
|
49
|
+
export const easeSpring = easingFromSamples(springSamples);
|
|
50
|
+
/** Critically damped, no overshoot. For things that travel inside bounds. */
|
|
51
|
+
export const easeSpringTight = easingFromSamples(springTightSamples);
|
package/dist/motion/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export { durations,
|
|
1
|
+
export { durations, fade, springy, travel } from "./motion.js";
|
|
2
|
+
export { easeSpring, easeSpringTight, easingFromSamples, type Easing } from "./easing.js";
|
|
2
3
|
export { usePressScale, type PressScale } from "./usePressScale.js";
|
|
3
4
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/motion/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/motion/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,iBAAiB,EAAE,KAAK,MAAM,EAAE,MAAM,UAAU,CAAC;AACvF,OAAO,EAAE,aAAa,EAAE,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC"}
|
package/dist/motion/index.js
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export { durations,
|
|
1
|
+
export { durations, fade, springy, travel } from "./motion.js";
|
|
2
|
+
export { easeSpring, easeSpringTight, easingFromSamples } from "./easing.js";
|
|
2
3
|
export { usePressScale } from "./usePressScale.js";
|
package/dist/motion/motion.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
/** Critically damped, no overshoot. For things that travel inside bounds. */
|
|
5
|
-
export declare const easeSpringTight: EasingFunction;
|
|
1
|
+
import { type WithTimingConfig } from "react-native-reanimated";
|
|
2
|
+
import { easeSpring, easeSpringTight } from "./easing.js";
|
|
3
|
+
export { easeSpring, easeSpringTight };
|
|
6
4
|
export declare const durations: {
|
|
7
5
|
readonly spring: 500;
|
|
8
6
|
readonly springSoft: 700;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"motion.d.ts","sourceRoot":"","sources":["../../src/motion/motion.ts"],"names":[],"mappings":"AAYA,OAAO,EAAsB,KAAK,
|
|
1
|
+
{"version":3,"file":"motion.d.ts","sourceRoot":"","sources":["../../src/motion/motion.ts"],"names":[],"mappings":"AAYA,OAAO,EAAsB,KAAK,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAEpF,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAEvD,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,CAAC;AAEvC,eAAO,MAAM,SAAS;;;;CAAgB,CAAC;AAEvC,yEAAyE;AACzE,wBAAgB,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,gBAAgB,UAG5D;AAED,sFAAsF;AACtF,wBAAgB,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,gBAAgB,UAG3D;AAED,gEAAgE;AAChE,wBAAgB,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,gBAAgB,UAGzD"}
|
package/dist/motion/motion.js
CHANGED
|
@@ -11,26 +11,9 @@
|
|
|
11
11
|
* duration is both simpler and actually identical.
|
|
12
12
|
*/
|
|
13
13
|
import { Easing, withTiming } from "react-native-reanimated";
|
|
14
|
-
import { grytDurations
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
*
|
|
18
|
-
* The body is a worklet so it can run on the UI thread — an easing evaluated
|
|
19
|
-
* on the JS thread would drop frames under exactly the load this system exists
|
|
20
|
-
* to survive. `samples` is captured by value, which worklets allow for plain
|
|
21
|
-
* arrays.
|
|
22
|
-
*/
|
|
23
|
-
function easingFromSamples(samples) {
|
|
24
|
-
const points = [...samples];
|
|
25
|
-
return (t) => {
|
|
26
|
-
"worklet";
|
|
27
|
-
return sampleCurve(points, t);
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
/** Overshoots ~12%. For things that scale in place. */
|
|
31
|
-
export const easeSpring = easingFromSamples(springSamples);
|
|
32
|
-
/** Critically damped, no overshoot. For things that travel inside bounds. */
|
|
33
|
-
export const easeSpringTight = easingFromSamples(springTightSamples);
|
|
14
|
+
import { grytDurations } from "@gryt/theme";
|
|
15
|
+
import { easeSpring, easeSpringTight } from "./easing.js";
|
|
16
|
+
export { easeSpring, easeSpringTight };
|
|
34
17
|
export const durations = grytDurations;
|
|
35
18
|
/** `withTiming` on the overshooting spring, at the standard duration. */
|
|
36
19
|
export function springy(to, config) {
|