GuideItem.js 2.06 KB
'use strict';

import React from 'react-native';
import Button from 'apsl-react-native-button';

let {
    StyleSheet,
    Component,
    View,
    Image,
    Text,
    Dimensions
} = React;

export default class GuideItem extends Component {

    constructor(props) {
        super(props);
    }

    static propTypes = {
        text: React.PropTypes.string,
        textStyle: View.propTypes.style,
        buttonText: React.PropTypes.string,
        buttonTextStyle: View.propTypes.style,
        onPress: React.PropTypes.func,
    };

    renderText() {
        if (this.props.text) {
            return (
                <Text style={[styles.text, this.props.textStyle]}>{this.props.text}</Text>
            );
        } else {
            return null;
        }
    }

    renderButton() {
        if (this.props.buttonText) {
            return (
                <Button style={[styles.button, this.buttonStyle]} 
                    textStyle={[styles.buttonText, this.props.buttonTextStyle]}
                    onPress={this.props.onPress} >
                    {this.props.buttonText}
                </Button>
            );
        } else {
            return null;
        }
    }

	render() {

        return (
            <Image style={styles.image} source={{uri: this.props.uri}} resizeMode={'contain'} >
                {this.renderText()}
                {this.renderButton()}
            </Image>
        );
    }
}

let {height, width} = Dimensions.get('window');
let textPaddingTop = height * 7 / 10;
let buttonMargin = (width - 165) / 2;

let styles = StyleSheet.create({
    image: {
        flex: 1,
        flexDirection: 'column',
        alignItems: 'center',
        width: width,
        height: height    
    },
    text: {
        color: '#000000',
        fontSize: 17,
        textAlign: 'center',
        marginTop: textPaddingTop,
    },
    button: {
        marginTop: 40,
        marginLeft: buttonMargin,
        marginRight: buttonMargin,
        backgroundColor: '#000000',
        borderRadius:5,
    },
    buttonText: {
        color: '#ffffff',  
    }
});