Skip to content

Commit fd0b58f

Browse files
committed
feat(toast): adjust entering exiting animation
1 parent 44e95ec commit fd0b58f

File tree

5 files changed

+45
-4
lines changed

5 files changed

+45
-4
lines changed

example/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"react-native-svg": "^15.12.1",
3939
"react-native-web": "^0.21.0",
4040
"react-native-worklets": "^0.5.1",
41+
"sonner-native": "^0.21.1",
4142
"tailwind-merge": "^3.3.1",
4243
"tailwind-variants": "^3.1.0",
4344
"tailwindcss": "^4.1.14",

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
type ToastComponentProps,
77
} from 'heroui-native';
88
import { View } from 'react-native';
9+
import { toast as sonnerToast } from 'sonner-native';
910
import type { UsageVariant } from '../../../components/component-presentation/types';
1011
import { UsageVariantFlatList } from '../../../components/component-presentation/usage-variant-flatlist';
1112

@@ -76,7 +77,6 @@ import { UsageVariantFlatList } from '../../../components/component-presentation
7677

7778
const MyToast = (props: ToastComponentProps) => {
7879
const { id, hide } = props;
79-
console.log('🔴 🔴', id); // VS remove
8080

8181
return (
8282
<Toast
@@ -123,6 +123,10 @@ const InteractiveDemoContent = () => {
123123
<Button onPress={() => toast.hide()} variant="destructive">
124124
Hide All Toasts
125125
</Button>
126+
127+
{/* <Button onPress={() => sonnerToast('Hello, World!')}>
128+
Sonner Toast
129+
</Button> */}
126130
</View>
127131
</View>
128132
);

example/src/app/_layout.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
configureReanimatedLogger,
1515
ReanimatedLogLevel,
1616
} from 'react-native-reanimated';
17+
import { Toaster } from 'sonner-native';
1718
import '../../global.css';
1819
import { AppThemeProvider } from '../contexts/app-theme-context';
1920

@@ -40,6 +41,7 @@ export default function Layout() {
4041
<AppThemeProvider>
4142
<HeroUINativeProvider>
4243
<Slot />
44+
<Toaster />
4345
</HeroUINativeProvider>
4446
</AppThemeProvider>
4547
</KeyboardProvider>

src/components/toast/toast.tsx

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { forwardRef, useMemo } from 'react';
22
import { View } from 'react-native';
33
import Animated, {
4+
Easing,
45
FadeInDown,
5-
FadeOutDown,
66
interpolate,
7+
Keyframe,
78
useAnimatedStyle,
89
withTiming,
910
} from 'react-native-reanimated';
@@ -24,6 +25,18 @@ import type {
2425
ToastRootProps,
2526
} from './toast.types';
2627

28+
const exiting = new Keyframe({
29+
0: {
30+
opacity: 1,
31+
transform: [{ translateY: 0 }, { scale: 1 }],
32+
},
33+
100: {
34+
opacity: 0.5,
35+
transform: [{ translateY: 100 }, { scale: 0.97 }],
36+
easing: Easing.in(Easing.ease),
37+
},
38+
});
39+
2740
const AnimatedToastRoot = Animated.createAnimatedComponent(ToastPrimitive.Root);
2841

2942
const [ToastProvider, useToast] = createContext<ToastContextValue>({
@@ -84,8 +97,13 @@ const ToastRoot = forwardRef<ViewRef, ToastRootProps>((props, ref) => {
8497
<ToastProvider value={contextValue}>
8598
<Animated.View
8699
className="absolute left-0 right-0 bottom-0"
87-
entering={FadeInDown.springify().delay(50)}
88-
exiting={FadeOutDown.springify()}
100+
entering={FadeInDown.springify()
101+
.withInitialValues({
102+
opacity: 1,
103+
transform: [{ translateY: 100 }],
104+
})
105+
.mass(3)}
106+
exiting={exiting.duration(200)}
89107
>
90108
<AnimatedToastRoot
91109
ref={ref}

yarn.lock

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8872,6 +8872,7 @@ __metadata:
88728872
react-native-svg: ^15.12.1
88738873
react-native-web: ^0.21.0
88748874
react-native-worklets: ^0.5.1
8875+
sonner-native: ^0.21.1
88758876
tailwind-merge: ^3.3.1
88768877
tailwind-variants: ^3.1.0
88778878
tailwindcss: ^4.1.14
@@ -14556,6 +14557,21 @@ __metadata:
1455614557
languageName: node
1455714558
linkType: hard
1455814559

14560+
"sonner-native@npm:^0.21.1":
14561+
version: 0.21.1
14562+
resolution: "sonner-native@npm:0.21.1"
14563+
peerDependencies:
14564+
react: "*"
14565+
react-native: "*"
14566+
react-native-gesture-handler: ">=2.16.1"
14567+
react-native-reanimated: ">=3.10.1"
14568+
react-native-safe-area-context: ">=4.10.5"
14569+
react-native-screens: ">=3.31.1"
14570+
react-native-svg: ">=15.6.0"
14571+
checksum: 02f75400859efc0e90f0fa7c7b46833ec990975b58f53dbce79d43142f5c506b89b1de66e980f088aef7039f6b5f7395c8ad538d06ad0c900e821336e08460d7
14572+
languageName: node
14573+
linkType: hard
14574+
1455914575
"source-map-js@npm:^1.2.1":
1456014576
version: 1.2.1
1456114577
resolution: "source-map-js@npm:1.2.1"

0 commit comments

Comments
 (0)