Button

Button is a wrapper around <TouchableOpacity /> or <TouchableNativeFeedback /> of react-native. It accepts all props supported by them. On iOs, Button renders to TouchableOpacity and on Android, it renders to TouchableNativeFeedback.

Button won’t work with Expo versions < 38. This is because we moved to Pressable component and Pressable is not available in Expo in version < 38. So we recommend using magnus version < 1.0.40 for expo versions < 38.

Example #1

See it on Snack

import { Button, Icon, Div } from "react-native-magnus";

<Div row>
  <Button bg="blue500" h={40} w={40} rounded="circle">
    <Icon name="like1" color="white" />
  </Button>
  <Button bg="yellow500" h={40} w={40} rounded="circle" ml="md">
    <Icon name="star" color="white" />
  </Button>
  <Button bg="red100" h={40} w={40} rounded="circle" ml="md">
    <Icon name="heart" color="red500" />
  </Button>
</Div>;

Example #2

See it on Snack

<Div row flexWrap="wrap">
  <Button
    mt="lg"
    px="xl"
    py="lg"
    bg="white"
    borderWidth={1}
    borderColor="red500"
    color="red500"
    underlayColor="red100"
  >
    Contact Us
  </Button>
  <Button
    mt="lg"
    ml="lg"
    px="xl"
    py="lg"
    bg="red500"
    color="white"
    underlayColor="red600"
  >
    Contact Us
  </Button>
  <Button
    mt="lg"
    px="xl"
    py="lg"
    bg="green700"
    color="white"
    suffix={<Icon name="arrowright" ml="md" color="white" />}
  >
    Contact Us
  </Button>
  <Button
    mt="lg"
    ml="md"
    px="xl"
    py="lg"
    bg="blue500"
    rounded="circle"
    color="white"
    shadow={2}
    prefix={<Icon name="caretright" mr="sm" color="white" />}
  >
    Play now
  </Button>
</Div>

Example #3

See it on Snack

<Button
  loading={true}
  block
  bg="blue600"
  suffix={<Icon name="search" color="white" fontFamily="Feather" />}
  p={12}
  color="white"
  rounded="circle"
  mt="lg">
  Loading State
</Button>
<Button
  block
  prefix={
    <Icon
      position="absolute"
      left={8}
      name="search"
      color="white"
      fontFamily="Feather"
    />
  }
  bg="blue600"
  p={12}
  color="white"
  rounded="circle"
  mt="lg">
  Button with Left Icon
</Button>
<Button
  block
  suffix={
    <Icon
      position="absolute"
      right={8}
      name="arrowright"
      color="white"
    />
  }
  bg="blue600"
  p={12}
  color="white"
  rounded="circle"
  mt="lg">
  Button with Right Icon
</Button>

Example #4

See it on Snack

<Div row justifyContent="center" alignItems="center" mt="xl">
  <Button
    bg="white"
    borderless
    shadow="sm"
    h={40}
    w={40}
    rounded="circle"
    alignSelf="center"
  >
    <Icon name="repeat" color="red500" fontFamily="Feather" />
  </Button>
  <Button
    bg="red500"
    h={60}
    w={60}
    mx="xl"
    rounded="circle"
    shadow="md"
    borderless
  >
    <Icon name="play" color="white" fontFamily="Feather" />
  </Button>
  <Button
    bg="white"
    borderless
    shadow="sm"
    h={40}
    w={40}
    rounded="circle"
    alignSelf="center"
  >
    <Icon name="skip-forward" color="red500" fontFamily="Feather" />
  </Button>
</Div>

Example #5

See it on Snack

<Button block color="white" p="none">
  <Div
    p="lg"
    flex={1}
    bgImg={{
      uri:
        "https://images.unsplash.com/photo-1477346611705-65d1883cee1e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1950&q=80",
    }}
  >
    <Text color="white" fontSize="3xl" fontWeight="bold">
      McLeod Ganj
    </Text>
    <Text color="white" fontSize="sm" mt="sm" opacity={0.9}>
      McLeod Ganj is a suburb of Dharamshala in Kangra district of Himachal
      Pradesh, India.
    </Text>
    <Div row mt="xl">
      <Text color="white">Explore</Text>
      <Icon name="arrowright" color="white" ml="md" />
    </Div>
  </Div>
</Button>

Props

Accepts all props supported by TouchableHighlight and TouchableNativeFeedback ( Android only ) of react-native

PropertyDescriptionTypeDefault
mmargin`stringnumber`
mtmargin top`stringnumber`
mrmargin right`stringnumber`
mbmargin bottom`stringnumber`
mlmargin margin left`stringnumber`
mxmargin horizonal`stringnumber`
mymargin vertical`stringnumber`
ppadding`stringnumber`
ptpadding top`stringnumber`
prpadding right`stringnumber`
pbpadding bottom`stringnumber`
plpadding margin left`stringnumber`
pxpadding horizonal`stringnumber`
pypadding vertical`stringnumber`
hheightnumber-
wwidthnumber-
bgbackground colorstringblue500
colortext color for buttonstringwhite
positionused to position the childrens`absolute”“relative”`
minHmininmum heightnumber-
minWminimum widthstring-
roundedborder radiusstringnone
loadingloading state for button. Renders the ActivityIndicator inside button when truebooleanfalse
loaderColorcolor for ActivityIndicator for loading statestringgray400
loaderSizesize for ActivityIndicator for loading statestringmd
disableddisabled state for button. Decreases the opacity and onPress handler won’t work when truebooleanfalse
borderColorcolor for borderstring-
borderTopColorcolor for border topstring-
borderRightColorcolor for border rightstring-
borderLeftColorcolor for border leftstring-
borderBottomColorcolor for border bottomstring-
borderWidthwidth for bordernumber-
borderTopWidthwidth for border topnumber-
borderRightWidthwidth for border rightnumber-
borderLeftWidthwidth for border leftnumber-
borderBottomWidthwidth for border bottomnumber-
borderlessIf the ripple can render outside it’s boundsbooleanfalse
rippleIf the ripple is enabled in case of androidbooleantrue
rippleColorripple colorstringgray900
suffixRenders a component on the right of buttonReactNode-
prefixRenders a component on the left of buttonReactNode-
blocksets the width to 100% when truebooleanfalse
flexflex property for containernumber-
shadowdescribe the depth of shadow to be usednumber-
shadowColorcolor for shadowstring-
justifyContentdescribes how to align children within the main axis of their container`“flex-start”“flex-end”
topnumber of logical pixels to offset the top edge of this component.number-
rightnumber of logical pixels to offset the right edge of this component.number-
bottomnumber of logical pixels to offset the bottom edge of this component.number-
leftnumber of logical pixels to offset the left edge of this component.number-
opacityopacitynumber-