Skip to content

Commit c26a629

Browse files
committed
fix(toast): action button highlight color
1 parent 21fffc4 commit c26a629

File tree

3 files changed

+55
-12
lines changed

3 files changed

+55
-12
lines changed

example/src/app/(home)/components/toast.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,12 @@ const MyToast1 = (props: ToastComponentProps) => {
8080
const { id, hide } = props;
8181

8282
return (
83-
<Toast variant="accent" className="flex-row items-center gap-3" {...props}>
83+
<Toast
84+
variant="success"
85+
duration="persistent"
86+
className="flex-row items-center gap-3"
87+
{...props}
88+
>
8489
<View className="flex-1">
8590
<Toast.Label>{id}</Toast.Label>
8691
<Toast.Description>

src/components/button/button.styles.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ const root = tv({
88
variant: {
99
primary: 'bg-accent',
1010
secondary: 'bg-default',
11-
tertiary: 'bg-default border border-border',
11+
tertiary: 'bg-default',
1212
ghost: 'bg-transparent',
1313
destructive: 'bg-danger',
14-
['destructive-soft']: 'bg-default border border-border',
14+
['destructive-soft']: 'bg-default',
1515
},
1616
size: {
1717
sm: 'h-[36px] px-3.5 gap-1.5',

src/components/toast/toast.tsx

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { GestureDetector } from 'react-native-gesture-handler';
44
import Animated from 'react-native-reanimated';
55
import { CloseIcon } from '../../helpers/components/close-icon';
66
import { Text } from '../../helpers/components/text';
7-
import { cn } from '../../helpers/theme';
7+
import { cn, useThemeColor } from '../../helpers/theme';
88
import type { ViewRef } from '../../helpers/types';
99
import { createContext } from '../../helpers/utils';
1010
import * as ToastPrimitive from '../../primitives/toast';
@@ -13,6 +13,7 @@ import type {
1313
ToastShowOptions,
1414
} from '../../providers/toast';
1515
import { Button } from '../button';
16+
import type { PressableFeedbackHighlightRootAnimation } from '../pressable-feedback';
1617
import { useToastRootAnimation } from './toast.animation';
1718
import { DISPLAY_NAME } from './toast.constants';
1819
import { useToastDuration } from './toast.hooks';
@@ -106,10 +107,8 @@ const ToastRoot = forwardRef<ViewRef, ToastRootProps>((props, ref) => {
106107
</AnimatedToastRoot>
107108
{/* Static toast instance */}
108109
<AnimatedToastRoot
109-
className={cn(
110-
tvStyles,
111-
'absolute top-[200px] opacity-0 pointer-events-none'
112-
)}
110+
pointerEvents="none"
111+
className={cn(tvStyles, 'absolute opacity-0')}
113112
style={[styleSheet.root, style]}
114113
onLayout={(event) => {
115114
const measuredHeight = event.nativeEvent.layout.height;
@@ -172,6 +171,39 @@ const ToastAction = forwardRef<View, ToastActionProps>((props, ref) => {
172171

173172
const { variant: toastVariant } = useToast();
174173

174+
const tvStyles = toastStyles.action({
175+
variant: toastVariant,
176+
className,
177+
});
178+
179+
const themeColorDefaultHover = useThemeColor('default-hover');
180+
const themeColorAccentHover = useThemeColor('accent-hover');
181+
const themeColorSuccessHover = useThemeColor('success-hover');
182+
const themeColorWarningHover = useThemeColor('warning-hover');
183+
const themeColorDangerHover = useThemeColor('danger-hover');
184+
185+
const highlightColorMap = useMemo(() => {
186+
switch (toastVariant) {
187+
case 'default':
188+
return themeColorDefaultHover;
189+
case 'accent':
190+
return themeColorAccentHover;
191+
case 'success':
192+
return themeColorSuccessHover;
193+
case 'warning':
194+
return themeColorWarningHover;
195+
case 'danger':
196+
return themeColorDangerHover;
197+
}
198+
}, [
199+
toastVariant,
200+
themeColorDefaultHover,
201+
themeColorAccentHover,
202+
themeColorSuccessHover,
203+
themeColorWarningHover,
204+
themeColorDangerHover,
205+
]);
206+
175207
const buttonVariant = useMemo(() => {
176208
if (variant) return variant;
177209

@@ -185,17 +217,23 @@ const ToastAction = forwardRef<View, ToastActionProps>((props, ref) => {
185217
}
186218
}, [toastVariant, variant]);
187219

188-
const tvStyles = toastStyles.action({
189-
variant: toastVariant,
190-
className,
191-
});
220+
const animationConfig = useMemo<PressableFeedbackHighlightRootAnimation>(
221+
() => ({
222+
highlight: {
223+
backgroundColor: { value: highlightColorMap },
224+
opacity: { value: [0, 1] },
225+
},
226+
}),
227+
[highlightColorMap]
228+
);
192229

193230
return (
194231
<Button
195232
ref={ref}
196233
variant={buttonVariant}
197234
size={size}
198235
className={tvStyles}
236+
animation={animationConfig}
199237
{...restProps}
200238
>
201239
{children}

0 commit comments

Comments
 (0)