GuideItem.js 2.1 KB
'use strict';

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

const {
    Component,
} = React;

const {
    StyleSheet,
    View,
    Image,
    Text,
    Dimensions,
} = ReactNative;

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={this.props.uri} resizeMode={'contain'} >
                {this.renderText()}
                {this.renderButton()}
            </Image>
        );
    }
}

let {width, height} = 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',
    }
});