Components

NativeBase is made from effective building blocks referred to as components. The Components are constructed in pure React Native platform along with some JavaScript functionality with rich set of customisable properties. These components allow you to quickly build the perfect interface.

NativeBase includes components such as layouts, header, footer, textbox, buttons, badge, icons, inputgroup, form, list, cards, thumbnails, progress bar, spinner etc.


Anatomy

Automatically animates views to their new positions.
A common way to use NativeBase layout is to have all the components within <Container>.



General Syntax
import {Container, Header, Content, Footer, Title} from 'native-base';
import React, {Component} from 'react-native';
​
export default class LayoutExample extends Component {
    render() {
        return (
            <Container> 
                <Header>
                    <Title>Header</Title>
                </Header>

                <Content>
                    // Your main content goes here
                </Content>

                <Footer>
                    <Title>Footer</Title>
                </Footer>
            </Container>
        );
    }
}


Configuration
Property Default Option Description
<Header> - - Renders as Header (navbar) of your screen.
Input values: Text, Button, Icon. read more
<Content> - - Represents the main content of your screen.
There can be only one <Content> component in a screen.
<Footer> - - Renders as Footer of your screen.
Input values: Text, Button, Icon. read more

Content

Syntax
import {Container, Content} from 'native-base';
import React, {Component} from 'react-native';
​
export default class ContentExample extends Component {
    render() {
        return (
            <Container> 
                <Content>
                    // Your main content goes here
                </Content>
            </Container>
        );
    }
}


Badge

All of us must have seen notification badges somewhere, such as on smart phones or facebook. NativeBase is here to include this into your collection of readymade components. Badges are numerical indicators of how many items are associated with an element. Badges can notify you that there are new or unread messages or notifications. These can be very effective in alerting the user to new things on your app.

Syntax
import {Container, Content, Badge} from 'native-base';
import React, {Component} from 'react-native';
​
export default class BadgeExample extends Component {
    render() {
        return (
            <Container>
                <Content>
                    <Badge>2</Badge>
                    <Badge primary>2</Badge>
                    <Badge success>2</Badge>
                    <Badge info>2</Badge>
                    <Badge warning>2</Badge>
                    <Badge danger>2</Badge>
                </Content>
            </Container>
        );
    }
}


Configuration
Property Default Option Description
backgroundColor red user-defined Background color for badge.
Note: Include the attributes within style.

Button

Button is a pure NativeBase component.
Buttons are the integral part of an application. They are used for various purposes like, submit or reset a form, navigate, performing interactive actions such as showing or hiding something in an app on click of the button, etc.



Syntax
import {Container, Content, Button} from 'native-base';
import React, {Component} from 'react-native';
​
export default class ButtonExample extends Component {
    render() {
        return (
            <Container>
                <Content>
                    // NativeBase default style
                    <Button> Click Me! </Button>
                </Content>
            </Container>
        );
    }
}


Configuration
Property Default Option Description
style - - Defines button style
textStyle - - Defines button text style
block - - Block level button
rounded - - Renders button with slightly round shaped edges.
bordered - - Applies outline button style.
transparent - - Gives you effect of Icon-buttons.
To have button with transparent background, include this prop.
small - - For small size button
large - - For large size button
iconLeft - - Used for Icon alignment.
Aligns icon to the left in button.
By default, icons are aligned to the left in button.
iconRight - - Used for Icon alignment.
Aligns icon to the right in button.

Button Theme

NativeBase provides buttons with wide range of colors, size and variuos other props.
NativeBase provides following color themes:

Syntax
import {Container, Content, Button} from 'native-base';
import React, {Component} from 'react-native';
​
export default class ButtonThemeExample extends Component {
    render() {
        return (
            <Container>
                <Content>
                    <Button primary> Primary </Button>
                    <Button success> Success </Button>
                    <Button info> Info </Button>
                    <Button warning> Warning </Button>
                    <Button danger> Danger </Button>
                </Content>
            </Container>
        );
    }
}

Block Button

A block level button spans the entire width of the parent element. Create block level buttons by adding block prop with the Button.

Syntax
import {Container, Content, Button} from 'native-base';
import React, {Component} from 'react-native';
​
export default class BlockButtonExample extends Component {
    render() {
        return (
            <Container>
                <Content>
                    <Button block> Primary </Button>
                    <Button block success> Success </Button>
                    <Button block info> Info </Button>
                    <Button block warning> Warning </Button>
                    <Button block danger> Danger </Button>
                </Content>
            </Container>
        );
    }
}

Rounded Button

Include rounded prop with Button to easily style your buttons.

Syntax
import {Container, Content, Button} from 'native-base';
import React, {Component} from 'react-native';
​
export default class RoundedButtonExample extends Component {
    render() {
        return (
            <Container>
                <Content>
                    <Button rounded> Primary </Button>
                    <Button rounded success> Success </Button>
                    <Button rounded info> Info </Button>
                    <Button rounded warning> Warning </Button>
                    <Button rounded danger> Danger </Button>
                </Content>
            </Container>
        );
    }
}

Icon Button

The Icon Buttons, can take text and/or icon as child elements inside the Button. read more
This goes as simple as this: include your choice of icon using Icon component within the Button component.

Syntax
import {Container, Content, Button, Icon} from 'native-base';
import React, {Component} from 'react-native';
​
export default class IconButtonExample extends Component {
    render() {
        return (
            <Container>
                <Content>
                    <Button primary>
                        <Icon name="ios-home" />
                        Home
                    </Button>

                    <Button success iconRight>
                        Next
                        <Icon name="ios-arrow-forward" />
                    </Button>

                    <Button info>
                        Previous
                        <Icon name="ios-arrow-back" />
                    </Button>
                
                    <Button warning>
                        <Icon name="ios-star" />
                    </Button>

                    <Button danger>
                        <Icon name="ios-close-circle" />
                    </Button>

                    <Button style={{backgroundColor: '#384850'}} >
                        <Icon name="ios-search" style={{color: '#00c497'}}/>
                    </Button>
                </Content>
            </Container>
        );
    }
}

Outline Button

Include bordered prop with Button to apply outline button style.

Syntax
import {Container, Content, Button} from 'native-base';
import React, {Component} from 'react-native';
​
export default class OutlineButtonExample extends Component {
    render() {
        return (
            <Container>
                <Content>
                    <Button bordered> Primary </Button>
                    <Button bordered success> Success </Button>
                    <Button bordered info> Info </Button>
                    <Button bordered warning> Warning </Button>
                    <Button bordered danger> Danger </Button>
                </Content>
            </Container>
        );
    }
}

Transparent Button

Include transparent prop with Button. This will render button without border and background color.

Syntax
import {Container, Content, Button} from 'native-base';
import React, {Component} from 'react-native';
​
export default class TransparentButtonExample extends Component {
    render() {
        return (
            <Container>
                <Content>
                    <Button transparent> Primary </Button>
                    <Button transparent success> Success </Button>
                    <Button transparent info> Info </Button>
                    <Button transparent warning> Warning </Button>
                    <Button transparent danger> Danger </Button>
                    <Button transparent>
                        <Icon name={'ios-home'} style={{fontSize: 20, color: '#00c497'}} />
                    </Button>
                </Content>
            </Container>
        );
    }
}

Button Size

Want to have buttons of fancy size?
Include the following props with your Button.

Syntax
import {Container, Content, Button} from 'native-base';
import React, {Component} from 'react-native';
​
export default class ButtonSizeExample extends Component {
    render() {
        return (
            <Container>
                <Content>
                    //Small size button
                    <Button small primary> Primary </Button>

                    //Regular size button
                    <Button success> Success </Button>

                    //Large size button
                    <Button large info> Info </Button>
                </Content>
            </Container>
        );
    }
}


Card

Card is a pure NativeBase component.
Card is a flexible and extensible content container. It includes options for headers and footers, a wide variety of content, contextual background colors, and powerful display options.
NativeBase Cards support a wide variety of content, including images, text, list groups, links, and more. Mix and match multiple content types to create the card you need.



Genertal Syntax
import {Container, Content, Card, CardItem, Text} from 'native-base';
import React, {Component} from 'react-native';
​
export default class CardExample extends Component {
    render() {
        return (
            <Container>
                <Content>
                    <Card>
                        <CardItem>                        
                            <Text>
                                //Your text here
                            </Text>
                        </CardItem>
                    </Card>
                </Content>
            </Container>
        );
    }
}


Configuration
Property Default Option Description
header - - Displays both as header and footer for cards.
note - - Sub caption for Card header.
cardBody - - Defines section for body of card.
The child components are rendered with proper spacing and alignment.

Card Header and Footer

To add an optional header and/or footer within a card, include header prop with the CardItem.

Syntax
import {Container, Content, Card, CardItem, Text} from 'native-base';
import React, {Component} from 'react-native';
​
export default class CardHeaderFooterExample extends Component {
    render() {
        return (
            <Container>
                <Content>
                    <Card>
                        <CardItem header>                        
                            <Text>Card Header</Text>
                        </CardItem>

                        <CardItem>                        
                            <Text>
                                //Your text here
                            </Text>
                        </CardItem>

                        <CardItem header>                        
                            <Text>Card Footer</Text>
                        </CardItem>
                   </Card>
                </Content>
            </Container>
        );
    }
}

Card List

Include CardItem subsequently within Card to create a card with lists.

Syntax
import {Container, Content, Card, CardItem, Text, Icon } from 'native-base';
import React, {Component} from 'react-native';
​
export default class CardListExample extends Component {
    render() {
        return (
            <Container>
                <Content>
                    <Card>
                        <CardItem>              
                            <Icon name="logo-google" />                
                            <Text>Google</Text>
                        </CardItem>
                   </Card>
                </Content>
            </Container>
        );
    }
}

Card Image

Want to have something more with Card Lists?
Include image with CardItem within Card along with some text before and after image to create a card with lists.
Here is your Card Image ready !

Syntax
import {Container, Content, Card, CardItem, Thumbnail, Text, Icon } from 'native-base';
import React, {Component, Image} from 'react-native';
​
export default class CardImageExample extends Component {
    render() {
        return (
            <Container>
                <Content>
                    <Card>
                        <CardItem>
                            <Thumbnail source={require('./img/guitar.jpeg')} />
                            <Text>Instrumental Songs</Text>
                            <Text note>Guitar</Text>
                        </CardItem>

                        <CardItem>                        
                            <Image style={{ resizeMode: 'cover' }} source={require('./img/music.png')} /> 
                        </CardItem>

                        <CardItem>
                            <Icon name={'ios-musical-notes'} style={{color : '#ED4A6A'}} />
                            <Text>Listen now</Text>                        
                        </CardItem>
                   </Card>
                </Content>
            </Container>
        );
    }
}

Card Showcase

Card Showcase is further customization of Card Image. It uses several different items.

Syntax
import {Container, Content, Card, CardItem, Thumbnail, Text, Button } from 'native-base';
import React, {Component, Image} from 'react-native';
​
export default class CardShowcaseExample extends Component {
    render() {
        return (
            <Container>
                <Content>
                    <Card>
                        <CardItem >                       
                            <Thumbnail source={require('./img/nativeBase-logo.png')} />
                            <Text>NativeBase</Text>
                            <Text note>April 15, 2016</Text>
                        </CardItem>

                        <CardItem cardBody> 
                            <Image style={{ resizeMode: 'cover' }} source={require('./img/wallpaper.png')} /> 
                            <Text>
                                //Your text here
                            </Text>
                            <Button transparent textStyle={{color: '#87838B'}}>
                                389 Stars
                            </Button>
                        </CardItem>
                   </Card>
                </Content>
            </Container>
        );
    }
}


Form

NativeBase makes use of List to design Forms that include group of related input components. Include any combination of NativeBase components to make up your form.

Syntax
import {Container, Content, List, ListItem, InputGroup, Input, Icon} from 'native-base';
import React, {Component} from 'react-native';
​
export default class FormExample extends Component {
    render() {
        return (
            <Container>
                <Content>
                    <List>
                        <ListItem>
                            <InputGroup>
                                <Icon name="ios-person" />
                                <Input placeholder="EMAIL" />
                            </InputGroup>
                        </ListItem>
                    
                        <ListItem>
                            <InputGroup>
                                <Icon name="ios-unlock" />
                                <Input placeholder="PASSWORD" secureTextEntry={true}/>
                            </InputGroup>
                        </ListItem>
                    
                        <ListItem>
                            <InputGroup >
                                <Input inlineLabel label="NAME" placeholder="John Doe" />
                            </InputGroup>
                        </ListItem>
                    
                        <ListItem>
                            <InputGroup >
                                <Input stackedLabel label="Address Line 1" placeholder="Address" />
                            </InputGroup>
                        </ListItem>
                    </List>
                </Content>
            </Container>
        );
    }
}

Configuration
Property Default Option Description
inlineLabel - - Label placed to the left of the input element. When the user enters text, the label does not hide. This can also be used along with placeholder.
stackedLabel - - Places the label on top of the input element which appears like a stack. This can also be used along with placeholder.


Icon

Choose from 700+ Icons . . .
Perfect, crisp, high definition icons and pixel ideal fonts powered by NativeBase to preserve matters very high first-rate. You will continually have pixel perfect icons on your initiatives.
Features of React Native Vector Icons:

Syntax
import {Container, Content, Icon} from 'native-base';
import React, {Component} from 'react-native';
​
export default class IconExample extends Component {
    render() {
        return (
            <Container>
                <Content>
                    <Icon name="ios-home" />
                    <Icon name="ios-menu" style={{fontSize: 20, color: 'red'}}/>
                </Content>
            </Container>
        );
    }
}


Configuration
Property Default Option Description read more
name - - Name of the icon.
color white user-defined Renders icon with defined color.
Note: Include this prop within style
fontSize 27 user-defined Renders icon with defined icon-size.
Note: Include this prop within style


InputGroup

This is a NativeBase component built on top of React Native's <TextInput>.
A foundational component for inputting text into the app via a keyboard. Props provide configurability for several features, such as auto-correction, auto-capitalization, placeholder text, and different keyboard types, such as a numeric keypad. Provides a number of attributes that follows styling and interaction guidelines for each platform, so that they are intuitive for users to interact with.



General Syntax
import {Container, Content, InputGroup, Input} from 'native-base';
import React, {Component} from 'react-native';
​
export default class InputGroupExample extends Component {
    render() {
        return (
            <Container>
                <Content>
                    <InputGroup>
                        <Input />
                    </InputGroup>
                </Content>
            </Container>
        );
    }
}


Configuration
Property Default Option Description
placeholder - - The string that will be rendered before text input has been entered. Optional user-defined placeholder for textbox.
borderType underline regular
underline
rounded
Wraps the textbox with predefined border options.
secureTextEntry false true
false
If true, the text input obscures the text entered so that sensitive text like passwords stay secure.
This prop can be passed to <Input>

Regular Textbox

To use the regular textbox which is rectangular in shape, include the borderType property and assign it with value as 'regular'.

Syntax
import {Container, Content, InputGroup, Input} from 'native-base';
import React, {Component} from 'react-native';
​
export default class RegularTextboxExample extends Component {
    render() {
        return (
            <Container>
                <Content>​
                    // Simple rectangular text input box
                    <InputGroup borderType="regular" >
                        <Input placeholder="Type your text here"/>
                    </InputGroup>
                </Content>
            </Container>
        );
    }
}

Underlined Textbox

To use the underlined textbox, include the borderType property and assign it with value as 'underline'.

Syntax
import {Container, Content, InputGroup, Input, Icon} from 'native-base';
import React, {Component} from 'react-native';
​
export default class UnderlinedTextboxExample extends Component {
    render() {
        return (
            <Container>
                <Content>​
                    // Underlined text input with placeholder text and an icon
                    <InputGroup borderType="underline" >
                        <Icon name="ios-home" style={{color:'#384850'}}/>
                        <Input placeholder="Type your text here" />
                    </InputGroup>
                </Content>
            </Container>
        );
    }
}

Rounded Textbox

To have a textbox with round type border, include the borderType property and assign it with value as 'rounded'.

Syntax
import {Container, Content, InputGroup, Input, Icon} from 'native-base';
import React, {Component} from 'react-native';
​
export default class RoundedTextboxExample extends Component {
    render() {
        return (
            <Container>
                <Content>
                    // Rounded text input box with icon
                    <InputGroup borderType="rounded" >
                        <Icon name="ios-home" style={{color:'#384850'}}/>
                        <Input style={{color: '#00c497'}} />
                    </InputGroup>
                </Content>
            </Container>
        );
    }
}


Layout

The layout system is an essential concept that needs to be mastered in order to create great layouts and UIs. React Native uses Flexbox to create the layouts, which is great when we need to accommodate our components and views in different screen sizes or even different devices. Flexbox is awesome but it could be tiresome for newbies.

Not being very good at Flexbox?
Here comes the Easy Grid of NativeBase, a wrapper of Flexbox.


The layout system in NativeBase is very powerful and flexible. No more worries about props of Flexbox such as alignItems, flexDirection, justifyContent, margin, padding, position, width etc. You can create any layout with all the available options that we have. In order to build custom layouts and components, understanding how layout works in NativeBase is not as hard as Flexbox. Flexbox makes it look like percentages, however what actually is happening is just ratios. On the easier part, ratios are easier to represent than percentage/decimals. For this reason, the Easy Grid takes in ratios in place of percentage.
Performance wise, Easy Grid is noteworthy and works as fine as Flexbox, not much of calculation.

Syntax
import {Container, Content} from 'native-base';
import { Col, Row, Grid } from "react-native-easy-grid";
import React, {Component} from 'react-native';
​
export default class LayoutExample extends Component {
    render() {
        return (
            <Container>
                <Content>
                    <Grid>
                        <Col style={{ backgroundColor: '#D954D7', height: 200 }}></Col>
                        <Col style={{ backgroundColor: '#D93735', height: 200  }}></Col>
                    </Grid>
                </Content>
            </Container>
        );
    }
}

NOTE: <Content> component uses <ScrollView>. This is required by <Col> and <Row> elements of Easy-Grid to have a defined height.



List

This component is completely built by NativeBase.
A base component for specifying lists of information. List must contain one or more list elements. Props provide configurability for several features. Provides a number of attributes that follows styling and interaction guidelines for each platform, so that they are intuitive for users to interact with.



Syntax
import {Container, Content, List, ListItem, Text} from 'native-base';
import React, {Component} from 'react-native';
​
export default class ListExample extends Component {
    render() {
        return (
            <Container>
                <Content>
                    <List>
                        <ListItem >
                            <Text>Simon Mignolet</Text>
                        </ListItem>
                        <ListItem>
                            <Text>Nathaniel Clyne</Text>
                        </ListItem>
                        <ListItem>
                            <Text>Dejan Lovren</Text>
                        </ListItem>
                    </List>
                </Content>
            </Container>
        );
    }
}


Configuration
Property Default Option Description
itemDivider - - Helps to organize and group the list items
note - - Sub caption for List Item.

List Divider

The List Divider component creates a list separator, which can be used for grouping list items. To create a divider for any child element of the list, include itemDivider prop with ListItem component. The List Divider of NativeBase comes with default style which is easily customisable.

Syntax
import {Container, Content, List, ListItem, Text} from 'native-base';
import React, {Component} from 'react-native';
​
export default class ListDividerExample extends Component {
    render() {
        return (
            <Container>
                <Content>
                    <List>
                        <ListItem itemDivider>
                            <Text>Goalkeeper</Text>
                        </ListItem>                    
                        <ListItem >
                            <Text>Simon Mignolet</Text>
                        </ListItem>
                        <ListItem itemDivider>
                            <Text>Defenders</Text>
                        </ListItem>  
                        <ListItem>
                            <Text>Nathaniel Clyne</Text>
                        </ListItem>
                        <ListItem>
                            <Text>Dejan Lovren</Text>
                        </ListItem>
                    </List>
                </Content>
            </Container>
        );
    }
}

List Icon

Lists can have icons assigned either to the left and/or right side of each list item. Along with icons, list item can also have badges assigned. To have note kind of text for list item, include note prop with Text component of ListItem.

Syntax
import {Container, Content, List, ListItem, Text, Icon, Badge} from 'native-base';
import React, {Component} from 'react-native';
​
export default class ListIconExample extends Component {
    render() {
        return (
            <Container>
                <Content>
                    <List>
                        <ListItem iconLeft>
                            <Icon name="ios-chatboxes" />
                            <Text>Simon Mignolet</Text>
                        </ListItem>
                        <ListItem iconLeft>
                            <Icon name="ios-alarm" />
                            <Text>Nathaniel Clyne</Text>
                            <Badge>2</Badge>
                        </ListItem>
                        <ListItem iconLeft>
                            <Icon name="ios-notifications" />
                            <Text>Dejan Lovren</Text>
                            <Text note>Note here</Text>
                        </ListItem>
                        <ListItem iconLeft iconRight>
                            <Icon name="ios-mic" />
                            <Text>Mama Sakho</Text>
                            <Icon name="ios-mic-outline" />
                        </ListItem>
                    </List>
                </Content>
            </Container>
        );
    }
}

List Avatar

List Avatars are medium to showcase an image with your list item whose dimension lays between icon and dimension. To create a avatar list, nest <Thumbnail> component within <ListItem> component.

Syntax
import {Container, Content, List, ListItem, Thumbnail, Text} from 'native-base';
import React, {Component} from 'react-native';
​
export default class ListAvatarExample extends Component {
    render() {
        return (
            <Container>
                <Content>
                    <List>
                        <ListItem>
                            <Thumbnail source={require('./img/hyundai-logo.png')} />
                            <Text>Hyundai</Text>
                            <Text note>1967</Text>
                        </ListItem>
                        <ListItem>
                            <Thumbnail source={require('./img/fiat-logo.jpg')} />
                            <Text>Fiat</Text>
                            <Text note>2007</Text>
                        </ListItem>
                    </List>
                </Content>
            </Container>
        );
    }
}

List Thumbnail

List Thumbnails are medium to exhibit an image with your list item. To create a thumbnail list, nest <Thumbnail> component within <ListItem> component with few props and style.

Syntax
import {Container, Content, List, ListItem, Thumbnail, Text} from 'native-base';
import React, {Component} from 'react-native';
​
export default class ListThumbnailExample extends Component {
    render() {
        return (
            <Container>
                <Content>
                    <List>
                        <ListItem>
                            <Thumbnail square size={80} source={require('./img/hyundai-logo.png')} />
                            <Text>Hyundai</Text>
                            <Text note>1967</Text>
                        </ListItem>
                        <ListItem>
                            <Thumbnail square size={80} source={require('./img/infiniti-logo.jpg')} />
                            <Text>Infiniti</Text>
                            <Text note>1989</Text>
                        </ListItem>
                    </List>
                </Content>
            </Container>
        );
    }
}


Progress Bar

A progress bar can be used to show a user how far along he/she is in a process.

Syntax
import {Container, Content, ProgressBar} from 'native-base';
import React, {Component} from 'react-native';
​
export default class ProgressBarExample extends Component {
    render() {
        return (
            <Container>
                <Content>
                    <ProgressBar progress={10} />
                    <ProgressBar progress={30} />
                </Content>
            </Container>
        );
    }
}

Configuration
Property Default Option Description
progress 50 user-defined Describes the percentage of work progressed


Spinner

If you have certain screens of your app that take some time to load, you may want to consider a page loader. A page loader is any kind of animation that visually communicates to a visitor that the page is loading and to just sit tight for a few seconds. Without a page loader, user might think that the app is being unresponsive and just click away in frustration. A page loader also provides a small distraction which can actually makes the wait seem much shorter.

Syntax
import {Container, Content, Spinner} from 'native-base';
import React, {Component} from 'react-native';
​
export default class SpinnerExample extends Component {
    render() {
        return (
            <Container>
                <Content>
                    <Spinner color="red" />
                    <Spinner color="green" />
                    <Spinner color="blue" />
                </Content>
            </Container>
        );
    }
}


Thumbnail

Thumbnail component works very similar to Image. It helps you to showcase an image with variuos dimensions and shapes. By default, Thumbnail renders an image in circular shape.
Replacing Component: React Native <Image>

Syntax
import {Container, Content, Thumbnail} from 'native-base';
import React, {Component} from 'react-native';
​
export default class ThumbnailExample extends Component {
    render() {
        return (
            <Container>
                <Content>
                    <Thumbnail source={require('./img/flower.jpg')} />
                    <Thumbnail square size={80} source={require('./img/flower.jpg')} />
                </Content>
            </Container>
        );
    }
}

Configuration
Property Default Option Description
source - - Image path for thumbnail.
square - - Represents shape of thumbnail.
By default thumbnail is circle in shape.
size 30 user-defined Dimension of thumbnail.



Keep waiting for more from us . . .