@expressive-ui/native 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +40 -2
- package/dist/Button.d.ts +48 -0
- package/dist/Button.d.ts.map +1 -0
- package/dist/Button.js +122 -0
- package/dist/Button.js.map +1 -0
- package/dist/Carousel.d.ts +13 -0
- package/dist/Carousel.d.ts.map +1 -0
- package/dist/Carousel.js +52 -0
- package/dist/Carousel.js.map +1 -0
- package/dist/Chips.d.ts +35 -0
- package/dist/Chips.d.ts.map +1 -0
- package/dist/Chips.js +138 -0
- package/dist/Chips.js.map +1 -0
- package/dist/Dialogs.d.ts +42 -0
- package/dist/Dialogs.d.ts.map +1 -0
- package/dist/Dialogs.js +115 -0
- package/dist/Dialogs.js.map +1 -0
- package/dist/ExpressiveCard.d.ts +20 -0
- package/dist/ExpressiveCard.d.ts.map +1 -0
- package/dist/ExpressiveCard.js +71 -0
- package/dist/ExpressiveCard.js.map +1 -0
- package/dist/Fab.d.ts +16 -0
- package/dist/Fab.d.ts.map +1 -0
- package/dist/Fab.js +104 -0
- package/dist/Fab.js.map +1 -0
- package/dist/Fields.d.ts +90 -0
- package/dist/Fields.d.ts.map +1 -0
- package/dist/Fields.js +211 -0
- package/dist/Fields.js.map +1 -0
- package/dist/Grid.d.ts +8 -0
- package/dist/Grid.d.ts.map +1 -0
- package/dist/Grid.js +16 -0
- package/dist/Grid.js.map +1 -0
- package/dist/Inputs.d.ts +33 -0
- package/dist/Inputs.d.ts.map +1 -0
- package/dist/Inputs.js +172 -0
- package/dist/Inputs.js.map +1 -0
- package/dist/List.d.ts +20 -0
- package/dist/List.d.ts.map +1 -0
- package/dist/List.js +222 -0
- package/dist/List.js.map +1 -0
- package/dist/Menu.d.ts +26 -0
- package/dist/Menu.d.ts.map +1 -0
- package/dist/Menu.js +117 -0
- package/dist/Menu.js.map +1 -0
- package/dist/Navigation.d.ts +34 -0
- package/dist/Navigation.d.ts.map +1 -0
- package/dist/Navigation.js +80 -0
- package/dist/Navigation.js.map +1 -0
- package/dist/Pickers.d.ts +16 -0
- package/dist/Pickers.d.ts.map +1 -0
- package/dist/Pickers.js +100 -0
- package/dist/Pickers.js.map +1 -0
- package/dist/Progress.d.ts +20 -0
- package/dist/Progress.d.ts.map +1 -0
- package/dist/Progress.js +93 -0
- package/dist/Progress.js.map +1 -0
- package/dist/Search.d.ts +50 -0
- package/dist/Search.d.ts.map +1 -0
- package/dist/Search.js +121 -0
- package/dist/Search.js.map +1 -0
- package/dist/Sheets.d.ts +44 -0
- package/dist/Sheets.d.ts.map +1 -0
- package/dist/Sheets.js +128 -0
- package/dist/Sheets.js.map +1 -0
- package/dist/Toolbar.d.ts +13 -0
- package/dist/Toolbar.d.ts.map +1 -0
- package/dist/Toolbar.js +38 -0
- package/dist/Toolbar.js.map +1 -0
- package/dist/Transition.d.ts +34 -0
- package/dist/Transition.d.ts.map +1 -0
- package/dist/Transition.js +93 -0
- package/dist/Transition.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/primitives.d.ts +41 -0
- package/dist/primitives.d.ts.map +1 -0
- package/dist/primitives.js +55 -0
- package/dist/primitives.js.map +1 -0
- package/dist/theme.d.ts +57 -0
- package/dist/theme.d.ts.map +1 -0
- package/dist/theme.js +89 -0
- package/dist/theme.js.map +1 -0
- package/package.json +53 -4
- package/src/Button.tsx +347 -0
- package/src/Carousel.tsx +108 -0
- package/src/Chips.tsx +292 -0
- package/src/Dialogs.tsx +252 -0
- package/src/ExpressiveCard.tsx +205 -0
- package/src/Fab.tsx +187 -0
- package/src/Fields.tsx +556 -0
- package/src/Grid.tsx +29 -0
- package/src/Inputs.tsx +290 -0
- package/src/List.tsx +295 -0
- package/src/Menu.tsx +238 -0
- package/src/Navigation.tsx +198 -0
- package/src/Pickers.tsx +151 -0
- package/src/Progress.tsx +192 -0
- package/src/Search.tsx +351 -0
- package/src/Sheets.tsx +273 -0
- package/src/Toolbar.tsx +88 -0
- package/src/Transition.tsx +155 -0
- package/src/index.ts +20 -0
- package/src/primitives.tsx +110 -0
- package/src/theme.tsx +125 -0
package/src/theme.tsx
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { createContext, useContext, useEffect, useMemo, useRef, useState, type ReactNode } from 'react';
|
|
2
|
+
import { AccessibilityInfo, Animated, Easing, useColorScheme } from 'react-native';
|
|
3
|
+
import { resolveLabels, springConfig, surfaceTiming, type ExpressiveLabels } from '@expressive-ui/core';
|
|
4
|
+
import { schemes, type ColorScheme, type MotionScheme, type SchemePair, type SpringToken, type ThemeMode } from '@expressive-ui/tokens';
|
|
5
|
+
|
|
6
|
+
export type IconRenderer = (name: string, options: { size: number; color: string; filled: boolean }) => ReactNode;
|
|
7
|
+
|
|
8
|
+
type ExpressiveTheme = {
|
|
9
|
+
mode: ThemeMode;
|
|
10
|
+
colors: ColorScheme;
|
|
11
|
+
locale: string;
|
|
12
|
+
labels: ExpressiveLabels;
|
|
13
|
+
reduceMotion: boolean;
|
|
14
|
+
motion: MotionScheme;
|
|
15
|
+
renderIcon: IconRenderer | null;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const ThemeContext = createContext<ExpressiveTheme>({
|
|
19
|
+
mode: 'light',
|
|
20
|
+
colors: schemes.light,
|
|
21
|
+
locale: 'pt-BR',
|
|
22
|
+
labels: resolveLabels('pt-BR'),
|
|
23
|
+
reduceMotion: false,
|
|
24
|
+
motion: 'expressive',
|
|
25
|
+
renderIcon: null,
|
|
26
|
+
});
|
|
27
|
+
export const useExpressiveTheme = () => useContext(ThemeContext);
|
|
28
|
+
|
|
29
|
+
export type ExpressiveThemeProviderProps = {
|
|
30
|
+
mode?: ThemeMode | 'system';
|
|
31
|
+
/** Esquema próprio — por exemplo createScheme(seed) de @expressive-ui/tokens/dynamic. */
|
|
32
|
+
scheme?: SchemePair;
|
|
33
|
+
/** Idioma dos textos de acessibilidade embutidos: pt-* usa português, os demais inglês. */
|
|
34
|
+
locale?: string;
|
|
35
|
+
/** Sobrescreve textos embutidos (rótulos de fechar, anúncios de reordenação etc.). */
|
|
36
|
+
labels?: Partial<ExpressiveLabels>;
|
|
37
|
+
/** Esquema de movimento do M3: expressive (molas que ultrapassam) ou standard (amortecidas). */
|
|
38
|
+
motion?: MotionScheme;
|
|
39
|
+
/**
|
|
40
|
+
* Ícones Material Symbols. Ex. com Expo:
|
|
41
|
+
* (name, { size, color }) => <MaterialIcons name={name.replace(/_/g, '-')} size={size} color={color} />
|
|
42
|
+
*/
|
|
43
|
+
renderIcon?: IconRenderer;
|
|
44
|
+
children: ReactNode;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export function ExpressiveThemeProvider({ mode = 'system', scheme, locale = 'pt-BR', motion = 'expressive', labels, renderIcon, children }: ExpressiveThemeProviderProps) {
|
|
48
|
+
const system = useColorScheme();
|
|
49
|
+
const reduceMotion = useReduceMotion();
|
|
50
|
+
const resolved: ThemeMode = mode === 'system' ? (system === 'dark' ? 'dark' : 'light') : mode;
|
|
51
|
+
const value = useMemo(
|
|
52
|
+
() => ({ mode: resolved, colors: (scheme ?? schemes)[resolved], locale, labels: resolveLabels(locale, labels), reduceMotion, motion, renderIcon: renderIcon ?? null }),
|
|
53
|
+
[resolved, scheme, locale, labels, reduceMotion, motion, renderIcon],
|
|
54
|
+
);
|
|
55
|
+
return <ThemeContext.Provider value={value}>{children}</ThemeContext.Provider>;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Mesmo comportamento do useReduceMotion do mobile-app-rhosse.
|
|
59
|
+
export function useReduceMotion() {
|
|
60
|
+
const [reduce, setReduce] = useState(false);
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
let active = true;
|
|
63
|
+
AccessibilityInfo.isReduceMotionEnabled()
|
|
64
|
+
.then((value) => active && setReduce(value))
|
|
65
|
+
.catch(() => {});
|
|
66
|
+
const sub = AccessibilityInfo.addEventListener('reduceMotionChanged', setReduce);
|
|
67
|
+
return () => {
|
|
68
|
+
active = false;
|
|
69
|
+
sub.remove();
|
|
70
|
+
};
|
|
71
|
+
}, []);
|
|
72
|
+
return reduce;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Valor animado que persegue `target` com a mola do token (driver JS: borderRadius e cores
|
|
77
|
+
* não rodam no driver nativo). Com "reduzir movimento" salta direto para o alvo.
|
|
78
|
+
*/
|
|
79
|
+
export function useSpringValue(target: number, token: SpringToken) {
|
|
80
|
+
const { reduceMotion, motion } = useExpressiveTheme();
|
|
81
|
+
const value = useRef(new Animated.Value(target)).current;
|
|
82
|
+
useEffect(() => {
|
|
83
|
+
const animation = reduceMotion
|
|
84
|
+
? Animated.timing(value, { toValue: target, duration: 0, useNativeDriver: false })
|
|
85
|
+
: Animated.spring(value, { toValue: target, ...springConfig(token, motion), useNativeDriver: false });
|
|
86
|
+
animation.start();
|
|
87
|
+
return () => animation.stop();
|
|
88
|
+
}, [target, token, reduceMotion, motion, value]);
|
|
89
|
+
return value;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const exit = surfaceTiming('exit');
|
|
93
|
+
/** Saída de superfície do M3: mais curta que a entrada e acelerando (emphasizedAccelerate). */
|
|
94
|
+
export function exitTiming(value: Animated.Value, toValue = 0, useNativeDriver = true) {
|
|
95
|
+
return Animated.timing(value, { toValue, duration: exit.duration, easing: Easing.bezier(...exit.bezier), useNativeDriver });
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Presença animada de sobreposições (dialogs, sheets, busca): mantém montado durante a saída.
|
|
100
|
+
* `progress` vai a 1 (aberto) com a mola spatialDefault e volta a 0 com a saída do M3 antes
|
|
101
|
+
* de desmontar; com "reduzir movimento" é instantâneo.
|
|
102
|
+
*/
|
|
103
|
+
export function usePresence(open: boolean, useNativeDriver = true) {
|
|
104
|
+
const { reduceMotion, motion } = useExpressiveTheme();
|
|
105
|
+
const progress = useRef(new Animated.Value(open ? 1 : 0)).current;
|
|
106
|
+
const opacity = useRef(new Animated.Value(open ? 1 : 0)).current;
|
|
107
|
+
const [mounted, setMounted] = useState(open);
|
|
108
|
+
useEffect(() => {
|
|
109
|
+
if (open) setMounted(true);
|
|
110
|
+
const animation = reduceMotion
|
|
111
|
+
? Animated.timing(progress, { toValue: open ? 1 : 0, duration: 0, useNativeDriver })
|
|
112
|
+
: open
|
|
113
|
+
? Animated.spring(progress, { toValue: 1, ...springConfig('spatialDefault', motion), useNativeDriver })
|
|
114
|
+
: exitTiming(progress, 0, useNativeDriver);
|
|
115
|
+
const effect = reduceMotion
|
|
116
|
+
? Animated.timing(opacity, { toValue: open ? 1 : 0, duration: 0, useNativeDriver })
|
|
117
|
+
: open
|
|
118
|
+
? Animated.spring(opacity, { toValue: 1, ...springConfig('effectsDefault', motion), useNativeDriver })
|
|
119
|
+
: exitTiming(opacity, 0, useNativeDriver);
|
|
120
|
+
const group = Animated.parallel([animation, effect]);
|
|
121
|
+
group.start(({ finished }) => finished && !open && setMounted(false));
|
|
122
|
+
return () => group.stop();
|
|
123
|
+
}, [open, progress, opacity, reduceMotion, motion, useNativeDriver]);
|
|
124
|
+
return { progress, opacity, mounted };
|
|
125
|
+
}
|