Merge pull request #8744 from internet-development/@APiligrim/update-toast
hot fix: imports for toast and alignment
This commit is contained in:
@@ -1,10 +1,20 @@
|
|||||||
import {type Theme, select} from '#/alf'
|
import {select, type Theme} from '#/alf'
|
||||||
import {CircleInfo_Stroke2_Corner0_Rounded as ErrorIcon} from '#/components/icons/CircleInfo'
|
|
||||||
import {Warning_Stroke2_Corner0_Rounded as WarningIcon} from '#/components/icons/Warning'
|
|
||||||
import {Check_Stroke2_Corner0_Rounded as SuccessIcon} from '#/components/icons/Check'
|
import {Check_Stroke2_Corner0_Rounded as SuccessIcon} from '#/components/icons/Check'
|
||||||
import {CircleInfo_Stroke2_Corner0_Rounded as CircleInfo} from '#/components/icons/CircleInfo'
|
import {CircleInfo_Stroke2_Corner0_Rounded as CircleInfo} from '#/components/icons/CircleInfo'
|
||||||
|
import {CircleInfo_Stroke2_Corner0_Rounded as ErrorIcon} from '#/components/icons/CircleInfo'
|
||||||
|
import {Warning_Stroke2_Corner0_Rounded as WarningIcon} from '#/components/icons/Warning'
|
||||||
|
|
||||||
export type ToastType = 'default' | 'success' | 'error' | 'warning' | 'info'
|
export type ToastType =
|
||||||
|
| 'default'
|
||||||
|
| 'success'
|
||||||
|
| 'error'
|
||||||
|
| 'warning'
|
||||||
|
| 'info'
|
||||||
|
| 'xmark'
|
||||||
|
| 'exclamation-circle'
|
||||||
|
| 'check'
|
||||||
|
| 'clipboard-check'
|
||||||
|
| 'circle-exclamation'
|
||||||
|
|
||||||
export const TOAST_ANIMATION_CONFIG = {
|
export const TOAST_ANIMATION_CONFIG = {
|
||||||
duration: 300,
|
duration: 300,
|
||||||
|
|||||||
@@ -17,15 +17,16 @@ import Animated, {
|
|||||||
} from 'react-native-reanimated'
|
} from 'react-native-reanimated'
|
||||||
import RootSiblings from 'react-native-root-siblings'
|
import RootSiblings from 'react-native-root-siblings'
|
||||||
import {useSafeAreaInsets} from 'react-native-safe-area-context'
|
import {useSafeAreaInsets} from 'react-native-safe-area-context'
|
||||||
|
|
||||||
import {useNonReactiveCallback} from '#/lib/hooks/useNonReactiveCallback'
|
import {useNonReactiveCallback} from '#/lib/hooks/useNonReactiveCallback'
|
||||||
import {atoms as a, useTheme} from '#/alf'
|
|
||||||
import {Text} from '#/components/Typography'
|
|
||||||
import {
|
import {
|
||||||
type ToastType,
|
|
||||||
TOAST_TYPE_TO_ICON,
|
|
||||||
getToastTypeStyles,
|
getToastTypeStyles,
|
||||||
TOAST_ANIMATION_CONFIG,
|
TOAST_ANIMATION_CONFIG,
|
||||||
} from './Toast.style'
|
TOAST_TYPE_TO_ICON,
|
||||||
|
type ToastType,
|
||||||
|
} from '#/view/com/util/Toast.style'
|
||||||
|
import {atoms as a, useTheme} from '#/alf'
|
||||||
|
import {Text} from '#/components/Typography'
|
||||||
|
|
||||||
const TIMEOUT = 2e3
|
const TIMEOUT = 2e3
|
||||||
|
|
||||||
@@ -56,8 +57,9 @@ function Toast({
|
|||||||
const [cardHeight, setCardHeight] = useState(0)
|
const [cardHeight, setCardHeight] = useState(0)
|
||||||
|
|
||||||
const toastStyles = getToastTypeStyles(t)
|
const toastStyles = getToastTypeStyles(t)
|
||||||
const colors = toastStyles[type]
|
const colors = toastStyles[type as keyof typeof toastStyles]
|
||||||
const IconComponent = TOAST_TYPE_TO_ICON[type]
|
const IconComponent =
|
||||||
|
TOAST_TYPE_TO_ICON[type as keyof typeof TOAST_TYPE_TO_ICON]
|
||||||
|
|
||||||
// for the exit animation to work on iOS the animated component
|
// for the exit animation to work on iOS the animated component
|
||||||
// must not be the root component
|
// must not be the root component
|
||||||
|
|||||||
@@ -4,14 +4,15 @@
|
|||||||
|
|
||||||
import {useEffect, useState} from 'react'
|
import {useEffect, useState} from 'react'
|
||||||
import {Pressable, StyleSheet, Text, View} from 'react-native'
|
import {Pressable, StyleSheet, Text, View} from 'react-native'
|
||||||
import {atoms as a, useTheme} from '#/alf'
|
|
||||||
import {
|
import {
|
||||||
type ToastType,
|
|
||||||
TOAST_TYPE_TO_ICON,
|
|
||||||
getToastTypeStyles,
|
getToastTypeStyles,
|
||||||
getToastWebAnimationStyles,
|
getToastWebAnimationStyles,
|
||||||
|
TOAST_TYPE_TO_ICON,
|
||||||
TOAST_WEB_KEYFRAMES,
|
TOAST_WEB_KEYFRAMES,
|
||||||
} from './Toast.style'
|
type ToastType,
|
||||||
|
} from '#/view/com/util/Toast.style'
|
||||||
|
import {atoms as a, useTheme} from '#/alf'
|
||||||
|
|
||||||
const DURATION = 3500
|
const DURATION = 3500
|
||||||
|
|
||||||
@@ -62,11 +63,11 @@ export const ToastContainer: React.FC<ToastContainerProps> = ({}) => {
|
|||||||
|
|
||||||
const toastTypeStyles = getToastTypeStyles(t)
|
const toastTypeStyles = getToastTypeStyles(t)
|
||||||
const toastStyles = activeToast
|
const toastStyles = activeToast
|
||||||
? toastTypeStyles[activeToast.type]
|
? toastTypeStyles[activeToast.type as keyof typeof toastTypeStyles]
|
||||||
: toastTypeStyles.default
|
: toastTypeStyles.default
|
||||||
|
|
||||||
const IconComponent = activeToast
|
const IconComponent = activeToast
|
||||||
? TOAST_TYPE_TO_ICON[activeToast.type]
|
? TOAST_TYPE_TO_ICON[activeToast.type as keyof typeof TOAST_TYPE_TO_ICON]
|
||||||
: TOAST_TYPE_TO_ICON.default
|
: TOAST_TYPE_TO_ICON.default
|
||||||
|
|
||||||
const animationStyles = getToastWebAnimationStyles()
|
const animationStyles = getToastWebAnimationStyles()
|
||||||
@@ -146,7 +147,7 @@ const styles = StyleSheet.create({
|
|||||||
maxWidth: 380,
|
maxWidth: 380,
|
||||||
padding: 20,
|
padding: 20,
|
||||||
flexDirection: 'row',
|
flexDirection: 'row',
|
||||||
alignItems: 'flex-start',
|
alignItems: 'center',
|
||||||
borderRadius: 10,
|
borderRadius: 10,
|
||||||
borderWidth: 1,
|
borderWidth: 1,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,22 +1,24 @@
|
|||||||
import {View, Pressable} from 'react-native'
|
import {Pressable, View} from 'react-native'
|
||||||
|
|
||||||
import {atoms as a, useTheme} from '#/alf'
|
|
||||||
import {Text, H1} from '#/components/Typography'
|
|
||||||
import {
|
|
||||||
type ToastType,
|
|
||||||
TOAST_TYPE_TO_ICON,
|
|
||||||
getToastTypeStyles,
|
|
||||||
} from '#/view/com/util/Toast.style'
|
|
||||||
import * as Toast from '#/view/com/util/Toast'
|
import * as Toast from '#/view/com/util/Toast'
|
||||||
|
import {
|
||||||
|
getToastTypeStyles,
|
||||||
|
TOAST_TYPE_TO_ICON,
|
||||||
|
type ToastType,
|
||||||
|
} from '#/view/com/util/Toast.style'
|
||||||
|
import {atoms as a, useTheme} from '#/alf'
|
||||||
|
import {H1, Text} from '#/components/Typography'
|
||||||
|
|
||||||
function ToastPreview({message, type}: {message: string; type: ToastType}) {
|
function ToastPreview({message, type}: {message: string; type: ToastType}) {
|
||||||
const t = useTheme()
|
const t = useTheme()
|
||||||
const toastStyles = getToastTypeStyles(t)
|
const toastStyles = getToastTypeStyles(t)
|
||||||
const colors = toastStyles[type]
|
const colors = toastStyles[type as keyof typeof toastStyles]
|
||||||
const IconComponent = TOAST_TYPE_TO_ICON[type]
|
const IconComponent =
|
||||||
|
TOAST_TYPE_TO_ICON[type as keyof typeof TOAST_TYPE_TO_ICON]
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Pressable
|
<Pressable
|
||||||
|
accessibilityRole="button"
|
||||||
onPress={() => Toast.show(message, type)}
|
onPress={() => Toast.show(message, type)}
|
||||||
style={[
|
style={[
|
||||||
{backgroundColor: colors.backgroundColor},
|
{backgroundColor: colors.backgroundColor},
|
||||||
|
|||||||
Reference in New Issue
Block a user