@webority-technologies/mobile 0.0.6 → 0.0.7
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 +3 -463
- package/lib/commonjs/components/Skeleton/Skeleton.js +20 -12
- package/lib/commonjs/components/Skeleton/SkeletonContent.js +25 -9
- package/lib/commonjs/components/Skeleton/SkeletonList.js +7 -2
- package/lib/commonjs/components/Skeleton/SkeletonProvider.js +48 -0
- package/lib/commonjs/components/Skeleton/SkeletonSkip.js +37 -0
- package/lib/commonjs/components/Skeleton/index.js +20 -0
- package/lib/commonjs/components/index.js +18 -0
- package/lib/module/components/Skeleton/Skeleton.js +20 -12
- package/lib/module/components/Skeleton/SkeletonContent.js +25 -9
- package/lib/module/components/Skeleton/SkeletonList.js +7 -2
- package/lib/module/components/Skeleton/SkeletonProvider.js +41 -0
- package/lib/module/components/Skeleton/SkeletonSkip.js +31 -0
- package/lib/module/components/Skeleton/index.js +2 -0
- package/lib/module/components/index.js +1 -1
- package/lib/typescript/commonjs/components/Skeleton/Skeleton.d.ts +9 -0
- package/lib/typescript/commonjs/components/Skeleton/SkeletonContent.d.ts +6 -0
- package/lib/typescript/commonjs/components/Skeleton/SkeletonList.d.ts +3 -0
- package/lib/typescript/commonjs/components/Skeleton/SkeletonProvider.d.ts +32 -0
- package/lib/typescript/commonjs/components/Skeleton/SkeletonSkip.d.ts +25 -0
- package/lib/typescript/commonjs/components/Skeleton/index.d.ts +4 -0
- package/lib/typescript/commonjs/components/index.d.ts +2 -2
- package/lib/typescript/module/components/Skeleton/Skeleton.d.ts +9 -0
- package/lib/typescript/module/components/Skeleton/SkeletonContent.d.ts +6 -0
- package/lib/typescript/module/components/Skeleton/SkeletonList.d.ts +3 -0
- package/lib/typescript/module/components/Skeleton/SkeletonProvider.d.ts +32 -0
- package/lib/typescript/module/components/Skeleton/SkeletonSkip.d.ts +25 -0
- package/lib/typescript/module/components/Skeleton/index.d.ts +4 -0
- package/lib/typescript/module/components/index.d.ts +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,471 +1,11 @@
|
|
|
1
1
|
# @webority-technologies/mobile
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
`v0.0.1` · MIT · React Native 0.81+ · React 19 · TypeScript strict
|
|
6
|
-
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
## Install
|
|
3
|
+
Internal React Native foundation for Webority projects — UI components, theme, API client, auth, logging, storage, formatters, validators, network, permissions, and version-check in one package.
|
|
10
4
|
|
|
11
5
|
```bash
|
|
12
6
|
npm install @webority-technologies/mobile
|
|
13
7
|
```
|
|
14
8
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
`react` 19.1 and `react-native` 0.81+ are required. Everything else is **optional** — install only what the modules you use need:
|
|
18
|
-
|
|
19
|
-
| Peer dep | Needed for |
|
|
20
|
-
| ------------------------------------------------- | ----------------------------------------------------------------- |
|
|
21
|
-
| `react-native-reanimated` (3.x) | `BottomSheet`, `Drawer`, `Swipeable` (others use native Animated) |
|
|
22
|
-
| `react-native-gesture-handler` (2.x) | `BottomSheet`, swipe-to-dismiss interactions |
|
|
23
|
-
| `react-native-safe-area-context` (5.x) | Layout components, modals, toast positioning |
|
|
24
|
-
| `react-native-vector-icons` (10.x) | Icon-bearing components (`Button`, `Avatar`, etc.) |
|
|
25
|
-
| `@react-native-async-storage/async-storage` (2.x) | `Storage` module + token persistence |
|
|
26
|
-
| `react-native-keychain` (9.x) | Secure credential storage (`storeToken` / `getToken`) |
|
|
27
|
-
| `react-native-device-info` (14.x) | `versionCheck` helpers |
|
|
28
|
-
| `@react-native-community/netinfo` (11.x) | `useNetworkStatus`, `NetworkStatusBanner` |
|
|
29
|
-
| `react-native-permissions` (4.x) | `Permissions` module |
|
|
30
|
-
| `react-native-compressor` (1.10+) | `compressImage` utility |
|
|
31
|
-
|
|
32
|
-
```bash
|
|
33
|
-
npm install react-native-reanimated \
|
|
34
|
-
react-native-gesture-handler \
|
|
35
|
-
react-native-safe-area-context \
|
|
36
|
-
react-native-vector-icons \
|
|
37
|
-
@react-native-async-storage/async-storage \
|
|
38
|
-
react-native-keychain \
|
|
39
|
-
react-native-device-info \
|
|
40
|
-
@react-native-community/netinfo \
|
|
41
|
-
react-native-permissions \
|
|
42
|
-
react-native-compressor
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
Follow each library's native-setup steps (Reanimated babel plugin, Gesture Handler import at the top of the entry file, vector-icons font linking, etc.).
|
|
46
|
-
|
|
47
|
-
---
|
|
48
|
-
|
|
49
|
-
## Setup
|
|
50
|
-
|
|
51
|
-
Wrap the app with `GestureHandlerRootView`, `SafeAreaProvider`, `ThemeProvider`, and `ToastProvider`. Initialize the SDK once at module scope.
|
|
52
|
-
|
|
53
|
-
```tsx
|
|
54
|
-
// App.tsx
|
|
55
|
-
import 'react-native-gesture-handler';
|
|
56
|
-
import React from 'react';
|
|
57
|
-
import { GestureHandlerRootView } from 'react-native-gesture-handler';
|
|
58
|
-
import { SafeAreaProvider } from 'react-native-safe-area-context';
|
|
59
|
-
import {
|
|
60
|
-
initWebority,
|
|
61
|
-
initUserAuth,
|
|
62
|
-
ThemeProvider,
|
|
63
|
-
ToastProvider,
|
|
64
|
-
NetworkStatusBanner
|
|
65
|
-
} from '@webority-technologies/mobile';
|
|
66
|
-
import store from './store';
|
|
67
|
-
import { logout, refreshToken } from './store/auth';
|
|
68
|
-
|
|
69
|
-
initWebority({
|
|
70
|
-
baseUrl: 'https://api.example.com',
|
|
71
|
-
environment: __DEV__ ? 'Development' : 'Production',
|
|
72
|
-
country: 'in' // optional, defaults to 'in'
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
initUserAuth(store, { logout, refreshToken });
|
|
76
|
-
|
|
77
|
-
export default function App(): JSX.Element {
|
|
78
|
-
return (
|
|
79
|
-
<GestureHandlerRootView style={{ flex: 1 }}>
|
|
80
|
-
<SafeAreaProvider>
|
|
81
|
-
<ThemeProvider>
|
|
82
|
-
<ToastProvider>
|
|
83
|
-
<NetworkStatusBanner />
|
|
84
|
-
{/* your screens */}
|
|
85
|
-
</ToastProvider>
|
|
86
|
-
</ThemeProvider>
|
|
87
|
-
</SafeAreaProvider>
|
|
88
|
-
</GestureHandlerRootView>
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
`initUI` is also exported for advanced setups that need to register UI-only globals (theme overrides, default color mode) without the API/auth side of the SDK.
|
|
94
|
-
|
|
95
|
-
---
|
|
96
|
-
|
|
97
|
-
## API surface
|
|
98
|
-
|
|
99
|
-
```ts
|
|
100
|
-
import {
|
|
101
|
-
// bootstrap
|
|
102
|
-
initWebority,
|
|
103
|
-
initUserAuth,
|
|
104
|
-
initUI,
|
|
105
|
-
|
|
106
|
-
// configuration
|
|
107
|
-
setConfig,
|
|
108
|
-
getConfig,
|
|
109
|
-
getConfigValue,
|
|
110
|
-
resetConfig,
|
|
111
|
-
|
|
112
|
-
// theme
|
|
113
|
-
ThemeProvider,
|
|
114
|
-
useTheme,
|
|
115
|
-
useThemeMode,
|
|
116
|
-
mergeTheme,
|
|
117
|
-
lightTheme,
|
|
118
|
-
darkTheme,
|
|
119
|
-
|
|
120
|
-
// hooks
|
|
121
|
-
useToggle,
|
|
122
|
-
useDebounce,
|
|
123
|
-
usePressAnimation,
|
|
124
|
-
|
|
125
|
-
// http
|
|
126
|
-
publicClient,
|
|
127
|
-
userClient,
|
|
128
|
-
|
|
129
|
-
// auth
|
|
130
|
-
storeToken,
|
|
131
|
-
getToken,
|
|
132
|
-
removeToken,
|
|
133
|
-
decodeJWT,
|
|
134
|
-
isJWTExpired,
|
|
135
|
-
getJWTExpiry,
|
|
136
|
-
|
|
137
|
-
// storage
|
|
138
|
-
Storage,
|
|
139
|
-
setStorageImplementation,
|
|
140
|
-
|
|
141
|
-
// logger + remote sink (Crashlytics / Sentry adapter)
|
|
142
|
-
Logger,
|
|
143
|
-
setRemoteLogger,
|
|
144
|
-
|
|
145
|
-
// version + force update
|
|
146
|
-
VersionCheck,
|
|
147
|
-
useVersionCheck,
|
|
148
|
-
ForceUpdateDialog,
|
|
149
|
-
|
|
150
|
-
// network
|
|
151
|
-
useNetworkStatus,
|
|
152
|
-
getNetworkStatus,
|
|
153
|
-
NetworkStatusBanner,
|
|
154
|
-
|
|
155
|
-
// permissions
|
|
156
|
-
Permissions,
|
|
157
|
-
|
|
158
|
-
// formatters
|
|
159
|
-
formatDate,
|
|
160
|
-
formatTime,
|
|
161
|
-
formatRelativeTime,
|
|
162
|
-
formatPhone,
|
|
163
|
-
formatCurrency,
|
|
164
|
-
formatNumber,
|
|
165
|
-
formatPercent,
|
|
166
|
-
formatCompactNumber,
|
|
167
|
-
getInitials,
|
|
168
|
-
|
|
169
|
-
// validators
|
|
170
|
-
isEmail,
|
|
171
|
-
isIndianMobile,
|
|
172
|
-
isPhone,
|
|
173
|
-
isUrl,
|
|
174
|
-
isStrongPassword,
|
|
175
|
-
isPan,
|
|
176
|
-
isGstin,
|
|
177
|
-
isAadhaar,
|
|
178
|
-
isIfsc,
|
|
179
|
-
isIndianPincode,
|
|
180
|
-
isHexColor,
|
|
181
|
-
isNumeric,
|
|
182
|
-
isInteger,
|
|
183
|
-
isAlphanumeric,
|
|
184
|
-
isBetween,
|
|
185
|
-
minLength,
|
|
186
|
-
maxLength,
|
|
187
|
-
|
|
188
|
-
// utilities
|
|
189
|
-
Responsive,
|
|
190
|
-
Spacing,
|
|
191
|
-
Padding,
|
|
192
|
-
Margin,
|
|
193
|
-
isTablet,
|
|
194
|
-
shadowStyle,
|
|
195
|
-
triggerHaptic,
|
|
196
|
-
compressImage,
|
|
197
|
-
|
|
198
|
-
// toast
|
|
199
|
-
ToastProvider,
|
|
200
|
-
toast,
|
|
201
|
-
useToast
|
|
202
|
-
|
|
203
|
-
// …41 UI components
|
|
204
|
-
} from '@webority-technologies/mobile';
|
|
205
|
-
```
|
|
206
|
-
|
|
207
|
-
---
|
|
208
|
-
|
|
209
|
-
## HTTP clients
|
|
210
|
-
|
|
211
|
-
### `publicClient`
|
|
212
|
-
|
|
213
|
-
Axios instance for unauthenticated calls. Handles retries (network errors, 429, 503), 30s timeout, environment-aware base URL, and standard headers (including gzip `Accept-Encoding`).
|
|
214
|
-
|
|
215
|
-
### `userClient`
|
|
216
|
-
|
|
217
|
-
Axios instance for authenticated calls. Injects a Bearer token from Keychain, queues concurrent 401s while a single refresh is in flight, and replays them on success. Wires into the host app's Redux store via `initUserAuth(store, { logout, refreshToken })`.
|
|
218
|
-
|
|
219
|
-
---
|
|
220
|
-
|
|
221
|
-
## Auth & tokens
|
|
222
|
-
|
|
223
|
-
```ts
|
|
224
|
-
import {
|
|
225
|
-
storeToken,
|
|
226
|
-
getToken,
|
|
227
|
-
removeToken,
|
|
228
|
-
decodeJWT,
|
|
229
|
-
isJWTExpired
|
|
230
|
-
} from '@webority-technologies/mobile';
|
|
231
|
-
|
|
232
|
-
await storeToken('accessToken', token, expiry);
|
|
233
|
-
const stored = await getToken('accessToken'); // { token, expiry } | null
|
|
234
|
-
if (stored && isJWTExpired(stored.token)) {
|
|
235
|
-
/* refresh */
|
|
236
|
-
}
|
|
237
|
-
const claims = decodeJWT<{ sub: string; role: string }>(stored.token);
|
|
238
|
-
```
|
|
239
|
-
|
|
240
|
-
Tokens are persisted via `react-native-keychain` with biometry-friendly defaults and graceful recovery from "Key permanently invalidated" errors.
|
|
241
|
-
|
|
242
|
-
---
|
|
243
|
-
|
|
244
|
-
## Storage
|
|
245
|
-
|
|
246
|
-
Typed `AsyncStorage` wrapper with safe JSON helpers. All operations swallow errors (logging them) and return falsy results so storage failures never crash the app.
|
|
247
|
-
|
|
248
|
-
```ts
|
|
249
|
-
import { Storage } from '@webority-technologies/mobile';
|
|
250
|
-
|
|
251
|
-
await Storage.setItem('lang', 'en');
|
|
252
|
-
const lang = await Storage.getItem('lang'); // string | null
|
|
253
|
-
|
|
254
|
-
await Storage.setJson('user', { id: '1', name: 'Navneet' });
|
|
255
|
-
const user = await Storage.getJson<User>('user'); // User | null
|
|
256
|
-
|
|
257
|
-
await Storage.multiSet({ pushToken: '…', deviceId: '…' });
|
|
258
|
-
await Storage.multiRemove(['pushToken']);
|
|
259
|
-
```
|
|
260
|
-
|
|
261
|
-
Override the backend (e.g. with MMKV) via `setStorageImplementation()`.
|
|
262
|
-
|
|
263
|
-
---
|
|
264
|
-
|
|
265
|
-
## Logger & crash reporting
|
|
266
|
-
|
|
267
|
-
`Logger.info / warn / error` write to the console. `Logger.recordError`, `Logger.breadcrumb`, `Logger.setUser`, and `Logger.setAttribute` forward to an optional **remote sink** that you wire from your app — keeping the library Firebase- and Sentry-agnostic.
|
|
268
|
-
|
|
269
|
-
```ts
|
|
270
|
-
import { Logger, setRemoteLogger } from '@webority-technologies/mobile';
|
|
271
|
-
import crashlytics from '@react-native-firebase/crashlytics';
|
|
272
|
-
|
|
273
|
-
setRemoteLogger({
|
|
274
|
-
log: (level, message) => crashlytics().log(`[${level}] ${message}`),
|
|
275
|
-
recordError: (error, ctx) => {
|
|
276
|
-
if (ctx) Object.entries(ctx).forEach(([k, v]) => crashlytics().setAttribute(k, String(v)));
|
|
277
|
-
crashlytics().recordError(error instanceof Error ? error : new Error(String(error)));
|
|
278
|
-
},
|
|
279
|
-
breadcrumb: (msg, data) => crashlytics().log(data ? `${msg} ${JSON.stringify(data)}` : msg),
|
|
280
|
-
setUser: (id) => crashlytics().setUserId(id ?? ''),
|
|
281
|
-
setAttribute: (k, v) => crashlytics().setAttribute(k, v == null ? '' : String(v))
|
|
282
|
-
});
|
|
283
|
-
|
|
284
|
-
Logger.recordError(new Error('boom'), { route: '/checkout', orderId: 42 });
|
|
285
|
-
```
|
|
286
|
-
|
|
287
|
-
The same shape works for Sentry, Bugsnag, Datadog, or any custom backend — implement only the methods you need.
|
|
288
|
-
|
|
289
|
-
---
|
|
290
|
-
|
|
291
|
-
## Version check & force update
|
|
292
|
-
|
|
293
|
-
```tsx
|
|
294
|
-
import { useVersionCheck, ForceUpdateDialog } from '@webority-technologies/mobile';
|
|
295
|
-
|
|
296
|
-
const { isUpdateRequired, updateUrl } = useVersionCheck(isAppReady);
|
|
297
|
-
return <ForceUpdateDialog visible={isUpdateRequired} mandatory updateUrl={updateUrl} />;
|
|
298
|
-
```
|
|
299
|
-
|
|
300
|
-
`useVersionCheck` only runs in `'Production'`. Country code (used for App Store / Play Store lookups) is configurable via `initWebority({ country: 'us' })`; defaults to `'in'`.
|
|
301
|
-
|
|
302
|
-
---
|
|
303
|
-
|
|
304
|
-
## Network status
|
|
305
|
-
|
|
306
|
-
```tsx
|
|
307
|
-
import { useNetworkStatus, NetworkStatusBanner } from '@webority-technologies/mobile';
|
|
308
|
-
|
|
309
|
-
// Mount once near the app root
|
|
310
|
-
<NetworkStatusBanner />;
|
|
311
|
-
|
|
312
|
-
// Or read it inside a screen
|
|
313
|
-
const { isConnected, isInternetReachable, type } = useNetworkStatus();
|
|
314
|
-
```
|
|
315
|
-
|
|
316
|
-
Falls back to an optimistic "online" status when `@react-native-community/netinfo` is not installed.
|
|
317
|
-
|
|
318
|
-
---
|
|
319
|
-
|
|
320
|
-
## Permissions
|
|
321
|
-
|
|
322
|
-
```ts
|
|
323
|
-
import { Permissions } from '@webority-technologies/mobile';
|
|
324
|
-
|
|
325
|
-
await Permissions.isAuthorized('camera'); // boolean
|
|
326
|
-
const status = await Permissions.ensure('photos'); // 'granted' | 'denied' | 'limited' | 'blocked' | 'unavailable'
|
|
327
|
-
if (status === 'blocked') await Permissions.openSettings();
|
|
328
|
-
```
|
|
329
|
-
|
|
330
|
-
Maps an abstract `PermissionKind` (camera, microphone, photos, location, contacts, calendar, notifications, bluetooth, …) to the right iOS / Android permission string under the hood.
|
|
331
|
-
|
|
332
|
-
---
|
|
333
|
-
|
|
334
|
-
## Formatters
|
|
335
|
-
|
|
336
|
-
```ts
|
|
337
|
-
formatDate(new Date(), 'medium'); // '8 Apr 2026'
|
|
338
|
-
formatRelativeTime(then, now); // '5 minutes ago'
|
|
339
|
-
formatPhone('9876512345'); // '+91 98765 12345'
|
|
340
|
-
formatCurrency(150000); // '₹1,50,000'
|
|
341
|
-
formatCurrency(99, { currency: 'USD', locale: 'en-US' }); // '$99.00'
|
|
342
|
-
formatCompactNumber(1500000); // '15L' (en-IN)
|
|
343
|
-
getInitials('Navneet Singh'); // 'NS'
|
|
344
|
-
```
|
|
345
|
-
|
|
346
|
-
All formatters default to `en-IN` locale (Indian numbering / DD-MMM-YYYY style) and accept overrides.
|
|
347
|
-
|
|
348
|
-
---
|
|
349
|
-
|
|
350
|
-
## Validators
|
|
351
|
-
|
|
352
|
-
Pragmatic regex-based validators that match common Indian-app needs:
|
|
353
|
-
|
|
354
|
-
```ts
|
|
355
|
-
isEmail('a@b.co'); // true
|
|
356
|
-
isIndianMobile('+919876512345'); // true
|
|
357
|
-
isPan('ABCDE1234F'); // true
|
|
358
|
-
isGstin('27AAPFU0939F1ZV'); // true
|
|
359
|
-
isIfsc('HDFC0001234'); // true
|
|
360
|
-
isIndianPincode('110001'); // true
|
|
361
|
-
isStrongPassword('Aa1!@#$%', { requireSymbol: true }); // true
|
|
362
|
-
```
|
|
363
|
-
|
|
364
|
-
Plus generic helpers: `isUrl`, `isNumeric`, `isInteger`, `isAlphanumeric`, `isHexColor`, `isBetween`, `minLength`, `maxLength`.
|
|
365
|
-
|
|
366
|
-
---
|
|
367
|
-
|
|
368
|
-
## Theme
|
|
369
|
-
|
|
370
|
-
`ThemeProvider` exposes the design-token surface (colors, typography, spacing, radius, shadows, motion) and tracks the system color-scheme automatically. Read it via `useTheme()`. Every shipped component reads from the active theme — no hard-coded colors anywhere. Customize with `mergeTheme` or `initUI({ light, dark })`.
|
|
371
|
-
|
|
372
|
-
---
|
|
373
|
-
|
|
374
|
-
## Toast
|
|
375
|
-
|
|
376
|
-
Imperative `toast.success(...)` / `toast.error(...)` from anywhere in the tree, or `useToast().show(...)` inside components.
|
|
377
|
-
|
|
378
|
-
```ts
|
|
379
|
-
toast.success('Saved.');
|
|
380
|
-
toast.error('Network is down', { description: 'Check your connection.' });
|
|
381
|
-
```
|
|
382
|
-
|
|
383
|
-
Mount `<ToastProvider>` once near the app root.
|
|
384
|
-
|
|
385
|
-
---
|
|
386
|
-
|
|
387
|
-
## Components
|
|
388
|
-
|
|
389
|
-
41 components across Layout, Forms & Inputs, Feedback & Status, Overlay, Navigation, and Data Display.
|
|
390
|
-
|
|
391
|
-
For the full catalog with props tables and minimal usage examples, see [`docs/COMPONENTS.md`](../../docs/COMPONENTS.md).
|
|
392
|
-
|
|
393
|
-
For runnable usage of every component, see [`example/`](../../example/).
|
|
394
|
-
|
|
395
|
-
---
|
|
396
|
-
|
|
397
|
-
## Designing skeleton-aware components
|
|
398
|
-
|
|
399
|
-
Presentational primitives (`Card`, `ListItem`, `Avatar`, `Badge`, `Banner`, `Chip`,
|
|
400
|
-
`Rating`, `Stepper`, `ImageGallery`) accept an optional
|
|
401
|
-
`loading?: boolean` prop. When `true`, the component renders its normal layout wrapped
|
|
402
|
-
in `<SkeletonContent loading mode="auto">` — the walker replaces every `<Text>`,
|
|
403
|
-
`<Image>`, and sized leaf `<View>` with a shimmer block matching the element's
|
|
404
|
-
dimensions. When `loading` is `false` or omitted, behaviour is unchanged.
|
|
405
|
-
|
|
406
|
-
Conventions for components that opt into this pattern:
|
|
407
|
-
|
|
408
|
-
- **Render gracefully with undefined data.** Use optional chaining and string defaults
|
|
409
|
-
so the auto walker has leaves to skeletonize even before data arrives:
|
|
410
|
-
`{item?.title ?? ' '}`, `{item?.subtitle ?? ' '}`. Never let a `<Text>` render `undefined`.
|
|
411
|
-
- **Use explicit dimensions on visual elements.** Set `width`/`height` on `<Image>` and
|
|
412
|
-
`<View>` leaves, and `fontSize` on `<Text>`, so the walker can size each shimmer
|
|
413
|
-
block correctly. Inline styles, `StyleSheet.create`, and arrays all work — they get
|
|
414
|
-
flattened.
|
|
415
|
-
- **Wrap once at the top.** Don't sprinkle `<SkeletonContent>` inside subtrees; wrap the
|
|
416
|
-
component's final return so the entire layout becomes a single coherent placeholder.
|
|
417
|
-
- **For data-driven lists, prefer `<SkeletonList>`.** It owns the "show N placeholder
|
|
418
|
-
rows while loading, then real data" branching so callers don't hand-roll it.
|
|
419
|
-
|
|
420
|
-
Before / after with `Card`:
|
|
421
|
-
|
|
422
|
-
```tsx
|
|
423
|
-
// Before — caller hand-rolls a placeholder branch
|
|
424
|
-
{
|
|
425
|
-
loading ? (
|
|
426
|
-
<SkeletonCard />
|
|
427
|
-
) : (
|
|
428
|
-
<Card>
|
|
429
|
-
<Text>{site.name}</Text>
|
|
430
|
-
<Text>{site.address}</Text>
|
|
431
|
-
</Card>
|
|
432
|
-
);
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
// After — Card itself is skeleton-aware
|
|
436
|
-
<Card loading={loading}>
|
|
437
|
-
<Text>{site?.name ?? ' '}</Text>
|
|
438
|
-
<Text>{site?.address ?? ' '}</Text>
|
|
439
|
-
</Card>;
|
|
440
|
-
```
|
|
441
|
-
|
|
442
|
-
### Two flavours of `loading`
|
|
443
|
-
|
|
444
|
-
Same prop name, different semantic by category:
|
|
445
|
-
|
|
446
|
-
- **Display primitives** (`Card`, `ListItem`, `Avatar`, `Badge`, `Banner`, `Chip`, `Rating`,
|
|
447
|
-
`Stepper`, `ImageGallery`) — `loading={true}` renders the component as a skeleton placeholder
|
|
448
|
-
via `SkeletonContent`'s auto walker. Use when the data driving the component is still being
|
|
449
|
-
fetched.
|
|
450
|
-
- **Interactive triggers** (`Button`) — `loading={true}` swaps the label for an inline `Spinner`,
|
|
451
|
-
hides leading/trailing icons, and disables press handling. The button keeps its footprint and
|
|
452
|
-
visual style. Use when an action is in flight (submit, save, delete) — pending action, not
|
|
453
|
-
data fetch.
|
|
454
|
-
|
|
455
|
-
Before / after with `Button`:
|
|
456
|
-
|
|
457
|
-
```tsx
|
|
458
|
-
// Before — caller swaps a separate spinner in
|
|
459
|
-
{
|
|
460
|
-
submitting ? <Spinner size="small" /> : <Button title="Save" onPress={save} />;
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
// After — Button itself signals the in-flight action
|
|
464
|
-
<Button title="Save" loading={submitting} onPress={save} />;
|
|
465
|
-
```
|
|
466
|
-
|
|
467
|
-
---
|
|
468
|
-
|
|
469
|
-
## License
|
|
9
|
+
This package is published for use inside Webority repositories. Documentation is maintained internally.
|
|
470
10
|
|
|
471
|
-
MIT
|
|
11
|
+
MIT © Webority Technologies.
|
|
@@ -8,6 +8,7 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
8
8
|
var _reactNative = require("react-native");
|
|
9
9
|
var _index = require("../../theme/index.js");
|
|
10
10
|
var _index2 = require("../../utils/index.js");
|
|
11
|
+
var _SkeletonProvider = require("./SkeletonProvider.js");
|
|
11
12
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
12
13
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
13
14
|
const SPEED_DURATION = {
|
|
@@ -33,23 +34,30 @@ const resolveWidth = width => {
|
|
|
33
34
|
const Skeleton = ({
|
|
34
35
|
width = '100%',
|
|
35
36
|
height = 16,
|
|
36
|
-
radius
|
|
37
|
-
variant
|
|
38
|
-
speed
|
|
37
|
+
radius,
|
|
38
|
+
variant,
|
|
39
|
+
speed,
|
|
40
|
+
colors,
|
|
39
41
|
style,
|
|
40
42
|
testID
|
|
41
43
|
}) => {
|
|
42
44
|
const theme = (0, _index.useTheme)();
|
|
45
|
+
const defaults = (0, _SkeletonProvider.useSkeletonDefaults)();
|
|
46
|
+
const resolvedVariant = variant ?? defaults.variant ?? 'shimmer';
|
|
47
|
+
const resolvedSpeed = speed ?? defaults.speed ?? 'normal';
|
|
48
|
+
const resolvedRadiusToken = radius ?? defaults.radius ?? 'sm';
|
|
49
|
+
const backgroundColor = colors?.background ?? defaults.colors?.background ?? theme.colors.skeleton.background;
|
|
50
|
+
const highlightColor = colors?.highlight ?? defaults.colors?.highlight ?? theme.colors.skeleton.highlight;
|
|
43
51
|
const styles = (0, _react.useMemo)(() => buildStyles(theme), [theme]);
|
|
44
|
-
const borderRadius = resolveRadius(theme,
|
|
52
|
+
const borderRadius = resolveRadius(theme, resolvedRadiusToken);
|
|
45
53
|
const resolvedWidth = resolveWidth(width);
|
|
46
54
|
const resolvedHeight = _index2.Responsive.size(height);
|
|
47
55
|
const progress = (0, _react.useRef)(new _reactNative.Animated.Value(0)).current;
|
|
48
56
|
const [containerWidth, setContainerWidth] = (0, _react.useState)(0);
|
|
49
57
|
(0, _react.useEffect)(() => {
|
|
50
58
|
progress.setValue(0);
|
|
51
|
-
const duration =
|
|
52
|
-
const animation =
|
|
59
|
+
const duration = resolvedVariant === 'pulse' ? PULSE_DURATION : SPEED_DURATION[resolvedSpeed];
|
|
60
|
+
const animation = resolvedVariant === 'pulse' ? _reactNative.Animated.loop(_reactNative.Animated.sequence([_reactNative.Animated.timing(progress, {
|
|
53
61
|
toValue: 1,
|
|
54
62
|
duration: duration / 2,
|
|
55
63
|
easing: _reactNative.Easing.inOut(_reactNative.Easing.ease),
|
|
@@ -69,17 +77,17 @@ const Skeleton = ({
|
|
|
69
77
|
return () => {
|
|
70
78
|
animation.stop();
|
|
71
79
|
};
|
|
72
|
-
}, [progress,
|
|
80
|
+
}, [progress, resolvedSpeed, resolvedVariant]);
|
|
73
81
|
const handleLayout = event => {
|
|
74
82
|
const next = event.nativeEvent.layout.width;
|
|
75
83
|
if (next !== containerWidth) setContainerWidth(next);
|
|
76
84
|
};
|
|
77
85
|
const overlay = (0, _react.useMemo)(() => {
|
|
78
|
-
if (
|
|
86
|
+
if (resolvedVariant === 'pulse') {
|
|
79
87
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Animated.View, {
|
|
80
88
|
pointerEvents: "none",
|
|
81
89
|
style: [_reactNative.StyleSheet.absoluteFillObject, {
|
|
82
|
-
backgroundColor:
|
|
90
|
+
backgroundColor: highlightColor,
|
|
83
91
|
opacity: progress.interpolate({
|
|
84
92
|
inputRange: [0, 1],
|
|
85
93
|
outputRange: [0, 0.6]
|
|
@@ -97,13 +105,13 @@ const Skeleton = ({
|
|
|
97
105
|
pointerEvents: "none",
|
|
98
106
|
style: [styles.shimmer, {
|
|
99
107
|
width: highlightWidth,
|
|
100
|
-
backgroundColor:
|
|
108
|
+
backgroundColor: highlightColor,
|
|
101
109
|
transform: [{
|
|
102
110
|
translateX
|
|
103
111
|
}]
|
|
104
112
|
}]
|
|
105
113
|
});
|
|
106
|
-
}, [containerWidth, progress, styles.shimmer,
|
|
114
|
+
}, [containerWidth, progress, styles.shimmer, highlightColor, resolvedVariant]);
|
|
107
115
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
|
|
108
116
|
onLayout: handleLayout,
|
|
109
117
|
accessible: true,
|
|
@@ -115,7 +123,7 @@ const Skeleton = ({
|
|
|
115
123
|
width: resolvedWidth,
|
|
116
124
|
height: resolvedHeight,
|
|
117
125
|
borderRadius,
|
|
118
|
-
backgroundColor
|
|
126
|
+
backgroundColor
|
|
119
127
|
}, style],
|
|
120
128
|
children: overlay
|
|
121
129
|
});
|
|
@@ -7,6 +7,7 @@ exports.default = exports.SkeletonContent = void 0;
|
|
|
7
7
|
var _react = _interopRequireWildcard(require("react"));
|
|
8
8
|
var _reactNative = require("react-native");
|
|
9
9
|
var _Skeleton = require("./Skeleton.js");
|
|
10
|
+
var _SkeletonSkip = require("./SkeletonSkip.js");
|
|
10
11
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
11
12
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
12
13
|
const flattenStyle = style => {
|
|
@@ -27,7 +28,7 @@ const resolveRadius = (raw, fallback) => {
|
|
|
27
28
|
if (typeof raw === 'number') return raw;
|
|
28
29
|
return fallback;
|
|
29
30
|
};
|
|
30
|
-
const skeletonizeNode = (node, variant, speed, keyHint = 'r') => {
|
|
31
|
+
const skeletonizeNode = (node, variant, speed, colors, keyHint = 'r') => {
|
|
31
32
|
if (node == null || typeof node === 'boolean') return null;
|
|
32
33
|
if (typeof node === 'string' || typeof node === 'number') {
|
|
33
34
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Skeleton.Skeleton, {
|
|
@@ -35,11 +36,12 @@ const skeletonizeNode = (node, variant, speed, keyHint = 'r') => {
|
|
|
35
36
|
height: 14,
|
|
36
37
|
radius: "sm",
|
|
37
38
|
variant: variant,
|
|
38
|
-
speed: speed
|
|
39
|
+
speed: speed,
|
|
40
|
+
colors: colors
|
|
39
41
|
}, `${keyHint}-text`);
|
|
40
42
|
}
|
|
41
43
|
if (Array.isArray(node)) {
|
|
42
|
-
return _react.Children.map(node, (child, index) => skeletonizeNode(child, variant, speed, `${keyHint}-${index}`));
|
|
44
|
+
return _react.Children.map(node, (child, index) => skeletonizeNode(child, variant, speed, colors, `${keyHint}-${index}`));
|
|
43
45
|
}
|
|
44
46
|
if (! /*#__PURE__*/(0, _react.isValidElement)(node)) return null;
|
|
45
47
|
const element = node;
|
|
@@ -47,6 +49,13 @@ const skeletonizeNode = (node, variant, speed, keyHint = 'r') => {
|
|
|
47
49
|
const elementStyle = flattenStyle(props.style);
|
|
48
50
|
const elementType = element.type;
|
|
49
51
|
|
|
52
|
+
// <SkeletonSkip /> → opt-out marker; render its children unchanged
|
|
53
|
+
if (elementType === _SkeletonSkip.SkeletonSkip) {
|
|
54
|
+
return /*#__PURE__*/(0, _react.cloneElement)(element, {
|
|
55
|
+
key: `${keyHint}-skip`
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
50
59
|
// <Image /> → fixed-size skeleton block matching style.width/height/borderRadius
|
|
51
60
|
if (elementType === _reactNative.Image) {
|
|
52
61
|
const width = resolveWidth(elementStyle.width, '100%');
|
|
@@ -58,6 +67,7 @@ const skeletonizeNode = (node, variant, speed, keyHint = 'r') => {
|
|
|
58
67
|
radius: radius,
|
|
59
68
|
variant: variant,
|
|
60
69
|
speed: speed,
|
|
70
|
+
colors: colors,
|
|
61
71
|
style: {
|
|
62
72
|
margin: typeof elementStyle.margin === 'number' ? elementStyle.margin : undefined
|
|
63
73
|
}
|
|
@@ -74,6 +84,7 @@ const skeletonizeNode = (node, variant, speed, keyHint = 'r') => {
|
|
|
74
84
|
radius: "sm",
|
|
75
85
|
variant: variant,
|
|
76
86
|
speed: speed,
|
|
87
|
+
colors: colors,
|
|
77
88
|
style: {
|
|
78
89
|
marginVertical: 2
|
|
79
90
|
}
|
|
@@ -84,7 +95,7 @@ const skeletonizeNode = (node, variant, speed, keyHint = 'r') => {
|
|
|
84
95
|
if (props.children != null) {
|
|
85
96
|
return /*#__PURE__*/(0, _react.cloneElement)(element, {
|
|
86
97
|
key: `${keyHint}-w`
|
|
87
|
-
}, skeletonizeNode(props.children, variant, speed, `${keyHint}-c`));
|
|
98
|
+
}, skeletonizeNode(props.children, variant, speed, colors, `${keyHint}-c`));
|
|
88
99
|
}
|
|
89
100
|
|
|
90
101
|
// Leaf <View /> with explicit dimensions → skeleton block
|
|
@@ -97,7 +108,8 @@ const skeletonizeNode = (node, variant, speed, keyHint = 'r') => {
|
|
|
97
108
|
height: height,
|
|
98
109
|
radius: radius,
|
|
99
110
|
variant: variant,
|
|
100
|
-
speed: speed
|
|
111
|
+
speed: speed,
|
|
112
|
+
colors: colors
|
|
101
113
|
}, `${keyHint}-vw`);
|
|
102
114
|
}
|
|
103
115
|
|
|
@@ -110,10 +122,11 @@ const skeletonizeNode = (node, variant, speed, keyHint = 'r') => {
|
|
|
110
122
|
const SkeletonContent = ({
|
|
111
123
|
loading,
|
|
112
124
|
children,
|
|
113
|
-
variant
|
|
114
|
-
speed
|
|
125
|
+
variant,
|
|
126
|
+
speed,
|
|
115
127
|
mode = 'auto',
|
|
116
128
|
count = 1,
|
|
129
|
+
colors,
|
|
117
130
|
style,
|
|
118
131
|
testID
|
|
119
132
|
}) => {
|
|
@@ -133,6 +146,7 @@ const SkeletonContent = ({
|
|
|
133
146
|
testID: testID,
|
|
134
147
|
variant: variant,
|
|
135
148
|
speed: speed,
|
|
149
|
+
colors: colors,
|
|
136
150
|
children: repeated
|
|
137
151
|
});
|
|
138
152
|
}
|
|
@@ -143,7 +157,7 @@ const SkeletonContent = ({
|
|
|
143
157
|
accessibilityLabel: "Loading",
|
|
144
158
|
accessibilityRole: "progressbar",
|
|
145
159
|
accessibilityLiveRegion: "polite",
|
|
146
|
-
children: skeletonizeNode(repeated, variant, speed)
|
|
160
|
+
children: skeletonizeNode(repeated, variant, speed, colors)
|
|
147
161
|
});
|
|
148
162
|
};
|
|
149
163
|
exports.SkeletonContent = SkeletonContent;
|
|
@@ -152,6 +166,7 @@ const BlockSkeleton = ({
|
|
|
152
166
|
children,
|
|
153
167
|
variant,
|
|
154
168
|
speed,
|
|
169
|
+
colors,
|
|
155
170
|
style,
|
|
156
171
|
testID
|
|
157
172
|
}) => {
|
|
@@ -188,7 +203,8 @@ const BlockSkeleton = ({
|
|
|
188
203
|
height: size.height,
|
|
189
204
|
radius: "md",
|
|
190
205
|
variant: variant,
|
|
191
|
-
speed: speed
|
|
206
|
+
speed: speed,
|
|
207
|
+
colors: colors
|
|
192
208
|
})
|
|
193
209
|
}) : null]
|
|
194
210
|
});
|