@flipova/foundation 2.3.0 → 2.4.0-beta.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/README.md +157 -156
- package/components/ui/accordion/ANIMATION_CUSTOMIZATION.md +16 -7
- package/components/ui/accordion/AccordionAnimatedHeight.tsx +3 -15
- package/components/ui/accordion/AccordionAnimatedIcon.tsx +2 -9
- package/components/ui/accordion/AnimatedHeight.tsx +3 -15
- package/components/ui/accordion/AnimatedIcon.tsx +2 -9
- package/components/ui/accordion/MIGRATION_SUMMARY.md +22 -11
- package/components/ui/accordion/USAGE_EXAMPLE.tsx +10 -25
- package/components/ui/accordion/index.tsx +71 -139
- package/components/ui/actionsheet/index.tsx +63 -105
- package/components/ui/alert/index.tsx +20 -50
- package/components/ui/alert-dialog/index.tsx +23 -48
- package/components/ui/avatar/index.tsx +32 -68
- package/components/ui/badge/index.tsx +18 -49
- package/components/ui/bottomsheet/index.tsx +20 -52
- package/components/ui/box/index.tsx +4 -9
- package/components/ui/box/index.web.tsx +3 -9
- package/components/ui/button/index.tsx +73 -109
- package/components/ui/calendar/creator.tsx +69 -30
- package/components/ui/calendar/index.tsx +81 -159
- package/components/ui/calendar/styles.tsx +10 -10
- package/components/ui/card/index.tsx +8 -9
- package/components/ui/card/index.web.tsx +4 -10
- package/components/ui/center/index.tsx +6 -11
- package/components/ui/center/index.web.tsx +3 -9
- package/components/ui/checkbox/index.tsx +46 -107
- package/components/ui/date-time-picker/creator.tsx +14 -1
- package/components/ui/date-time-picker/index.tsx +107 -156
- package/components/ui/date-time-picker/index.web.tsx +11 -33
- package/components/ui/date-time-picker/styles.tsx +5 -5
- package/components/ui/divider/index.tsx +5 -6
- package/components/ui/drawer/index.tsx +108 -128
- package/components/ui/fab/index.tsx +25 -68
- package/components/ui/flat-list/index.tsx +11 -8
- package/components/ui/form-control/index.tsx +49 -90
- package/components/ui/gluestack-ui-provider/index.tsx +4 -18
- package/components/ui/gluestack-ui-provider/index.web.tsx +10 -11
- package/components/ui/gluestack-ui-provider/script.ts +1 -3
- package/components/ui/gluestack-ui-provider/theme-context.ts +2 -2
- package/components/ui/gluestack-ui-provider/useGluestackColors.ts +2 -6
- package/components/ui/grid/index.tsx +128 -165
- package/components/ui/grid/index.web.tsx +17 -19
- package/components/ui/grid/styles.tsx +1 -3
- package/components/ui/heading/index.tsx +146 -169
- package/components/ui/heading/index.web.tsx +7 -28
- package/components/ui/heading/styles.tsx +5 -5
- package/components/ui/hstack/index.tsx +16 -15
- package/components/ui/hstack/index.web.tsx +17 -17
- package/components/ui/hstack/styles.tsx +5 -5
- package/components/ui/icon/index.tsx +95 -486
- package/components/ui/icon/index.web.tsx +79 -439
- package/components/ui/image/index.tsx +13 -18
- package/components/ui/image-viewer/index.tsx +149 -221
- package/components/ui/image-viewer/index.web.tsx +88 -113
- package/components/ui/input/index.tsx +20 -33
- package/components/ui/link/index.tsx +16 -22
- package/components/ui/liquid-glass/index.tsx +19 -25
- package/components/ui/menu/index.tsx +44 -66
- package/components/ui/modal/index.tsx +70 -91
- package/components/ui/popover/index.tsx +102 -121
- package/components/ui/portal/index.tsx +5 -6
- package/components/ui/pressable/index.tsx +5 -9
- package/components/ui/progress/index.tsx +4 -11
- package/components/ui/radio/index.tsx +47 -83
- package/components/ui/select/index.tsx +38 -59
- package/components/ui/select/select-actionsheet.tsx +61 -108
- package/components/ui/skeleton/index.tsx +22 -43
- package/components/ui/skeleton/index.web.tsx +63 -75
- package/components/ui/slider/index.tsx +36 -56
- package/components/ui/spinner/index.tsx +1 -10
- package/components/ui/switch/index.tsx +6 -13
- package/components/ui/table/index.tsx +39 -102
- package/components/ui/table/index.web.tsx +41 -79
- package/components/ui/tabs/TabsAnimatedIndicator.tsx +10 -38
- package/components/ui/tabs/creator.tsx +32 -24
- package/components/ui/tabs/index.tsx +253 -309
- package/components/ui/text/index.tsx +23 -37
- package/components/ui/text/index.web.tsx +33 -35
- package/components/ui/text/styles.tsx +5 -5
- package/components/ui/textarea/index.tsx +24 -38
- package/components/ui/toast/index.tsx +47 -52
- package/components/ui/tooltip/index.tsx +12 -28
- package/components/ui/vstack/index.tsx +17 -17
- package/components/ui/vstack/index.web.tsx +17 -17
- package/components/ui/vstack/styles.tsx +5 -5
- package/design/tools/design.js +15 -12
- package/design/tools/npm.js +4 -3
- package/dist/{chunk-B277QSR5.mjs → chunk-2R66P5X5.mjs} +1816 -3124
- package/dist/chunk-2R66P5X5.mjs.map +1 -0
- package/dist/{chunk-GD37RFBR.js → chunk-LCTFQJZM.js} +1816 -3124
- package/dist/chunk-LCTFQJZM.js.map +1 -0
- package/dist/index.js +294 -294
- package/dist/index.mjs +1 -1
- package/dist/ui/index.js +294 -294
- package/dist/ui/index.mjs +1 -1
- package/package.json +12 -7
- package/dist/chunk-B277QSR5.mjs.map +0 -1
- package/dist/chunk-GD37RFBR.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,156 +1,157 @@
|
|
|
1
|
-
# @flipova/foundation
|
|
2
|
-
|
|
3
|
-
[](https://www.npmjs.com/package/@flipova/foundation)
|
|
4
|
-
[](https://opensource.org/licenses/MIT)
|
|
5
|
-
|
|
6
|
-
gluestack-ui components for React Native (iOS, Android) and Web, plus a
|
|
7
|
-
registry-driven theming pipeline.
|
|
8
|
-
|
|
9
|
-
## Design pipeline
|
|
10
|
-
|
|
11
|
-
The design pipeline has a single function:
|
|
12
|
-
|
|
13
|
-
> **`design/tokens.xml` + `design/themes.xml`**
|
|
14
|
-
>
|
|
15
|
-
>
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
the
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
|
35
|
-
|
|
|
36
|
-
| `npm run design:gen
|
|
37
|
-
| `npm run design:check` |
|
|
38
|
-
| `npm run design:
|
|
39
|
-
| `npm run design:
|
|
40
|
-
| `npm run design:
|
|
41
|
-
| `npm run design:
|
|
42
|
-
| `npm run design:
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
npm install
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
the
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
`design:
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
|
68
|
-
|
|
|
69
|
-
| `npx flipova-design
|
|
70
|
-
| `npx flipova-design
|
|
71
|
-
| `npx flipova-design
|
|
72
|
-
| `npx flipova-design
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
`@flipova/foundation/
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
`
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
npm run design:
|
|
98
|
-
npm run design:
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
import {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
`
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
1
|
+
# @flipova/foundation
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@flipova/foundation)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
|
|
6
|
+
gluestack-ui components for React Native (iOS, Android) and Web, plus a
|
|
7
|
+
registry-driven theming pipeline.
|
|
8
|
+
|
|
9
|
+
## Design pipeline
|
|
10
|
+
|
|
11
|
+
The design pipeline has a single function:
|
|
12
|
+
|
|
13
|
+
> **`design/tokens.xml` + `design/themes.xml`**
|
|
14
|
+
>
|
|
15
|
+
> - -> `components/ui/gluestack-ui-provider/config.ts` (gluestack / nativewind colour vars)
|
|
16
|
+
> - -> `components/ui/gluestack-ui-provider/tokens.js` (Tailwind/nativewind token theme)
|
|
17
|
+
|
|
18
|
+
Role ids in `themes.xml` are the gluestack CSS variable names (dash-prefixed at
|
|
19
|
+
generation time), so the design registry and the runtime theme config always
|
|
20
|
+
speak the same language. Every colour is emitted as a space-separated RGB
|
|
21
|
+
triplet, enabling Tailwind opacity modifiers such as `bg-primary/50`.
|
|
22
|
+
|
|
23
|
+
The scale tokens (spacing, radii, breakpoints, typography, shadow, z-index,
|
|
24
|
+
opacity, motion) are emitted as a Tailwind `theme` fragment, and the semantic
|
|
25
|
+
colours are derived from the `themes.xml` roles. `tailwind.config.js` contains
|
|
26
|
+
**no design value**: it just does `extend: tokens.theme`. The XML registries are
|
|
27
|
+
therefore the single source of truth for both the gluestack runtime vars and
|
|
28
|
+
the Tailwind/nativewind theme.
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npm run design:pipeline # gen + check + verify + lint + doc
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
| Script | What it does |
|
|
35
|
+
| :------------------------- | :--------------------------------------------------- |
|
|
36
|
+
| `npm run design:gen` | compile tokens/themes into `config.ts` + `tokens.js` |
|
|
37
|
+
| `npm run design:gen:check` | verify regeneration is a no-op (drift check) |
|
|
38
|
+
| `npm run design:check` | determinism rules + XSD pass + ruff |
|
|
39
|
+
| `npm run design:verify` | verify the committed canonical index |
|
|
40
|
+
| `npm run design:canonical` | re-emit `design/canonical.index.txt` |
|
|
41
|
+
| `npm run design:lint` | XSD-validate every design XML |
|
|
42
|
+
| `npm run design:doc` | regenerate the docs site (`docs/generated`) |
|
|
43
|
+
| `npm run design:edit` | open the XSD-driven XML editor |
|
|
44
|
+
|
|
45
|
+
Never hand-edit the generated `config.ts`, `tokens.js` or `docs/generated/**` -
|
|
46
|
+
the next run overwrites them. And never add a design value to
|
|
47
|
+
`tailwind.config.js`: it only wires the generated theme.
|
|
48
|
+
|
|
49
|
+
## Install
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
npm install @flipova/foundation
|
|
53
|
+
npm install gluestack-ui
|
|
54
|
+
npx flipova-design init
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
`init` **does not copy the registries into your project**. The XML registries and
|
|
58
|
+
the whole toolchain stay in `node_modules/@flipova/foundation/design`, and the
|
|
59
|
+
command only injects the app-level wiring that the package cannot own:
|
|
60
|
+
|
|
61
|
+
- `tailwind.config.js`, `postcss.config.js`, `globals.css` - created only when
|
|
62
|
+
missing (never overwritten unless `--force`);
|
|
63
|
+
- the `design:*` npm scripts in your `package.json` (`design:gen`, `design:lint`,
|
|
64
|
+
`design:check`, `design:verify`, `design:canonical`, `design:doc`,
|
|
65
|
+
`design:pipeline`).
|
|
66
|
+
|
|
67
|
+
| Command | What it does |
|
|
68
|
+
| :--------------------------------- | :---------------------------------------------------- |
|
|
69
|
+
| `npx flipova-design where` | print the resolved registries/artifacts paths |
|
|
70
|
+
| `npx flipova-design inject` | re-run the injection only |
|
|
71
|
+
| `npx flipova-design adopt` | copy the registries into the project and own them |
|
|
72
|
+
| `npx flipova-design gen [--check]` | compile the registries into `config.ts` + `tokens.js` |
|
|
73
|
+
| `npx flipova-design lint` | XSD-validate the registries |
|
|
74
|
+
|
|
75
|
+
`gen` writes into the resolved output root, i.e. straight into the installed
|
|
76
|
+
package (`node_modules/@flipova/foundation/components/ui/gluestack-ui-provider`),
|
|
77
|
+
so the artifacts consumed by `@flipova/foundation/tokens` and
|
|
78
|
+
`@flipova/foundation/ui` are always the ones the pipeline produced.
|
|
79
|
+
|
|
80
|
+
## Own the design system
|
|
81
|
+
|
|
82
|
+
An app that wants its own branding adopts the registries:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
npx flipova-design adopt
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
That copies `manifest.xml`, `schema.xsd`, `tokens.xml`, `themes.xml`,
|
|
89
|
+
`documentation.xml` and `canonical.index.txt` into `design/` - and **not** the
|
|
90
|
+
toolchain, which stays in `node_modules`. It rewrites the manifest outputs to
|
|
91
|
+
`theme/config.ts` and `theme/tokens.js`, and creates `theme/provider.tsx`.
|
|
92
|
+
|
|
93
|
+
From then on the project is the source of truth:
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
# edit design/tokens.xml and design/themes.xml - the colours, the scales, the roles
|
|
97
|
+
npm run design:gen # -> theme/config.ts + theme/tokens.js
|
|
98
|
+
npm run design:verify # the registries are in step with the artifacts
|
|
99
|
+
npm run design:check # determinism + XSD, on YOUR registries
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Wire the two artifacts into the app:
|
|
103
|
+
|
|
104
|
+
```js
|
|
105
|
+
// tailwind.config.js
|
|
106
|
+
const tokens = require('./theme/tokens');
|
|
107
|
+
module.exports = { presets: [require('nativewind/preset')], theme: { extend: tokens.theme } };
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
```tsx
|
|
111
|
+
// theme/provider.tsx (generated by adopt)
|
|
112
|
+
import { createGluestackUIProvider } from '@flipova/foundation/ui';
|
|
113
|
+
import { config } from './config';
|
|
114
|
+
export const AppThemeProvider = createGluestackUIProvider(config);
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
The package still provides the components, the generator and every token the app
|
|
118
|
+
does not override. `npx flipova-design where` always says which side is in charge.
|
|
119
|
+
|
|
120
|
+
The generated theme is wired into your Tailwind config (app-level files are not
|
|
121
|
+
shipped by the package):
|
|
122
|
+
|
|
123
|
+
```js
|
|
124
|
+
// tailwind.config.js
|
|
125
|
+
const tokens = require('@flipova/foundation/tokens');
|
|
126
|
+
module.exports = {
|
|
127
|
+
presets: [require('nativewind/preset')],
|
|
128
|
+
theme: { extend: tokens.theme },
|
|
129
|
+
};
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
and the provider is mounted once at the root:
|
|
133
|
+
|
|
134
|
+
```tsx
|
|
135
|
+
import { GluestackUIProvider } from '@flipova/foundation/ui';
|
|
136
|
+
// <GluestackUIProvider mode="system"> ... </GluestackUIProvider>
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
The design tooling needs Python 3.8+ with `lxml` (`design/tools/requirements.txt`).
|
|
140
|
+
Resolution order: `$FOUNDATION_PYTHON`, then `$FOUNDATION_VENV`, then
|
|
141
|
+
`design/tools/.venv`, then any `python3`/`python` on `PATH` that can import
|
|
142
|
+
`lxml`.
|
|
143
|
+
|
|
144
|
+
## Documentation
|
|
145
|
+
|
|
146
|
+
The full guide (installation, theming, tokens, the gluestack config, tools,
|
|
147
|
+
contributing) is generated from `design/documentation.xml` into the Docusaurus
|
|
148
|
+
site under `docs/`:
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
cd docs && npm start
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## License
|
|
155
|
+
|
|
156
|
+
MIT © Flipova. Participation is governed by
|
|
157
|
+
[the Code of Conduct](CODE_OF_CONDUCT.md).
|
|
@@ -43,38 +43,42 @@ export const accordionAnimationConfig = {
|
|
|
43
43
|
### Example Customizations
|
|
44
44
|
|
|
45
45
|
#### Faster Animations
|
|
46
|
+
|
|
46
47
|
```typescript
|
|
47
48
|
export const accordionAnimationConfig = {
|
|
48
|
-
contentDuration: 150,
|
|
49
|
-
iconDuration: 150,
|
|
49
|
+
contentDuration: 150, // Faster expand/collapse
|
|
50
|
+
iconDuration: 150, // Faster icon rotation
|
|
50
51
|
iconRotation: 180,
|
|
51
52
|
};
|
|
52
53
|
```
|
|
53
54
|
|
|
54
55
|
#### Slower, More Dramatic
|
|
56
|
+
|
|
55
57
|
```typescript
|
|
56
58
|
export const accordionAnimationConfig = {
|
|
57
|
-
contentDuration: 500,
|
|
58
|
-
iconDuration: 400,
|
|
59
|
+
contentDuration: 500, // Slower, more visible
|
|
60
|
+
iconDuration: 400, // Slightly faster icon
|
|
59
61
|
iconRotation: 180,
|
|
60
62
|
};
|
|
61
63
|
```
|
|
62
64
|
|
|
63
65
|
#### Different Icon Rotation
|
|
66
|
+
|
|
64
67
|
```typescript
|
|
65
68
|
export const accordionAnimationConfig = {
|
|
66
69
|
contentDuration: 300,
|
|
67
70
|
iconDuration: 300,
|
|
68
|
-
iconRotation: 90,
|
|
71
|
+
iconRotation: 90, // Quarter turn instead of flip
|
|
69
72
|
};
|
|
70
73
|
```
|
|
71
74
|
|
|
72
75
|
#### No Icon Rotation
|
|
76
|
+
|
|
73
77
|
```typescript
|
|
74
78
|
export const accordionAnimationConfig = {
|
|
75
79
|
contentDuration: 300,
|
|
76
|
-
iconDuration: 0,
|
|
77
|
-
iconRotation: 0,
|
|
80
|
+
iconDuration: 0, // Instant (no animation)
|
|
81
|
+
iconRotation: 0, // No rotation
|
|
78
82
|
};
|
|
79
83
|
```
|
|
80
84
|
|
|
@@ -111,12 +115,14 @@ animatedValue.value = withTiming(isExpanded ? 1 : 0, {
|
|
|
111
115
|
### What Changed
|
|
112
116
|
|
|
113
117
|
**Before (Old Animated API):**
|
|
118
|
+
|
|
114
119
|
- ❌ Ran on JS thread (could drop frames)
|
|
115
120
|
- ❌ Hardcoded 200ms duration in core
|
|
116
121
|
- ❌ No icon rotation
|
|
117
122
|
- ❌ Not customizable
|
|
118
123
|
|
|
119
124
|
**After (Reanimated):**
|
|
125
|
+
|
|
120
126
|
- ✅ Runs on UI thread (60fps always)
|
|
121
127
|
- ✅ Customizable durations
|
|
122
128
|
- ✅ Icon rotation included
|
|
@@ -129,12 +135,14 @@ None! The API remains the same. Your existing accordion code will work without c
|
|
|
129
135
|
## Why Reanimated?
|
|
130
136
|
|
|
131
137
|
**Performance:** Animations run on the UI thread, ensuring smooth 60fps even when:
|
|
138
|
+
|
|
132
139
|
- Fetching data
|
|
133
140
|
- Rendering lists
|
|
134
141
|
- Running heavy JavaScript operations
|
|
135
142
|
- Navigating between screens
|
|
136
143
|
|
|
137
144
|
**Better User Experience:** Users will notice the difference, especially on:
|
|
145
|
+
|
|
138
146
|
- Mid-range and low-end devices
|
|
139
147
|
- During app startup
|
|
140
148
|
- When multiple things are happening at once
|
|
@@ -153,6 +161,7 @@ accordion/
|
|
|
153
161
|
## Need Help?
|
|
154
162
|
|
|
155
163
|
If you want to implement more complex animations:
|
|
164
|
+
|
|
156
165
|
1. Check the [Reanimated documentation](https://docs.swmansion.com/react-native-reanimated/)
|
|
157
166
|
2. Look at `AnimatedHeight.tsx` and `AnimatedIcon.tsx` for examples
|
|
158
167
|
3. All standard Reanimated APIs are available
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { LayoutChangeEvent } from 'react-native';
|
|
3
|
-
import Animated, {
|
|
4
|
-
useSharedValue,
|
|
5
|
-
useAnimatedStyle,
|
|
6
|
-
withTiming,
|
|
7
|
-
} from 'react-native-reanimated';
|
|
3
|
+
import Animated, { useSharedValue, useAnimatedStyle, withTiming } from 'react-native-reanimated';
|
|
8
4
|
|
|
9
5
|
interface AnimatedHeightProps {
|
|
10
6
|
isExpanded: boolean;
|
|
@@ -13,12 +9,7 @@ interface AnimatedHeightProps {
|
|
|
13
9
|
style?: any;
|
|
14
10
|
}
|
|
15
11
|
|
|
16
|
-
export const AnimatedHeight: React.FC<AnimatedHeightProps> = ({
|
|
17
|
-
isExpanded,
|
|
18
|
-
children,
|
|
19
|
-
duration = 300,
|
|
20
|
-
style,
|
|
21
|
-
}) => {
|
|
12
|
+
export const AnimatedHeight: React.FC<AnimatedHeightProps> = ({ isExpanded, children, duration = 300, style }) => {
|
|
22
13
|
const measuredHeight = useSharedValue(0);
|
|
23
14
|
const progress = useSharedValue(isExpanded ? 1 : 0);
|
|
24
15
|
|
|
@@ -45,10 +36,7 @@ export const AnimatedHeight: React.FC<AnimatedHeightProps> = ({
|
|
|
45
36
|
|
|
46
37
|
return (
|
|
47
38
|
<Animated.View style={[animatedStyle, style]}>
|
|
48
|
-
<Animated.View
|
|
49
|
-
onLayout={onLayout}
|
|
50
|
-
style={{ position: 'absolute', width: '100%' }}
|
|
51
|
-
>
|
|
39
|
+
<Animated.View onLayout={onLayout} style={{ position: 'absolute', width: '100%' }}>
|
|
52
40
|
{children}
|
|
53
41
|
</Animated.View>
|
|
54
42
|
</Animated.View>
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import React, { useEffect } from 'react';
|
|
2
|
-
import Animated, {
|
|
3
|
-
useSharedValue,
|
|
4
|
-
useAnimatedStyle,
|
|
5
|
-
withTiming,
|
|
6
|
-
interpolate,
|
|
7
|
-
} from 'react-native-reanimated';
|
|
2
|
+
import Animated, { useSharedValue, useAnimatedStyle, withTiming, interpolate } from 'react-native-reanimated';
|
|
8
3
|
|
|
9
4
|
interface AnimatedIconProps {
|
|
10
5
|
isExpanded: boolean;
|
|
@@ -35,7 +30,5 @@ export const AnimatedIcon: React.FC<AnimatedIconProps> = ({
|
|
|
35
30
|
};
|
|
36
31
|
}, [rotation, animatedValue]);
|
|
37
32
|
|
|
38
|
-
return
|
|
39
|
-
<Animated.View style={[animatedStyle, style]}>{children}</Animated.View>
|
|
40
|
-
);
|
|
33
|
+
return <Animated.View style={[animatedStyle, style]}>{children}</Animated.View>;
|
|
41
34
|
};
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { LayoutChangeEvent } from 'react-native';
|
|
3
|
-
import Animated, {
|
|
4
|
-
useSharedValue,
|
|
5
|
-
useAnimatedStyle,
|
|
6
|
-
withTiming,
|
|
7
|
-
} from 'react-native-reanimated';
|
|
3
|
+
import Animated, { useSharedValue, useAnimatedStyle, withTiming } from 'react-native-reanimated';
|
|
8
4
|
|
|
9
5
|
interface AnimatedHeightProps {
|
|
10
6
|
isExpanded: boolean;
|
|
@@ -13,12 +9,7 @@ interface AnimatedHeightProps {
|
|
|
13
9
|
style?: any;
|
|
14
10
|
}
|
|
15
11
|
|
|
16
|
-
export const AnimatedHeight: React.FC<AnimatedHeightProps> = ({
|
|
17
|
-
isExpanded,
|
|
18
|
-
children,
|
|
19
|
-
duration = 300,
|
|
20
|
-
style,
|
|
21
|
-
}) => {
|
|
12
|
+
export const AnimatedHeight: React.FC<AnimatedHeightProps> = ({ isExpanded, children, duration = 300, style }) => {
|
|
22
13
|
const measuredHeight = useSharedValue(0);
|
|
23
14
|
const progress = useSharedValue(isExpanded ? 1 : 0);
|
|
24
15
|
|
|
@@ -45,10 +36,7 @@ export const AnimatedHeight: React.FC<AnimatedHeightProps> = ({
|
|
|
45
36
|
|
|
46
37
|
return (
|
|
47
38
|
<Animated.View style={[animatedStyle, style]}>
|
|
48
|
-
<Animated.View
|
|
49
|
-
onLayout={onLayout}
|
|
50
|
-
style={{ position: 'absolute', width: '100%' }}
|
|
51
|
-
>
|
|
39
|
+
<Animated.View onLayout={onLayout} style={{ position: 'absolute', width: '100%' }}>
|
|
52
40
|
{children}
|
|
53
41
|
</Animated.View>
|
|
54
42
|
</Animated.View>
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import React, { useEffect } from 'react';
|
|
2
|
-
import Animated, {
|
|
3
|
-
useSharedValue,
|
|
4
|
-
useAnimatedStyle,
|
|
5
|
-
withTiming,
|
|
6
|
-
interpolate,
|
|
7
|
-
} from 'react-native-reanimated';
|
|
2
|
+
import Animated, { useSharedValue, useAnimatedStyle, withTiming, interpolate } from 'react-native-reanimated';
|
|
8
3
|
|
|
9
4
|
interface AnimatedIconProps {
|
|
10
5
|
isExpanded: boolean;
|
|
@@ -35,7 +30,5 @@ export const AnimatedIcon: React.FC<AnimatedIconProps> = ({
|
|
|
35
30
|
};
|
|
36
31
|
}, [rotation, animatedValue]);
|
|
37
32
|
|
|
38
|
-
return
|
|
39
|
-
<Animated.View style={[animatedStyle, style]}>{children}</Animated.View>
|
|
40
|
-
);
|
|
33
|
+
return <Animated.View style={[animatedStyle, style]}>{children}</Animated.View>;
|
|
41
34
|
};
|
|
@@ -9,6 +9,7 @@ Successfully migrated the Accordion component from the **old Animated API** to *
|
|
|
9
9
|
## 🎯 Key Improvements
|
|
10
10
|
|
|
11
11
|
### **Before (Old Implementation)**
|
|
12
|
+
|
|
12
13
|
- ❌ Used old React Native `Animated` API (deprecated)
|
|
13
14
|
- ❌ Ran on JS thread (could drop frames)
|
|
14
15
|
- ❌ Hardcoded 200ms duration in core package
|
|
@@ -17,6 +18,7 @@ Successfully migrated the Accordion component from the **old Animated API** to *
|
|
|
17
18
|
- ❌ Animation logic locked in core package
|
|
18
19
|
|
|
19
20
|
### **After (New Implementation)**
|
|
21
|
+
|
|
20
22
|
- ✅ Uses **React Native Reanimated** (modern, industry standard)
|
|
21
23
|
- ✅ Runs on **UI thread** (60fps guaranteed, no JS blocking)
|
|
22
24
|
- ✅ **Customizable** animation durations (300ms default, user can change)
|
|
@@ -29,6 +31,7 @@ Successfully migrated the Accordion component from the **old Animated API** to *
|
|
|
29
31
|
## 📁 Files Created/Modified
|
|
30
32
|
|
|
31
33
|
### **New Files Created:**
|
|
34
|
+
|
|
32
35
|
```
|
|
33
36
|
src/components/ui/accordion/
|
|
34
37
|
├── AnimatedHeight.tsx ✨ NEW - Reanimated height animation
|
|
@@ -40,6 +43,7 @@ src/components/ui/accordion/
|
|
|
40
43
|
```
|
|
41
44
|
|
|
42
45
|
### **Modified Files:**
|
|
46
|
+
|
|
43
47
|
```
|
|
44
48
|
src/components/ui/accordion/
|
|
45
49
|
└── index.tsx 🔄 UPDATED - Uses new animated components
|
|
@@ -56,13 +60,14 @@ packages/gluestack-core/src/accordion/creator/
|
|
|
56
60
|
### **1. Automatic Icon Rotation**
|
|
57
61
|
|
|
58
62
|
**Before:**
|
|
63
|
+
|
|
59
64
|
```tsx
|
|
60
65
|
<AccordionTrigger>
|
|
61
66
|
{({ isExpanded }) => (
|
|
62
67
|
<>
|
|
63
68
|
<AccordionTitleText>Question?</AccordionTitleText>
|
|
64
69
|
{isExpanded ? (
|
|
65
|
-
<AccordionIcon as={ChevronUpIcon} />
|
|
70
|
+
<AccordionIcon as={ChevronUpIcon} /> // Manual switch
|
|
66
71
|
) : (
|
|
67
72
|
<AccordionIcon as={ChevronDownIcon} />
|
|
68
73
|
)}
|
|
@@ -72,10 +77,11 @@ packages/gluestack-core/src/accordion/creator/
|
|
|
72
77
|
```
|
|
73
78
|
|
|
74
79
|
**After:**
|
|
80
|
+
|
|
75
81
|
```tsx
|
|
76
82
|
<AccordionTrigger>
|
|
77
83
|
<AccordionTitleText>Question?</AccordionTitleText>
|
|
78
|
-
<AccordionIcon as={ChevronDownIcon} />
|
|
84
|
+
<AccordionIcon as={ChevronDownIcon} /> {/* Rotates automatically! */}
|
|
79
85
|
</AccordionTrigger>
|
|
80
86
|
```
|
|
81
87
|
|
|
@@ -85,15 +91,16 @@ Users can now edit `animation-config.ts`:
|
|
|
85
91
|
|
|
86
92
|
```typescript
|
|
87
93
|
export const accordionAnimationConfig = {
|
|
88
|
-
contentDuration: 300,
|
|
89
|
-
iconDuration: 300,
|
|
90
|
-
iconRotation: 180,
|
|
94
|
+
contentDuration: 300, // Change to 500 for slower
|
|
95
|
+
iconDuration: 300, // Change to 150 for faster
|
|
96
|
+
iconRotation: 180, // Change to 90 for quarter turn
|
|
91
97
|
};
|
|
92
98
|
```
|
|
93
99
|
|
|
94
100
|
### **3. Advanced Customization**
|
|
95
101
|
|
|
96
102
|
Users can directly modify `AnimatedHeight.tsx` and `AnimatedIcon.tsx` for:
|
|
103
|
+
|
|
97
104
|
- Custom easing curves
|
|
98
105
|
- Spring physics
|
|
99
106
|
- Different animation types
|
|
@@ -105,12 +112,12 @@ Users can directly modify `AnimatedHeight.tsx` and `AnimatedIcon.tsx` for:
|
|
|
105
112
|
|
|
106
113
|
### **Measured Improvements:**
|
|
107
114
|
|
|
108
|
-
| Scenario
|
|
109
|
-
|
|
110
|
-
| **Normal usage**
|
|
111
|
-
| **During data fetch** | 30-40 fps
|
|
112
|
-
| **During navigation** | 25-35 fps
|
|
113
|
-
| **Low-end devices**
|
|
115
|
+
| Scenario | Old (Animated API) | New (Reanimated) | Improvement |
|
|
116
|
+
| --------------------- | ------------------ | ---------------- | ----------------- |
|
|
117
|
+
| **Normal usage** | 50-60 fps | **60 fps** | Consistent |
|
|
118
|
+
| **During data fetch** | 30-40 fps | **60 fps** | **2x smoother** |
|
|
119
|
+
| **During navigation** | 25-35 fps | **60 fps** | **2.4x smoother** |
|
|
120
|
+
| **Low-end devices** | 20-30 fps | **60 fps** | **2-3x smoother** |
|
|
114
121
|
|
|
115
122
|
### **Why It's Faster:**
|
|
116
123
|
|
|
@@ -143,18 +150,21 @@ Animation → UI Thread → Screen
|
|
|
143
150
|
### **Key Components:**
|
|
144
151
|
|
|
145
152
|
#### **AnimatedHeight.tsx**
|
|
153
|
+
|
|
146
154
|
- Uses `measure()` to get content height
|
|
147
155
|
- Animates height from 0 → measured height
|
|
148
156
|
- Runs entirely on UI thread via worklets
|
|
149
157
|
- Customizable duration
|
|
150
158
|
|
|
151
159
|
#### **AnimatedIcon.tsx**
|
|
160
|
+
|
|
152
161
|
- Uses `interpolate()` for smooth rotation
|
|
153
162
|
- Animates from 0° → configurable rotation angle
|
|
154
163
|
- Independent animation timing
|
|
155
164
|
- Runs on UI thread
|
|
156
165
|
|
|
157
166
|
#### **animation-config.ts**
|
|
167
|
+
|
|
158
168
|
- Single source of truth for animation settings
|
|
159
169
|
- Users can easily modify without touching component code
|
|
160
170
|
- Type-safe configuration
|
|
@@ -241,6 +251,7 @@ This pattern can be applied to other components:
|
|
|
241
251
|
## 🎉 Result
|
|
242
252
|
|
|
243
253
|
The Accordion component is now:
|
|
254
|
+
|
|
244
255
|
- **Performant** (60fps on UI thread)
|
|
245
256
|
- **Modern** (Reanimated, not old Animated API)
|
|
246
257
|
- **Customizable** (users can modify all settings)
|