0

I have a item that i want to be align to the middle and one to the bottom.

enter image description here

I want the logo image in the center, but I can't figure out how to do it.

import React, { Component } from 'react';
import { Container, Content, Text, Button, View } from 'native-base';
import { StyleSheet, Image } from 'react-native'

export default class WelcomeScreen extends Component {

render() {
    return (
        <Container>
            <Content contentContainerStyle={styles.container}>
                <View style={styles.imgContainer}>
                    <Image
                        source={require('../../assets/images/logos/logo.png')}
                    />
                </View>
                <View style={styles.btnContainer}>
                    <Button block primary onPress={() => this.props.navigation.navigate('Signin')} rounded>
                        <Text>Sign in</Text>
                    </Button>
                    <Button block light style={{ marginTop: 15 }} onPress={() => this.props.navigation.navigate('Signup')} rounded>
                        <Text>Sign up</Text>
                    </Button>
                </View>
            </Content>
        </Container>
    );
}
}

const styles = StyleSheet.create({
    container: {
        flex: 1,
        alignItems: 'center',
        justifyContent: 'center'
    },
    imgContainer: {
        flex: 1,
    },
    btnContainer: {
        width: 300,
    }
})
Vikram Deshmukh
  • 12,304
  • 4
  • 36
  • 38
Millenial2020
  • 2,465
  • 9
  • 38
  • 83
  • Possible duplicate of [How to horizontally center a
    ?](https://stackoverflow.com/questions/114543/how-to-horizontally-center-a-div)
    – sibasishm Nov 05 '19 at 05:34

3 Answers3

2

Try this

imgContainer: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center'
}
Anhdevit
  • 1,926
  • 2
  • 16
  • 29
0

Here's an HTML CSS only example for you that you can easily tweak to solve your problem.

body {
  margin: 0;
}
#main {
  display: flex;
  flex-direction: column;
  height: 100vh;
  justify-content: space-between;
}
.container {
  align-items: middle;
  margin: 0 auto;
  align-self: middle;
  width: 300px;
  height: 80px;
  background-color: steelblue;
  vertical-align: afar;
}
<div id="main">
  <div class="container">
    abc
  </div>
  <div class="container">
    xyz
  </div>
</div>

The trick lies in the following CSS properties:

  • flex-direction: column
  • justify-content: space-between
Vikram Deshmukh
  • 12,304
  • 4
  • 36
  • 38
0

if you want the image to align center in the screen except for the button height, you can use the following code, and replace the view in ImageContainer to Image

render() {
    return (
        <Container>           
             <View
             style={styles.imgContainer}>
             <View  style={{backgroundColor:'red',height:50,width:50}} />
             </View>

            <Content contentContainerStyle={styles.container}>

                <View style={styles.btnContainer}>
                    <Button block primary onPress={() => this.props.navigation.navigate('Signin')} rounded>
                        <Text>Sign in</Text>
                    </Button>
                    <Button block light style={{ marginTop: 15 }} onPress={() => this.props.navigation.navigate('Signup')} rounded>
                        <Text>Sign up</Text>
                    </Button>
                </View>
            </Content>
        </Container>
    );
}
}

const styles = StyleSheet.create({
    container: {
        flex: 1,
        alignItems: 'center',
        justifyContent: 'flex-end'
    },
    imgContainer: {
        position:'absolute',
        justifyContent:'center',
        alignItems:'center',
        height:Dimensions.get('window').height-40,
        width:Dimensions.get('window').width,
        flex: 1,
    },
    btnContainer: {
        height:200,
        width: 300,
        alignItems:'center',
        justifyContent: 'flex-end',
        marginBottom:20
    }
})

Lenoarod
  • 3,441
  • 14
  • 25