@ledgerhq/lumen-ui-rnative 0.1.41 → 0.1.43
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/dist/module/lib/Components/Banner/Banner.js +5 -9
- package/dist/module/lib/Components/Banner/Banner.js.map +1 -1
- package/dist/module/lib/Components/MediaButton/MediaButton.js +17 -21
- package/dist/module/lib/Components/MediaButton/MediaButton.js.map +1 -1
- package/dist/module/lib/Components/MediaButton/MediaButton.test.js +26 -1
- package/dist/module/lib/Components/MediaButton/MediaButton.test.js.map +1 -1
- package/dist/module/lib/Components/SegmentedControl/SegmentedControl.test.js +162 -66
- package/dist/module/lib/Components/SegmentedControl/SegmentedControl.test.js.map +1 -1
- package/dist/module/lib/Components/SegmentedControl/usePillLayout.js +19 -15
- package/dist/module/lib/Components/SegmentedControl/usePillLayout.js.map +1 -1
- package/dist/module/lib/Components/Trend/Trend.js +19 -16
- package/dist/module/lib/Components/Trend/Trend.js.map +1 -1
- package/dist/typescript/src/lib/Components/Banner/Banner.d.ts.map +1 -1
- package/dist/typescript/src/lib/Components/Banner/types.d.ts +3 -3
- package/dist/typescript/src/lib/Components/Banner/types.d.ts.map +1 -1
- package/dist/typescript/src/lib/Components/MediaButton/MediaButton.d.ts.map +1 -1
- package/dist/typescript/src/lib/Components/SegmentedControl/usePillLayout.d.ts.map +1 -1
- package/dist/typescript/src/lib/Components/Trend/Trend.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/lib/Components/Banner/Banner.tsx +8 -11
- package/src/lib/Components/Banner/types.ts +3 -3
- package/src/lib/Components/MediaButton/MediaButton.test.tsx +41 -1
- package/src/lib/Components/MediaButton/MediaButton.tsx +17 -21
- package/src/lib/Components/SegmentedControl/SegmentedControl.test.tsx +152 -60
- package/src/lib/Components/SegmentedControl/usePillLayout.ts +21 -12
- package/src/lib/Components/Trend/Trend.tsx +24 -22
|
@@ -6,6 +6,7 @@ import React, {
|
|
|
6
6
|
useEffect,
|
|
7
7
|
useMemo,
|
|
8
8
|
useRef,
|
|
9
|
+
useState,
|
|
9
10
|
} from 'react';
|
|
10
11
|
import type { LayoutChangeEvent } from 'react-native';
|
|
11
12
|
import {
|
|
@@ -49,7 +50,9 @@ export function usePillLayout({
|
|
|
49
50
|
const pillWidth = useSharedValue(0);
|
|
50
51
|
const pillHeight = useSharedValue(0);
|
|
51
52
|
const hasLayoutRef = useRef(false);
|
|
53
|
+
const animatePillRef = useRef(false);
|
|
52
54
|
const buttonLayoutsRef = useRef(new Map<string, ButtonLayout>());
|
|
55
|
+
const [layoutReady, setLayoutReady] = useState(false);
|
|
53
56
|
|
|
54
57
|
const timingConfig = useTimingConfig({
|
|
55
58
|
duration: 300,
|
|
@@ -67,9 +70,7 @@ export function usePillLayout({
|
|
|
67
70
|
|
|
68
71
|
if (!hasLayoutRef.current) {
|
|
69
72
|
hasLayoutRef.current = true;
|
|
70
|
-
|
|
71
|
-
pillTranslateX.value = selectedIndex * slotWidth;
|
|
72
|
-
}
|
|
73
|
+
setLayoutReady(true);
|
|
73
74
|
}
|
|
74
75
|
}
|
|
75
76
|
};
|
|
@@ -78,31 +79,38 @@ export function usePillLayout({
|
|
|
78
79
|
(value: string, layout: ButtonLayout): void => {
|
|
79
80
|
buttonLayoutsRef.current.set(value, layout);
|
|
80
81
|
|
|
81
|
-
if (
|
|
82
|
+
if (
|
|
83
|
+
tabLayout === 'fit' &&
|
|
84
|
+
!hasLayoutRef.current &&
|
|
85
|
+
value === selectedValue
|
|
86
|
+
) {
|
|
82
87
|
hasLayoutRef.current = true;
|
|
83
|
-
|
|
84
|
-
pillTranslateX.value = layout.x;
|
|
85
|
-
pillWidth.value = layout.width;
|
|
86
|
-
}
|
|
88
|
+
setLayoutReady(true);
|
|
87
89
|
}
|
|
88
90
|
},
|
|
89
|
-
[tabLayout, selectedValue
|
|
91
|
+
[tabLayout, selectedValue],
|
|
90
92
|
);
|
|
91
93
|
|
|
92
94
|
useEffect(() => {
|
|
93
95
|
if (!hasLayoutRef.current) return;
|
|
94
96
|
|
|
97
|
+
const skipAnimation = !animatePillRef.current;
|
|
98
|
+
if (skipAnimation) {
|
|
99
|
+
animatePillRef.current = true;
|
|
100
|
+
}
|
|
101
|
+
const config = skipAnimation ? { duration: 0 } : timingConfig;
|
|
102
|
+
|
|
95
103
|
if (tabLayout === 'fit') {
|
|
96
104
|
const layout = buttonLayoutsRef.current.get(selectedValue);
|
|
97
105
|
if (layout) {
|
|
98
|
-
pillTranslateX.value = withTiming(layout.x,
|
|
99
|
-
pillWidth.value = withTiming(layout.width,
|
|
106
|
+
pillTranslateX.value = withTiming(layout.x, config);
|
|
107
|
+
pillWidth.value = withTiming(layout.width, config);
|
|
100
108
|
}
|
|
101
109
|
} else {
|
|
102
110
|
if (selectedIndex >= 0 && pillWidth.value > 0) {
|
|
103
111
|
pillTranslateX.value = withTiming(
|
|
104
112
|
selectedIndex * pillWidth.value,
|
|
105
|
-
|
|
113
|
+
config,
|
|
106
114
|
);
|
|
107
115
|
}
|
|
108
116
|
}
|
|
@@ -113,6 +121,7 @@ export function usePillLayout({
|
|
|
113
121
|
pillWidth,
|
|
114
122
|
pillTranslateX,
|
|
115
123
|
timingConfig,
|
|
124
|
+
layoutReady,
|
|
116
125
|
]);
|
|
117
126
|
|
|
118
127
|
const animatedPillStyle = useAnimatedStyle(
|
|
@@ -3,7 +3,7 @@ import { StyleSheet } from 'react-native';
|
|
|
3
3
|
import { useCommonTranslation } from '../../../i18n';
|
|
4
4
|
import type { LumenTextStyle } from '../../../styles';
|
|
5
5
|
import { useStyleSheet } from '../../../styles';
|
|
6
|
-
import {
|
|
6
|
+
import { TriangleDown, TriangleUp } from '../../Symbols';
|
|
7
7
|
import type { IconSize } from '../Icon';
|
|
8
8
|
import { Box, Text } from '../Utility';
|
|
9
9
|
import type { TrendProps } from './types';
|
|
@@ -17,6 +17,23 @@ function getVariant(value: number): TrendVariant {
|
|
|
17
17
|
return value > 0 ? 'positive' : 'negative';
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
const iconMap = {
|
|
21
|
+
positive: TriangleUp,
|
|
22
|
+
negative: TriangleDown,
|
|
23
|
+
neutral: null,
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const iconSizeMap: Record<NonNullable<TrendProps['size']>, IconSize> = {
|
|
27
|
+
md: 16,
|
|
28
|
+
sm: 12,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const iconColorMap: Record<TrendVariant, LumenTextStyle['color']> = {
|
|
32
|
+
positive: 'success',
|
|
33
|
+
negative: 'error',
|
|
34
|
+
neutral: 'muted',
|
|
35
|
+
};
|
|
36
|
+
|
|
20
37
|
export function Trend({
|
|
21
38
|
value,
|
|
22
39
|
size = 'md',
|
|
@@ -35,26 +52,9 @@ export function Trend({
|
|
|
35
52
|
|
|
36
53
|
const styles = useStyles({ size, variant, disabled });
|
|
37
54
|
|
|
38
|
-
const Icon =
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
neutral: Minus,
|
|
42
|
-
}[variant];
|
|
43
|
-
|
|
44
|
-
const iconSize = (
|
|
45
|
-
{
|
|
46
|
-
md: 16,
|
|
47
|
-
sm: 12,
|
|
48
|
-
} as const
|
|
49
|
-
)[size] as IconSize;
|
|
50
|
-
|
|
51
|
-
const iconColor = (
|
|
52
|
-
{
|
|
53
|
-
positive: 'success',
|
|
54
|
-
negative: 'error',
|
|
55
|
-
neutral: 'muted',
|
|
56
|
-
} as const
|
|
57
|
-
)[variant] as LumenTextStyle['color'];
|
|
55
|
+
const Icon = iconMap[variant];
|
|
56
|
+
const iconSize = iconSizeMap[size];
|
|
57
|
+
const iconColor = iconColorMap[variant];
|
|
58
58
|
|
|
59
59
|
const absoluteFormattedValue = `${Math.abs(value).toFixed(2)}%`;
|
|
60
60
|
const formattedValue =
|
|
@@ -71,7 +71,9 @@ export function Trend({
|
|
|
71
71
|
style={[styles.container, style]}
|
|
72
72
|
{...props}
|
|
73
73
|
>
|
|
74
|
-
|
|
74
|
+
{Icon && (
|
|
75
|
+
<Icon size={iconSize} color={disabled ? 'disabled' : iconColor} />
|
|
76
|
+
)}
|
|
75
77
|
<Text style={styles.text}>{formattedValue}</Text>
|
|
76
78
|
</Box>
|
|
77
79
|
);
|