Button
The Button component creates a tappable button with native SwiftUI styling.
Import
Section titled “Import”import { SwiftUI } from '@mgcrea/react-native-swiftui';<SwiftUI.Button title="Press Me" onPress={() => console.log('Button pressed!')}/>| Prop | Type | Default | Description |
|---|---|---|---|
title | string | - | Button text label |
disabled | boolean | false | Disable button interaction |
buttonStyle | NativeButtonStyle | "default" | Visual style of the button |
style | StyleProp<NativeTextStyle> | - | Style properties |
onPress | () => void | - | Callback when button is pressed |
children | ReactNode | - | Custom button content |
Button Styles
Section titled “Button Styles”<SwiftUI.VStack spacing={10}> <SwiftUI.Button title="Default" buttonStyle="default" onPress={() => {}} /> <SwiftUI.Button title="Plain" buttonStyle="plain" onPress={() => {}} /> <SwiftUI.Button title="Bordered" buttonStyle="bordered" onPress={() => {}} /> <SwiftUI.Button title="Bordered Prominent" buttonStyle="borderedProminent" onPress={() => {}} /> <SwiftUI.Button title="Borderless" buttonStyle="borderless" onPress={() => {}} /></SwiftUI.VStack>Available styles:
default- Standard button appearanceplain- Text-only buttonbordered- Button with borderborderedProminent- Filled button with accent colorborderless- Button without bordersubtle- Subtle button stylepicker- Style optimized for picker buttons
Disabled State
Section titled “Disabled State”<SwiftUI.Button title="Disabled Button" disabled onPress={() => {}}/>Custom Content
Section titled “Custom Content”Buttons can contain child components:
<SwiftUI.Button onPress={() => {}}> <SwiftUI.HStack spacing={8}> <SwiftUI.Image name="system:star.fill" style={{ color: 'gold' }} /> <SwiftUI.Text text="Favorite" /> </SwiftUI.HStack></SwiftUI.Button>Styling
Section titled “Styling”<SwiftUI.Button title="Styled Button" style={{ color: 'white', backgroundColor: '#007AFF', padding: 12, borderRadius: 8, }} onPress={() => {}}/>Examples
Section titled “Examples”Form Submit Button
Section titled “Form Submit Button”<SwiftUI.Form> <SwiftUI.Section header="Account"> <SwiftUI.TextField label="Email" text={email} onChange={setEmail} /> <SwiftUI.TextField label="Password" text={password} onChange={setPassword} secure /> </SwiftUI.Section> <SwiftUI.Section> <SwiftUI.Button title="Sign In" buttonStyle="borderedProminent" onPress={handleSignIn} /> </SwiftUI.Section></SwiftUI.Form>Action Buttons
Section titled “Action Buttons”<SwiftUI.HStack spacing={16}> <SwiftUI.Button title="Cancel" buttonStyle="bordered" onPress={handleCancel} /> <SwiftUI.Button title="Confirm" buttonStyle="borderedProminent" onPress={handleConfirm} /></SwiftUI.HStack>Conditional Disable
Section titled “Conditional Disable”const [isValid, setIsValid] = useState(false);
<SwiftUI.Button title="Submit" disabled={!isValid} onPress={handleSubmit}/>