@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.
Files changed (108) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +40 -2
  3. package/dist/Button.d.ts +48 -0
  4. package/dist/Button.d.ts.map +1 -0
  5. package/dist/Button.js +122 -0
  6. package/dist/Button.js.map +1 -0
  7. package/dist/Carousel.d.ts +13 -0
  8. package/dist/Carousel.d.ts.map +1 -0
  9. package/dist/Carousel.js +52 -0
  10. package/dist/Carousel.js.map +1 -0
  11. package/dist/Chips.d.ts +35 -0
  12. package/dist/Chips.d.ts.map +1 -0
  13. package/dist/Chips.js +138 -0
  14. package/dist/Chips.js.map +1 -0
  15. package/dist/Dialogs.d.ts +42 -0
  16. package/dist/Dialogs.d.ts.map +1 -0
  17. package/dist/Dialogs.js +115 -0
  18. package/dist/Dialogs.js.map +1 -0
  19. package/dist/ExpressiveCard.d.ts +20 -0
  20. package/dist/ExpressiveCard.d.ts.map +1 -0
  21. package/dist/ExpressiveCard.js +71 -0
  22. package/dist/ExpressiveCard.js.map +1 -0
  23. package/dist/Fab.d.ts +16 -0
  24. package/dist/Fab.d.ts.map +1 -0
  25. package/dist/Fab.js +104 -0
  26. package/dist/Fab.js.map +1 -0
  27. package/dist/Fields.d.ts +90 -0
  28. package/dist/Fields.d.ts.map +1 -0
  29. package/dist/Fields.js +211 -0
  30. package/dist/Fields.js.map +1 -0
  31. package/dist/Grid.d.ts +8 -0
  32. package/dist/Grid.d.ts.map +1 -0
  33. package/dist/Grid.js +16 -0
  34. package/dist/Grid.js.map +1 -0
  35. package/dist/Inputs.d.ts +33 -0
  36. package/dist/Inputs.d.ts.map +1 -0
  37. package/dist/Inputs.js +172 -0
  38. package/dist/Inputs.js.map +1 -0
  39. package/dist/List.d.ts +20 -0
  40. package/dist/List.d.ts.map +1 -0
  41. package/dist/List.js +222 -0
  42. package/dist/List.js.map +1 -0
  43. package/dist/Menu.d.ts +26 -0
  44. package/dist/Menu.d.ts.map +1 -0
  45. package/dist/Menu.js +117 -0
  46. package/dist/Menu.js.map +1 -0
  47. package/dist/Navigation.d.ts +34 -0
  48. package/dist/Navigation.d.ts.map +1 -0
  49. package/dist/Navigation.js +80 -0
  50. package/dist/Navigation.js.map +1 -0
  51. package/dist/Pickers.d.ts +16 -0
  52. package/dist/Pickers.d.ts.map +1 -0
  53. package/dist/Pickers.js +100 -0
  54. package/dist/Pickers.js.map +1 -0
  55. package/dist/Progress.d.ts +20 -0
  56. package/dist/Progress.d.ts.map +1 -0
  57. package/dist/Progress.js +93 -0
  58. package/dist/Progress.js.map +1 -0
  59. package/dist/Search.d.ts +50 -0
  60. package/dist/Search.d.ts.map +1 -0
  61. package/dist/Search.js +121 -0
  62. package/dist/Search.js.map +1 -0
  63. package/dist/Sheets.d.ts +44 -0
  64. package/dist/Sheets.d.ts.map +1 -0
  65. package/dist/Sheets.js +128 -0
  66. package/dist/Sheets.js.map +1 -0
  67. package/dist/Toolbar.d.ts +13 -0
  68. package/dist/Toolbar.d.ts.map +1 -0
  69. package/dist/Toolbar.js +38 -0
  70. package/dist/Toolbar.js.map +1 -0
  71. package/dist/Transition.d.ts +34 -0
  72. package/dist/Transition.d.ts.map +1 -0
  73. package/dist/Transition.js +93 -0
  74. package/dist/Transition.js.map +1 -0
  75. package/dist/index.d.ts +21 -0
  76. package/dist/index.d.ts.map +1 -0
  77. package/dist/index.js +21 -0
  78. package/dist/index.js.map +1 -0
  79. package/dist/primitives.d.ts +41 -0
  80. package/dist/primitives.d.ts.map +1 -0
  81. package/dist/primitives.js +55 -0
  82. package/dist/primitives.js.map +1 -0
  83. package/dist/theme.d.ts +57 -0
  84. package/dist/theme.d.ts.map +1 -0
  85. package/dist/theme.js +89 -0
  86. package/dist/theme.js.map +1 -0
  87. package/package.json +53 -4
  88. package/src/Button.tsx +347 -0
  89. package/src/Carousel.tsx +108 -0
  90. package/src/Chips.tsx +292 -0
  91. package/src/Dialogs.tsx +252 -0
  92. package/src/ExpressiveCard.tsx +205 -0
  93. package/src/Fab.tsx +187 -0
  94. package/src/Fields.tsx +556 -0
  95. package/src/Grid.tsx +29 -0
  96. package/src/Inputs.tsx +290 -0
  97. package/src/List.tsx +295 -0
  98. package/src/Menu.tsx +238 -0
  99. package/src/Navigation.tsx +198 -0
  100. package/src/Pickers.tsx +151 -0
  101. package/src/Progress.tsx +192 -0
  102. package/src/Search.tsx +351 -0
  103. package/src/Sheets.tsx +273 -0
  104. package/src/Toolbar.tsx +88 -0
  105. package/src/Transition.tsx +155 -0
  106. package/src/index.ts +20 -0
  107. package/src/primitives.tsx +110 -0
  108. 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
+ }