@nexub/react-native 2.1.0 → 2.3.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 (52) hide show
  1. package/README.md +3 -1
  2. package/lib/module/components/containers.js +13 -5
  3. package/lib/module/components/containers.js.map +1 -1
  4. package/lib/module/components/display.js +33 -0
  5. package/lib/module/components/display.js.map +1 -1
  6. package/lib/module/components/feedback.js +65 -45
  7. package/lib/module/components/feedback.js.map +1 -1
  8. package/lib/module/components/inputs.js +101 -55
  9. package/lib/module/components/inputs.js.map +1 -1
  10. package/lib/module/components/mobile.js +70 -63
  11. package/lib/module/components/mobile.js.map +1 -1
  12. package/lib/module/components/overlays.js +5 -2
  13. package/lib/module/components/overlays.js.map +1 -1
  14. package/lib/module/index.js +1 -0
  15. package/lib/module/index.js.map +1 -1
  16. package/lib/module/patterns/home.js +201 -0
  17. package/lib/module/patterns/home.js.map +1 -0
  18. package/lib/module/patterns/index.js +1 -0
  19. package/lib/module/patterns/index.js.map +1 -1
  20. package/lib/module/primitives/Pressable.js +4 -2
  21. package/lib/module/primitives/Pressable.js.map +1 -1
  22. package/lib/module/theme/motion.js +60 -0
  23. package/lib/module/theme/motion.js.map +1 -0
  24. package/lib/typescript/components/containers.d.ts.map +1 -1
  25. package/lib/typescript/components/display.d.ts +7 -1
  26. package/lib/typescript/components/display.d.ts.map +1 -1
  27. package/lib/typescript/components/feedback.d.ts +4 -1
  28. package/lib/typescript/components/feedback.d.ts.map +1 -1
  29. package/lib/typescript/components/inputs.d.ts.map +1 -1
  30. package/lib/typescript/components/mobile.d.ts.map +1 -1
  31. package/lib/typescript/components/overlays.d.ts.map +1 -1
  32. package/lib/typescript/index.d.ts +2 -0
  33. package/lib/typescript/index.d.ts.map +1 -1
  34. package/lib/typescript/patterns/home.d.ts +50 -0
  35. package/lib/typescript/patterns/home.d.ts.map +1 -0
  36. package/lib/typescript/patterns/index.d.ts +2 -0
  37. package/lib/typescript/patterns/index.d.ts.map +1 -1
  38. package/lib/typescript/primitives/Pressable.d.ts.map +1 -1
  39. package/lib/typescript/theme/motion.d.ts +70 -0
  40. package/lib/typescript/theme/motion.d.ts.map +1 -0
  41. package/package.json +4 -4
  42. package/src/components/containers.tsx +17 -6
  43. package/src/components/display.tsx +31 -0
  44. package/src/components/feedback.tsx +23 -4
  45. package/src/components/inputs.tsx +59 -11
  46. package/src/components/mobile.tsx +8 -4
  47. package/src/components/overlays.tsx +4 -1
  48. package/src/index.ts +2 -0
  49. package/src/patterns/home.tsx +211 -0
  50. package/src/patterns/index.ts +2 -0
  51. package/src/primitives/Pressable.tsx +4 -1
  52. package/src/theme/motion.ts +83 -0
@@ -0,0 +1,211 @@
1
+ import * as React from 'react';
2
+ import { View } from 'react-native';
3
+ import { moneyFormatter } from '@nexub/core';
4
+ import type { NativeIconProps } from '@nexub/icons/native';
5
+ import { Button } from '../components/actions';
6
+ import { Card, ListItem, ListSection } from '../components/containers';
7
+ import { Amount, Avatar, Badge } from '../components/display';
8
+ import { RefreshControl } from '../components/mobile';
9
+ import { Pressable } from '../primitives/Pressable';
10
+ import { ScreenContainer } from '../primitives/ScreenContainer';
11
+ import { Heading, Text } from '../primitives/Text';
12
+ import { useTheme } from '../theme/ThemeProvider';
13
+ import type { Transaction } from './money';
14
+
15
+ export interface QuickAction {
16
+ id: string;
17
+ label: string;
18
+ icon?: React.ComponentType<NativeIconProps>;
19
+ onPress: () => void;
20
+ }
21
+
22
+ export interface Insight {
23
+ id: string;
24
+ title: string;
25
+ body: string;
26
+ action?: { label: string; onPress: () => void };
27
+ }
28
+
29
+ export interface HomeScreenProps {
30
+ /** e.g. "Good morning, Mei". Leave out when the native header shows the title. */
31
+ greeting?: string;
32
+ balance: { value: number; currency: string; label?: string };
33
+ /** Send, Add money, Request… Up to four fit one row. */
34
+ quickActions?: QuickAction[];
35
+ /** The latest few transactions. */
36
+ recent?: Transaction[];
37
+ onTransactionPress?: (t: Transaction) => void;
38
+ /** Shows "See all" beside Recent activity. */
39
+ onSeeAllActivity?: () => void;
40
+ insights?: Insight[];
41
+ onRefresh?: () => void;
42
+ refreshing?: boolean;
43
+ /** Copy overrides. */
44
+ labels?: Partial<{ totalBalance: string; recentActivity: string; seeAll: string; insights: string }>;
45
+ }
46
+
47
+ /**
48
+ * Money-app home (Payub): balance hero with quick actions, recent activity,
49
+ * insights and pull-to-refresh. Web twin: `DashboardPage` in @nexub/patterns.
50
+ */
51
+ export function HomeScreen({
52
+ greeting,
53
+ balance,
54
+ quickActions = [],
55
+ recent = [],
56
+ onTransactionPress,
57
+ onSeeAllActivity,
58
+ insights = [],
59
+ onRefresh,
60
+ refreshing = false,
61
+ labels,
62
+ }: HomeScreenProps) {
63
+ const { roles, tokens, locale } = useTheme();
64
+ const l = {
65
+ totalBalance: 'Total balance',
66
+ recentActivity: 'Recent activity',
67
+ seeAll: 'See all',
68
+ insights: 'Insights',
69
+ ...labels,
70
+ };
71
+ const balanceLabel = balance.label ?? l.totalBalance;
72
+
73
+ return (
74
+ <ScreenContainer
75
+ gap="6"
76
+ refreshControl={
77
+ onRefresh ? <RefreshControl refreshing={refreshing} onRefresh={onRefresh} /> : undefined
78
+ }
79
+ >
80
+ {greeting && <Heading variant="headline-sm">{greeting}</Heading>}
81
+
82
+ <Card tone="surface-container" style={{ padding: tokens.spacing[5], gap: tokens.spacing[5] }}>
83
+ <View
84
+ accessible
85
+ accessibilityLabel={`${balanceLabel}, ${moneyFormatter(balance.currency, locale).format(balance.value)}`}
86
+ style={{ gap: tokens.spacing[1] }}
87
+ >
88
+ <Text variant="label-lg" color="on-surface-variant">
89
+ {balanceLabel}
90
+ </Text>
91
+ <Amount value={balance.value} currency={balance.currency} locale={locale} size="display" />
92
+ </View>
93
+ {quickActions.length > 0 && (
94
+ <View style={{ flexDirection: 'row', justifyContent: 'space-between', gap: tokens.spacing[2] }}>
95
+ {quickActions.slice(0, 4).map((a) => {
96
+ const Icon = a.icon;
97
+ return (
98
+ <Pressable
99
+ key={a.id}
100
+ accessibilityRole="button"
101
+ accessibilityLabel={a.label}
102
+ haptic="selection"
103
+ onPress={a.onPress}
104
+ style={{
105
+ flex: 1,
106
+ alignItems: 'center',
107
+ gap: tokens.spacing[2],
108
+ paddingVertical: tokens.spacing[2],
109
+ borderRadius: tokens.shape.container,
110
+ }}
111
+ >
112
+ <View
113
+ style={{
114
+ width: 48,
115
+ height: 48,
116
+ borderRadius: 24,
117
+ alignItems: 'center',
118
+ justifyContent: 'center',
119
+ backgroundColor: roles['primary-container'],
120
+ }}
121
+ >
122
+ {Icon && <Icon size="md" color={roles['on-primary-container']} />}
123
+ </View>
124
+ <Text variant="label-md" numberOfLines={1}>
125
+ {a.label}
126
+ </Text>
127
+ </Pressable>
128
+ );
129
+ })}
130
+ </View>
131
+ )}
132
+ </Card>
133
+
134
+ {recent.length > 0 && (
135
+ <View style={{ gap: tokens.spacing[2] }}>
136
+ <View
137
+ style={{
138
+ flexDirection: 'row',
139
+ alignItems: 'center',
140
+ justifyContent: 'space-between',
141
+ paddingStart: tokens.spacing[4],
142
+ }}
143
+ >
144
+ <Text variant="title-sm" color="on-surface-variant" accessibilityRole="header">
145
+ {l.recentActivity}
146
+ </Text>
147
+ {onSeeAllActivity && (
148
+ <Button variant="text" size="sm" onPress={onSeeAllActivity}>
149
+ {l.seeAll}
150
+ </Button>
151
+ )}
152
+ </View>
153
+ <ListSection inset={68}>
154
+ {recent.map((t) => (
155
+ <ListItem
156
+ key={t.id}
157
+ title={t.title}
158
+ subtitle={t.subtitle}
159
+ leading={<Avatar name={t.title} src={t.image} />}
160
+ trailing={
161
+ <View style={{ alignItems: 'flex-end', gap: 2 }}>
162
+ <Amount
163
+ value={t.amount}
164
+ currency={t.currency}
165
+ locale={locale}
166
+ tone="auto"
167
+ signDisplay="exceptZero"
168
+ />
169
+ {t.status && (
170
+ <Badge tone={t.status === 'failed' ? 'danger' : 'warning'} size="sm">
171
+ {t.status === 'failed' ? 'Failed' : 'Pending'}
172
+ </Badge>
173
+ )}
174
+ </View>
175
+ }
176
+ variant={onTransactionPress ? 'navigation' : 'static'}
177
+ onPress={onTransactionPress && (() => onTransactionPress(t))}
178
+ />
179
+ ))}
180
+ </ListSection>
181
+ </View>
182
+ )}
183
+
184
+ {insights.length > 0 && (
185
+ <View style={{ gap: tokens.spacing[3] }}>
186
+ <Text
187
+ variant="title-sm"
188
+ color="on-surface-variant"
189
+ accessibilityRole="header"
190
+ style={{ paddingHorizontal: tokens.spacing[4] }}
191
+ >
192
+ {l.insights}
193
+ </Text>
194
+ {insights.map((i) => (
195
+ <Card key={i.id}>
196
+ <Text variant="title-sm">{i.title}</Text>
197
+ <Text variant="body-sm" color="on-surface-variant">
198
+ {i.body}
199
+ </Text>
200
+ {i.action && (
201
+ <Button variant="text" size="sm" onPress={i.action.onPress} style={{ alignSelf: 'flex-start' }}>
202
+ {i.action.label}
203
+ </Button>
204
+ )}
205
+ </Card>
206
+ ))}
207
+ </View>
208
+ )}
209
+ </ScreenContainer>
210
+ );
211
+ }
@@ -1,4 +1,6 @@
1
1
  // @nexub/react-native/patterns — screen templates built only from public components.
2
+ export { HomeScreen } from './home';
3
+ export type { HomeScreenProps, QuickAction, Insight } from './home';
2
4
  export { AuthScreen, SignInScreen, VerifyCodeScreen, LockScreen } from './auth';
3
5
  export type {
4
6
  AuthScreenProps,
@@ -11,6 +11,9 @@ import {
11
11
  import Animated, { useAnimatedStyle, useSharedValue, withSpring } from 'react-native-reanimated';
12
12
  import type { HapticToken } from '../theme/haptics';
13
13
  import { useHaptics, useTheme, type RoleName } from '../theme/ThemeProvider';
14
+ import { nxSpring } from '../theme/motion';
15
+
16
+ const PRESS_SPRING = nxSpring('spatial', 'fast');
14
17
 
15
18
  // The touchable itself animates and takes `style`, so layout props (flex,
16
19
  // position, margins) apply to the element that sits in the parent's layout.
@@ -48,7 +51,7 @@ export function Pressable({
48
51
  const { roles, tokens } = useTheme();
49
52
  const play = useHaptics();
50
53
  const pressed = useSharedValue(0);
51
- const spring = tokens.motion.spring.spatial.fast;
54
+ const spring = PRESS_SPRING;
52
55
  const opacity = tokens.state.pressed;
53
56
  const scale = pressScale === false ? 1 : pressScale;
54
57
 
@@ -0,0 +1,83 @@
1
+ import {
2
+ FadeIn,
3
+ FadeInDown,
4
+ FadeInUp,
5
+ FadeOut,
6
+ FadeOutDown,
7
+ FadeOutUp,
8
+ LinearTransition,
9
+ ReduceMotion,
10
+ SlideOutLeft,
11
+ SlideOutRight,
12
+ ZoomIn,
13
+ ZoomOut,
14
+ } from 'react-native-reanimated';
15
+ import { native } from '@nexub/tokens/native';
16
+
17
+ // Layout-animation presets built from the same spring tokens as the web
18
+ // (`motion.spring.*` → CSS linear() there, Reanimated springs here).
19
+ // Enter rides `spatial` (position and size, a hair of settle); exit is quicker
20
+ // on `effects` and never overshoots. Every preset honours the OS Reduce Motion
21
+ // setting (ReduceMotion.System): the change lands without travel.
22
+
23
+ export type SpringFamily = keyof typeof native.motion.spring;
24
+ export type SpringSpeed = keyof (typeof native.motion.spring)['spatial'];
25
+
26
+ /** `withSpring` config for a spring token, honouring Reduce Motion. */
27
+ export function nxSpring(family: SpringFamily = 'spatial', speed: SpringSpeed = 'default') {
28
+ return { ...native.motion.spring[family][speed], reduceMotion: ReduceMotion.System };
29
+ }
30
+
31
+ export type EnterKind = 'fade' | 'up' | 'down' | 'scale';
32
+ export type ExitKind = 'fade' | 'up' | 'down' | 'scale' | 'start' | 'end';
33
+
34
+ const ENTER = { fade: FadeIn, up: FadeInUp, down: FadeInDown, scale: ZoomIn } as const;
35
+ const EXIT = { fade: FadeOut, up: FadeOutUp, down: FadeOutDown, scale: ZoomOut } as const;
36
+
37
+ /**
38
+ * `entering` animation on the spatial spring.
39
+ * `up` rises into place (rows, toasts from below); `down` drops in (banners).
40
+ *
41
+ * ```tsx
42
+ * <Animated.View entering={nxEnter('up')} exiting={nxExit('down')} layout={nxLayout()} />
43
+ * ```
44
+ */
45
+ export function nxEnter(kind: EnterKind = 'fade', speed: SpringSpeed = 'default') {
46
+ const s = native.motion.spring.spatial[speed];
47
+ return ENTER[kind]
48
+ .springify()
49
+ .stiffness(s.stiffness)
50
+ .damping(s.damping)
51
+ .mass(s.mass)
52
+ .reduceMotion(ReduceMotion.System);
53
+ }
54
+
55
+ /**
56
+ * `exiting` animation on the effects spring: quicker than enter, no overshoot.
57
+ * `start` / `end` slide out toward that edge (swipe-to-delete), following RTL.
58
+ */
59
+ export function nxExit(kind: ExitKind = 'fade', speed: SpringSpeed = 'fast', rtl = false) {
60
+ const s = native.motion.spring.effects[speed];
61
+ const builder =
62
+ kind === 'start' || kind === 'end'
63
+ ? (kind === 'start') !== rtl
64
+ ? SlideOutLeft
65
+ : SlideOutRight
66
+ : EXIT[kind];
67
+ return builder
68
+ .springify()
69
+ .stiffness(s.stiffness)
70
+ .damping(s.damping)
71
+ .mass(s.mass)
72
+ .reduceMotion(ReduceMotion.System);
73
+ }
74
+
75
+ /** `layout` transition: siblings glide to their new place on the spatial spring. */
76
+ export function nxLayout(speed: SpringSpeed = 'default') {
77
+ const s = native.motion.spring.spatial[speed];
78
+ return LinearTransition.springify()
79
+ .stiffness(s.stiffness)
80
+ .damping(s.damping)
81
+ .mass(s.mass)
82
+ .reduceMotion(ReduceMotion.System);
83
+ }