react-native: NativeBase how to center a control

16k views Asked by At

I have just discovered NativeBase for react-native and I really love it. I am following the tutorial from their website. I understand that NativeBase uses Easy-Grid for the layout. I would like to vertically center a button on my page. This is a simple interface for a test application I am building:

<Container> 
    <Header>
        <Button trnsparent>
            <Icon name='ios-menu' />
        </Button>             
        <Title>Poki</Title>                    
    </Header>

    <Content style={{padding: 10}}>  
        <Grid>
            <Col>
                <Button block bordered info style={{flex: 1}}>Login</Button>
            </Col>
        </Grid>
    </Content>

    <Footer>
        <FooterTab>
            <Button transparent>
                <Icon name='ios-call' />
            </Button>  
        </FooterTab>
    </Footer>
</Container>

And this is the result on my genymotion emulator: enter image description here

How can I vertically center the login button on my page using easy-grid? I have tried to apply flexbox properties with no result.

Thank you for your help.

2

There are 2 answers

3
max23_ On BEST ANSWER

Try changing to this:

<Content contentContainerStyle={{flex: 1}} style={{padding: 10}}>
  <Grid style={{alignItems: 'center'}}>
    <Col>
      <Button block bordered info>
        Login
      </Button>
    </Col>
  </Grid>
</Content>
0
Adoel On

And i try this code works too :

<Grid >
    <Col>
        <Row>
            <Text>Ananta Riding Club</Text>
        </Row>
    </Col>
    <Col contentContainerStyle={{flex: 1}}>
        <Row style={{justifyContent: 'flex-end'}}>
            <Text >07.00 AM</Text>  
        </Row>
    </Col>
</Grid>