@bloxwap/hig 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +29 -2
- package/contracts/dist/index.js +123 -4
- package/contracts/dist/invariants.d.ts +17 -0
- package/contracts/dist/invariants.js +24 -0
- package/contracts/dist/login.d.ts +34 -0
- package/contracts/dist/login.js +43 -0
- package/contracts/dist/messages.d.ts +57 -3
- package/contracts/dist/messages.js +20 -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 +10 -1
- package/native/dist/account-block.js +17 -7
- package/native/dist/animated-number-model.d.ts +41 -1
- package/native/dist/animated-number-model.js +201 -23
- package/native/dist/animated-number.d.ts +39 -1
- package/native/dist/animated-number.js +164 -17
- package/native/dist/announce.d.ts +2 -0
- package/native/dist/announce.js +10 -0
- package/native/dist/asset-balance-row.d.ts +3 -1
- package/native/dist/asset-balance-row.js +15 -4
- 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 +2 -0
- package/native/dist/bar-mark.js +4 -2
- package/native/dist/bar-pnl.js +2 -1
- package/native/dist/blocks.d.ts +9 -2
- package/native/dist/blocks.js +8 -1
- package/native/dist/brand.js +2 -1
- package/native/dist/button.d.ts +7 -2
- package/native/dist/button.js +13 -3
- 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 +5 -1
- package/native/dist/deposit-block.d.ts +19 -0
- package/native/dist/deposit-block.js +17 -0
- package/native/dist/explainer-block.d.ts +91 -0
- package/native/dist/explainer-block.js +34 -0
- package/native/dist/field.d.ts +5 -1
- package/native/dist/field.js +27 -6
- 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 +10 -1
- package/native/dist/language-block.js +11 -4
- package/native/dist/list-group.d.ts +3 -1
- package/native/dist/list-group.js +26 -13
- package/native/dist/login-block.d.ts +4 -0
- package/native/dist/login-block.js +22 -0
- package/native/dist/manage-position-block.d.ts +8 -1
- package/native/dist/manage-position-block.js +7 -2
- package/native/dist/market-row.js +19 -8
- package/native/dist/navigation.js +5 -3
- package/native/dist/number-format.d.ts +6 -0
- package/native/dist/number-format.js +9 -0
- package/native/dist/pickers.d.ts +8 -0
- package/native/dist/pickers.js +3 -3
- package/native/dist/position-block.d.ts +5 -5
- 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 +10 -1
- package/native/dist/profile-block.js +8 -3
- package/native/dist/provider.d.ts +5 -2
- package/native/dist/provider.js +27 -5
- package/native/dist/qr-code.d.ts +33 -0
- package/native/dist/qr-code.js +29 -0
- package/native/dist/radio-group.d.ts +19 -7
- package/native/dist/radio-group.js +39 -10
- package/native/dist/reward-block.d.ts +10 -7
- package/native/dist/reward-block.js +9 -4
- package/native/dist/screen-header.d.ts +13 -3
- package/native/dist/screen-header.js +12 -4
- package/native/dist/select.js +4 -2
- package/native/dist/selection.d.ts +2 -1
- package/native/dist/selection.js +1 -0
- package/native/dist/setting-switch.d.ts +1 -1
- package/native/dist/setting-switch.js +7 -3
- package/native/dist/slider.js +5 -1
- package/native/dist/sound-haptics-block.js +1 -1
- package/native/dist/status.d.ts +41 -9
- package/native/dist/status.js +34 -17
- package/native/dist/sticky-header.js +9 -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 → swap-block.d.ts} +18 -8
- package/native/dist/{swap-panel-block.js → swap-block.js} +63 -35
- package/native/dist/swap-parts.d.ts +3 -10
- package/native/dist/swap-parts.js +22 -24
- package/native/dist/swap-shared.d.ts +2 -2
- package/native/dist/swap-shared.js +10 -6
- package/native/dist/swap-sheet.d.ts +3 -3
- package/native/dist/swap-sheet.js +3 -3
- package/native/dist/swap-views.js +1 -1
- package/native/dist/target-block.d.ts +7 -1
- package/native/dist/target-block.js +13 -6
- package/native/dist/toast.d.ts +47 -0
- package/native/dist/toast.js +386 -0
- package/native/dist/token-action-block.d.ts +11 -2
- package/native/dist/token-action-block.js +10 -4
- package/native/dist/trade-history-list-block.js +7 -4
- package/native/dist/wallet-address-core.js +6 -3
- package/native-fonts/README.md +1 -1
- package/og-fonts/README.md +1 -1
- package/package.json +155 -11
- 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 +18 -0
- package/react/dist/animated-number-model.js +75 -5
- package/react/dist/animated-number.d.ts +45 -1
- package/react/dist/animated-number.js +137 -6
- package/react/dist/asset-balance-row.d.ts +3 -1
- package/react/dist/asset-balance-row.js +10 -4
- 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/blocks/account-block.d.ts +5 -1
- package/react/dist/blocks/account-block.js +11 -6
- 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/deposit-block.d.ts +19 -0
- package/react/dist/blocks/deposit-block.js +15 -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 +5 -1
- package/react/dist/blocks/language-block.js +4 -3
- package/react/dist/blocks/login-block.d.ts +4 -0
- package/react/dist/blocks/login-block.js +14 -0
- package/react/dist/blocks/manage-position-block.d.ts +3 -1
- package/react/dist/blocks/manage-position-block.js +2 -2
- package/react/dist/blocks/market-row.js +8 -3
- package/react/dist/blocks/notifications-block.d.ts +3 -1
- package/react/dist/blocks/notifications-block.js +2 -2
- package/react/dist/blocks/pickers.d.ts +9 -0
- package/react/dist/blocks/pickers.js +4 -2
- package/react/dist/blocks/position-block.d.ts +3 -3
- 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 +5 -1
- package/react/dist/blocks/profile-block.js +12 -13
- package/react/dist/blocks/reward-block.d.ts +13 -8
- package/react/dist/blocks/reward-block.js +7 -4
- package/react/dist/blocks/screen-header.d.ts +10 -2
- package/react/dist/blocks/screen-header.js +7 -4
- package/react/dist/blocks/setting-switch.js +6 -3
- package/react/dist/blocks/signals-block.d.ts +3 -1
- package/react/dist/blocks/signals-block.js +4 -3
- package/react/dist/blocks/sound-haptics-block.d.ts +3 -1
- package/react/dist/blocks/sound-haptics-block.js +2 -2
- package/react/dist/blocks/sticky-header.d.ts +14 -4
- package/react/dist/blocks/sticky-header.js +68 -8
- package/react/dist/blocks/swap/settings.js +2 -1
- package/react/dist/blocks/swap/shared.d.ts +22 -22
- package/react/dist/blocks/swap/shared.js +30 -28
- package/react/dist/blocks/{swap-panel-block.d.ts → swap-block.d.ts} +19 -8
- package/react/dist/blocks/swap-block.js +215 -0
- package/react/dist/blocks/swap-sheet.d.ts +3 -3
- package/react/dist/blocks/swap-sheet.js +3 -3
- package/react/dist/blocks/target-block.d.ts +7 -1
- package/react/dist/blocks/target-block.js +10 -4
- package/react/dist/blocks/token-action-block.d.ts +6 -2
- package/react/dist/blocks/token-action-block.js +3 -2
- package/react/dist/blocks/trade-history-detail-block.d.ts +3 -1
- package/react/dist/blocks/trade-history-detail-block.js +2 -2
- package/react/dist/blocks/trade-history-list-block.d.ts +3 -1
- package/react/dist/blocks/trade-history-list-block.js +7 -4
- package/react/dist/blocks.d.ts +8 -2
- package/react/dist/blocks.js +7 -1
- package/react/dist/brand.js +2 -1
- package/react/dist/button.d.ts +9 -3
- package/react/dist/button.js +8 -3
- package/react/dist/confetti.d.ts +27 -0
- package/react/dist/confetti.js +240 -0
- package/react/dist/data.js +8 -1
- package/react/dist/field.d.ts +6 -1
- package/react/dist/field.js +18 -9
- package/react/dist/gesture-sheet.d.ts +15 -1
- package/react/dist/gesture-sheet.js +53 -8
- package/react/dist/list-group.js +11 -7
- package/react/dist/navigation.js +11 -3
- package/react/dist/overlay.d.ts +1 -4
- package/react/dist/overlay.js +1 -3
- package/react/dist/popover.d.ts +30 -0
- package/react/dist/popover.js +34 -0
- package/react/dist/preset-group.d.ts +30 -0
- package/react/dist/preset-group.js +13 -0
- package/react/dist/provider.d.ts +2 -2
- package/react/dist/provider.js +23 -6
- 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 +13 -5
- package/react/dist/selection.js +13 -8
- 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 +260 -165
- package/react/dist/toast.d.ts +19 -12
- package/react/dist/toast.js +29 -7
- package/react/dist/wallet-address-core.d.ts +8 -4
- package/react/dist/wallet-address-core.js +10 -5
- package/tokens/README.md +2 -2
- package/tokens/assets/onramps/apple-pay.svg +33 -0
- package/tokens/assets/onramps/bank.svg +98 -0
- package/tokens/assets/onramps/blink.svg +37 -0
- package/tokens/assets/onramps/cashapp.svg +33 -0
- package/tokens/assets/onramps/crypto.svg +121 -0
- package/tokens/assets/onramps/exchange.svg +105 -0
- package/tokens/dist/deposit-icons.d.ts +1 -0
- package/tokens/dist/deposit-icons.js +28 -0
- 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
- package/react/dist/blocks/swap-panel-block.js +0 -178
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { validateSnapPoints } from './gesture-sheet-model.js';
|
|
3
|
+
import React, { createContext, useCallback, useContext, useEffect, useId, useMemo, useRef, useState } from 'react';
|
|
4
|
+
import { AccessibilityInfo, BackHandler, findNodeHandle, Keyboard, Platform, Pressable, StyleSheet, View } from 'react-native';
|
|
5
|
+
import Reanimated, { cancelAnimation, Easing, ReduceMotion, runOnJS, useAnimatedProps, useAnimatedReaction, useAnimatedScrollHandler, useAnimatedStyle, useDerivedValue, useSharedValue, withSpring, withTiming } from 'react-native-reanimated';
|
|
6
|
+
import { Gesture, GestureDetector } from 'react-native-gesture-handler';
|
|
7
|
+
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
8
|
+
import { nativeMetrics as tokens } from '@bloxwap/hig/tokens';
|
|
9
|
+
import * as en from '@bloxwap/hig/contracts/messages';
|
|
10
|
+
import { Raised, useColors, useHIG } from './provider.js';
|
|
11
|
+
import { Heading, Text, Stack } from './surface.js';
|
|
12
|
+
import { Button } from './button.js';
|
|
13
|
+
import { backdropProgress, detentHeights, dragPosition, releaseTarget, SHEET_RESIZE, SHEET_SPRING } from './gesture-sheet-model.js';
|
|
14
|
+
const HostContext = createContext(null);
|
|
15
|
+
/**
|
|
16
|
+
* Where modal sheets draw: wrap the screen (inside GestureHandlerRootView and SafeAreaProvider) once. Sheets render in a
|
|
17
|
+
* layer over its children, so they cover the tab bar and anything else inside it. Without a host a modal sheet draws in place.
|
|
18
|
+
*/
|
|
19
|
+
export function GestureSheetHost({ children, style }) {
|
|
20
|
+
const [layers, setLayers] = useState([]);
|
|
21
|
+
const value = useMemo(() => ({
|
|
22
|
+
show: (id, node) => setLayers(current => { const index = current.findIndex(layer => layer.id === id); if (index < 0)
|
|
23
|
+
return [...current, { id, node }]; if (current[index].node === node)
|
|
24
|
+
return current; const next = current.slice(); next[index] = { id, node }; return next; }),
|
|
25
|
+
hide: id => setLayers(current => current.some(layer => layer.id === id) ? current.filter(layer => layer.id !== id) : current),
|
|
26
|
+
}), []);
|
|
27
|
+
return _jsx(HostContext.Provider, { value: value, children: _jsxs(View, { style: [styles.fill, style], children: [children, layers.map(layer => _jsx(View, { pointerEvents: 'box-none', style: StyleSheet.absoluteFill, children: layer.node }, layer.id))] }) });
|
|
28
|
+
}
|
|
29
|
+
const ScrollContext = createContext(null);
|
|
30
|
+
/**
|
|
31
|
+
* A ScrollView that shares the drag with its sheet: at the top detent it scrolls, and a pull down from the top of the
|
|
32
|
+
* content moves the sheet; below the top detent the drag moves the sheet and the content stays put. Outside a sheet it is a
|
|
33
|
+
* plain ScrollView. Bounce and overscroll are off so the content cannot move while the sheet does.
|
|
34
|
+
*/
|
|
35
|
+
export const GestureSheetScrollView = React.forwardRef(function GestureSheetScrollView(props, ref) {
|
|
36
|
+
const sheet = useContext(ScrollContext);
|
|
37
|
+
const ownY = useSharedValue(0), ownCount = useSharedValue(0), free = useSharedValue(true);
|
|
38
|
+
const scrollY = sheet?.scrollY ?? ownY, scrollers = sheet?.scrollers ?? ownCount, atTop = sheet?.atTop ?? free, pan = sheet?.pan;
|
|
39
|
+
const native = useMemo(() => pan ? Gesture.Native().simultaneousWithExternalGesture(pan) : Gesture.Native(), [pan]);
|
|
40
|
+
useEffect(() => { scrollers.value += 1; return () => { scrollers.value -= 1; scrollY.value = 0; }; }, [scrollers, scrollY]);
|
|
41
|
+
const onScroll = useAnimatedScrollHandler(event => {
|
|
42
|
+
'worklet';
|
|
43
|
+
scrollY.value = event.contentOffset.y;
|
|
44
|
+
});
|
|
45
|
+
const animatedProps = useAnimatedProps(() => {
|
|
46
|
+
'worklet';
|
|
47
|
+
return { scrollEnabled: atTop.value };
|
|
48
|
+
});
|
|
49
|
+
return _jsx(GestureDetector, { gesture: native, children: _jsx(Reanimated.ScrollView, { keyboardShouldPersistTaps: 'handled', ...props, ref: ref, bounces: false, overScrollMode: 'never', scrollEventThrottle: 16, onScroll: onScroll, animatedProps: animatedProps }) });
|
|
50
|
+
});
|
|
51
|
+
const RESIZE = { duration: SHEET_RESIZE.duration, easing: Easing.bezier(...SHEET_RESIZE.curve) };
|
|
52
|
+
const focusOn = (node) => { if (!node)
|
|
53
|
+
return; try {
|
|
54
|
+
const handle = findNodeHandle(node);
|
|
55
|
+
if (handle != null) {
|
|
56
|
+
AccessibilityInfo.setAccessibilityFocus(handle);
|
|
57
|
+
if (Platform.OS === 'android')
|
|
58
|
+
AccessibilityInfo.sendAccessibilityEvent(node, 'viewHoverEnter');
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
catch { /* A detached focus target cannot block the sheet. */ } };
|
|
62
|
+
const OFFSCREEN = 100000;
|
|
63
|
+
/** The sheet itself. It lives in the host's layer (modal) or in place (inline), so a parent re-render reaches it only through the props below. */
|
|
64
|
+
function Surface({ open, onOpenChange, title, description, children, contentMode = 'default', titleRef, returnFocusRef, labelledBy, closeLabel, dismissible = true, presentation = 'modal', onDismiss, onChange, onHardwareBackPress, topInset, bottomInset, handle = true, backgroundStyle, raised = true, backdropOpacity = 1, testID, snapPoints, initialIndex = 0, enableDynamicSizing = false, maxDynamicContentSize, onClosed }) {
|
|
65
|
+
const env = useHIG(), colors = useColors(), insets = useSafeAreaInsets();
|
|
66
|
+
const top = topInset ?? insets.top, bottom = bottomInset ?? insets.bottom;
|
|
67
|
+
const id = (part) => testID === undefined ? undefined : part ? `${testID}-${part}` : testID;
|
|
68
|
+
const heading = useRef(null);
|
|
69
|
+
const latest = useRef({ open, onOpenChange, onDismiss, onChange, onHardwareBackPress, onClosed, returnFocusRef, titleRef, contentMode });
|
|
70
|
+
latest.current = { open, onOpenChange, onDismiss, onChange, onHardwareBackPress, onClosed, returnFocusRef, titleRef, contentMode };
|
|
71
|
+
// Layout the JS side needs: the room under the top inset sizes the content box. It changes on rotation and when Android resizes the window for the keyboard, not while the sheet moves.
|
|
72
|
+
const [room, setRoom] = useState(0);
|
|
73
|
+
const roomValue = useSharedValue(0), contentHeight = useSharedValue(0), position = useSharedValue(OFFSCREEN), dragStart = useSharedValue(0), rebase = useSharedValue(0), dragging = useSharedValue(false), closing = useSharedValue(false), shown = useSharedValue(open), keyboard = useSharedValue(0), kick = useSharedValue(0);
|
|
74
|
+
const points = useSharedValue(snapPoints ?? []), dynamic = useSharedValue(enableDynamicSizing), ceiling = useSharedValue(maxDynamicContentSize ?? 0), canDismiss = useSharedValue(dismissible), reduce = useSharedValue(env.reducedMotion);
|
|
75
|
+
const detentCount = enableDynamicSizing ? 1 : (snapPoints ?? []).length;
|
|
76
|
+
const active = useSharedValue(Math.max(0, Math.min(initialIndex, detentCount - 1)));
|
|
77
|
+
const scrollY = useSharedValue(0), scrollers = useSharedValue(0);
|
|
78
|
+
const pointsKey = JSON.stringify(snapPoints ?? []);
|
|
79
|
+
useEffect(() => { points.value = snapPoints ?? []; dynamic.value = enableDynamicSizing; ceiling.value = maxDynamicContentSize ?? 0; canDismiss.value = dismissible; reduce.value = env.reducedMotion; }, [pointsKey, enableDynamicSizing, maxDynamicContentSize, dismissible, env.reducedMotion]);
|
|
80
|
+
// translateY of each detent, tallest first. Empty until the sheet knows its room (and, sized by content, its content).
|
|
81
|
+
const positions = useDerivedValue(() => {
|
|
82
|
+
'worklet';
|
|
83
|
+
const space = roomValue.value;
|
|
84
|
+
if (space <= 0)
|
|
85
|
+
return [];
|
|
86
|
+
const heights = dynamic.value ? (contentHeight.value > 0 ? [Math.min(contentHeight.value, ceiling.value > 0 ? Math.min(ceiling.value, space) : space)] : []) : detentHeights(points.value, space);
|
|
87
|
+
const result = [];
|
|
88
|
+
for (let index = heights.length - 1; index >= 0; index--)
|
|
89
|
+
result.push(space - heights[index]);
|
|
90
|
+
return result;
|
|
91
|
+
});
|
|
92
|
+
const atTop = useDerivedValue(() => {
|
|
93
|
+
'worklet';
|
|
94
|
+
return positions.value.length === 0 || position.value <= positions.value[0] + 0.5;
|
|
95
|
+
});
|
|
96
|
+
const reported = useRef(-1);
|
|
97
|
+
const settled = useCallback((index) => {
|
|
98
|
+
if (!latest.current.open || reported.current === index)
|
|
99
|
+
return;
|
|
100
|
+
reported.current = index;
|
|
101
|
+
latest.current.onChange?.(index);
|
|
102
|
+
}, []);
|
|
103
|
+
const requested = useRef(false);
|
|
104
|
+
const requestClose = useCallback(() => { if (requested.current || !latest.current.open)
|
|
105
|
+
return; requested.current = true; latest.current.onOpenChange(false); }, []);
|
|
106
|
+
// An inline sheet first mounts closed. Only a sheet that was shown can be dismissed.
|
|
107
|
+
const presented = useRef(false), closeFrame = useRef(null);
|
|
108
|
+
const finishClose = useCallback(() => {
|
|
109
|
+
// One frame for a host that answers `onOpenChange(false)` asynchronously, then: still open means the dismissal was rejected and the sheet returns to its detent.
|
|
110
|
+
if (closeFrame.current !== null)
|
|
111
|
+
cancelAnimationFrame(closeFrame.current);
|
|
112
|
+
closeFrame.current = requestAnimationFrame(() => {
|
|
113
|
+
closeFrame.current = null;
|
|
114
|
+
requested.current = false;
|
|
115
|
+
closing.value = false;
|
|
116
|
+
if (latest.current.open) {
|
|
117
|
+
kick.value += 1;
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
if (!presented.current)
|
|
121
|
+
return;
|
|
122
|
+
presented.current = false;
|
|
123
|
+
reported.current = -1;
|
|
124
|
+
focusOn(latest.current.returnFocusRef?.current ?? null);
|
|
125
|
+
latest.current.onDismiss?.();
|
|
126
|
+
latest.current.onClosed();
|
|
127
|
+
});
|
|
128
|
+
}, [closing, kick]);
|
|
129
|
+
useEffect(() => () => { if (closeFrame.current !== null)
|
|
130
|
+
cancelAnimationFrame(closeFrame.current); }, []);
|
|
131
|
+
useEffect(() => { requested.current = false; shown.value = open; if (open) {
|
|
132
|
+
presented.current = true;
|
|
133
|
+
reported.current = -1;
|
|
134
|
+
active.value = Math.max(0, Math.min(initialIndex, detentCount - 1));
|
|
135
|
+
} }, [open]);
|
|
136
|
+
// Open focus: once per presentation, after the first frame so the content exists.
|
|
137
|
+
useEffect(() => { if (!open)
|
|
138
|
+
return; const frame = requestAnimationFrame(() => focusOn(latest.current.contentMode === 'custom' ? (latest.current.titleRef?.current ?? heading.current) : heading.current)); return () => cancelAnimationFrame(frame); }, [open]);
|
|
139
|
+
useEffect(() => { if (!open)
|
|
140
|
+
return; const subscription = BackHandler.addEventListener('hardwareBackPress', () => { if (latest.current.onHardwareBackPress)
|
|
141
|
+
return latest.current.onHardwareBackPress(); if (dismissible)
|
|
142
|
+
requestClose(); return true; }); return () => subscription.remove(); }, [open, dismissible, requestClose]);
|
|
143
|
+
// iOS lifts the sheet over the keyboard. Android resizes the window instead, which arrives here as a new room.
|
|
144
|
+
useEffect(() => { if (Platform.OS !== 'ios')
|
|
145
|
+
return; const show = Keyboard.addListener('keyboardWillShow', event => { keyboard.value = withTiming(event.endCoordinates.height, { duration: event.duration || 250 }); }), hide = Keyboard.addListener('keyboardWillHide', event => { keyboard.value = withTiming(0, { duration: event.duration || 250 }); }); return () => { show.remove(); hide.remove(); }; }, [keyboard]);
|
|
146
|
+
// The one place the sheet is told where to rest: opening, closing, a new detent set and content that changed height all arrive here and become one spring on the UI thread.
|
|
147
|
+
useAnimatedReaction(() => {
|
|
148
|
+
'worklet';
|
|
149
|
+
const list = positions.value, space = roomValue.value;
|
|
150
|
+
if (space <= 0)
|
|
151
|
+
return { target: -1, kick: kick.value, index: active.value };
|
|
152
|
+
if (!shown.value)
|
|
153
|
+
return { target: space, kick: kick.value, index: active.value };
|
|
154
|
+
if (list.length === 0)
|
|
155
|
+
return { target: -1, kick: kick.value, index: active.value };
|
|
156
|
+
const index = Math.max(0, Math.min(list.length - 1, active.value));
|
|
157
|
+
return { target: list[list.length - 1 - index], kick: kick.value, index };
|
|
158
|
+
}, (next, previous) => {
|
|
159
|
+
'worklet';
|
|
160
|
+
const target = next.target;
|
|
161
|
+
if (target < 0 || dragging.value || (previous !== null && target === previous.target && next.kick === previous.kick && next.index === previous.index))
|
|
162
|
+
return;
|
|
163
|
+
const space = roomValue.value;
|
|
164
|
+
if (position.value > space)
|
|
165
|
+
position.value = space;
|
|
166
|
+
const closes = target >= space;
|
|
167
|
+
if (closes && closing.value)
|
|
168
|
+
return;
|
|
169
|
+
const motion = { ...SHEET_SPRING, reduceMotion: reduce.value ? ReduceMotion.Always : ReduceMotion.System };
|
|
170
|
+
if (closes) {
|
|
171
|
+
closing.value = true;
|
|
172
|
+
position.value = withSpring(target, motion, finished => {
|
|
173
|
+
'worklet';
|
|
174
|
+
if (finished)
|
|
175
|
+
runOnJS(finishClose)();
|
|
176
|
+
});
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
const index = next.index;
|
|
180
|
+
active.value = index;
|
|
181
|
+
// Content that changed height while the sheet rests moves on the resize curve. Opening and a new detent index use the spring.
|
|
182
|
+
const resized = previous !== null && previous.target >= 0 && previous.target < space && next.kick === previous.kick && next.index === previous.index;
|
|
183
|
+
if (resized && !reduce.value) {
|
|
184
|
+
position.value = withTiming(target, RESIZE, finished => {
|
|
185
|
+
'worklet';
|
|
186
|
+
if (finished)
|
|
187
|
+
runOnJS(settled)(index);
|
|
188
|
+
});
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
position.value = withSpring(target, motion, finished => {
|
|
192
|
+
'worklet';
|
|
193
|
+
if (finished)
|
|
194
|
+
runOnJS(settled)(index);
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
const pan = useMemo(() => Gesture.Pan().activeOffsetY([-6, 6]).failOffsetX([-28, 28])
|
|
198
|
+
.onStart(() => {
|
|
199
|
+
'worklet';
|
|
200
|
+
cancelAnimation(position);
|
|
201
|
+
dragStart.value = position.value;
|
|
202
|
+
rebase.value = 0;
|
|
203
|
+
dragging.value = true;
|
|
204
|
+
closing.value = false;
|
|
205
|
+
})
|
|
206
|
+
.onChange(event => {
|
|
207
|
+
'worklet';
|
|
208
|
+
const list = positions.value;
|
|
209
|
+
if (list.length === 0)
|
|
210
|
+
return;
|
|
211
|
+
const space = roomValue.value, highest = list[0], lowest = list[list.length - 1];
|
|
212
|
+
// At the top detent with the content scrolled, the scroller owns the drag. The sheet holds still and the drag is rebased, so it picks up from here once the content is back at its top.
|
|
213
|
+
if (scrollers.value > 0 && dragStart.value <= highest + 0.5 && (scrollY.value > 0 || event.translationY - rebase.value < 0)) {
|
|
214
|
+
rebase.value = event.translationY;
|
|
215
|
+
position.value = highest;
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
position.value = dragPosition(dragStart.value + event.translationY - rebase.value, highest, lowest, space, canDismiss.value);
|
|
219
|
+
})
|
|
220
|
+
.onEnd(event => {
|
|
221
|
+
'worklet';
|
|
222
|
+
dragging.value = false;
|
|
223
|
+
const list = positions.value;
|
|
224
|
+
if (list.length === 0)
|
|
225
|
+
return;
|
|
226
|
+
const space = roomValue.value, target = releaseTarget(position.value, event.velocityY, list, space, canDismiss.value);
|
|
227
|
+
const motion = { ...SHEET_SPRING, velocity: event.velocityY, reduceMotion: reduce.value ? ReduceMotion.Always : ReduceMotion.System };
|
|
228
|
+
if (target < 0) {
|
|
229
|
+
closing.value = true;
|
|
230
|
+
runOnJS(requestClose)();
|
|
231
|
+
position.value = withSpring(space, motion, finished => {
|
|
232
|
+
'worklet';
|
|
233
|
+
if (finished)
|
|
234
|
+
runOnJS(finishClose)();
|
|
235
|
+
});
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
const index = list.length - 1 - target;
|
|
239
|
+
active.value = index;
|
|
240
|
+
position.value = withSpring(list[target], motion, finished => {
|
|
241
|
+
'worklet';
|
|
242
|
+
if (finished)
|
|
243
|
+
runOnJS(settled)(index);
|
|
244
|
+
});
|
|
245
|
+
})
|
|
246
|
+
.onFinalize(() => {
|
|
247
|
+
'worklet';
|
|
248
|
+
dragging.value = false;
|
|
249
|
+
}), []);
|
|
250
|
+
const scroll = useMemo(() => ({ pan, scrollY, scrollers, atTop }), [pan, scrollY, scrollers, atTop]);
|
|
251
|
+
// Only transforms and opacity change while the sheet moves, so no frame lays anything out.
|
|
252
|
+
const surfaceStyle = useAnimatedStyle(() => {
|
|
253
|
+
'worklet';
|
|
254
|
+
return { transform: [{ translateY: Math.max(0, position.value - keyboard.value) }] };
|
|
255
|
+
});
|
|
256
|
+
const backdropStyle = useAnimatedStyle(() => {
|
|
257
|
+
'worklet';
|
|
258
|
+
const list = positions.value, space = roomValue.value;
|
|
259
|
+
return { opacity: list.length === 0 ? 0 : backdropProgress(position.value, list[list.length - 1], space) * backdropOpacity };
|
|
260
|
+
});
|
|
261
|
+
const onRoom = useCallback((event) => { const next = Math.max(0, event.nativeEvent.layout.height - top); roomValue.value = next; setRoom(current => current === next ? current : next); }, [top, roomValue]);
|
|
262
|
+
const onContent = useCallback((event) => { contentHeight.value = event.nativeEvent.layout.height; }, [contentHeight]);
|
|
263
|
+
const tallest = useMemo(() => enableDynamicSizing ? 0 : Math.max(0, ...detentHeights(snapPoints ?? [], room)), [enableDynamicSizing, pointsKey, room]);
|
|
264
|
+
const limit = enableDynamicSizing ? (maxDynamicContentSize ? Math.min(maxDynamicContentSize, room) : room) : tallest;
|
|
265
|
+
const modal = presentation === 'modal';
|
|
266
|
+
const accessibility = { ...(modal ? { accessibilityViewIsModal: true, onAccessibilityEscape: dismissible ? requestClose : undefined } : { accessibilityElementsHidden: !open, importantForAccessibility: open ? 'auto' : 'no-hide-descendants' }), ...(labelledBy ? { accessibilityLabelledBy: labelledBy } : {}) };
|
|
267
|
+
const hiddenTitle = !titleRef ? _jsx(Heading, { ref: heading, accessible: true, accessibilityLabel: title, style: styles.hidden, children: title }) : null;
|
|
268
|
+
const content = contentMode === 'custom'
|
|
269
|
+
? _jsxs(View, { ...accessibility, testID: id('content'), collapsable: false, style: [enableDynamicSizing ? styles.shrink : styles.grow, { direction: env.direction }], children: [hiddenTitle, children] })
|
|
270
|
+
: _jsx(GestureSheetScrollView, { ...accessibility, testID: id('content'), style: enableDynamicSizing ? styles.shrink : styles.grow, contentContainerStyle: { padding: tokens.space.xl, paddingBottom: tokens.space.xl + bottom, direction: env.direction }, children: _jsxs(Stack, { children: [_jsx(Heading, { ref: heading, children: title }), description ? _jsx(Text, { children: description }) : null, children, _jsx(Button, { intent: 'secondary', onPress: requestClose, children: closeLabel ?? env.messages.close ?? en.close })] }) });
|
|
271
|
+
const lifted = raised ? _jsx(Raised, { children: content }) : content;
|
|
272
|
+
return _jsxs(View, { testID: id(''), pointerEvents: open ? 'box-none' : 'none', style: StyleSheet.absoluteFill, onLayout: onRoom, children: [backdropOpacity > 0 ? _jsx(Reanimated.View, { testID: id('backdrop'), pointerEvents: open ? 'auto' : 'none', style: [StyleSheet.absoluteFill, styles.backdrop, backdropStyle], children: _jsx(Pressable, { accessible: false, importantForAccessibility: 'no', style: styles.fill, onPress: dismissible ? requestClose : undefined }) }) : null, _jsx(GestureDetector, { gesture: pan, children: _jsx(Reanimated.View, { testID: id('surface'), renderToHardwareTextureAndroid: true, style: [styles.surface, { top, backgroundColor: colors.overlay, borderTopLeftRadius: tokens.radius.xl, borderTopRightRadius: tokens.radius.xl }, backgroundStyle, surfaceStyle], children: room > 0 ? _jsx(ScrollContext.Provider, { value: scroll, children: _jsxs(View, { onLayout: onContent, style: [enableDynamicSizing ? { maxHeight: limit } : { height: limit }, contentMode === 'custom' ? { paddingBottom: bottom } : null], children: [handle ? _jsx(View, { testID: id('handle'), accessible: false, importantForAccessibility: 'no', style: styles.handle, children: _jsx(View, { style: [styles.grip, { backgroundColor: colors.action }] }) }) : null, lifted] }) }) : null }) })] });
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* HIG's own sheet, one engine for iOS and Android: Reanimated moves it and Gesture Handler reads the finger, both on the UI
|
|
276
|
+
* thread. While it moves only a transform and the backdrop's opacity change, so content of any weight costs no layout per frame.
|
|
277
|
+
* Host supplies GestureHandlerRootView, SafeAreaProvider and, for modal sheets, GestureSheetHost.
|
|
278
|
+
*/
|
|
279
|
+
export const GestureSheet = React.memo(function GestureSheet(props) {
|
|
280
|
+
if (!props.enableDynamicSizing)
|
|
281
|
+
validateSnapPoints(props.snapPoints ?? [], props.initialIndex);
|
|
282
|
+
if (props.enableDynamicSizing && props.snapPoints !== undefined)
|
|
283
|
+
throw new Error('Content-sized GestureSheet does not accept fixed snapPoints.');
|
|
284
|
+
if (!props.enableDynamicSizing && (props.snapPoints ?? []).length === 0)
|
|
285
|
+
throw new Error('GestureSheet requires at least one snap point.');
|
|
286
|
+
if (props.maxDynamicContentSize !== undefined && (!Number.isFinite(props.maxDynamicContentSize) || props.maxDynamicContentSize <= 0))
|
|
287
|
+
throw new Error('GestureSheet maxDynamicContentSize must be finite and greater than zero.');
|
|
288
|
+
const host = useContext(HostContext), key = useId(), inline = props.presentation === 'inline' || !host;
|
|
289
|
+
// A modal sheet stays mounted from the moment it opens until its closing motion has finished.
|
|
290
|
+
const [mounted, setMounted] = useState(props.open);
|
|
291
|
+
if (props.open && !mounted)
|
|
292
|
+
setMounted(true);
|
|
293
|
+
const onClosed = useCallback(() => setMounted(false), []);
|
|
294
|
+
const surface = _jsx(Surface, { ...props, onClosed: onClosed });
|
|
295
|
+
useEffect(() => { if (inline || !host)
|
|
296
|
+
return; if (mounted)
|
|
297
|
+
host.show(key, surface);
|
|
298
|
+
else
|
|
299
|
+
host.hide(key); });
|
|
300
|
+
useEffect(() => () => { if (host)
|
|
301
|
+
host.hide(key); }, [host, key]);
|
|
302
|
+
if (!inline)
|
|
303
|
+
return null;
|
|
304
|
+
return props.presentation === 'inline' || mounted ? surface : null;
|
|
305
|
+
});
|
|
306
|
+
const styles = StyleSheet.create({
|
|
307
|
+
fill: { flex: 1 },
|
|
308
|
+
backdrop: { backgroundColor: '#000b' },
|
|
309
|
+
surface: { position: 'absolute', left: 0, right: 0, bottom: 0, overflow: 'hidden' },
|
|
310
|
+
handle: { alignItems: 'center', paddingTop: 12, paddingBottom: 8 },
|
|
311
|
+
grip: { width: 36, height: 5, borderRadius: 3 },
|
|
312
|
+
grow: { flex: 1, minHeight: 0 },
|
|
313
|
+
shrink: { flexShrink: 1, minHeight: 0 },
|
|
314
|
+
hidden: { position: 'absolute', width: 1, height: 1, overflow: 'hidden' },
|
|
315
|
+
});
|
|
@@ -36,12 +36,16 @@ interface GestureSheetCommonProps {
|
|
|
36
36
|
handleIndicatorStyle?: BottomSheetModalProps['handleIndicatorStyle'];
|
|
37
37
|
backgroundComponent?: BottomSheetModalProps['backgroundComponent'];
|
|
38
38
|
backgroundStyle?: BottomSheetModalProps['backgroundStyle'];
|
|
39
|
+
/** Content sits one elevation up, so wells, list rows and quiet fills step up one shade to stay visible on HIG's `overlay` fill. Pass `false` when `backgroundStyle` or `backgroundComponent` paints the page `background` instead; the fills then match the page. Defaults to `true`. */
|
|
40
|
+
raised?: boolean;
|
|
39
41
|
/** Screen-level inline hosts may retain their existing sibling overlay order. */
|
|
40
42
|
containerStyle?: BottomSheetModalProps['containerStyle'];
|
|
41
43
|
/** Optional host animation and backdrop policies; HIG reduced-motion mapping remains applied. */
|
|
42
44
|
animateOnMount?: BottomSheetModalProps['animateOnMount'];
|
|
43
45
|
animationConfigs?: BottomSheetModalProps['animationConfigs'];
|
|
44
46
|
backdropComponent?: BottomSheetModalProps['backdropComponent'];
|
|
47
|
+
/** `nativeID` of a heading inside the sheet that names it, such as a block's `headingId`: the sheet's content takes `accessibilityLabelledBy` (Android). The `title` still names the sheet elsewhere. Same prop as web. */
|
|
48
|
+
labelledBy?: string;
|
|
45
49
|
}
|
|
46
50
|
export type GestureSheetProps = GestureSheetCommonProps & (
|
|
47
51
|
/** Modal is the default. Inline retains the screen-level backend and its child state while closed. */
|
|
@@ -69,5 +73,5 @@ export type GestureSheetProps = GestureSheetCommonProps & (
|
|
|
69
73
|
maxDynamicContentSize?: BottomSheetModalProps['maxDynamicContentSize'];
|
|
70
74
|
});
|
|
71
75
|
/** Optional backend: host supplies GestureHandlerRootView, SafeAreaProvider and BottomSheetModalProvider. */
|
|
72
|
-
export declare function GestureSheet({ open, onOpenChange, title, description, children, contentMode, titleRef, presentation, sheetRef, snapPoints, enableDynamicSizing, maxDynamicContentSize, enableContentPanningGesture, keyboardBehavior, keyboardBlurBehavior, android_keyboardInputMode, initialIndex, dismissible, returnFocusRef, closeLabel, onDismiss, onChange, onHardwareBackPress, topInset, bottomInset, modalRef, handleComponent, handleStyle, handleIndicatorStyle, backgroundComponent, backgroundStyle, containerStyle, animateOnMount, animationConfigs, backdropComponent }: GestureSheetProps): React.JSX.Element;
|
|
76
|
+
export declare function GestureSheet({ open, onOpenChange, title, description, children, contentMode, raised, titleRef, presentation, sheetRef, snapPoints, enableDynamicSizing, maxDynamicContentSize, enableContentPanningGesture, keyboardBehavior, keyboardBlurBehavior, android_keyboardInputMode, initialIndex, dismissible, returnFocusRef, closeLabel, onDismiss, onChange, onHardwareBackPress, topInset, bottomInset, modalRef, handleComponent, handleStyle, handleIndicatorStyle, backgroundComponent, backgroundStyle, containerStyle, animateOnMount, animationConfigs, backdropComponent, labelledBy }: GestureSheetProps): React.JSX.Element;
|
|
73
77
|
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { validateSnapPoints } from './gesture-sheet-model.js';
|
|
3
|
+
import { useEffect, useRef, useCallback, useImperativeHandle, useMemo } from 'react';
|
|
3
4
|
import { AccessibilityInfo, BackHandler, findNodeHandle, Platform, View } from 'react-native';
|
|
4
5
|
import BottomSheet, { BottomSheetModal, BottomSheetScrollView, BottomSheetBackdrop, BottomSheetView } from '@gorhom/bottom-sheet';
|
|
5
6
|
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
@@ -10,10 +11,12 @@ import { Raised, useColors, useHIG } from './provider.js';
|
|
|
10
11
|
import { Heading, Text, Stack } from './surface.js';
|
|
11
12
|
import { Button } from './button.js';
|
|
12
13
|
/** Optional backend: host supplies GestureHandlerRootView, SafeAreaProvider and BottomSheetModalProvider. */
|
|
13
|
-
export function GestureSheet({ open, onOpenChange, title, description, children, contentMode = 'default', titleRef, presentation = 'modal', sheetRef, snapPoints, enableDynamicSizing = false, maxDynamicContentSize, enableContentPanningGesture, keyboardBehavior = 'interactive', keyboardBlurBehavior = 'restore', android_keyboardInputMode = 'adjustResize', initialIndex = 0, dismissible = true, returnFocusRef, closeLabel, onDismiss, onChange, onHardwareBackPress, topInset, bottomInset, modalRef, handleComponent, handleStyle, handleIndicatorStyle, backgroundComponent, backgroundStyle, containerStyle, animateOnMount, animationConfigs, backdropComponent }) {
|
|
14
|
+
export function GestureSheet({ open, onOpenChange, title, description, children, contentMode = 'default', raised = true, titleRef, presentation = 'modal', sheetRef, snapPoints, enableDynamicSizing = false, maxDynamicContentSize, enableContentPanningGesture, keyboardBehavior = 'interactive', keyboardBlurBehavior = 'restore', android_keyboardInputMode = 'adjustResize', initialIndex = 0, dismissible = true, returnFocusRef, closeLabel, onDismiss, onChange, onHardwareBackPress, topInset, bottomInset, modalRef, handleComponent, handleStyle, handleIndicatorStyle, backgroundComponent, backgroundStyle, containerStyle, animateOnMount, animationConfigs, backdropComponent, labelledBy }) {
|
|
14
15
|
if (enableDynamicSizing && snapPoints !== undefined)
|
|
15
16
|
throw new Error('Content-sized GestureSheet does not accept fixed snapPoints.');
|
|
16
17
|
const fixedSnapPoints = snapPoints ?? [];
|
|
18
|
+
if (!enableDynamicSizing)
|
|
19
|
+
validateSnapPoints(fixedSnapPoints, initialIndex);
|
|
17
20
|
if (!enableDynamicSizing && fixedSnapPoints.length === 0)
|
|
18
21
|
throw new Error('GestureSheet requires at least one snap point.');
|
|
19
22
|
if (maxDynamicContentSize !== undefined && (!Number.isFinite(maxDynamicContentSize) || maxDynamicContentSize <= 0))
|
|
@@ -26,6 +29,7 @@ export function GestureSheet({ open, onOpenChange, title, description, children,
|
|
|
26
29
|
const startingIndex = Math.max(0, Math.min(initialIndex, detentCount - 1));
|
|
27
30
|
const activeIndex = useRef(startingIndex), detentFrame = useRef(null), pendingSnap = useRef(false);
|
|
28
31
|
const detentKey = JSON.stringify(fixedSnapPoints);
|
|
32
|
+
const backendSnapPoints = useMemo(() => [...fixedSnapPoints], [detentKey]);
|
|
29
33
|
const latest = useRef({ open, onOpenChange, returnFocusRef, onDismiss, onHardwareBackPress });
|
|
30
34
|
latest.current = { open, onOpenChange, returnFocusRef, onDismiss, onHardwareBackPress };
|
|
31
35
|
const env = useHIG(), colors = useColors(), insets = useSafeAreaInsets();
|
|
@@ -141,13 +145,16 @@ export function GestureSheet({ open, onOpenChange, title, description, children,
|
|
|
141
145
|
} });
|
|
142
146
|
}, [focus, presentation, requestClose]);
|
|
143
147
|
const inlineAccessibility = presentation === 'inline' ? { accessibilityElementsHidden: !open, importantForAccessibility: open ? 'auto' : 'no-hide-descendants', pointerEvents: open ? 'auto' : 'none' } : {};
|
|
144
|
-
const contentAccessibility = { ...inlineAccessibility, ...(presentation === 'modal' && { accessibilityViewIsModal: true, onAccessibilityEscape: requestClose }) };
|
|
148
|
+
const contentAccessibility = { ...inlineAccessibility, ...(presentation === 'modal' && { accessibilityViewIsModal: true, onAccessibilityEscape: requestClose }), ...(labelledBy ? { accessibilityLabelledBy: labelledBy } : {}) };
|
|
145
149
|
const content = contentMode === 'custom' ? _jsxs(CustomContent, { ...contentAccessibility, accessible: false, collapsable: false, style: { ...(!enableDynamicSizing && { flex: 1, flexShrink: 1, minHeight: 0 }), direction: env.direction }, children: [!titleRef && _jsx(Heading, { ref: heading, accessible: true, accessibilityLabel: title, style: { position: 'absolute', width: 1, height: 1, overflow: 'hidden' }, children: title }), children] }) : _jsx(BottomSheetScrollView, { ...contentAccessibility, accessible: false, keyboardShouldPersistTaps: 'handled', contentContainerStyle: { padding: tokens.space.xl, paddingBottom: tokens.space.xl + (bottomInset ?? insets.bottom) }, children: _jsxs(Stack, { children: [_jsx(Heading, { ref: heading, children: title }), description && _jsx(Text, { children: description }), children, _jsx(Button, { intent: 'secondary', onPress: requestClose, children: closeLabel ?? env.messages.close ?? en.close })] }) });
|
|
146
150
|
// Expose individual children instead of grouping the sheet as one adjustable element. Gorhom forwards only
|
|
147
151
|
// basic accessibility props, so modal escape and VoiceOver scope belong on its measured or scrolling content.
|
|
148
152
|
// Inline content keeps its native state while closed, with all descendants hidden from accessibility.
|
|
149
153
|
// No stroke: the sheet is the `overlay` fill, darker than a card, lifted by a soft shadow.
|
|
150
|
-
const sheetFill = { backgroundColor: colors.overlay, borderRadius: tokens.radius.xl, boxShadow: '0 -8px 32px #0008' };
|
|
151
|
-
const
|
|
152
|
-
|
|
154
|
+
const sheetFill = useMemo(() => ({ backgroundColor: colors.overlay, borderRadius: tokens.radius.xl, boxShadow: '0 -8px 32px #0008' }), [colors.overlay]);
|
|
155
|
+
const sheetBackground = useMemo(() => backgroundStyle ? [sheetFill, backgroundStyle] : sheetFill, [sheetFill, backgroundStyle]);
|
|
156
|
+
const sheetIndicator = useMemo(() => { const fill = { backgroundColor: colors.action }; return handleIndicatorStyle ? [fill, handleIndicatorStyle] : fill; }, [colors.action, handleIndicatorStyle]);
|
|
157
|
+
const backendProps = { accessible: false, accessibilityLabel: title, index: presentation === 'inline' && !open ? -1 : presented.current ? Math.max(0, Math.min(activeIndex.current, detentCount - 1)) : startingIndex, snapPoints: enableDynamicSizing ? undefined : backendSnapPoints, enableDynamicSizing, maxDynamicContentSize: enableDynamicSizing ? maxDynamicContentSize : undefined, enableContentPanningGesture, enablePanDownToClose: dismissible, topInset: topInset ?? insets.top, bottomInset: bottomInset ?? insets.bottom, keyboardBehavior, keyboardBlurBehavior, android_keyboardInputMode, overrideReduceMotion: env.reducedMotion ? ReduceMotion.Always : ReduceMotion.System, animateOnMount, animationConfigs, backdropComponent: backdropComponent === undefined ? backdrop : backdropComponent, handleComponent, handleStyle, backgroundComponent, containerStyle, backgroundStyle: sheetBackground, handleIndicatorStyle: sheetIndicator, onChange: handleChange };
|
|
158
|
+
const lifted = raised ? _jsx(Raised, { children: content }) : content;
|
|
159
|
+
return presentation === 'inline' ? _jsx(BottomSheet, { ...backendProps, ref: inline, accessibilityElementsHidden: !open, importantForAccessibility: open ? 'auto' : 'no-hide-descendants', onClose: handleSettledClose, children: lifted }) : _jsx(BottomSheetModal, { ...backendProps, ref: sheet, enableDismissOnClose: true, stackBehavior: 'push', onDismiss: handleSettledClose, children: lifted });
|
|
153
160
|
}
|
package/native/dist/icons.d.ts
CHANGED
|
@@ -1,29 +1,32 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
/** Decorative shared symbols. The containing control or text carries the name. */
|
|
2
3
|
export declare function SearchIcon({ color }: {
|
|
3
4
|
color: string;
|
|
4
5
|
}): React.JSX.Element;
|
|
5
|
-
/** Points down; the caller rotates it. */
|
|
6
6
|
export declare function ChevronIcon({ color }: {
|
|
7
7
|
color: string;
|
|
8
8
|
}): React.JSX.Element;
|
|
9
|
-
/** A QR glyph: three finder squares and two cells. */
|
|
10
9
|
export declare function QrIcon({ color }: {
|
|
11
10
|
color: string;
|
|
12
11
|
}): React.JSX.Element;
|
|
13
12
|
export declare function CloseIcon({ color }: {
|
|
14
13
|
color: string;
|
|
15
14
|
}): React.JSX.Element;
|
|
16
|
-
/** A pencil: a slanted barrel over the line it writes on. */
|
|
17
15
|
export declare function EditIcon({ color }: {
|
|
18
16
|
color: string;
|
|
19
17
|
}): React.JSX.Element;
|
|
18
|
+
export declare function EmptyIcon({ color }: {
|
|
19
|
+
color: string;
|
|
20
|
+
}): React.JSX.Element;
|
|
21
|
+
export declare function EyeIcon({ color }: {
|
|
22
|
+
color: string;
|
|
23
|
+
}): React.JSX.Element;
|
|
20
24
|
export type SeverityIconKind = 'info' | 'success' | 'warning' | 'error';
|
|
21
|
-
/** Shape as well as colour tells the severities apart: warning is a diamond, the others a circle with their own mark. */
|
|
22
25
|
export declare function SeverityIcon({ kind, color }: {
|
|
23
26
|
kind: SeverityIconKind;
|
|
24
27
|
color: string;
|
|
25
28
|
}): React.JSX.Element;
|
|
26
|
-
|
|
27
|
-
export declare function EmptyIcon({ color }: {
|
|
29
|
+
export declare function TrendIcon({ color, direction }: {
|
|
28
30
|
color: string;
|
|
31
|
+
direction: 'up' | 'down';
|
|
29
32
|
}): React.JSX.Element;
|
package/native/dist/icons.js
CHANGED
|
@@ -1,24 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
export function
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { ChevronDown } from '@bloxwap/icons/native/chevron-down';
|
|
3
|
+
import { CircleCheck } from '@bloxwap/icons/native/circle-check';
|
|
4
|
+
import { CircleX } from '@bloxwap/icons/native/circle-x';
|
|
5
|
+
import { Eye } from '@bloxwap/icons/native/eye';
|
|
6
|
+
import { Inbox } from '@bloxwap/icons/native/inbox';
|
|
7
|
+
import { Info } from '@bloxwap/icons/native/info';
|
|
8
|
+
import { PenLine } from '@bloxwap/icons/native/pen-line';
|
|
9
|
+
import { QrCode } from '@bloxwap/icons/native/qr-code';
|
|
10
|
+
import { Search } from '@bloxwap/icons/native/search';
|
|
11
|
+
import { TrendingDown } from '@bloxwap/icons/native/trending-down';
|
|
12
|
+
import { TrendingUp } from '@bloxwap/icons/native/trending-up';
|
|
13
|
+
import { TriangleAlert } from '@bloxwap/icons/native/triangle-alert';
|
|
14
|
+
import { X } from '@bloxwap/icons/native/x';
|
|
15
|
+
/** Decorative shared symbols. The containing control or text carries the name. */
|
|
16
|
+
export function SearchIcon({ color }) { return _jsx(Search, { size: 18, color: color }); }
|
|
17
|
+
export function ChevronIcon({ color }) { return _jsx(ChevronDown, { size: 20, color: color }); }
|
|
18
|
+
export function QrIcon({ color }) { return _jsx(QrCode, { size: 20, color: color }); }
|
|
19
|
+
export function CloseIcon({ color }) { return _jsx(X, { size: 20, color: color }); }
|
|
20
|
+
export function EditIcon({ color }) { return _jsx(PenLine, { size: 20, color: color }); }
|
|
21
|
+
export function EmptyIcon({ color }) { return _jsx(Inbox, { size: 48, color: color }); }
|
|
22
|
+
export function EyeIcon({ color }) { return _jsx(Eye, { size: 20, color: color }); }
|
|
23
|
+
const severitySymbols = { info: Info, success: CircleCheck, warning: TriangleAlert, error: CircleX };
|
|
24
|
+
export function SeverityIcon({ kind, color }) { const Symbol = severitySymbols[kind]; return _jsx(Symbol, { size: 20, color: color }); }
|
|
25
|
+
export function TrendIcon({ color, direction }) { const Symbol = direction === 'down' ? TrendingDown : TrendingUp; return _jsx(Symbol, { size: 20, color: color }); }
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { type ScrollViewProps } from 'react-native';
|
|
2
3
|
/** One language the host offers. */
|
|
3
4
|
export interface LanguageOption {
|
|
4
5
|
/** Stable id the host switches on, usually a BCP 47 tag such as `pt-BR`. */
|
|
@@ -27,9 +28,17 @@ export interface LanguageBlockProps {
|
|
|
27
28
|
disabled?: boolean;
|
|
28
29
|
/** A muted line under the header that explains the screen: Choose the language used throughout the app. */
|
|
29
30
|
description?: string;
|
|
31
|
+
/** 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. Place it in a bounded container, such as a sheet body. */
|
|
32
|
+
stickyHeader?: boolean;
|
|
33
|
+
/** With `stickyHeader`: the header's fill once content is under it. Defaults to the background role; in a sheet pass the sheet's fill. */
|
|
34
|
+
stickyHeaderBackground?: string;
|
|
35
|
+
/** The scroll view used with `stickyHeader`, such as a sheet library's own. Defaults to React Native's ScrollView. */
|
|
36
|
+
scrollComponent?: React.ComponentType<ScrollViewProps>;
|
|
37
|
+
/** `nativeID` of the title, so a sheet around the block can name itself with `accessibilityLabelledBy` (Android). */
|
|
38
|
+
headingId?: string;
|
|
30
39
|
testID?: string;
|
|
31
40
|
}
|
|
32
41
|
/** The languages whose name, description or code contains the query, ignoring case and accents. An empty query keeps every language, in the host's order. */
|
|
33
42
|
export declare function filterLanguages(languages: readonly LanguageOption[], query: string): LanguageOption[];
|
|
34
43
|
/** Choose the app's language as one screen: a header, a search field, then each language as a row with its flag, its own name over the reader's name for it, and a check on the one in use. */
|
|
35
|
-
export declare function LanguageBlock({ title, onBack, headerAction, languages, value, onSelect, search, disabled, description, testID }: LanguageBlockProps): React.JSX.Element;
|
|
44
|
+
export declare function LanguageBlock({ title, onBack, headerAction, languages, value, onSelect, search, disabled, description, stickyHeader, stickyHeaderBackground, scrollComponent, headingId, testID }: LanguageBlockProps): React.JSX.Element;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Check } from '@bloxwap/icons/native/check';
|
|
2
3
|
import { useMemo, useState } from 'react';
|
|
3
4
|
import { Image, Pressable, View } from 'react-native';
|
|
5
|
+
import { StickyHeaderLayout } from './sticky-header.js';
|
|
4
6
|
import { useColors, useFills, useHIG, useMessages } from './provider.js';
|
|
5
7
|
import { Text } from './surface.js';
|
|
6
8
|
import { IconButton } from './button.js';
|
|
@@ -15,16 +17,21 @@ export function filterLanguages(languages, query) {
|
|
|
15
17
|
const hidden = { accessible: false, accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants' };
|
|
16
18
|
const avatar = 40;
|
|
17
19
|
/** Choose the app's language as one screen: a header, a search field, then each language as a row with its flag, its own name over the reader's name for it, and a check on the one in use. */
|
|
18
|
-
export function LanguageBlock({ title, onBack, headerAction, languages, value = null, onSelect, search = true, disabled, description, testID }) {
|
|
20
|
+
export function LanguageBlock({ title, onBack, headerAction, languages, value = null, onSelect, search = true, disabled, description, stickyHeader, stickyHeaderBackground, scrollComponent, headingId, testID }) {
|
|
19
21
|
const colors = useColors(), fills = useFills(), t = useMessages(), { direction } = useHIG();
|
|
20
22
|
const [query, setQuery] = useState('');
|
|
21
23
|
const rows = useMemo(() => filterLanguages(languages, query), [languages, query]);
|
|
22
24
|
const heading = title ?? t.language;
|
|
23
25
|
const shape = { width: avatar, height: avatar, borderRadius: avatar / 2, backgroundColor: fills.raised, alignItems: 'center', justifyContent: 'center', overflow: 'hidden' };
|
|
24
26
|
const row = (pressed) => ({ flexDirection: 'row', alignItems: 'center', gap: 12, minHeight: 56, paddingVertical: 8, paddingStart: 8, paddingEnd: 16, borderRadius: 28, backgroundColor: pressed ? fills.well : 'transparent' });
|
|
25
|
-
|
|
27
|
+
const header = _jsxs(View, { style: stickyHeader ? { direction, flexDirection: 'row', alignItems: 'center', minHeight: 44 } : { flexDirection: 'row', alignItems: 'center', minHeight: 44 }, children: [_jsx(View, { style: { minWidth: 44, alignItems: 'flex-start' }, children: onBack ? _jsx(IconButton, { intent: 'ghost', label: t.back, suppressFeedback: true, testID: testID ? `${testID}-back` : undefined, onPress: onBack, children: _jsx(View, { style: { transform: [{ rotate: direction === 'rtl' ? '-90deg' : '90deg' }] }, children: _jsx(ChevronIcon, { color: colors.text }) }) }) : null }), _jsx(Text, { testID: testID ? `${testID}-title` : undefined, nativeID: headingId, accessibilityRole: 'header', numberOfLines: 1, style: { flex: 1, textAlign: 'center', fontSize: 17, lineHeight: 24, fontWeight: '600', color: colors.text }, children: heading }), _jsx(View, { style: { minWidth: 44, alignItems: 'flex-end' }, children: headerAction })] });
|
|
28
|
+
const body = _jsxs(_Fragment, { children: [description ? _jsx(Text, { testID: testID ? `${testID}-description` : undefined, style: { paddingHorizontal: 4, fontSize: 14, lineHeight: 21, color: colors.muted }, children: description }) : null, search ? _jsx(SearchInput, { testID: testID ? `${testID}-search` : undefined, accessibilityLabel: t.searchLanguages, placeholder: t.searchLanguages, value: query, onChangeText: setQuery, returnKeyType: 'search', autoCapitalize: 'none', autoCorrect: false, spellCheck: false }) : null, rows.length === 0 ? _jsx(Text, { testID: testID ? `${testID}-empty` : undefined, accessibilityLiveRegion: 'polite', style: { paddingVertical: 32, textAlign: 'center', fontSize: 14, lineHeight: 20, color: colors.muted }, children: t.noResults }) :
|
|
26
29
|
_jsx(View, { testID: testID ? `${testID}-list` : undefined, accessibilityRole: 'radiogroup', accessibilityLabel: heading, style: { gap: 4 }, children: rows.map(language => {
|
|
27
30
|
const selected = language.code === value;
|
|
28
|
-
return _jsxs(Pressable, { testID: testID ? `${testID}-${language.code}` : undefined, accessibilityRole: 'radio', accessibilityState: disabled ? { checked: selected, disabled: true } : { checked: selected }, accessibilityLabel: [language.name, language.description].filter(Boolean).join(', '), accessibilityLanguage: language.code, disabled: disabled, onPress: () => onSelect(language), style: disabled ? ({ pressed }) => ({ ...row(pressed), opacity: 0.5 }) : ({ pressed }) => row(pressed), children: [_jsx(View, { ...hidden, children: typeof language.flag === 'string' ? _jsx(Image, { accessible: false, accessibilityIgnoresInvertColors: true, source: { uri: language.flag }, style: shape }) : _jsx(View, { style: shape, children: language.flag ?? _jsx(Text, { accessible: false, maxFontSizeMultiplier: 1, style: { fontSize: 12, lineHeight: 16, fontWeight: '600', color: colors.muted }, children: language.code.slice(0, 2).toUpperCase() }) }) }), _jsxs(View, { ...hidden, style: { flex: 1, flexShrink: 1, minWidth: 0 }, children: [_jsx(Text, { style: { fontSize: 16, lineHeight: 24, fontWeight: '600', color: colors.text }, children: language.name }), language.description ? _jsx(Text, { style: { fontSize: 14, lineHeight: 20, color: colors.muted }, children: language.description }) : null] }), selected ? _jsx(
|
|
31
|
+
return _jsxs(Pressable, { testID: testID ? `${testID}-${language.code}` : undefined, accessibilityRole: 'radio', accessibilityState: disabled ? { checked: selected, disabled: true } : { checked: selected }, accessibilityLabel: [language.name, language.description].filter(Boolean).join(', '), accessibilityLanguage: language.code, disabled: disabled, onPress: () => onSelect(language), style: disabled ? ({ pressed }) => ({ ...row(pressed), opacity: 0.5 }) : ({ pressed }) => row(pressed), children: [_jsx(View, { ...hidden, children: typeof language.flag === 'string' ? _jsx(Image, { accessible: false, accessibilityIgnoresInvertColors: true, source: { uri: language.flag }, style: shape }) : _jsx(View, { style: shape, children: language.flag ?? _jsx(Text, { accessible: false, maxFontSizeMultiplier: 1, style: { fontSize: 12, lineHeight: 16, fontWeight: '600', color: colors.muted }, children: language.code.slice(0, 2).toUpperCase() }) }) }), _jsxs(View, { ...hidden, style: { flex: 1, flexShrink: 1, minWidth: 0 }, children: [_jsx(Text, { style: { fontSize: 16, lineHeight: 24, fontWeight: '600', color: colors.text }, children: language.name }), language.description ? _jsx(Text, { style: { fontSize: 14, lineHeight: 20, color: colors.muted }, children: language.description }) : null] }), selected ? _jsx(Check, { size: 20, color: colors.text, testID: testID ? `${testID}-check` : undefined }) : null] }, language.code);
|
|
29
32
|
}) })] });
|
|
33
|
+
// The sticky layout puts the header and the body in separate views, so the body's first gap is its top padding.
|
|
34
|
+
if (stickyHeader)
|
|
35
|
+
return _jsx(StickyHeaderLayout, { testID: testID, headerTestID: testID ? `${testID}-sticky-header` : 'language-sticky-header', header: header, background: stickyHeaderBackground, scrollComponent: scrollComponent, bodyStyle: { direction, gap: 16, paddingTop: 16 }, children: body });
|
|
36
|
+
return _jsxs(View, { testID: testID, style: { direction, padding: 16, gap: 16 }, children: [header, body] });
|
|
30
37
|
}
|
|
@@ -24,8 +24,10 @@ export interface ListGroupProps {
|
|
|
24
24
|
export declare function ListGroup({ title, titleAccessory, action, intro, children, testID }: ListGroupProps): React.JSX.Element;
|
|
25
25
|
export interface ListRowProps extends Omit<PressableProps, 'children' | 'style' | 'onPress' | 'disabled' | 'role' | 'accessibilityRole' | 'accessibilityLabel' | 'accessibilityState' | 'aria-label' | 'aria-checked' | 'aria-disabled' | 'aria-busy' | 'aria-selected'> {
|
|
26
26
|
label: string;
|
|
27
|
-
/** A muted second line under the label, such as a subtitle or an address. The row grows to fit it, and it is read with the label (as the hint of a switch row). */
|
|
27
|
+
/** A muted second line under the label, such as a subtitle or an address. The row grows to fit it, and it is read with the label (as the hint of a switch row). A string, a number, one Text element, or a fragment or array with bare text among its children (`<>Ends in <Text>3m</Text></>`) is drawn in the muted Text; any other node (several Text elements, a row with an icon, a live figure) is drawn as given in a View, styled by the host. A component of the host's own that renders bare strings must be wrapped in a Text, as anywhere in a View. Its text is read as concatenated, so give such a row `accessibilityLabel`. */
|
|
28
28
|
description?: React.ReactNode;
|
|
29
|
+
/** What the row reads as, in place of its label, description and value: Long BTC, 10×, 0.5 BTC, up $12. A pressable row keeps its busy text after it, a switch row is named by it (its description and value stay its hint), and a static row becomes one element named by it (with a `trailing` control, the label, description and value become that element and the control stays its own target). */
|
|
30
|
+
accessibilityLabel?: string;
|
|
29
31
|
/** Colours the label: `destructive` for an action that deletes or ends something, `muted` for one that is done or inactive. */
|
|
30
32
|
tone?: 'destructive' | 'muted';
|
|
31
33
|
/** Artwork before the label, such as an icon. Decorative: the label names the row. */
|