@onlynative/inertia 0.0.1-alpha.0

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 (63) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/LICENSE +21 -0
  3. package/README.md +90 -0
  4. package/dist/index.d.mts +185 -0
  5. package/dist/index.d.ts +185 -0
  6. package/dist/index.js +817 -0
  7. package/dist/index.js.map +1 -0
  8. package/dist/index.mjs +796 -0
  9. package/dist/index.mjs.map +1 -0
  10. package/dist/motion/Image.d.mts +12 -0
  11. package/dist/motion/Image.d.ts +12 -0
  12. package/dist/motion/Image.js +656 -0
  13. package/dist/motion/Image.js.map +1 -0
  14. package/dist/motion/Image.mjs +650 -0
  15. package/dist/motion/Image.mjs.map +1 -0
  16. package/dist/motion/Pressable.d.mts +15 -0
  17. package/dist/motion/Pressable.d.ts +15 -0
  18. package/dist/motion/Pressable.js +656 -0
  19. package/dist/motion/Pressable.js.map +1 -0
  20. package/dist/motion/Pressable.mjs +650 -0
  21. package/dist/motion/Pressable.mjs.map +1 -0
  22. package/dist/motion/ScrollView.d.mts +12 -0
  23. package/dist/motion/ScrollView.d.ts +12 -0
  24. package/dist/motion/ScrollView.js +656 -0
  25. package/dist/motion/ScrollView.js.map +1 -0
  26. package/dist/motion/ScrollView.mjs +650 -0
  27. package/dist/motion/ScrollView.mjs.map +1 -0
  28. package/dist/motion/Text.d.mts +11 -0
  29. package/dist/motion/Text.d.ts +11 -0
  30. package/dist/motion/Text.js +656 -0
  31. package/dist/motion/Text.js.map +1 -0
  32. package/dist/motion/Text.mjs +650 -0
  33. package/dist/motion/Text.mjs.map +1 -0
  34. package/dist/motion/View.d.mts +11 -0
  35. package/dist/motion/View.d.ts +11 -0
  36. package/dist/motion/View.js +656 -0
  37. package/dist/motion/View.js.map +1 -0
  38. package/dist/motion/View.mjs +650 -0
  39. package/dist/motion/View.mjs.map +1 -0
  40. package/dist/types-CmbXx-G3.d.mts +185 -0
  41. package/dist/types-CmbXx-G3.d.ts +185 -0
  42. package/llms.txt +78 -0
  43. package/package.json +120 -0
  44. package/src/config/MotionConfig.tsx +30 -0
  45. package/src/config/MotionConfigContext.ts +53 -0
  46. package/src/config/index.ts +9 -0
  47. package/src/index.ts +49 -0
  48. package/src/motion/Image.tsx +9 -0
  49. package/src/motion/Pressable.tsx +12 -0
  50. package/src/motion/ScrollView.tsx +9 -0
  51. package/src/motion/Text.tsx +8 -0
  52. package/src/motion/View.tsx +8 -0
  53. package/src/motion/createMotionComponent.tsx +850 -0
  54. package/src/motion/index.ts +26 -0
  55. package/src/presence/Presence.tsx +165 -0
  56. package/src/presence/PresenceContext.ts +28 -0
  57. package/src/presence/index.ts +6 -0
  58. package/src/transitions/easing.ts +29 -0
  59. package/src/transitions/index.ts +2 -0
  60. package/src/transitions/resolve.ts +265 -0
  61. package/src/types.ts +207 -0
  62. package/src/values/index.ts +1 -0
  63. package/src/values/useVariants.ts +60 -0
package/package.json ADDED
@@ -0,0 +1,120 @@
1
+ {
2
+ "name": "@onlynative/inertia",
3
+ "version": "0.0.1-alpha.0",
4
+ "description": "Declarative animation primitives for React Native, built on react-native-reanimated.",
5
+ "license": "MIT",
6
+ "author": "OnlyNative",
7
+ "homepage": "https://github.com/onlynative/inertia",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/onlynative/inertia.git",
11
+ "directory": "packages/core"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/onlynative/inertia/issues"
15
+ },
16
+ "keywords": [
17
+ "react-native",
18
+ "reanimated",
19
+ "animation",
20
+ "motion",
21
+ "expo",
22
+ "framer-motion",
23
+ "react-spring",
24
+ "declarative"
25
+ ],
26
+ "sideEffects": false,
27
+ "main": "./dist/index.js",
28
+ "module": "./dist/index.mjs",
29
+ "types": "./dist/index.d.ts",
30
+ "react-native": "./src/index.ts",
31
+ "source": "./src/index.ts",
32
+ "exports": {
33
+ ".": {
34
+ "types": "./dist/index.d.ts",
35
+ "react-native": "./src/index.ts",
36
+ "source": "./src/index.ts",
37
+ "import": "./dist/index.mjs",
38
+ "require": "./dist/index.js"
39
+ },
40
+ "./view": {
41
+ "types": "./dist/motion/View.d.ts",
42
+ "react-native": "./src/motion/View.tsx",
43
+ "source": "./src/motion/View.tsx",
44
+ "import": "./dist/motion/View.mjs",
45
+ "require": "./dist/motion/View.js"
46
+ },
47
+ "./text": {
48
+ "types": "./dist/motion/Text.d.ts",
49
+ "react-native": "./src/motion/Text.tsx",
50
+ "source": "./src/motion/Text.tsx",
51
+ "import": "./dist/motion/Text.mjs",
52
+ "require": "./dist/motion/Text.js"
53
+ },
54
+ "./image": {
55
+ "types": "./dist/motion/Image.d.ts",
56
+ "react-native": "./src/motion/Image.tsx",
57
+ "source": "./src/motion/Image.tsx",
58
+ "import": "./dist/motion/Image.mjs",
59
+ "require": "./dist/motion/Image.js"
60
+ },
61
+ "./pressable": {
62
+ "types": "./dist/motion/Pressable.d.ts",
63
+ "react-native": "./src/motion/Pressable.tsx",
64
+ "source": "./src/motion/Pressable.tsx",
65
+ "import": "./dist/motion/Pressable.mjs",
66
+ "require": "./dist/motion/Pressable.js"
67
+ },
68
+ "./scroll-view": {
69
+ "types": "./dist/motion/ScrollView.d.ts",
70
+ "react-native": "./src/motion/ScrollView.tsx",
71
+ "source": "./src/motion/ScrollView.tsx",
72
+ "import": "./dist/motion/ScrollView.mjs",
73
+ "require": "./dist/motion/ScrollView.js"
74
+ },
75
+ "./package.json": "./package.json"
76
+ },
77
+ "files": [
78
+ "dist",
79
+ "src",
80
+ "llms.txt",
81
+ "README.md",
82
+ "LICENSE",
83
+ "CHANGELOG.md",
84
+ "!**/__tests__",
85
+ "!**/*.test.*"
86
+ ],
87
+ "scripts": {
88
+ "build": "tsup",
89
+ "dev": "tsup --watch",
90
+ "typecheck": "tsc --noEmit",
91
+ "test": "jest",
92
+ "size": "size-limit",
93
+ "size:why": "size-limit --why",
94
+ "lint": "eslint src",
95
+ "clean": "rm -rf dist .turbo *.tsbuildinfo"
96
+ },
97
+ "peerDependencies": {
98
+ "react": ">=19.0.0",
99
+ "react-native": ">=0.81.0",
100
+ "react-native-reanimated": ">=4.0.0"
101
+ },
102
+ "devDependencies": {
103
+ "@react-native/babel-preset": "^0.81.5",
104
+ "@size-limit/preset-small-lib": "^11.1.0",
105
+ "@testing-library/react-native": "^13.3.3",
106
+ "@types/jest": "^29.5.14",
107
+ "@types/react": "^19.1.0",
108
+ "jest": "^29.7.0",
109
+ "react": "19.1.0",
110
+ "react-native": "0.81.5",
111
+ "react-native-reanimated": "~4.1.1",
112
+ "react-test-renderer": "19.1.0",
113
+ "size-limit": "^11.1.0",
114
+ "tsup": "^8.3.5",
115
+ "typescript": "^5.7.3"
116
+ },
117
+ "publishConfig": {
118
+ "access": "public"
119
+ }
120
+ }
@@ -0,0 +1,30 @@
1
+ import { type ReactNode, useMemo } from 'react'
2
+ import {
3
+ MotionConfigContext,
4
+ type MotionConfigValue,
5
+ type ReducedMotion,
6
+ } from './MotionConfigContext'
7
+
8
+ /**
9
+ * Provider that controls how descendant Motion primitives respond to
10
+ * reduced-motion preferences. Wrap the root of your app once with the
11
+ * default (`reducedMotion="user"`) to respect the OS accessibility setting,
12
+ * or scope a subtree with `'always'` / `'never'` for specific use cases.
13
+ */
14
+ export function MotionConfig({
15
+ reducedMotion = 'user',
16
+ children,
17
+ }: {
18
+ reducedMotion?: ReducedMotion
19
+ children: ReactNode
20
+ }) {
21
+ const value = useMemo<MotionConfigValue>(
22
+ () => ({ reducedMotion }),
23
+ [reducedMotion],
24
+ )
25
+ return (
26
+ <MotionConfigContext.Provider value={value}>
27
+ {children}
28
+ </MotionConfigContext.Provider>
29
+ )
30
+ }
@@ -0,0 +1,53 @@
1
+ import { createContext, useContext } from 'react'
2
+ import { useReducedMotion } from 'react-native-reanimated'
3
+
4
+ /**
5
+ * How descendant Motion primitives should treat reduced-motion preferences.
6
+ *
7
+ * - `'user'` (default): defer to the OS accessibility setting via
8
+ * Reanimated's `useReducedMotion()`. This is the only value that respects
9
+ * user choice and is the right default for app-level wrappers.
10
+ * - `'never'`: animate regardless of OS setting. Use sparingly — e.g. for
11
+ * onboarding transitions you've decided are essential.
12
+ * - `'always'`: never animate, regardless of OS setting. Useful for tests
13
+ * and snapshots.
14
+ */
15
+ export type ReducedMotion = 'user' | 'never' | 'always'
16
+
17
+ export interface MotionConfigValue {
18
+ reducedMotion: ReducedMotion
19
+ }
20
+
21
+ /**
22
+ * Default config used when a Motion primitive is rendered without a
23
+ * `<MotionConfig>` ancestor. `'user'` means respect the OS setting.
24
+ */
25
+ export const DEFAULT_MOTION_CONFIG: MotionConfigValue = {
26
+ reducedMotion: 'user',
27
+ }
28
+
29
+ export const MotionConfigContext = createContext<MotionConfigValue>(
30
+ DEFAULT_MOTION_CONFIG,
31
+ )
32
+
33
+ /**
34
+ * Read the active `<MotionConfig>` from a descendant. Returns the default
35
+ * (`'user'`) when no provider is present.
36
+ */
37
+ export function useMotionConfig(): MotionConfigValue {
38
+ return useContext(MotionConfigContext)
39
+ }
40
+
41
+ /**
42
+ * Resolve the active reduced-motion mode to a boolean. `'user'` consults
43
+ * Reanimated's OS-backed hook; `'always'` / `'never'` shortcut. Motion
44
+ * primitives call this to decide whether to swap transitions for
45
+ * `no-animation`.
46
+ */
47
+ export function useShouldReduceMotion(): boolean {
48
+ const { reducedMotion } = useMotionConfig()
49
+ const osReduced = useReducedMotion()
50
+ if (reducedMotion === 'never') return false
51
+ if (reducedMotion === 'always') return true
52
+ return osReduced
53
+ }
@@ -0,0 +1,9 @@
1
+ export { MotionConfig } from './MotionConfig'
2
+ export {
3
+ MotionConfigContext,
4
+ DEFAULT_MOTION_CONFIG,
5
+ useMotionConfig,
6
+ useShouldReduceMotion,
7
+ type MotionConfigValue,
8
+ type ReducedMotion,
9
+ } from './MotionConfigContext'
package/src/index.ts ADDED
@@ -0,0 +1,49 @@
1
+ /**
2
+ * `@onlynative/inertia` — declarative animation primitives for React Native.
3
+ *
4
+ * v0.1 surface: `Motion.View` / `Motion.Text` / `Motion.Image` /
5
+ * `Motion.Pressable` / `Motion.ScrollView`, with `initial` / `animate` /
6
+ * `exit` / `transition` / `variants` / `gesture` / `controller` /
7
+ * `onAnimationEnd` props. Sequences, repeats (single-value and
8
+ * sequence-level), spring / timing / decay / no-animation transitions,
9
+ * and `<Presence>` for mount / unmount transitions all in scope.
10
+ * `<MotionConfig reducedMotion>` gates motion against the OS setting.
11
+ */
12
+ export {
13
+ Motion,
14
+ MotionView,
15
+ MotionText,
16
+ MotionImage,
17
+ MotionPressable,
18
+ MotionScrollView,
19
+ createMotionComponent,
20
+ } from './motion'
21
+ export { MotionConfig, useMotionConfig, useShouldReduceMotion } from './config'
22
+ export type { MotionConfigValue, ReducedMotion } from './config'
23
+ export { Presence, usePresence } from './presence'
24
+ export type { PresenceContextValue } from './presence'
25
+ export {
26
+ resolveTransition,
27
+ resolveAnimatableValue,
28
+ ensureWorkletEasing,
29
+ } from './transitions'
30
+ export { useVariants } from './values'
31
+ export type {
32
+ AnimatableValue,
33
+ AnimateStyle,
34
+ AnimationCallbackInfo,
35
+ DecayTransition,
36
+ GestureSubStates,
37
+ MotionComponent,
38
+ MotionProps,
39
+ NoAnimationTransition,
40
+ PerPropertyTransition,
41
+ RepeatConfig,
42
+ SequenceStep,
43
+ SpringTransition,
44
+ TimingTransition,
45
+ Transition,
46
+ TransitionConfig,
47
+ VariantController,
48
+ VariantsMap,
49
+ } from './types'
@@ -0,0 +1,9 @@
1
+ import { Image } from 'react-native'
2
+ import { createMotionComponent } from './createMotionComponent'
3
+
4
+ /**
5
+ * Animatable `Image`. Inherits `Image`'s prop surface, with `animate` /
6
+ * `initial` / `exit` / `transition` typed against `ImageStyle` (so
7
+ * `tintColor` is accepted on `animate` here, but rejected on `Motion.View`).
8
+ */
9
+ export const MotionImage = createMotionComponent(Image)
@@ -0,0 +1,12 @@
1
+ import { Pressable } from 'react-native'
2
+ import { createMotionComponent } from './createMotionComponent'
3
+
4
+ /**
5
+ * Animatable `Pressable`. The `gesture` prop's `pressed` sub-state hooks into
6
+ * Pressable's native `onPressIn` / `onPressOut` via the factory's handler
7
+ * composition, picking up touch slop and accessibility semantics for free.
8
+ *
9
+ * Note: the function-style `style={(state) => ...}` Pressable form is not
10
+ * supported. Drive press-state styling through `gesture.pressed` instead.
11
+ */
12
+ export const MotionPressable = createMotionComponent(Pressable)
@@ -0,0 +1,9 @@
1
+ import { ScrollView } from 'react-native'
2
+ import { createMotionComponent } from './createMotionComponent'
3
+
4
+ /**
5
+ * Animatable `ScrollView`. Animations apply to the scroll container itself —
6
+ * useful for entrance transforms or fades on the whole list. Scroll-position
7
+ * driven animation (`useScroll`) lands in the values layer.
8
+ */
9
+ export const MotionScrollView = createMotionComponent(ScrollView)
@@ -0,0 +1,8 @@
1
+ import { Text } from 'react-native'
2
+ import { createMotionComponent } from './createMotionComponent'
3
+
4
+ /**
5
+ * Animatable `Text`. Inherits `Text`'s prop surface, with `animate` /
6
+ * `initial` / `exit` / `transition` typed against `TextStyle`.
7
+ */
8
+ export const MotionText = createMotionComponent(Text)
@@ -0,0 +1,8 @@
1
+ import { View } from 'react-native'
2
+ import { createMotionComponent } from './createMotionComponent'
3
+
4
+ /**
5
+ * Animatable `View`. Inherits `View`'s prop surface, with `animate` /
6
+ * `initial` / `exit` / `transition` typed against `ViewStyle`.
7
+ */
8
+ export const MotionView = createMotionComponent(View)