Mobilens English

流程 · 账号

通知设置

这个流程的所有画面

加载

修改

何时出现
怎么离开
下一步
行为规则

    用法

    import { NotificationSettings, type SettingsApi } from '@/components/mobilens/NotificationSettings';
    
    const api: SettingsApi = {
      async load() {
        const res = await fetch('https://api.example.com/me/notifications');
        if (!res.ok) throw new Error(String(res.status));
        return res.json();
      },
      async save(key, value) {
        const res = await fetch('https://api.example.com/me/notifications', { method: 'PATCH', body: JSON.stringify({ [key]: value }) });
        return res.ok ? 'saved' : 'failed';
      },
    };
    
    export function NotificationSettingsScreen() {
      return (
        <NotificationSettings
          api={api}
          toggles={[
            { key: 'push', label: 'Push notifications', description: 'On this phone' },
            { key: 'replies', label: 'Replies', under: 'push' },
            { key: 'mentions', label: 'Mentions', under: 'push' },
          ]}
          choice={{ key: 'digest', label: 'Email summary', options: [{ value: 'off', label: 'Off' }, { value: 'weekly', label: 'Weekly' }] }}
        />
      );
    }
    

    API

    参数类型默认值说明
    api SettingsApi – load and save, connected to your backend.
    toggles ToggleSetting[] – The switches, in order.
    title? string 'Notifications' Heading above the notification settings.
    labels? Partial<NotificationSettingsLabels> – The words the screen shows. Pass a partial set to change only some of them.
    choice? ChoiceSetting – One choice under the switches, such as how often to email a summary.
    initialState? SettingsState – Where to start. Defaults to loading; pass a state in tests.
    onStepChange? (step: SettingsStep) => void – Called with every step the screen enters, for analytics or logging.
    onSaved? (key: string, value: boolean | string) => void – Called after one changed setting has been successfully saved.

    这个流程用到的控件