Installation
The Button component requires the following dependencies:- This is already installed in the project.
How to Import?
Features
- Haptic feedback support (on native platforms)
- Loading state with ActivityIndicator
- Icon support (left or right positioned)
- Customizable styling
- Theme integration
- Disabled state
- Pressed state animation
- TypeScript support
Props
Prop | Type | Required | Description |
---|---|---|---|
onPress | () => void | Yes | Function to call when button is pressed |
children | React.ReactNode | Yes | Content to display inside the button |
style | ViewStyle | ViewStyle[] | No | Custom styles for the button |
textStyle | TextStyle | No | Custom styles for the text |
bgColor | string | No | Background color of the button |
disabled | boolean | No | Disables the button when true |
loading | boolean | No | Shows loading indicator when true |
icon | React.ReactNode | No | Icon component to display |
iconPosition | 'left' | 'right' | No | Position of the icon (default: ‘left’) |
borderColor | string | No | Color of the button border |
borderWidth | number | No | Width of the button border |
height | number | No | Custom height for the button |
Usage
Basic Usage
With Loading State
With Icon
Custom Styling
Don’t forget to use
constants/appConstants.ts
to defining your theme.Styling
The button comes with default styles that can be customized:- Default border radius from
BORDER_RADIUS.sm
- Flexible height (default from
BUTTON_HEIGHT.md
) - Pressed state reduces opacity to 0.8 and scales to 0.99
- Disabled state reduces opacity to 0.5
- Icons have horizontal margin from
MARGIN.sm
Theme Integration
The button automatically integrates with your app’s theme system using theuseTheme
hook:
Notes
- Haptic feedback is automatically triggered on button press (native platforms only)
- Loading state automatically disables the button
- The button supports both single and array style props for flexible styling
- Icons are wrapped in a View container with horizontal margin
- The component is fully type-safe with TypeScript
Best Practices
- Always provide a meaningful onPress handler
- Use loading state for async operations
- Provide appropriate feedback for disabled states
- Consider using icons to enhance visual communication
- Maintain consistent styling across your application
- Use the theme system for consistent color schemes