NativeBase comes in handy when looking for an open-source UI library for your React Native apps. It has a good number of basic components that make developing React Native apps easier and faster.
These components can be categorized into
Box
, similar to the HTML div, is used for low-level layout needs.
Box
into a componentimport { Box } from 'native-base';
<Box
bg="primary.100"
p={2}
_text={{
fontSize: "md",
fontWeight: "bold",
color: "white",
}}
>
Educative is great
</Box>
Button
is used to trigger actions on the screen, like navigating to a new page.
Button
into a componentimport { Button } from 'native-base';
<Button
onPress={() =>
console.log("You pressed me")}
>
Bottom
</Button>
Input
is a text field used for getting user input. It is mostly used in forms to get user input that can later be sent to a server.
Input
into a componentimport { Input } from 'native-base';
<Input
w="100%"
placeholder="Enter your name"
mx={1}
_light={{
placeholderTextColor: "red.400",
}}
_dark={{
placeholderTextColor: "red.50",
}}
/>
Alerts
are used to show customized messages in the app.
Alert
into a componentimport { Alert } from 'native-base';
<Alert status="warning" w="100%">
<Alert.Icon />
<Alert.Title>
{`Educative rocks`}
</Alert.Title>
</Alert>
Select
is also used for collecting user input. However, it appears in a dropdown form.
Select
into a componentimport { Select } from 'native-base';
<Select
minWidth={200}
accessibilityLabel="Select your favorite comic"
placeholder="Select your favorite comic"
onValueChange={(itemValue) => setLanguage(itemValue)}
_selectedItem={{
bg: "cyan.600"
}}
>
<Select.Item label="JavaScript" value="js" />
<Select.Item label="Dc Comics" value="dc" />
<Select.Item label="Marvel" value="mv" />
</Select>
Spinner
can be used to display a loading effect.
Spinner
into a componentimport { Spinner } from 'native-base';
<Spinner accessibilityLabel="Loading posts" />
Toast
can be used to show alerts on top of an overlay. It is usually used to give feedback to a user after an action has taken place. Its default timeout is 5 seconds.
Like other components, it can be customized. Its location on the screen is flexible.
Toast
into a componentimport { useToast } from 'native-base';
<Button
onPress={() =>
toast.show({
title: "Welcome Back, John Doe!",
})
}
>
Bottom
</Button>
Modal
shows content in a window overlay. Any content behind a modal can’t be accessed by the user until the modal is closed.
Modal
into a componentimport { Modal } from 'native-base';
<Modal>
<Modal.Content>
<Modal.CloseButton />
<Modal.Header>Educative</Modal.Header>
<Modal.Body>
Learn with us, and take your career to another level.
</Modal.Body>
<Modal.Footer>
<Button.Group>
<Button>
Start Now
</Button>
<Button>
Close
</Button>
</Button.Group>
</Modal.Footer>
</Modal.Content>
</Modal>
Tooltip
is an informative message that appears when a user interacts with an element. This interaction can be initiated through either a keyboard-hover or a mouse-hover gesture.
Tooltip
into a componentimport { Tooltip } from 'native-base';
<Tooltip label="Hey, Welcome to Educative!" openDelay={300}>
<Button>Show</Button>
</Tooltip>
Action Sheet
is used to display a set of options in a dialog. It appears over the app’s content.
ActionSheet
into a componentimport { Actionsheet } from 'native-base';
<Actionsheet>
<Actionsheet.Content>
<Actionsheet.Item>
More
</Actionsheet.Item>
<Actionsheet.Item>
Accept
</Actionsheet.Item>
<Actionsheet.Item>
Reject
</Actionsheet.Item>
</Actionsheet.Content>
</Actionsheet>