ScaleRocket/Mobile

Button

Customizable Button component with variants, sizes, loading state, and icon support.

Button

ScaleRocket Mobile includes a flexible Button component that replaces the default React Native TouchableOpacity with consistent styling and built-in loading states.

Basic Usage

import { Button } from "@/components/ui/Button";

export default function MyScreen() {
  return (
    <Button title="Get Started" onPress={() => console.log("pressed")} />
  );
}

Variants

The Button supports multiple visual variants:

<Button title="Primary" variant="primary" onPress={handlePress} />
<Button title="Secondary" variant="secondary" onPress={handlePress} />
<Button title="Outline" variant="outline" onPress={handlePress} />
<Button title="Ghost" variant="ghost" onPress={handlePress} />
<Button title="Destructive" variant="destructive" onPress={handlePress} />
VariantUse Case
primaryMain actions (submit, continue)
secondarySecondary actions (cancel, back)
outlineTertiary actions with border
ghostMinimal style for inline actions
destructiveDangerous actions (delete, remove)

Sizes

Three built-in sizes control padding and font size:

<Button title="Small" size="sm" onPress={handlePress} />
<Button title="Medium" size="md" onPress={handlePress} />
<Button title="Large" size="lg" onPress={handlePress} />

Loading State

Pass loading={true} to show a spinner and disable interaction:

const [loading, setLoading] = useState(false);

<Button
  title="Save"
  loading={loading}
  onPress={async () => {
    setLoading(true);
    await saveData();
    setLoading(false);
  }}
/>

When loading, the button automatically:

  • Replaces text with an ActivityIndicator
  • Disables touch events
  • Reduces opacity

Icon Buttons

Add an icon before or after the label:

import { Ionicons } from "@expo/vector-icons";

<Button
  title="Add Item"
  icon={<Ionicons name="add" size={18} color="white" />}
  onPress={handlePress}
/>

<Button
  title="Next"
  iconRight={<Ionicons name="arrow-forward" size={18} color="white" />}
  onPress={handlePress}
/>

Full Width

By default buttons are auto-width. Set fullWidth for form actions:

<Button title="Sign In" fullWidth onPress={handleSignIn} />

Customization

Override styles via the style and textStyle props:

<Button
  title="Custom"
  style={{ backgroundColor: "#8B5CF6", borderRadius: 12 }}
  textStyle={{ fontWeight: "700", fontSize: 16 }}
  onPress={handlePress}
/>

Disabled State

<Button title="Submit" disabled={!isValid} onPress={handleSubmit} />

The disabled state reduces opacity to 0.5 and prevents touch events.

Component Props

PropTypeDefaultDescription
titlestringrequiredButton label
variantstring"primary"Visual variant
size"sm" | "md" | "lg""md"Button size
loadingbooleanfalseShow loading spinner
disabledbooleanfalseDisable interaction
fullWidthbooleanfalseStretch to container width
iconReactNodeLeft icon element
iconRightReactNodeRight icon element

On this page