Skip to content

Commit 9c3f79b

Browse files
committed
feat(example-app): handle toasts hide from components screen
1 parent 95c09f2 commit 9c3f79b

File tree

2 files changed

+48
-5
lines changed

2 files changed

+48
-5
lines changed

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Ionicons } from '@expo/vector-icons';
2-
import { useRouter } from 'expo-router';
3-
import { Accordion } from 'heroui-native';
2+
import { usePathname, useRouter } from 'expo-router';
3+
import { Accordion, useToast } from 'heroui-native';
4+
import { useEffect } from 'react';
45
import { View } from 'react-native';
56
import { withUniwind } from 'uniwind';
67
import { AppText } from '../../../components/app-text';
@@ -106,6 +107,16 @@ const components: Component[] = [
106107

107108
export default function App() {
108109
const router = useRouter();
110+
const pathname = usePathname();
111+
112+
const { toast, isToastVisible } = useToast();
113+
114+
useEffect(() => {
115+
if (isToastVisible && pathname === '/components') {
116+
toast.hide('all');
117+
}
118+
// eslint-disable-next-line react-hooks/exhaustive-deps
119+
}, [isToastVisible, pathname]);
109120

110121
return (
111122
<ScreenScrollView contentContainerClassName="px-4">

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

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
type ToastComponentProps,
1010
} from 'heroui-native';
1111
import { useCallback, useRef, useState } from 'react';
12-
import { TextInput, View } from 'react-native';
12+
import { Platform, TextInput, View } from 'react-native';
1313
import { withUniwind } from 'uniwind';
1414
import type { UsageVariant } from '../../../components/component-presentation/types';
1515
import { UsageVariantFlatList } from '../../../components/component-presentation/usage-variant-flatlist';
@@ -524,7 +524,7 @@ const CustomToastsContent = () => {
524524

525525
// ------------------------------------------------------------------------------
526526

527-
const TOAST_VARIANTS: UsageVariant[] = [
527+
const TOAST_VARIANTS_IOS: UsageVariant[] = [
528528
{
529529
value: 'default-variants',
530530
label: 'Default variants',
@@ -557,6 +557,38 @@ const TOAST_VARIANTS: UsageVariant[] = [
557557
},
558558
];
559559

560+
const TOAST_VARIANTS_ANDROID: UsageVariant[] = [
561+
{
562+
value: 'default-variants',
563+
label: 'Default variants',
564+
content: <DefaultVariantsContent />,
565+
},
566+
{
567+
value: 'placement-variants',
568+
label: 'Placement variants',
569+
content: <PlacementVariantsContent />,
570+
},
571+
{
572+
value: 'different-content-sizes',
573+
label: 'Different content sizes',
574+
content: <DifferentContentSizesContent />,
575+
},
576+
{
577+
value: 'keyboard-avoiding',
578+
label: 'Keyboard avoiding',
579+
content: <KeyboardAvoidingContent />,
580+
},
581+
{
582+
value: 'custom-toasts',
583+
label: 'Custom toasts',
584+
content: <CustomToastsContent />,
585+
},
586+
];
587+
560588
export default function ToastScreen() {
561-
return <UsageVariantFlatList data={TOAST_VARIANTS} />;
589+
return (
590+
<UsageVariantFlatList
591+
data={Platform.OS === 'ios' ? TOAST_VARIANTS_IOS : TOAST_VARIANTS_ANDROID}
592+
/>
593+
);
562594
}

0 commit comments

Comments
 (0)