@bloxwap/hig 0.6.0 → 0.8.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 +2 -2
- package/chart/README.md +13 -2
- package/chart/dist/altimeter-burst.d.ts +4 -0
- package/chart/dist/altimeter-burst.js +43 -0
- package/chart/dist/altimeter-chart.d.ts +52 -0
- package/chart/dist/altimeter-chart.js +275 -0
- package/chart/dist/altimeter-model.d.ts +43 -0
- package/chart/dist/altimeter-model.js +148 -0
- package/chart/dist/altimeter-targets.d.ts +33 -0
- package/chart/dist/altimeter-targets.js +88 -0
- package/chart/dist/bitcoin-price.d.ts +8 -0
- package/chart/dist/bitcoin-price.js +41 -0
- package/chart/dist/champions-league.d.ts +19 -0
- package/chart/dist/champions-league.js +104 -0
- package/chart/dist/index.d.ts +6 -0
- package/chart/dist/index.js +5 -0
- package/chart/dist/outcome-chart.d.ts +37 -0
- package/chart/dist/outcome-chart.js +212 -0
- package/chart/dist/outcome-model.d.ts +43 -0
- package/chart/dist/outcome-model.js +71 -0
- package/chart/dist/plus-grid.d.ts +6 -0
- package/chart/dist/plus-grid.js +29 -0
- package/contracts/README.md +1 -1
- package/contracts/dist/avatar.d.ts +68 -0
- package/contracts/dist/avatar.js +93 -0
- package/contracts/dist/confetti.d.ts +174 -0
- package/contracts/dist/confetti.js +138 -0
- package/contracts/dist/decimal.d.ts +7 -0
- package/contracts/dist/decimal.js +35 -0
- package/contracts/dist/index.d.ts +45 -2
- package/contracts/dist/index.js +145 -4
- package/contracts/dist/invariants.d.ts +17 -0
- package/contracts/dist/invariants.js +24 -0
- package/contracts/dist/messages.d.ts +62 -2
- package/contracts/dist/messages.js +22 -2
- package/contracts/dist/number-flow.d.ts +90 -0
- package/contracts/dist/number-flow.js +150 -0
- package/contracts/dist/qr.d.ts +151 -0
- package/contracts/dist/qr.js +581 -0
- package/contracts/dist/toast.d.ts +168 -0
- package/contracts/dist/toast.js +171 -0
- package/feedback/README.md +1 -1
- package/feedback/dist/contract.js +1 -1
- package/feedback/dist/react.js +2 -4
- package/native/README.md +6 -1
- package/native/dist/account-block.d.ts +62 -7
- package/native/dist/account-block.js +54 -11
- package/native/dist/animated-number-model.d.ts +47 -1
- package/native/dist/animated-number-model.js +248 -21
- package/native/dist/animated-number.d.ts +41 -1
- package/native/dist/animated-number.js +165 -17
- package/native/dist/announce.d.ts +2 -0
- package/native/dist/announce.js +10 -0
- package/native/dist/asset-balance-row.d.ts +19 -1
- package/native/dist/asset-balance-row.js +24 -8
- package/native/dist/assets-block.d.ts +115 -0
- package/native/dist/assets-block.js +87 -0
- package/native/dist/async-result.d.ts +2 -0
- package/native/dist/async-result.js +11 -0
- package/native/dist/avatar-frame.d.ts +29 -0
- package/native/dist/avatar-frame.js +56 -0
- package/native/dist/avatar.d.ts +21 -0
- package/native/dist/avatar.js +31 -0
- package/native/dist/bar-mark.d.ts +16 -2
- package/native/dist/bar-mark.js +23 -7
- package/native/dist/bar-pnl.js +7 -5
- package/native/dist/blocks.d.ts +13 -14
- package/native/dist/blocks.js +10 -6
- package/native/dist/brand.js +2 -1
- package/native/dist/button.d.ts +7 -2
- package/native/dist/button.js +16 -4
- package/native/dist/checkbox.js +2 -1
- package/native/dist/confetti.d.ts +33 -0
- package/native/dist/confetti.js +143 -0
- package/native/dist/confirm-block.d.ts +98 -0
- package/native/dist/confirm-block.js +48 -0
- package/native/dist/data.d.ts +1 -1
- package/native/dist/data.js +8 -4
- package/native/dist/explainer-block.d.ts +91 -0
- package/native/dist/explainer-block.js +34 -0
- package/native/dist/field.d.ts +19 -5
- package/native/dist/field.js +56 -9
- package/native/dist/figure.d.ts +23 -0
- package/native/dist/figure.js +10 -0
- package/native/dist/gesture-sheet-model.d.ts +50 -0
- package/native/dist/gesture-sheet-model.js +105 -0
- package/native/dist/gesture-sheet-next.d.ts +82 -0
- package/native/dist/gesture-sheet-next.js +315 -0
- package/native/dist/gesture-sheet.d.ts +5 -1
- package/native/dist/gesture-sheet.js +13 -6
- package/native/dist/icons.d.ts +9 -6
- package/native/dist/icons.js +25 -24
- package/native/dist/language-block.d.ts +14 -1
- package/native/dist/language-block.js +11 -4
- package/native/dist/list-group.d.ts +44 -8
- package/native/dist/list-group.js +84 -13
- package/native/dist/manage-position-block.d.ts +35 -2
- package/native/dist/manage-position-block.js +41 -11
- package/native/dist/market-row.d.ts +46 -0
- package/native/dist/market-row.js +41 -0
- package/native/dist/navigation.js +5 -3
- package/native/dist/notifications-block.d.ts +30 -2
- package/native/dist/notifications-block.js +16 -8
- package/native/dist/number-format.d.ts +6 -0
- package/native/dist/number-format.js +9 -0
- package/native/dist/pickers.d.ts +32 -2
- package/native/dist/pickers.js +17 -9
- package/native/dist/position-block.d.ts +66 -10
- package/native/dist/position-block.js +45 -11
- package/native/dist/preset-group.d.ts +31 -0
- package/native/dist/preset-group.js +39 -0
- package/native/dist/preset-picker-block.d.ts +107 -0
- package/native/dist/preset-picker-block.js +43 -0
- package/native/dist/profile-block.d.ts +38 -5
- package/native/dist/profile-block.js +31 -6
- package/native/dist/provider.d.ts +14 -5
- package/native/dist/provider.js +32 -6
- package/native/dist/qr-code.d.ts +33 -0
- package/native/dist/qr-code.js +29 -0
- package/native/dist/radio-group.d.ts +23 -5
- package/native/dist/radio-group.js +40 -12
- package/native/dist/recipes.d.ts +6 -0
- package/native/dist/recipes.js +6 -0
- package/native/dist/reward-block.d.ts +55 -13
- package/native/dist/reward-block.js +37 -14
- package/native/dist/screen-header.d.ts +59 -0
- package/native/dist/screen-header.js +37 -0
- package/native/dist/select.js +4 -2
- package/native/dist/selection.d.ts +3 -2
- package/native/dist/selection.js +1 -0
- package/native/dist/setting-header.d.ts +2 -8
- package/native/dist/setting-header.js +2 -11
- package/native/dist/setting-switch.d.ts +15 -2
- package/native/dist/setting-switch.js +11 -4
- package/native/dist/signals-block.d.ts +26 -2
- package/native/dist/signals-block.js +14 -4
- package/native/dist/slider.js +5 -1
- package/native/dist/sound-haptics-block.d.ts +29 -2
- package/native/dist/sound-haptics-block.js +19 -8
- package/native/dist/status.d.ts +47 -14
- package/native/dist/status.js +39 -22
- package/native/dist/sticky-header.d.ts +28 -0
- package/native/dist/sticky-header.js +29 -0
- package/native/dist/surface.d.ts +3 -1
- package/native/dist/surface.js +2 -1
- package/native/dist/swap-amount-card.d.ts +57 -0
- package/native/dist/swap-amount-card.js +31 -0
- package/native/dist/swap-panel-block.d.ts +11 -4
- package/native/dist/swap-panel-block.js +67 -38
- package/native/dist/swap-parts.d.ts +5 -10
- package/native/dist/swap-parts.js +22 -24
- package/native/dist/swap-shared.d.ts +8 -2
- package/native/dist/swap-shared.js +10 -6
- package/native/dist/swap-views.js +6 -4
- package/native/dist/switch-row.d.ts +3 -2
- package/native/dist/switch-row.js +5 -3
- package/native/dist/switch.d.ts +4 -2
- package/native/dist/switch.js +3 -3
- package/native/dist/target-block.d.ts +40 -7
- package/native/dist/target-block.js +31 -11
- package/native/dist/toast.d.ts +47 -0
- package/native/dist/toast.js +386 -0
- package/native/dist/token-action-block.d.ts +26 -9
- package/native/dist/token-action-block.js +21 -8
- package/native/dist/trade-history-detail-block.d.ts +26 -1
- package/native/dist/trade-history-detail-block.js +17 -9
- package/native/dist/trade-history-list-block.d.ts +71 -5
- package/native/dist/trade-history-list-block.js +55 -17
- package/native/dist/wallet-address-core.d.ts +25 -0
- package/native/dist/wallet-address-core.js +34 -0
- package/native/dist/wallet-address.d.ts +6 -10
- package/native/dist/wallet-address.js +16 -20
- package/native-fonts/README.md +1 -1
- package/og-fonts/README.md +1 -1
- package/package.json +131 -2
- package/react/README.md +3 -1
- package/react/dist/animated-number-flow.d.ts +72 -0
- package/react/dist/animated-number-flow.js +316 -0
- package/react/dist/animated-number-model.d.ts +24 -0
- package/react/dist/animated-number-model.js +106 -3
- package/react/dist/animated-number.d.ts +49 -1
- package/react/dist/animated-number.js +146 -11
- package/react/dist/asset-balance-row.d.ts +19 -1
- package/react/dist/asset-balance-row.js +17 -3
- package/react/dist/async-result.d.ts +2 -0
- package/react/dist/async-result.js +11 -0
- package/react/dist/avatar.d.ts +25 -0
- package/react/dist/avatar.js +50 -0
- package/react/dist/bar-mark.d.ts +5 -2
- package/react/dist/bar-mark.js +5 -3
- package/react/dist/blocks/account-block.d.ts +57 -7
- package/react/dist/blocks/account-block.js +51 -11
- package/react/dist/blocks/assets-block.d.ts +106 -0
- package/react/dist/blocks/assets-block.js +135 -0
- package/react/dist/blocks/confirm-block.d.ts +91 -0
- package/react/dist/blocks/confirm-block.js +31 -0
- package/react/dist/blocks/explainer-block.d.ts +80 -0
- package/react/dist/blocks/explainer-block.js +20 -0
- package/react/dist/blocks/install-command.js +3 -1
- package/react/dist/blocks/language-block.d.ts +9 -1
- package/react/dist/blocks/language-block.js +8 -6
- package/react/dist/blocks/manage-position-block.d.ts +30 -2
- package/react/dist/blocks/manage-position-block.js +23 -4
- package/react/dist/blocks/market-row.d.ts +20 -9
- package/react/dist/blocks/market-row.js +17 -4
- package/react/dist/blocks/notifications-block.d.ts +27 -2
- package/react/dist/blocks/notifications-block.js +11 -2
- package/react/dist/blocks/pickers.d.ts +30 -1
- package/react/dist/blocks/pickers.js +32 -10
- package/react/dist/blocks/position-block.d.ts +34 -11
- package/react/dist/blocks/position-block.js +16 -5
- package/react/dist/blocks/preset-picker-block.d.ts +85 -0
- package/react/dist/blocks/preset-picker-block.js +19 -0
- package/react/dist/blocks/profile-block.d.ts +33 -6
- package/react/dist/blocks/profile-block.js +31 -6
- package/react/dist/blocks/reward-block.d.ts +65 -21
- package/react/dist/blocks/reward-block.js +24 -11
- package/react/dist/blocks/screen-header.d.ts +34 -2
- package/react/dist/blocks/screen-header.js +17 -6
- package/react/dist/blocks/setting-switch.d.ts +14 -1
- package/react/dist/blocks/setting-switch.js +11 -4
- package/react/dist/blocks/signals-block.d.ts +23 -2
- package/react/dist/blocks/signals-block.js +6 -5
- package/react/dist/blocks/sound-haptics-block.d.ts +27 -3
- package/react/dist/blocks/sound-haptics-block.js +11 -7
- package/react/dist/blocks/sticky-header.d.ts +19 -0
- package/react/dist/blocks/sticky-header.js +103 -0
- package/react/dist/blocks/swap/amount-card.js +2 -1
- package/react/dist/blocks/swap/settings.js +4 -3
- package/react/dist/blocks/swap/shared.d.ts +29 -23
- package/react/dist/blocks/swap/shared.js +36 -32
- package/react/dist/blocks/swap-panel-block.d.ts +12 -3
- package/react/dist/blocks/swap-panel-block.js +72 -37
- package/react/dist/blocks/target-block.d.ts +35 -7
- package/react/dist/blocks/target-block.js +26 -12
- package/react/dist/blocks/token-action-block.d.ts +21 -8
- package/react/dist/blocks/token-action-block.js +9 -6
- package/react/dist/blocks/trade-history-detail-block.d.ts +23 -1
- package/react/dist/blocks/trade-history-detail-block.js +5 -4
- package/react/dist/blocks/trade-history-list-block.d.ts +31 -5
- package/react/dist/blocks/trade-history-list-block.js +20 -10
- package/react/dist/blocks.d.ts +12 -8
- package/react/dist/blocks.js +6 -2
- package/react/dist/brand.js +2 -1
- package/react/dist/button.d.ts +9 -3
- package/react/dist/button.js +12 -5
- package/react/dist/confetti.d.ts +27 -0
- package/react/dist/confetti.js +240 -0
- package/react/dist/data.js +11 -4
- package/react/dist/field.d.ts +20 -5
- package/react/dist/field.js +30 -8
- package/react/dist/figure.d.ts +23 -0
- package/react/dist/figure.js +12 -0
- package/react/dist/gesture-sheet.d.ts +15 -1
- package/react/dist/gesture-sheet.js +53 -8
- package/react/dist/list-group.d.ts +41 -8
- package/react/dist/list-group.js +49 -13
- package/react/dist/navigation.js +11 -3
- package/react/dist/overlay.d.ts +28 -3
- package/react/dist/overlay.js +29 -3
- package/react/dist/preset-group.d.ts +30 -0
- package/react/dist/preset-group.js +13 -0
- package/react/dist/provider.d.ts +42 -5
- package/react/dist/provider.js +84 -10
- package/react/dist/qr-code.d.ts +32 -0
- package/react/dist/qr-code.js +28 -0
- package/react/dist/select.js +10 -3
- package/react/dist/selection.d.ts +18 -4
- package/react/dist/selection.js +20 -10
- package/react/dist/slider.js +5 -1
- package/react/dist/status.d.ts +14 -10
- package/react/dist/status.js +17 -9
- package/react/dist/styles.css +380 -150
- package/react/dist/surface.d.ts +5 -1
- package/react/dist/surface.js +1 -1
- package/react/dist/toast.d.ts +19 -12
- package/react/dist/toast.js +29 -7
- package/react/dist/wallet-address-core.d.ts +27 -0
- package/react/dist/wallet-address-core.js +29 -0
- package/react/dist/wallet-address.d.ts +6 -12
- package/react/dist/wallet-address.js +5 -16
- package/tokens/README.md +2 -2
- package/tokens/dist/index.d.ts +16 -0
- package/tokens/dist/index.js +16 -0
- package/tokens/dist/manifest.json +8 -0
- package/tokens/dist/tokens.css +6 -0
|
@@ -1,21 +1,37 @@
|
|
|
1
1
|
import { createElement as _createElement } from "react";
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { memo, useEffect, useMemo, useRef, useState } from 'react';
|
|
4
4
|
import { PixelRatio, StyleSheet, View } from 'react-native';
|
|
5
|
-
import Reanimated, { cancelAnimation, Easing, ReduceMotion, useAnimatedStyle, useSharedValue, withTiming } from 'react-native-reanimated';
|
|
5
|
+
import Reanimated, { cancelAnimation, defineAnimation, Easing, ReduceMotion, useAnimatedStyle, useSharedValue, withTiming } from 'react-native-reanimated';
|
|
6
|
+
import { numberFlowDeltas, numberFlowDigitLength, numberFlowEasingSamples, resolveNumberFlowTimings } from '@bloxwap/hig/contracts/number-flow';
|
|
6
7
|
import * as en from '@bloxwap/hig/contracts/messages';
|
|
8
|
+
import { presentNumberFormat } from '@bloxwap/hig/contracts';
|
|
7
9
|
import { tokens } from '@bloxwap/hig/tokens';
|
|
8
|
-
import { createNumberReelModel, formatNumberReadout, numberTrendDirection, safeNumberLayout } from './animated-number-model.js';
|
|
9
|
-
import { useColors, useHIG } from './provider.js';
|
|
10
|
+
import { createNumberFlowRoll, createNumberReelModel, formatNumberReadout, numberFlowReelOffset, numberReelPlace, numberReelPlaces, numberTrendDirection, safeNumberLayout, sampleReelEasing } from './animated-number-model.js';
|
|
11
|
+
import { useColors, useHIG, useNumberLocale } from './provider.js';
|
|
10
12
|
import { detectScript, Text } from './surface.js';
|
|
11
13
|
const numberTypographyKeys = new Set(['fontFamily', 'fontSize', 'fontWeight', 'lineHeight', 'letterSpacing', 'textAlign']);
|
|
12
14
|
// Android Fabric reads colour 0 as "unset", so 'transparent' (0x00000000) drew the hidden reading in the default
|
|
13
15
|
// black under the reels. Clear white is non-zero there and still invisible.
|
|
14
|
-
const
|
|
16
|
+
const hiddenColor = '#ffffff00';
|
|
17
|
+
// While the reels draw, the reading stays for assistive technology and tests but leaves the flow, so the readout is sized by
|
|
18
|
+
// what it draws. It sits on the side the figure is aligned to; in a row it is measured at its own width and never wraps.
|
|
19
|
+
const hiddenReading = { left: { color: hiddenColor, position: 'absolute', top: 0, left: 0 }, right: { color: hiddenColor, position: 'absolute', top: 0, right: 0 }, center: { color: hiddenColor, position: 'absolute', top: 0, left: 0, right: 0 } };
|
|
20
|
+
// The reel row is the readout's in-flow content: it keeps its content width (no shrink) and the readout takes that width.
|
|
21
|
+
const reelRowStyle = { flexDirection: 'row', alignItems: 'center', flexShrink: 0, direction: 'ltr' };
|
|
15
22
|
const clampedDuration = (duration) => Number.isFinite(duration) && duration > 0 ? Math.min(duration, 600) : 0;
|
|
16
|
-
|
|
23
|
+
const sameGlyphs = (first, second) => first === second || (first.length === second.length && first.every((glyph, index) => glyph === second[index]));
|
|
24
|
+
/**
|
|
25
|
+
* One place of a sliding figure: twenty glyphs in a column behind a window one glyph high. A readout draws again for every
|
|
26
|
+
* value (and whenever its parent does), and most of its places have the digit they had, so a reel is drawn again only when its
|
|
27
|
+
* digit, its motion or its face changes. The trend alone does not count: it only matters to a digit that changed.
|
|
28
|
+
*/
|
|
29
|
+
const DigitReel = memo(function DigitReel({ digits, digit, trend, duration, reducedMotion, width, height, style, styleKey, script, maxFontSizeMultiplier }) {
|
|
17
30
|
const position = useSharedValue(digit), previousDigit = useRef(digit);
|
|
18
|
-
const animatedStyle = useAnimatedStyle(() =>
|
|
31
|
+
const animatedStyle = useAnimatedStyle(() => {
|
|
32
|
+
'worklet';
|
|
33
|
+
return { transform: [{ translateY: -position.value * height }] };
|
|
34
|
+
}, [height]);
|
|
19
35
|
useEffect(() => {
|
|
20
36
|
const motionDuration = clampedDuration(duration);
|
|
21
37
|
if (previousDigit.current === digit) {
|
|
@@ -53,9 +69,86 @@ function DigitReel({ digits, digit, trend, duration, reducedMotion, width, heigh
|
|
|
53
69
|
position.value = withTiming(destination, { duration: motionDuration, easing: Easing.bezier(...tokens.easing.standard), reduceMotion: ReduceMotion.Never });
|
|
54
70
|
}, [digit, trend, duration, reducedMotion, position]);
|
|
55
71
|
useEffect(() => () => cancelAnimation(position), [position]);
|
|
56
|
-
|
|
57
|
-
|
|
72
|
+
// The rows only change with the face, so they are the same elements while the reel turns: a new digit moves the column and draws no text again.
|
|
73
|
+
const rows = useMemo(() => Array.from({ length: 20 }, (_, index) => { const glyph = digits[index % 10]; return _jsx(Text, { accessible: false, script: script, maxFontSizeMultiplier: maxFontSizeMultiplier, style: [style, { width, height, textAlign: 'center' }], children: glyph }, `${index}:${glyph}`); }), [digits, width, height, styleKey, script, maxFontSizeMultiplier]);
|
|
74
|
+
return _jsx(View, { collapsable: false, style: { width, height, overflow: 'hidden' }, children: _jsx(Reanimated.View, { style: animatedStyle, children: rows }) });
|
|
75
|
+
}, (previous, next) => previous.digit === next.digit && previous.duration === next.duration && previous.reducedMotion === next.reducedMotion && sameGlyphs(previous.digits, next.digits) && previous.width === next.width && previous.height === next.height && previous.styleKey === next.styleKey && previous.script === next.script && previous.maxFontSizeMultiplier === next.maxFontSizeMultiplier);
|
|
76
|
+
/**
|
|
77
|
+
* The moving part of a flowing place: `length + 1` glyphs in a column, translated on the UI thread. It mounts on the place's
|
|
78
|
+
* first turn, already showing the digit it replaces, and stays for the turns after it. Its position counts glyphs on a reel of
|
|
79
|
+
* `length`, so a turn on a reel of another length (a limited place given a digit past its limit, or back) starts from the
|
|
80
|
+
* digit it replaces rather than from a position counted on the old reel.
|
|
81
|
+
*/
|
|
82
|
+
function FlowStrip({ glyphs, length, from, digit, delta, step, enter, duration, samples, fade, fadeSamples, width, height, style, styleKey, script, maxFontSizeMultiplier }) {
|
|
83
|
+
const position = useSharedValue(from), opacity = useSharedValue(enter && fade > 0 ? 0 : 1), applied = useRef(null);
|
|
84
|
+
const animatedStyle = useAnimatedStyle(() => {
|
|
85
|
+
'worklet';
|
|
86
|
+
return { opacity: opacity.value, transform: [{ translateY: numberFlowReelOffset(position.value, length, height) }] };
|
|
87
|
+
}, [length, height]);
|
|
88
|
+
useEffect(() => {
|
|
89
|
+
const last = applied.current;
|
|
90
|
+
applied.current = { step, digit, length };
|
|
91
|
+
if (!last || last.step !== step) {
|
|
92
|
+
if (duration > 0 && delta) {
|
|
93
|
+
// A reel of another length: what is in flight was counted on the old one, so this turn starts from the digit it replaces.
|
|
94
|
+
if (last && last.length !== length) {
|
|
95
|
+
cancelAnimation(position);
|
|
96
|
+
position.value = digit - delta;
|
|
97
|
+
}
|
|
98
|
+
// A new turn joins whatever is still in flight; the roll works out where it ends from where the reel was going.
|
|
99
|
+
position.value = defineAnimation(digit, () => {
|
|
100
|
+
'worklet';
|
|
101
|
+
return createNumberFlowRoll(delta, duration, samples);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
cancelAnimation(position);
|
|
106
|
+
position.value = digit;
|
|
107
|
+
}
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
// Motion was turned off, the digit changed without a turn or the reel changed length: land on the digit, cutting short whatever was in flight.
|
|
111
|
+
if (last.digit !== digit || last.length !== length || duration <= 0) {
|
|
112
|
+
cancelAnimation(position);
|
|
113
|
+
position.value = digit;
|
|
114
|
+
}
|
|
115
|
+
}, [step, digit, delta, length, duration, samples, position]);
|
|
116
|
+
useEffect(() => {
|
|
117
|
+
if (!enter)
|
|
118
|
+
return;
|
|
119
|
+
if (fade > 0)
|
|
120
|
+
opacity.value = withTiming(1, { duration: fade, easing: (progress) => {
|
|
121
|
+
'worklet';
|
|
122
|
+
return sampleReelEasing(fadeSamples, progress);
|
|
123
|
+
}, reduceMotion: ReduceMotion.Never });
|
|
124
|
+
// Motion was turned off while the place was still arriving: it is simply there.
|
|
125
|
+
else {
|
|
126
|
+
cancelAnimation(opacity);
|
|
127
|
+
opacity.value = 1;
|
|
128
|
+
}
|
|
129
|
+
}, [enter, fade, fadeSamples, opacity]);
|
|
130
|
+
// Forgetting the applied turn lets an effect that runs again after this cleanup (React's development double mount) start it again rather than leave the reel where the cancel stopped it.
|
|
131
|
+
useEffect(() => () => { cancelAnimation(position); cancelAnimation(opacity); applied.current = null; }, [position, opacity]);
|
|
132
|
+
// The rows only change with the reel and the face, so they are the same elements from one turn to the next: a turn moves the strip and draws no text again.
|
|
133
|
+
const rows = useMemo(() => Array.from({ length: length + 1 }, (_, index) => _jsx(Text, { accessible: false, script: script, maxFontSizeMultiplier: maxFontSizeMultiplier, style: [style, { width, height, textAlign: 'center' }], children: glyphs[index % length] }, index)), [glyphs, length, width, height, styleKey, script, maxFontSizeMultiplier]);
|
|
134
|
+
return _jsx(Reanimated.View, { style: animatedStyle, children: rows });
|
|
58
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* One place of a flowing figure. At rest it is a single glyph in a box the size of the widest digit; the strip that rolls
|
|
138
|
+
* mounts the first time the place turns, so a screen of figures that never change mounts one text per digit. A place that
|
|
139
|
+
* joins a figure already on screen arrives turning, from zero.
|
|
140
|
+
*/
|
|
141
|
+
const FlowDigit = memo(function FlowDigit(props) {
|
|
142
|
+
const { glyphs, digit, delta, step, width, height, style, script, maxFontSizeMultiplier } = props;
|
|
143
|
+
// Where the strip starts from. Set during render, so the strip mounts in the commit that first turns the place.
|
|
144
|
+
const [strip, setStrip] = useState(step > 0 && delta !== 0 ? { from: digit - delta, enter: true } : null);
|
|
145
|
+
if (!strip && step > 0 && delta !== 0)
|
|
146
|
+
setStrip({ from: digit - delta, enter: false });
|
|
147
|
+
return _jsx(View, { collapsable: false, style: { width, height, overflow: 'hidden' }, children: strip ? _jsx(FlowStrip, { ...props, from: strip.from, enter: strip.enter }) : _jsx(Text, { accessible: false, script: script, maxFontSizeMultiplier: maxFontSizeMultiplier, style: [style, { width, height, textAlign: 'center' }], children: glyphs[digit] }) });
|
|
148
|
+
}, (previous, next) => previous.digit === next.digit && previous.step === next.step && previous.delta === next.delta && previous.length === next.length && sameGlyphs(previous.glyphs, next.glyphs) && previous.width === next.width && previous.height === next.height && previous.duration === next.duration && previous.samples === next.samples && previous.fade === next.fade && previous.fadeSamples === next.fadeSamples && previous.styleKey === next.styleKey && previous.script === next.script && previous.maxFontSizeMultiplier === next.maxFontSizeMultiplier);
|
|
149
|
+
/** A part of the figure that does not turn: a sign, a separator, an affix. Drawn again only when its text or its face changes. */
|
|
150
|
+
const StillPart = memo(function StillPart({ text, style, script, maxFontSizeMultiplier }) { return _jsx(Text, { accessible: false, script: script, maxFontSizeMultiplier: maxFontSizeMultiplier, style: style, children: text }); }, (previous, next) => previous.text === next.text && previous.styleKey === next.styleKey && previous.script === next.script && previous.maxFontSizeMultiplier === next.maxFontSizeMultiplier);
|
|
151
|
+
const noTurns = new Map();
|
|
59
152
|
function recordGlyph(measurements, key, index, event, setMetrics) {
|
|
60
153
|
const { width, height } = event.nativeEvent.layout;
|
|
61
154
|
if (!Number.isFinite(width) || !Number.isFinite(height) || width <= 0 || height <= 0)
|
|
@@ -68,16 +161,30 @@ function recordGlyph(measurements, key, index, event, setMetrics) {
|
|
|
68
161
|
return;
|
|
69
162
|
setMetrics(current => current?.key === key && current.width === measuredWidth && current.height === measuredHeight ? current : { key, width: measuredWidth, height: measuredHeight });
|
|
70
163
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
164
|
+
/** `AnimatedNumberReadout` with NumberFlow's motion by default: the same component and the same props, under the name the product uses for it. */
|
|
165
|
+
export function NumberFlow({ motion = 'flow', ...props }) { return _jsx(AnimatedNumberReadout, { motion: motion, ...props }); }
|
|
166
|
+
/** On web, moves the flowing figures inside it together when one changes width. Native figures change width at once, so this draws its children and nothing else; it exists so one tree serves both platforms. */
|
|
167
|
+
export function NumberFlowGroup({ children }) { return _jsx(_Fragment, { children: children }); }
|
|
168
|
+
/**
|
|
169
|
+
* A number that moves place by place when its value changes. It slides by default; `motion='flow'` (or `NumberFlow`, which is
|
|
170
|
+
* this component flowing by default) gives it NumberFlow's motion. Either way assistive technology gets one static reading,
|
|
171
|
+
* and reduced motion draws each new value at once.
|
|
172
|
+
*/
|
|
173
|
+
export function AnimatedNumberReadout({ value, options: requested, formattedValue, animateFormatted, stale, label, tone = 'text', style, testID, maxFontSizeMultiplier, trend, prefix, suffix, duration: requestedDuration, motion = 'slide', animated = true, spinTiming, transformTiming, opacityTiming, digits, continuous = false }) {
|
|
174
|
+
const duration = requestedDuration ?? 180, flow = motion === 'flow';
|
|
175
|
+
const locale = useNumberLocale();
|
|
176
|
+
const { messages, direction, reducedMotion: reduced, fontFamily, fontFamilies, fontFamiliesByScript, letterSpacingByScript, maxFontSizeMultiplier: providerMaxFontSizeMultiplier, numberFormat } = useHIG(), colors = useColors(), reducedMotion = reduced || !animated;
|
|
177
|
+
const options = presentNumberFormat(requested, numberFormat), optionsKey = options ? JSON.stringify(options) : '';
|
|
178
|
+
// The reading and its reels depend on the value and the format alone. A readout draws more often than its value changes (its
|
|
179
|
+
// parent draws, the digits are measured, a turn is worked out), and none of those renders formats anything again.
|
|
180
|
+
const reading = useMemo(() => formatNumberReadout(value, locale, options, formattedValue, prefix, suffix), [value, locale, optionsKey, formattedValue, prefix, suffix]), staleSuffix = stale ? ` ${messages.stale ?? en.stale}` : '';
|
|
74
181
|
const previousValue = useRef(value), directionTrend = numberTrendDirection(trend, previousValue.current, value);
|
|
75
182
|
useEffect(() => { previousValue.current = value; }, [value]);
|
|
76
183
|
const typography = Object.fromEntries(Object.entries(StyleSheet.flatten(style) ?? {}).filter(([key]) => numberTypographyKeys.has(key)));
|
|
77
|
-
const color = colors[tone === 'positive' || tone === 'negative' || tone === 'muted' || tone === 'up' || tone === 'down' ? tone : 'text'];
|
|
184
|
+
const color = colors[tone === 'positive' || tone === 'negative' || tone === 'warning' || tone === 'muted' || tone === 'faint' || tone === 'up' || tone === 'down' ? tone : 'text'];
|
|
78
185
|
const textStyle = [typography, { color, fontVariant: ['tabular-nums'] }];
|
|
79
186
|
const script = detectScript(`${reading.text}${staleSuffix}`, locale);
|
|
80
|
-
const model = createNumberReelModel(value, locale, options, formattedValue, direction);
|
|
187
|
+
const model = useMemo(() => createNumberReelModel(value, locale, options, formattedValue, direction, animateFormatted, reading.core), [value, locale, optionsKey, formattedValue, direction, animateFormatted]);
|
|
81
188
|
const safeModel = model && safeNumberLayout(`${prefix ?? ''}${suffix ?? ''}${staleSuffix}`, direction) ? model : null;
|
|
82
189
|
let fontScale = 0;
|
|
83
190
|
try {
|
|
@@ -91,7 +198,48 @@ export function AnimatedNumberReadout({ value, options, formattedValue, stale, l
|
|
|
91
198
|
const [metrics, setMetrics] = useState(null);
|
|
92
199
|
const activeModel = safeModel && fontScale > 0 && Number.isFinite(fontScale) && metrics?.key === measurementKey ? safeModel : null;
|
|
93
200
|
const activeMetrics = activeModel ? metrics : null;
|
|
94
|
-
const
|
|
201
|
+
const align = typography.textAlign === 'right' ? 'right' : typography.textAlign === 'center' ? 'center' : 'left';
|
|
202
|
+
const justifyContent = align === 'right' ? 'flex-end' : align === 'center' ? 'center' : 'flex-start';
|
|
95
203
|
const visualProps = { accessible: false, script, maxFontSizeMultiplier };
|
|
96
|
-
|
|
204
|
+
// Flowing: the turn of every place for this change, worked out in the render that first draws the new reading so the places
|
|
205
|
+
// that turn get their strip in the same commit. Kept in state (not a ref) so a render React throws away leaves no trace.
|
|
206
|
+
const timings = resolveNumberFlowTimings({ duration: requestedDuration, spinTiming, transformTiming, opacityTiming }), spinSamples = numberFlowEasingSamples(timings.spin.easing), fadeSamples = numberFlowEasingSamples(timings.opacity.easing);
|
|
207
|
+
const [flowStep, setFlowStep] = useState(null);
|
|
208
|
+
let turns = noTurns;
|
|
209
|
+
if (flow && activeModel) {
|
|
210
|
+
// A new locale or format is a different reading rather than a new value, as on web: it is drawn at once and the next value rolls from it.
|
|
211
|
+
const signature = `${locale}\u0000${optionsKey}\u0000${formattedValue ? 1 : 0}`;
|
|
212
|
+
if (!flowStep || flowStep.key !== measurementKey || flowStep.signature !== signature)
|
|
213
|
+
setFlowStep({ key: measurementKey, signature, canonical: activeModel.canonical, value, places: numberReelPlaces(activeModel), turns: noTurns });
|
|
214
|
+
else if (flowStep.canonical !== activeModel.canonical) {
|
|
215
|
+
const places = numberReelPlaces(activeModel), moving = !reducedMotion && timings.spin.duration > 0, deltas = moving ? numberFlowDeltas(flowStep.places, places, { trend: numberTrendDirection(trend, flowStep.value, value), digits, continuous }) : null, before = new Map(flowStep.places.map(place => [place.key, place.digit])), next = new Map();
|
|
216
|
+
for (const place of places) {
|
|
217
|
+
const delta = deltas?.get(place.key) ?? 0, old = flowStep.turns.get(place.key);
|
|
218
|
+
// The same reel the shared model counted the turn on: long enough for both ends of it.
|
|
219
|
+
if (delta)
|
|
220
|
+
next.set(place.key, { step: (old?.step ?? 0) + 1, delta, length: numberFlowDigitLength(digits, place.place, Math.max(place.digit, before.get(place.key) ?? 0)) });
|
|
221
|
+
// No turn: the place keeps its reel while its digit still fits it.
|
|
222
|
+
else if (old)
|
|
223
|
+
next.set(place.key, place.digit < old.length ? old : { ...old, length: numberFlowDigitLength(digits, place.place, place.digit) });
|
|
224
|
+
}
|
|
225
|
+
setFlowStep({ key: measurementKey, signature, canonical: activeModel.canonical, value, places, turns: next });
|
|
226
|
+
turns = next;
|
|
227
|
+
}
|
|
228
|
+
else
|
|
229
|
+
turns = flowStep.turns;
|
|
230
|
+
}
|
|
231
|
+
else if (flowStep)
|
|
232
|
+
setFlowStep(null);
|
|
233
|
+
const styleKey = JSON.stringify([typography, color]), partProps = { style: textStyle, styleKey, script, maxFontSizeMultiplier };
|
|
234
|
+
// The ten digits, measured for a face and size: drawn again when what is measured changes, not with every value.
|
|
235
|
+
const probes = useMemo(() => safeModel ? _jsx(View, { accessible: false, accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants', pointerEvents: 'none', style: { position: 'absolute', opacity: 0, flexDirection: 'row' }, children: safeModel.digits.map((glyph, index) => _createElement(Text, { ...visualProps, key: `${measurementKey}:${index}`, onLayout: event => recordGlyph(measurements, measurementKey, index, event, setMetrics), style: textStyle }, glyph)) }) : null, [measurementKey, color]);
|
|
236
|
+
// The reels are drawn in the readout's flow, so the readout is exactly as wide as the row it draws: the composed sign, every
|
|
237
|
+
// static part read from the text, each reel at the widest digit's advance and the affixes, each its own text, measured by
|
|
238
|
+
// the layout pass that draws it. The reading they replace leaves the flow (it stays, invisible, for assistive technology).
|
|
239
|
+
// Before, the reels were an overlay on the reading, and the readout only grew to the reels after their row reported its
|
|
240
|
+
// width; on the Seeker (Android) the readout kept the reading's width, so `+100.00%` drew past its box into the following
|
|
241
|
+
// ` on margin`. Wherever the parts are wider than the reading (separate texts lose the reading's kerning, a face without
|
|
242
|
+
// tabular digits), the readout is now wider by that much; where they match (iOS), nothing moves. Each reel clips its own
|
|
243
|
+
// column, so nothing bleeds vertically, and no frame clips a glyph.
|
|
244
|
+
return _jsxs(View, { collapsable: false, style: activeModel ? { position: 'relative', flexDirection: 'row', alignItems: 'center', justifyContent } : { position: 'relative' }, children: [_jsxs(Text, { accessibilityLabel: label ? `${label}: ${reading.text}${staleSuffix}` : undefined, testID: testID, maxFontSizeMultiplier: maxFontSizeMultiplier, style: [textStyle, activeModel ? hiddenReading[align] : undefined], children: [reading.text, staleSuffix] }), probes, activeModel && activeMetrics && _jsxs(View, { collapsable: false, accessible: false, accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants', pointerEvents: 'none', style: reelRowStyle, children: [prefix && _jsx(StillPart, { ...partProps, text: prefix }), activeModel.tokens.map(token => token.kind === 'static' ? _createElement(StillPart, { ...partProps, key: token.key, text: token.value }) : flow ? _jsx(FlowDigit, { glyphs: activeModel.digits, length: turns.get(token.key)?.length ?? numberFlowDigitLength(digits, numberReelPlace(token), token.digit ?? 0), digit: token.digit ?? 0, delta: turns.get(token.key)?.delta ?? 0, step: turns.get(token.key)?.step ?? 0, duration: reducedMotion ? 0 : timings.spin.duration, samples: spinSamples, fade: reducedMotion ? 0 : timings.opacity.duration, fadeSamples: fadeSamples, width: activeMetrics.width, height: activeMetrics.height, style: textStyle, styleKey: styleKey, script: script, maxFontSizeMultiplier: maxFontSizeMultiplier }, token.key) : _jsx(DigitReel, { digits: activeModel.digits, digit: token.digit ?? 0, trend: directionTrend, duration: duration, reducedMotion: reducedMotion, width: activeMetrics.width, height: activeMetrics.height, style: textStyle, styleKey: styleKey, script: script, maxFontSizeMultiplier: maxFontSizeMultiplier }, token.key)), (suffix || staleSuffix) && _jsx(StillPart, { ...partProps, text: `${suffix ?? ''}${staleSuffix}` })] })] });
|
|
97
245
|
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/** Speaks a message to VoiceOver or TalkBack. On iOS an error interrupts what is being read and anything else queues behind it; Android's announcement has no interrupting mode. A failure is swallowed: the visible text remains. */
|
|
2
|
+
export declare function speak(message: string, severity: string): void;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AccessibilityInfo, Platform } from 'react-native';
|
|
2
|
+
/** Speaks a message to VoiceOver or TalkBack. On iOS an error interrupts what is being read and anything else queues behind it; Android's announcement has no interrupting mode. A failure is swallowed: the visible text remains. */
|
|
3
|
+
export function speak(message, severity) { if (Platform.OS === 'web' || !message)
|
|
4
|
+
return; try {
|
|
5
|
+
if (Platform.OS === 'ios' && typeof AccessibilityInfo.announceForAccessibilityWithOptions === 'function')
|
|
6
|
+
AccessibilityInfo.announceForAccessibilityWithOptions(message, { queue: severity !== 'error' });
|
|
7
|
+
else
|
|
8
|
+
AccessibilityInfo.announceForAccessibility(message);
|
|
9
|
+
}
|
|
10
|
+
catch { /* The visible message and navigable text remain available. */ } }
|
|
@@ -12,9 +12,27 @@ export interface AssetBalanceRowProps {
|
|
|
12
12
|
balance?: number | null;
|
|
13
13
|
/** Format of the units line; default `{maximumFractionDigits:6}`. */
|
|
14
14
|
balanceOptions?: Intl.NumberFormatOptions;
|
|
15
|
+
/** Host text after the units figure, such as ` HYPE`. Drawn and read only when the units are known. */
|
|
16
|
+
unitsSuffix?: string;
|
|
17
|
+
/** `units` puts the units on the headline line in place of the value and draws no second line, for a holding with no dollar value. Default `value`. */
|
|
18
|
+
headline?: 'value' | 'units';
|
|
19
|
+
/** `false` draws no figures at all, for a row that is just an item to pick, such as a method or a chain. Default `true`. */
|
|
20
|
+
amounts?: boolean;
|
|
21
|
+
/** Short muted host text under the figures, such as the ledger a holding sits in. Read after them. */
|
|
22
|
+
tag?: string;
|
|
23
|
+
/** Host content on the trailing edge, after the figures. Inside a pressable row it must not be interactive. The row reads it as one label, last: its text, or `trailingLabel`. */
|
|
24
|
+
trailing?: React.ReactNode;
|
|
25
|
+
/** What the row reads for `trailing`, in place of its text, for an icon or a figure whose text is not what should be heard. */
|
|
26
|
+
trailingLabel?: string;
|
|
27
|
+
/** `trailing` holds a control, such as a Copy or Remove button: it stays its own accessibility element and touch target beside the row, out of the row's reading and outside the row's press (`<testID>-trailing`). The rest of the row is then one element (with `onSelect`, the button `<testID>-main`) read as before without the trailing text. */
|
|
28
|
+
trailingInteractive?: boolean;
|
|
29
|
+
/** Marks the row in use: a check on the trailing edge and `accessibilityState.selected`. */
|
|
30
|
+
selected?: boolean;
|
|
31
|
+
/** Dims the row, ignores presses and reads as unavailable. */
|
|
32
|
+
disabled?: boolean;
|
|
15
33
|
/** Makes the row a button. */
|
|
16
34
|
onSelect?: () => void;
|
|
17
35
|
testID?: string;
|
|
18
36
|
}
|
|
19
37
|
/** One holding as a capsule row: a round avatar, the asset's name over its symbol, and its dollar value over its units. The avatar is padded equally on every side, so the capsule end is concentric with it, and both numbers update place by place. */
|
|
20
|
-
export declare function AssetBalanceRow({ name, symbol, icon, value, balance, balanceOptions, onSelect, testID }: AssetBalanceRowProps): React.JSX.Element;
|
|
38
|
+
export declare function AssetBalanceRow({ name, symbol, icon, value, balance, balanceOptions, unitsSuffix, headline, amounts, tag, trailing, trailingLabel, trailingInteractive, selected, disabled, onSelect, testID }: AssetBalanceRowProps): React.JSX.Element;
|
|
@@ -1,21 +1,37 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Check } from '@bloxwap/icons/native/check';
|
|
3
|
+
import { useState } from 'react';
|
|
2
4
|
import { Image, Pressable, View } from 'react-native';
|
|
3
|
-
import { useColors, useFills,
|
|
5
|
+
import { useColors, useFills, useNumberLocale, usePresentNumber } from './provider.js';
|
|
4
6
|
import { Text } from './surface.js';
|
|
5
7
|
import { AnimatedNumberReadout } from './animated-number.js';
|
|
6
8
|
import { formatNumberReadout } from './animated-number-model.js';
|
|
9
|
+
import { plainText } from './text-content.js';
|
|
7
10
|
const usd = { style: 'currency', currency: 'USD' };
|
|
8
11
|
const units = { maximumFractionDigits: 6 };
|
|
9
12
|
const avatar = 40;
|
|
10
13
|
const hidden = { accessible: false, accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants' };
|
|
11
14
|
/** One holding as a capsule row: a round avatar, the asset's name over its symbol, and its dollar value over its units. The avatar is padded equally on every side, so the capsule end is concentric with it, and both numbers update place by place. */
|
|
12
|
-
export function AssetBalanceRow({ name, symbol, icon, value, balance, balanceOptions = units, onSelect, testID }) {
|
|
13
|
-
const colors = useColors(), fills = useFills(),
|
|
14
|
-
const
|
|
15
|
-
const
|
|
15
|
+
export function AssetBalanceRow({ name, symbol, icon, value, balance, balanceOptions = units, unitsSuffix, headline = 'value', amounts = true, tag, trailing, trailingLabel, trailingInteractive, selected, disabled, onSelect, testID }) {
|
|
16
|
+
const colors = useColors(), fills = useFills(), locale = useNumberLocale(), present = usePresentNumber();
|
|
17
|
+
const [held, setHeld] = useState(false);
|
|
18
|
+
const split = !!trailingInteractive && trailing != null && trailing !== false;
|
|
19
|
+
const unitsFirst = headline === 'units', hasUnits = amounts && !unitsFirst && balance !== undefined;
|
|
20
|
+
const unitsText = () => formatNumberReadout(balance, locale, balanceOptions, undefined, undefined, unitsSuffix).text;
|
|
21
|
+
const headlineText = amounts ? unitsFirst ? unitsText() : formatNumberReadout(value, locale, present(usd)).text : null;
|
|
22
|
+
const label = [name, symbol, headlineText, hasUnits ? unitsText() : null, tag || null, split ? null : trailingLabel ?? (trailing != null && trailing !== false ? plainText(trailing) : null)].filter(Boolean).join(', ');
|
|
23
|
+
const state = selected || disabled ? { ...(selected ? { selected: true } : {}), ...(disabled ? { disabled: true } : {}) } : undefined;
|
|
24
|
+
const strong = disabled ? colors.muted : colors.text;
|
|
16
25
|
const shape = { width: avatar, height: avatar, borderRadius: avatar / 2, backgroundColor: fills.raised, alignItems: 'center', justifyContent: 'center', overflow: 'hidden' };
|
|
17
26
|
const art = typeof icon === 'string' ? _jsx(Image, { accessible: false, accessibilityIgnoresInvertColors: true, source: { uri: icon }, style: shape }) : _jsx(View, { style: shape, children: icon ?? _jsx(Text, { accessible: false, maxFontSizeMultiplier: 1, style: { fontSize: 12, lineHeight: 16, fontWeight: '600', color: colors.muted }, children: symbol.slice(0, 3) }) });
|
|
18
|
-
const row = (pressed) => ({ flexDirection: 'row', alignItems: 'center', gap: 12, minHeight: 56, paddingVertical: 8, paddingStart: 8, paddingEnd: 16, borderRadius: 28, backgroundColor: pressed ? fills.raised : fills.well });
|
|
19
|
-
const content = _jsxs(_Fragment, { children: [_jsx(View, { ...hidden, children: art }), _jsxs(View, { ...hidden, style: { flex: 1, flexShrink: 1, minWidth: 0 }, children: [_jsx(Text, { numberOfLines: 1, style: { fontSize: 16, lineHeight: 24, fontWeight: '600', color:
|
|
20
|
-
|
|
27
|
+
const row = (pressed) => ({ flexDirection: 'row', alignItems: 'center', gap: 12, minHeight: 56, paddingVertical: 8, paddingStart: 8, paddingEnd: 16, borderRadius: 28, backgroundColor: pressed && !disabled ? fills.raised : fills.well });
|
|
28
|
+
const content = _jsxs(_Fragment, { children: [_jsx(View, { ...hidden, style: disabled ? { opacity: 0.5 } : undefined, children: art }), _jsxs(View, { ...hidden, style: { flex: 1, flexShrink: 1, minWidth: 0 }, children: [_jsx(Text, { numberOfLines: 1, style: { fontSize: 16, lineHeight: 24, fontWeight: '600', color: strong }, children: name }), _jsx(Text, { numberOfLines: 1, style: { fontSize: 14, lineHeight: 20, color: colors.muted }, children: symbol })] }), amounts || tag ? _jsxs(View, { ...hidden, style: { alignItems: 'flex-end', justifyContent: 'center' }, children: [amounts ? unitsFirst ? _jsx(AnimatedNumberReadout, { value: balance, options: balanceOptions, suffix: unitsSuffix, tone: disabled ? 'muted' : undefined, testID: testID ? `${testID}-balance` : undefined, style: { fontSize: 16, lineHeight: 24, fontWeight: '600' } }) : _jsx(AnimatedNumberReadout, { value: value, options: usd, tone: disabled ? 'muted' : undefined, testID: testID ? `${testID}-value` : undefined, style: { fontSize: 16, lineHeight: 24, fontWeight: '600' } }) : null, hasUnits ? _jsx(AnimatedNumberReadout, { value: balance, options: balanceOptions, suffix: unitsSuffix, tone: 'muted', testID: testID ? `${testID}-balance` : undefined, style: { fontSize: 14, lineHeight: 20 } }) : null, tag ? _jsx(Text, { testID: testID ? `${testID}-tag` : undefined, numberOfLines: 1, style: { fontSize: 12, lineHeight: 18, color: colors.muted }, children: tag }) : null] }) : null, trailing != null && trailing !== false && !split ? _jsx(View, { ...hidden, testID: testID ? `${testID}-trailing` : undefined, style: { flexDirection: 'row', alignItems: 'center', gap: 8 }, children: trailing }) : null] });
|
|
29
|
+
const check = selected ? _jsx(Check, { size: 20, color: strong, testID: testID ? `${testID}-check` : undefined }) : null;
|
|
30
|
+
if (split) {
|
|
31
|
+
// The control leaves the row's element: the rest is one element (or button), the control its own target beside it.
|
|
32
|
+
const main = { flex: 1, minWidth: 0, flexDirection: 'row', alignItems: 'center', gap: 12, alignSelf: 'stretch' };
|
|
33
|
+
return _jsxs(View, { testID: testID, style: row(held), children: [onSelect ? _jsx(Pressable, { testID: testID ? `${testID}-main` : undefined, accessibilityRole: 'button', accessibilityLabel: label, accessibilityState: state, disabled: disabled, onPress: onSelect, onPressIn: () => setHeld(true), onPressOut: () => setHeld(false), style: main, children: content })
|
|
34
|
+
: _jsx(View, { testID: testID ? `${testID}-main` : undefined, accessible: true, accessibilityLabel: label, accessibilityState: state, style: main, children: content }), _jsx(View, { testID: testID ? `${testID}-trailing` : undefined, style: { flexDirection: 'row', alignItems: 'center', gap: 8 }, children: trailing }), check] });
|
|
35
|
+
}
|
|
36
|
+
return onSelect ? _jsxs(Pressable, { testID: testID, accessibilityRole: 'button', accessibilityLabel: label, accessibilityState: state, disabled: disabled, onPress: onSelect, style: ({ pressed }) => row(pressed), children: [content, check] }) : _jsxs(View, { testID: testID, accessible: true, accessibilityLabel: label, accessibilityState: state, style: row(false), children: [content, check] });
|
|
21
37
|
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type ScrollViewProps } from 'react-native';
|
|
3
|
+
/** A market's live heat signal: `watch` while it is being watched, `up` or `down` once it trends. */
|
|
4
|
+
export type AssetSignal = 'watch' | 'up' | 'down';
|
|
5
|
+
/** The three views of the list: every market, the markets with an open position, and the markets with a signal. */
|
|
6
|
+
export type AssetsView = 'all' | 'positions' | 'trend';
|
|
7
|
+
/** One market the host offers. Every word is host text. */
|
|
8
|
+
export interface AssetItem {
|
|
9
|
+
/** Stable id the host switches on. */
|
|
10
|
+
id: string;
|
|
11
|
+
/** Bitcoin. */
|
|
12
|
+
name: string;
|
|
13
|
+
/** BTC. */
|
|
14
|
+
symbol: string;
|
|
15
|
+
/** `id` of the `AssetCategory` whose section the market sits in. */
|
|
16
|
+
category: string;
|
|
17
|
+
/** Short host text after the symbol on the second line, such as the maximum leverage: `40×`. */
|
|
18
|
+
detail?: string;
|
|
19
|
+
/** Round artwork: an image URL or a host element. Without it the row shows the first letters of the symbol. */
|
|
20
|
+
icon?: string | React.ReactElement;
|
|
21
|
+
/** The trailing signal disc. `null` draws an empty disc, for a market with no signal yet; leave it out to draw no disc. */
|
|
22
|
+
signal?: AssetSignal | null;
|
|
23
|
+
/** The viewer holds an open position in this market, so it shows under Positions. */
|
|
24
|
+
position?: boolean;
|
|
25
|
+
/** Host content on the trailing edge, before the signal disc, such as the live result of the viewer's open position. It is drawn only (inside the row button, hidden from assistive technology); the row reads `trailingLabel` for it. Test ID `<testID>-<id>-trailing`. */
|
|
26
|
+
trailing?: React.ReactNode;
|
|
27
|
+
/** Words the row reads after its symbol line, such as `open position`, for what `trailing` shows. */
|
|
28
|
+
trailingLabel?: string;
|
|
29
|
+
/** More text the search matches, such as an alias or a ticker on another venue. */
|
|
30
|
+
keywords?: string;
|
|
31
|
+
disabled?: boolean;
|
|
32
|
+
}
|
|
33
|
+
/** A market type: a section of the list and a capsule in the category filter. */
|
|
34
|
+
export interface AssetCategory {
|
|
35
|
+
id: string;
|
|
36
|
+
/** Crypto. */
|
|
37
|
+
label: string;
|
|
38
|
+
/** A badge on the section heading's trailing edge, such as OPEN. Bloxwap trades around the clock, so there is no closed badge: use `opensAt` for a legacy market that is shut. */
|
|
39
|
+
status?: {
|
|
40
|
+
label: string;
|
|
41
|
+
tone?: 'positive' | 'negative' | 'warning' | 'info';
|
|
42
|
+
};
|
|
43
|
+
/** When the legacy market behind this category next opens, as epoch milliseconds or a `Date`. While it is ahead, the badge counts down to it (“Opens in 2:14:33”) in place of `status`, and the heading reads it in words. Once it passes, `status` shows again. */
|
|
44
|
+
opensAt?: number | Date;
|
|
45
|
+
}
|
|
46
|
+
export interface AssetsBlockProps {
|
|
47
|
+
/** Shows a clear button in the search field while it holds text: it empties the query and returns focus to the field. Named by `messages.clearSearch`; test ID `<testID>-search-clear`. */
|
|
48
|
+
clearable?: boolean;
|
|
49
|
+
/** Heading. Defaults to the built-in “Assets”. */
|
|
50
|
+
title?: string;
|
|
51
|
+
/** Shows Close on the trailing edge of the header. */
|
|
52
|
+
onClose?: () => void;
|
|
53
|
+
assets: readonly AssetItem[];
|
|
54
|
+
/** Sections and filter capsules, in order. A market whose category is not listed is not shown. */
|
|
55
|
+
categories: readonly AssetCategory[];
|
|
56
|
+
onSelect: (asset: AssetItem) => void;
|
|
57
|
+
/** `id` of the market in use: its row is marked selected. */
|
|
58
|
+
selectedId?: string | null;
|
|
59
|
+
view?: AssetsView;
|
|
60
|
+
defaultView?: AssetsView;
|
|
61
|
+
onViewChange?: (view: AssetsView) => void;
|
|
62
|
+
/** `id` of the chosen category; `''` is All. */
|
|
63
|
+
category?: string;
|
|
64
|
+
defaultCategory?: string;
|
|
65
|
+
onCategoryChange?: (category: string) => void;
|
|
66
|
+
query?: string;
|
|
67
|
+
defaultQuery?: string;
|
|
68
|
+
onQueryChange?: (query: string) => void;
|
|
69
|
+
/** `false` leaves out the category filter. Defaults to `true` when there is more than one category. */
|
|
70
|
+
categoryFilter?: boolean;
|
|
71
|
+
/** The horizontal scroll view the category capsules sit in, such as a sheet library's ScrollView. Forwarded to `Filter`. */
|
|
72
|
+
filterScrollComponent?: React.ComponentType<ScrollViewProps>;
|
|
73
|
+
/** Shows the loading text in place of the empty text while the list is empty. */
|
|
74
|
+
loading?: boolean;
|
|
75
|
+
/** Keeps the header pinned while the rest scrolls: the block becomes its own scroll view with the header as its sticky first child, transparent at rest and filled once content scrolls under it (test ID `<testID>-sticky-header`, `assets-sticky-header` without one). Place it in a bounded container, such as a sheet body. */
|
|
76
|
+
stickyHeader?: boolean;
|
|
77
|
+
/** With `stickyHeader`: the header's fill once content is under it. Defaults to the background role; in a sheet pass the sheet's fill. */
|
|
78
|
+
stickyHeaderBackground?: string;
|
|
79
|
+
/** The scroll view used with `stickyHeader`, such as a sheet library's own. Defaults to React Native's ScrollView. */
|
|
80
|
+
scrollComponent?: React.ComponentType<ScrollViewProps>;
|
|
81
|
+
/** `nativeID` of the title, so a sheet around the block can name itself with `accessibilityLabelledBy` (Android), as `GestureSheet labelledBy` does. */
|
|
82
|
+
headingId?: string;
|
|
83
|
+
/** Freezes the opening countdown at the text it last showed, stops its timer and its digits rolling, for example while the sheet is closed or the app is in the background. */
|
|
84
|
+
paused?: boolean;
|
|
85
|
+
/** The host's clock in epoch milliseconds, read for the opening countdown. Defaults to `Date.now`. */
|
|
86
|
+
now?: () => number;
|
|
87
|
+
/** A button under the empty text, drawn only while the list is empty and not `loading`, such as Browse all markets on an empty Positions view. Test ID `testID`, else `<testID>-empty-action`. */
|
|
88
|
+
emptyAction?: AssetsEmptyAction;
|
|
89
|
+
/** Focuses the search field on mount, raising the keyboard, so typing filters at once. */
|
|
90
|
+
autoFocusSearch?: boolean;
|
|
91
|
+
/** While the search field holds a query, the keyboard's Search key chooses the first enabled match, as a search box's top hit. By default it only closes the keyboard. */
|
|
92
|
+
enterChoosesFirst?: boolean;
|
|
93
|
+
testID?: string;
|
|
94
|
+
}
|
|
95
|
+
/** The empty list's action. */
|
|
96
|
+
export interface AssetsEmptyAction {
|
|
97
|
+
label: string;
|
|
98
|
+
onPress: () => void;
|
|
99
|
+
testID?: string;
|
|
100
|
+
}
|
|
101
|
+
/** The markets a view, category and query leave, grouped by category in the host's order. Empty sections are dropped. */
|
|
102
|
+
export declare function filterAssets(assets: readonly AssetItem[], categories: readonly AssetCategory[], { view, category, query }?: {
|
|
103
|
+
view?: AssetsView;
|
|
104
|
+
category?: string;
|
|
105
|
+
query?: string;
|
|
106
|
+
}): {
|
|
107
|
+
category: AssetCategory;
|
|
108
|
+
assets: AssetItem[];
|
|
109
|
+
}[];
|
|
110
|
+
/**
|
|
111
|
+
* Choose a market as one screen: a header, a search field, category capsules, the All / Positions / Trend views, then the
|
|
112
|
+
* markets in sections by category, each with its icon, name, symbol and detail on one line each, and its signal disc. The host
|
|
113
|
+
* owns the data and the scrolling, unless `stickyHeader` makes the block its own scroll view.
|
|
114
|
+
*/
|
|
115
|
+
export declare function AssetsBlock({ title, onClose, assets, categories, onSelect, selectedId, view, defaultView, onViewChange, category, defaultCategory, onCategoryChange, query, defaultQuery, onQueryChange, categoryFilter, filterScrollComponent, loading, stickyHeader, stickyHeaderBackground, scrollComponent, headingId, clearable, paused, now: clock, emptyAction, autoFocusSearch, enterChoosesFirst, testID }: AssetsBlockProps): React.JSX.Element;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
3
|
+
import { formatCountdown } from '@bloxwap/hig/contracts';
|
|
4
|
+
import { Image, Pressable, View } from 'react-native';
|
|
5
|
+
import { useColors, useFills, useHIG, useMessages } from './provider.js';
|
|
6
|
+
import { Text } from './surface.js';
|
|
7
|
+
import { AnimatedNumberReadout } from './animated-number.js';
|
|
8
|
+
import { SearchInput } from './field.js';
|
|
9
|
+
import { Filter, SegmentedControl } from './radio-group.js';
|
|
10
|
+
import { ScreenHeader, HeaderClose } from './screen-header.js';
|
|
11
|
+
import { StickyHeaderLayout } from './sticky-header.js';
|
|
12
|
+
import { EyeIcon, TrendIcon } from './icons.js';
|
|
13
|
+
import { Button } from './button.js';
|
|
14
|
+
const fold = (text) => text.normalize('NFD').replace(/[̀-ͯ]/g, '').toLowerCase();
|
|
15
|
+
/** The markets a view, category and query leave, grouped by category in the host's order. Empty sections are dropped. */
|
|
16
|
+
export function filterAssets(assets, categories, { view = 'all', category = '', query = '' } = {}) {
|
|
17
|
+
const needle = fold(query.trim());
|
|
18
|
+
const keep = (asset) => (view === 'all' || (view === 'positions' ? !!asset.position : asset.signal != null)) && (needle === '' || fold(`${asset.name} ${asset.symbol} ${asset.keywords ?? ''}`).includes(needle));
|
|
19
|
+
return categories.filter(entry => category === '' || entry.id === category).map(entry => ({ category: entry, assets: assets.filter(asset => asset.category === entry.id && keep(asset)) })).filter(section => section.assets.length > 0);
|
|
20
|
+
}
|
|
21
|
+
/** Controlled when `value` is set, otherwise local. No feedback: the filter and segmented control emit their own, and typing emits none. */
|
|
22
|
+
function useHostState(value, initial, onChange) {
|
|
23
|
+
const [local, setLocal] = useState(initial);
|
|
24
|
+
const current = value === undefined ? local : value;
|
|
25
|
+
return [current, next => { if (Object.is(next, current))
|
|
26
|
+
return; if (value === undefined)
|
|
27
|
+
setLocal(next); onChange?.(next); }];
|
|
28
|
+
}
|
|
29
|
+
/** The host clock, ticking each second while one of `openings` is still ahead and not `paused`; paused keeps the last reading (or takes one) and judges "ahead" against it, so a host re-render after an opening passes keeps the frozen text. */
|
|
30
|
+
function useNow(openings, paused, clock) {
|
|
31
|
+
const [now, setNow] = useState(() => { const first = clock(); return openings.some(at => at > first) ? first : null; });
|
|
32
|
+
const read = useRef(clock);
|
|
33
|
+
read.current = clock;
|
|
34
|
+
const reading = paused && now != null ? now : openings.length ? clock() : 0;
|
|
35
|
+
const active = openings.some(at => at > reading);
|
|
36
|
+
useEffect(() => { if (!active) {
|
|
37
|
+
setNow(null);
|
|
38
|
+
return;
|
|
39
|
+
} if (paused) {
|
|
40
|
+
setNow(last => last ?? read.current());
|
|
41
|
+
return;
|
|
42
|
+
} setNow(read.current()); const tick = setInterval(() => setNow(read.current()), 1000); return () => clearInterval(tick); }, [active, paused]);
|
|
43
|
+
return active ? now : null;
|
|
44
|
+
}
|
|
45
|
+
const opensAtTime = (category) => category.opensAt == null ? null : +category.opensAt;
|
|
46
|
+
const hidden = { accessible: false, accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants' };
|
|
47
|
+
const disc = 44;
|
|
48
|
+
/**
|
|
49
|
+
* Choose a market as one screen: a header, a search field, category capsules, the All / Positions / Trend views, then the
|
|
50
|
+
* markets in sections by category, each with its icon, name, symbol and detail on one line each, and its signal disc. The host
|
|
51
|
+
* owns the data and the scrolling, unless `stickyHeader` makes the block its own scroll view.
|
|
52
|
+
*/
|
|
53
|
+
export function AssetsBlock({ title, onClose, assets, categories, onSelect, selectedId = null, view, defaultView = 'all', onViewChange, category, defaultCategory = '', onCategoryChange, query, defaultQuery = '', onQueryChange, categoryFilter, filterScrollComponent, loading, stickyHeader, stickyHeaderBackground, scrollComponent, headingId, clearable, paused = false, now: clock = Date.now, emptyAction, autoFocusSearch, enterChoosesFirst, testID }) {
|
|
54
|
+
const colors = useColors(), fills = useFills(), t = useMessages(), { direction, locale } = useHIG();
|
|
55
|
+
const id = (part) => testID === undefined ? undefined : `${testID}-${part}`;
|
|
56
|
+
const [currentView, setView] = useHostState(view, defaultView, onViewChange);
|
|
57
|
+
const [currentCategory, setCategory] = useHostState(category, defaultCategory, onCategoryChange);
|
|
58
|
+
const [currentQuery, setQuery] = useHostState(query, defaultQuery, onQueryChange);
|
|
59
|
+
const sections = useMemo(() => filterAssets(assets, categories, { view: currentView, category: currentCategory, query: currentQuery }), [assets, categories, currentView, currentCategory, currentQuery]);
|
|
60
|
+
// The clock runs only while a section on screen has an opening still ahead.
|
|
61
|
+
const now = useNow(sections.flatMap(section => { const at = opensAtTime(section.category); return at == null ? [] : [at]; }), paused, clock);
|
|
62
|
+
const signalName = { watch: t.signalWatch, up: t.signalUp, down: t.signalDown };
|
|
63
|
+
const signalColor = { watch: colors.warning, up: colors.positive, down: colors.negative };
|
|
64
|
+
const toneColor = { positive: colors.positive, negative: colors.negative, warning: colors.warning, info: colors.info };
|
|
65
|
+
const empty = loading ? `${t.loading}…` : currentQuery.trim() !== '' ? t.noResults : currentView === 'positions' ? t.noPositions : currentView === 'trend' ? t.noTrend : t.noItems;
|
|
66
|
+
const round = { width: disc, height: disc, borderRadius: disc / 2, alignItems: 'center', justifyContent: 'center', overflow: 'hidden' };
|
|
67
|
+
const row = (asset) => {
|
|
68
|
+
const second = asset.detail ? `${asset.symbol} · ${asset.detail}` : asset.symbol;
|
|
69
|
+
const selected = asset.id === selectedId;
|
|
70
|
+
const style = ({ pressed }) => ({ flexDirection: 'row', alignItems: 'center', gap: 12, minHeight: 64, padding: 8, borderRadius: 32, backgroundColor: pressed || selected ? fills.well : 'transparent', opacity: asset.disabled ? 0.5 : 1 });
|
|
71
|
+
return _jsx(Pressable, { testID: id(asset.id), accessibilityRole: 'button', accessibilityLabel: [asset.name, second, asset.trailingLabel, asset.signal ? signalName[asset.signal] : null].filter(Boolean).join(', '), accessibilityState: { selected, disabled: !!asset.disabled }, disabled: asset.disabled, onPress: () => onSelect(asset), style: style, children: ({ pressed }) => _jsxs(_Fragment, { children: [_jsx(View, { ...hidden, children: typeof asset.icon === 'string' ? _jsx(Image, { accessible: false, accessibilityIgnoresInvertColors: true, source: { uri: asset.icon }, style: round }) : _jsx(View, { style: [round, { backgroundColor: fills.raised }], children: asset.icon ?? _jsx(Text, { accessible: false, maxFontSizeMultiplier: 1, style: { fontSize: 12, lineHeight: 16, fontWeight: '600', color: colors.muted }, children: asset.symbol.slice(0, 4) }) }) }), _jsxs(View, { ...hidden, style: { flex: 1, flexShrink: 1, minWidth: 0 }, children: [_jsx(Text, { numberOfLines: 1, style: { fontSize: 16, lineHeight: 24, fontWeight: '600', color: colors.text }, children: asset.name }), _jsx(Text, { numberOfLines: 1, style: { fontSize: 14, lineHeight: 20, color: colors.muted }, children: second })] }), asset.trailing != null && asset.trailing !== false ? _jsx(View, { ...hidden, testID: id(`${asset.id}-trailing`), style: { flexShrink: 0, alignItems: 'flex-end' }, children: asset.trailing }) : null, asset.signal === undefined ? null : _jsx(View, { ...hidden, testID: id(`${asset.id}-signal`), style: [round, { backgroundColor: asset.signal ? `${signalColor[asset.signal]}26` : pressed || selected ? fills.raised : fills.well }], children: asset.signal === 'watch' ? _jsx(EyeIcon, { color: colors.warning }) : asset.signal ? _jsx(TrendIcon, { color: signalColor[asset.signal], direction: asset.signal }) : null })] }) }, asset.id);
|
|
72
|
+
};
|
|
73
|
+
const showFilter = (categoryFilter ?? true) && categories.length > 1;
|
|
74
|
+
const header = _jsx(ScreenHeader, { title: title ?? t.assets, testID: id('header'), headingId: headingId, action: onClose ? _jsx(HeaderClose, { onClose: onClose, label: t.close, testID: id('close') }) : undefined });
|
|
75
|
+
const body = _jsxs(_Fragment, { children: [_jsx(SearchInput, { testID: id('search'), accessibilityLabel: t.searchMarkets, placeholder: `${t.searchMarkets}…`, value: currentQuery, onChangeText: setQuery, onClear: clearable ? () => setQuery('') : undefined, autoFocus: autoFocusSearch, returnKeyType: 'search', onSubmitEditing: enterChoosesFirst ? () => { const first = currentQuery.trim() === '' ? undefined : sections.flatMap(section => section.assets).find(asset => !asset.disabled); if (first)
|
|
76
|
+
onSelect(first); } : undefined, autoCapitalize: 'none', autoCorrect: false, spellCheck: false }), showFilter ? _jsx(Filter, { label: t.marketCategories, options: [{ value: '', label: t.assetsAll }, ...categories.map(entry => ({ value: entry.id, label: entry.label }))], value: currentCategory, onValueChange: setCategory, scrollComponent: filterScrollComponent, bleed: 16 }) : null, _jsx(SegmentedControl, { hideLabel: true, testID: id('view'), label: t.assetsView, options: [{ value: 'all', label: t.assetsAll }, { value: 'positions', label: t.assetsPositions }, { value: 'trend', label: t.assetsTrend }], value: currentView, onValueChange: next => setView(next) }), sections.length === 0 ? _jsxs(View, { style: { gap: 16, alignItems: 'center' }, children: [_jsx(Text, { testID: id('empty'), accessibilityLiveRegion: 'polite', style: { alignSelf: 'stretch', paddingVertical: 32, textAlign: 'center', fontSize: 14, lineHeight: 20, color: colors.muted }, children: empty }), !loading && emptyAction ? _jsx(Button, { intent: 'secondary', testID: emptyAction.testID ?? id('empty-action'), onPress: emptyAction.onPress, style: { alignSelf: 'center' }, children: emptyAction.label }) : null] }) :
|
|
77
|
+
_jsx(View, { testID: id('list'), style: { gap: 16 }, children: sections.map(section => {
|
|
78
|
+
const at = opensAtTime(section.category);
|
|
79
|
+
const remaining = now != null && at != null && at > now ? at - now : null, countdown = remaining != null ? formatCountdown(remaining, locale) : null;
|
|
80
|
+
const status = countdown ? { label: `${t.opensIn} ${countdown.visible}`, spoken: `${t.opensIn} ${countdown.spoken}`, color: colors.muted, fill: fills.well } : section.category.status ? { label: section.category.status.label, spoken: section.category.status.label, color: toneColor[section.category.status.tone ?? 'positive'], fill: `${toneColor[section.category.status.tone ?? 'positive']}26` } : null;
|
|
81
|
+
return _jsxs(View, { testID: id(`section-${section.category.id}`), style: { gap: 4 }, children: [_jsxs(View, { testID: id(`section-${section.category.id}-header`), style: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', gap: 12, minHeight: 32, paddingHorizontal: 8 }, children: [_jsx(Text, { accessibilityRole: 'header', accessibilityLabel: status ? `${section.category.label}, ${status.spoken}` : undefined, style: { flexShrink: 1, fontSize: 14, lineHeight: 20, fontWeight: '500', color: colors.muted }, children: section.category.label }), status ? _jsx(View, { ...hidden, testID: id(`status-${section.category.id}`), style: { borderRadius: 9999, paddingVertical: 2, paddingHorizontal: 10, backgroundColor: status.fill }, children: countdown && remaining != null ? _jsx(AnimatedNumberReadout, { value: Math.ceil(remaining / 1000), formattedValue: countdown.visible, animateFormatted: true, duration: paused ? 0 : undefined, prefix: `${t.opensIn} `, testID: id(`countdown-${section.category.id}`), tone: 'muted', maxFontSizeMultiplier: 1.4, style: { fontSize: 12, lineHeight: 16, fontWeight: '600', letterSpacing: 0.25 } }) : _jsx(Text, { maxFontSizeMultiplier: 1.4, style: { fontSize: 12, lineHeight: 16, fontWeight: '600', letterSpacing: 1, fontVariant: ['tabular-nums'], color: status.color }, children: status.label }) }) : null] }), _jsx(View, { style: { gap: 4 }, children: section.assets.map(row) })] }, section.category.id);
|
|
82
|
+
}) })] });
|
|
83
|
+
// The sticky layout puts the header and the body in separate views, so the body's first gap is its top padding.
|
|
84
|
+
if (stickyHeader)
|
|
85
|
+
return _jsx(StickyHeaderLayout, { testID: testID, headerTestID: id('sticky-header') ?? 'assets-sticky-header', header: header, background: stickyHeaderBackground, scrollComponent: scrollComponent, bodyStyle: { direction, gap: 16, paddingTop: 16 }, children: body });
|
|
86
|
+
return _jsxs(View, { testID: testID, style: { direction, padding: 16, gap: 16 }, children: [header, body] });
|
|
87
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
/** Start an operation and test whether its result still belongs to this owner. */
|
|
3
|
+
export function useAsyncResult(owner) {
|
|
4
|
+
const state = useRef({ owner, generation: 0, alive: true });
|
|
5
|
+
if (!Object.is(state.current.owner, owner)) {
|
|
6
|
+
state.current.owner = owner;
|
|
7
|
+
state.current.generation++;
|
|
8
|
+
}
|
|
9
|
+
useEffect(() => { state.current.alive = true; return () => { state.current.alive = false; state.current.generation++; }; }, []);
|
|
10
|
+
return () => { const generation = ++state.current.generation; return () => state.current.alive && state.current.generation === generation; };
|
|
11
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type ImageSourcePropType } from 'react-native';
|
|
3
|
+
/** The side of an avatar when `size` is left out. */
|
|
4
|
+
export declare const avatarSize = 40;
|
|
5
|
+
/** What every Avatar takes, with or without the generated face. */
|
|
6
|
+
export interface AvatarFrameProps {
|
|
7
|
+
/** The person or account. It is the accessible name, and the first two letters are the initials. */
|
|
8
|
+
name: string;
|
|
9
|
+
/** An image to show instead, cropped to fill the box. If it fails to load, or it names no image (`{uri: undefined}`, an empty address), the fallback shows in its place. */
|
|
10
|
+
source?: ImageSourcePropType;
|
|
11
|
+
/** Width and height in dp. Defaults to 40. With it, the initials are drawn at 40% of the size and keep that size at every system text size, so they stay inside the box. A size that is not a finite number of zero or more is ignored. */
|
|
12
|
+
size?: number;
|
|
13
|
+
/** A square with no rounded corners instead of a disc, for a host that clips it to its own shape. */
|
|
14
|
+
square?: boolean;
|
|
15
|
+
/** Hides the avatar from VoiceOver and TalkBack, for an avatar beside the name it stands for. */
|
|
16
|
+
decorative?: boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The same frame props: each one identical, and `source` the same image in whichever object.
|
|
20
|
+
* Each prop is read by name, because walking a list of names costs as much as the render it saves. `tests/native/avatar-typecheck.tsx` lists every prop, so a new one is seen there.
|
|
21
|
+
*/
|
|
22
|
+
export declare const sameFrame: (a: AvatarFrameProps, b: AvatarFrameProps) => boolean;
|
|
23
|
+
/**
|
|
24
|
+
* The box behind every Avatar: the image, else `face` clipped to the box, else the first two letters on the well fill.
|
|
25
|
+
* Internal. `status` renders it with no face and `avatar` with the generated one, so only the `avatar` entry loads `react-native-svg`.
|
|
26
|
+
*/
|
|
27
|
+
export declare function AvatarFrame({ name, source, size, square, decorative, face }: AvatarFrameProps & {
|
|
28
|
+
face?: React.ReactNode;
|
|
29
|
+
}): React.JSX.Element;
|