Mobilens English

控件 · 按钮

按钮

所有状态

何时出现
行为规则

    用法

    import { useState } from 'react';
    import { View } from 'react-native';
    import { Button } from '@/components/mobilens/Button';
    
    export function SaveBar({ save, cancel }: { save: () => Promise<void>; cancel: () => void }) {
      const [saving, setSaving] = useState(false);
      return (
        <View style={{ gap: 12 }}>
          <Button
            title="Save changes"
            loading={saving}
            onPress={async () => {
              setSaving(true);
              try {
                await save();
              } finally {
                setSaving(false);
              }
            }}
          />
          <Button title="Cancel" variant="secondary" disabled={saving} onPress={cancel} />
        </View>
      );
    }
    

    API

    参数类型默认值说明
    title string – The label. Keep it a verb: "Send code", not "OK".
    onPress? () => void – Called on tap. Not called while loading or disabled.
    variant? ButtonVariant 'primary' primary for the one main action on a screen, destructive for what cannot be undone.
    loading? boolean false Shows a spinner in place of the label, keeps the width, and ignores taps.
    disabled? boolean false Greyed out and ignores taps. Screen readers say "dimmed".
    icon? ReactNode – Shown before the label.
    color? string – Override the label and spinner colour while enabled.
    backgroundColor? string – Override the enabled button surface colour.
    minHeight? number – Minimum height of the visible button surface, in points.
    style? StyleProp<ViewStyle> – Layout only, such as margins or alignSelf. Width fills the parent by default.

    用在这些流程里