为什么我的ImageBackground不再扩展到屏幕底部了?

时间:2018-05-02 12:52:35

标签: reactjs react-native

我已将我的ImageBackground包装在ScrollView中,但现在我的内容不再延伸到底部了。仅供参考,ScrollView一直到底,但Imagebackground没有。如果没有ScrollView,内容将一直到底部,而下方没有任何空间。有谁知道为什么我的ScrollView阻止我的ImageBackground到达屏幕的底部?我遗漏了与外部内容无关的样式。

import React, {Component} from 'react';
import PropTypes from 'prop-types';
import {View, StyleSheet, Text, ImageBackground, TouchableOpacity, Image, ActivityIndicator, ScrollView} from 'react-native';
import Header from '../../components/Header/Header';
import Loader from "../../components/Login/Loader";
import {loadCustomerOrderDetails} from '../../actions/AppActions'
import {connect} from "react-redux";
import {Actions} from 'react-native-router-flux';
import {createIconSetFromIcoMoon} from 'react-native-vector-icons';
import selection from '../../selection';

const MBIcon = createIconSetFromIcoMoon(selection);

class Home extends Component {
    constructor(props) {
        super(props);
        this.props.dispatch(loadCustomerOrderDetails(this.props.customerId));
    }

    render() {
        const {isLoading, details} = this.props.customerData;
        const {invoices, unsubmittedOrders, itemIssues, deliveryStats} = details;
        let customerName = 'Select Account...';
        if (unsubmittedOrders && unsubmittedOrders.customerName) {
            customerName = unsubmittedOrders.customerName;
        }
        return (
            <View style={styles.wrapper}>
                <Header style={styles.header}/>
                <ScrollView style={{ flex: 1 }}>
                    <ImageBackground source={require('../../assets/loginBG.jpg')} style={styles.backgroundImage}>

                        <View>
                            <Image style={styles.mblogo} source={require('../../assets/mb_logo.png')} />
                        </View>

                        {isLoading &&
                            <ActivityIndicator
                                style={{alignSelf: 'center'}}
                                animating={true}
                                size='large'
                            />
                        }

                    </ImageBackground>
                </ScrollView>
            </View>
        );
    }
}

Home.propTypes = {
    customerData: PropTypes.object,
    customerId: PropTypes.string,
}

function mapStateToProps(state) {
    const {customerData, app} =  state;
    return {
        customerData: customerData,
        customerId: app.customerId
    };
}

export default connect(mapStateToProps)(Home);

var styles = StyleSheet.create({
    wrapper: {
        flex: 1,
        backgroundColor: 'transparent',
        position: 'relative'
    },
    header: {
        height: 200,
        width: '100%',
        position: 'absolute',
        top: 0,
        left: 0,
        right: 0
    },
    backgroundImage: {
        flexDirection: 'column',
        justifyContent: 'flex-start',
        alignItems: 'center',
        backgroundColor:'rgba(0,0,0,0.45)',
        width: null,
        height: '100%',
        marginTop: 55, 
        flex: 1, 
        position: 'relative', 
        bottom: 0
    },
    content: {
        flex: 1,
        justifyContent: 'space-between',
    },
    homeSection: {
        flex: 2,
        flexDirection: 'column',
        justifyContent: 'flex-start',
        alignItems: 'center',
        width: '90%',
        margin: 'auto',
    },
    cartBtnContainer: {
        flexDirection: 'row',
        justifyContent: 'space-between',
        alignItems: 'center',
        marginVertical: 8
    },
    footerBtn: {
        width: '45%',
        height: 48,
        justifyContent: 'center',
        alignItems: 'center',
        borderRadius: 24,
    }
});

enter image description here

1 个答案:

答案 0 :(得分:1)

ScrollView放入ImageBackground

<ImageBackground>
    <ScrollView>
    ......
    </ScrollView>
</ImageBackground>