Mobilens English

控件 · 反馈

底部提示条

所有状态

何时出现
行为规则

    用法

    import type { ReactNode } from 'react';
    import { View } from 'react-native';
    import { Snackbar, useSnackbar } from '@/components/mobilens/Snackbar';
    
    export function Inbox({ archive, unarchive, children }: { archive: (id: string) => Promise<void>; unarchive: (id: string) => void; children: (onArchive: (id: string) => void) => ReactNode }) {
      const snack = useSnackbar();
    
      const onArchive = async (id: string) => {
        try {
          await archive(id);
          snack.show({ text: 'Conversation archived', action: { label: 'Undo', onPress: () => unarchive(id) } });
        } catch {
          snack.show({ text: "Couldn't archive. Try again.", tone: 'error' });
        }
      };
    
      return (
        <View style={{ flex: 1 }}>
          {children(onArchive)}
          <Snackbar {...snack.props} />
        </View>
      );
    }
    

    API

    参数类型默认值说明
    message SnackbarMessage | null – The message on screen, or null for none. useSnackbar() manages this for you.
    onDismiss () => void – Called when it should go away: time ran out, the action was tapped, or it was swiped down.
    duration? number 4000 How long it stays, in ms. With a screen reader on, a message with an action stays until it is used.

    用在这些流程里