@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.
@@ -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);
@@ -1,3 +1,4 @@
1
- export { durations, easeSpring, easeSpringTight, fade, springy, travel } from "./motion.js";
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,UAAU,EAAE,eAAe,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACzF,OAAO,EAAE,aAAa,EAAE,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC"}
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"}
@@ -1,2 +1,3 @@
1
- export { durations, easeSpring, easeSpringTight, fade, springy, travel } from "./motion.js";
1
+ export { durations, fade, springy, travel } from "./motion.js";
2
+ export { easeSpring, easeSpringTight, easingFromSamples } from "./easing.js";
2
3
  export { usePressScale } from "./usePressScale.js";
@@ -1,8 +1,6 @@
1
- import { type EasingFunction, type WithTimingConfig } from "react-native-reanimated";
2
- /** Overshoots ~12%. For things that scale in place. */
3
- export declare const easeSpring: EasingFunction;
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,cAAc,EAAE,KAAK,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAoBzG,uDAAuD;AACvD,eAAO,MAAM,UAAU,gBAAmC,CAAC;AAE3D,6EAA6E;AAC7E,eAAO,MAAM,eAAe,gBAAwC,CAAC;AAErE,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"}
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"}
@@ -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, sampleCurve, springSamples, springTightSamples } from "@gryt/theme";
15
- /**
16
- * Turn a sample list into an easing.
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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gryt/ui-native",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "Gryt's design system on React Native. Same tokens as @gryt/ui, a different renderer.",