|
1 | 1 | import Feather from '@expo/vector-icons/Feather'; |
2 | 2 | import Octicons from '@expo/vector-icons/Octicons'; |
3 | 3 | import { Button, useToast, type ToastComponentProps } from 'heroui-native'; |
4 | | -import { useCallback } from 'react'; |
5 | | -import { View } from 'react-native'; |
| 4 | +import { useCallback, useRef, useState } from 'react'; |
| 5 | +import { TextInput, View } from 'react-native'; |
6 | 6 | import { withUniwind } from 'uniwind'; |
7 | 7 | import type { UsageVariant } from '../../../components/component-presentation/types'; |
8 | 8 | import { UsageVariantFlatList } from '../../../components/component-presentation/usage-variant-flatlist'; |
@@ -199,6 +199,62 @@ const DifferentContentSizesContent = () => { |
199 | 199 |
|
200 | 200 | // ------------------------------------------------------------------------------ |
201 | 201 |
|
| 202 | +const KeyboardAvoidingContent = () => { |
| 203 | + const [isFocused, setIsFocused] = useState(false); |
| 204 | + |
| 205 | + const { toast } = useToast(); |
| 206 | + |
| 207 | + const inputRef = useRef<TextInput>(null); |
| 208 | + |
| 209 | + return ( |
| 210 | + <View className="flex-1 items-center justify-center px-5 gap-5"> |
| 211 | + <Button |
| 212 | + variant="secondary" |
| 213 | + onPress={() => { |
| 214 | + toast.show({ |
| 215 | + variant: 'success', |
| 216 | + duration: 'persistent', |
| 217 | + placement: 'bottom', |
| 218 | + label: 'Payment successful', |
| 219 | + description: |
| 220 | + 'Your subscription has been renewed. You will be charged $9.99/month. Thank you for your continued support.', |
| 221 | + actionLabel: 'Close', |
| 222 | + onActionPress: ({ hide }) => { |
| 223 | + hide(); |
| 224 | + inputRef.current?.blur(); |
| 225 | + }, |
| 226 | + }); |
| 227 | + }} |
| 228 | + > |
| 229 | + Show toast |
| 230 | + </Button> |
| 231 | + <Button |
| 232 | + onPress={() => { |
| 233 | + if (isFocused) { |
| 234 | + inputRef.current?.blur(); |
| 235 | + } else { |
| 236 | + inputRef.current?.focus(); |
| 237 | + } |
| 238 | + }} |
| 239 | + variant="secondary" |
| 240 | + > |
| 241 | + Toggle keyboard |
| 242 | + </Button> |
| 243 | + <Button onPress={() => toast.hide('all')} variant="destructive-soft"> |
| 244 | + Hide toast |
| 245 | + </Button> |
| 246 | + <TextInput |
| 247 | + ref={inputRef} |
| 248 | + className="opacity-0 pointer-events-none" |
| 249 | + onFocus={() => setIsFocused(true)} |
| 250 | + onBlur={() => setIsFocused(false)} |
| 251 | + /> |
| 252 | + </View> |
| 253 | + ); |
| 254 | +}; |
| 255 | + |
| 256 | +// ------------------------------------------------------------------------------ |
| 257 | + |
202 | 258 | const CustomToastsContent = () => { |
203 | 259 | const { toast } = useToast(); |
204 | 260 | const LOADING_TOAST_ID = 'loading-toast'; |
@@ -350,6 +406,11 @@ const TOAST_VARIANTS: UsageVariant[] = [ |
350 | 406 | label: 'Different content sizes', |
351 | 407 | content: <DifferentContentSizesContent />, |
352 | 408 | }, |
| 409 | + { |
| 410 | + value: 'keyboard-avoiding', |
| 411 | + label: 'Keyboard avoiding', |
| 412 | + content: <KeyboardAvoidingContent />, |
| 413 | + }, |
353 | 414 | { |
354 | 415 | value: 'custom-toasts', |
355 | 416 | label: 'Custom toasts', |
|
0 commit comments