不向下滚动到底部

Not scrolling down to bottom

我尝试了具有类似问题的不同解决方案,但 none 对我有用。当我向下滚动时,我的平面列表没有滚动到底部并且滚动条超出了屏幕。在平面列表中,属于同一天的项目(LoneAlert)组件在顶部有一个日期分隔符(Separator)组件。

随着列表中项目数量的增加,项目数量也被下推 increase.ex:如果列表包含 10 个项目,则下推 1 个项目,如果列表有 25 个项目,则下推 3 个项目被推倒。 如果我删除 Header 组件,那么它就可以正常工作。但我不知道如何解决这个问题。我该怎么做?

我尝试用视图包装 flatList 组件并为视图提供 flex:1 但它不起作用。

在 App.js 中(没有样式)。

return (
  <View>
    <AlertList allAlert={this.state.alerts}/>
  </View>
);

在AlertList.js

_renderItem = ({item, index}) => {
    console.log(index);
    console.log(item);
    // if the alert day is equal to current day or 
    // alert day is equal to previous day or
    // first alert day in the array is equal to current  day
    // separator bar display none for that alert by passing props showSeparator

    if(current_day == item.alert_time.toDate().getDay()
    || index > 0 &&item.alert_time.toDate().getDay() == all_alerts[index -1].alert_time.toDate().getDay()
    || index==0 && item.alert_time.toDate().getDay() == current_day ){
        return (
            <LoneAlert
            alertObject = {item} showSeparator ={false}/>
        )
    }else{
        return(
            <LoneAlert
            alertObject = {item} showSeparator ={true}/>
        )
    }
};

checkConnection = () =>{
    if (netInfo.isConnected == false || netInfo.isReachable == false ){
        return <ConnectionMsg/>
    }else{
        return(
            <View>
                <HeaderBar/>
                <View style = {{ flex:1 }}>
                    <FlatList data={props.allAlert}
                    renderItem = {this._renderItem}
                    />
                </View>
            </View>
        );
    }
};


return(
    <View>
        {this.checkConnection()}
    </View>
);
};

export default AlertList;

In LoneAlert.js(side flatlist 中的项目)

return(
    <View>
        <View>
            {this.renderTimeSeparator(props.alertObject.alert_time.toDate(), props.showSeparator)}
        </View>
        <View style = {styles.wrapper}>
            <View style = {styles.alertImageWrapper}>
                {this.renderAlertImage(props.alertObject.alert_reason,70,70,'alertImage')}
            </View>
            <View style = {styles.textWrapper}>
                <Text style = {styles.bedNumber}>{props.alertObject.bedNo}</Text>
                {this.capitalizeAlertMessage(props.alertObject.alert_reason, styles.alertMessage)}
                <Text style = {styles.dateTime}>{this.timeFormatConverter(props.alertObject.alert_time.toDate())}</Text>
            </View>
            <View style = {styles.dismissalWrapper}>
                {this.renderDismissalImage(props.alertObject.dismissal_reason,30,30,styles.dismissalImage)}
                {this.renderDismissalText(props.alertObject.dismissal_reason, styles.dismissalText)}
            </View>
        </View>
    </View>
);
};

const styles = StyleSheet.create({
wrapper:{
    flexDirection: 'row',
    padding: 10,
    paddingRight:0,
    borderBottomWidth: 1,
    borderBottomColor: "#D0D0D0",
    backgroundColor: '#E7EAED',
},
alertImageWrapper:{
    // backgroundColor: "red",
    height:"100%",
    width:60,
    marginRight: 13,
    flexDirection: 'row',
    alignItems: 'center'

},
alertImage:{
},
textWrapper:{
    // backgroundColor:"green"
    paddingLeft: 15
},

bedNumber:{
    color:"#434343",
    fontFamily:"Arial",
    fontWeight:'bold',
    fontSize: 24,
},
alertMessage:{
    color:"#434343",
    fontFamily:"Arial",
    fontWeight:'bold',
    fontSize: 14,
},
dateTime:{
    color:"#434343",
    fontFamily:"Arial",
    fontSize: 14,
},

dismissalWrapper:{
    marginLeft: 'auto',
    // backgroundColor:"green",
    width:70,

},

dismissalImage:{
    marginLeft: 'auto',
    marginRight:'auto',
    // backgroundColor:"red"
},

dismissalText:{
    // backgroundColor:"blue",
    textAlign: 'center'
}
});

export default LoneAlert;

在Separator.js

render(){
return(
        <View style={styles.Bar}>
            <Text style ={styles.dateStyle}>{this.props.date[0]}, 
{this.props.date[1]} {this.props.date[2]}</Text>
        </View>
        );
    }

}
const styles = StyleSheet.create({
Bar:{
    // height: 34,
    paddingTop: 5,
    paddingLeft: 10,
    // backgroundColor: "#7C7C7C",
    backgroundColor: '#E7EAED',
    fontFamily:"Arial",
    fontWeight:'bold',
    fontSize: 14,
    color:"#FFFFFF",
    textAlign: "center",
    flexDirection: 'row',
    alignItems: 'center'
},
dateStyle:{
    // backgroundColor: 'blue',
    color:"#9B9B9B",
    fontWeight:'bold',
}
});

export default Separator;

在HeaderBar.js

const HeaderBar = (props) => {
return(
    <View>
        <View style={styles.HeaderBar}>
            <Image style = {styles.spIcon} source={require('../../assets/images/smartPeep-icon.png')}/>
            <Text style = {styles.alertTitle}>
            Alert history
            </Text>
        </View>
        <View style = {styles.FirstSeparator}>
                <Text style = {styles.AlertDetailLabel}>Alert Type</Text>
                <Text style = {styles.DismissalLabel}>Resolved by</Text>
        </View>
    </View>
)
};  

const styles = StyleSheet.create({
HeaderBar:{
    width: "100%",
    padding: 7,
    backgroundColor:"#E7EAED",
    height:58,
    flexDirection: 'row',
    alignItems: "center"
},
spIcon:{
    width: 40,
    marginRight: 22,
    height: "100%",
    // backgroundColor: "green"
},
alertTitle:{
    maxWidth:180,
    fontFamily:"Arial",
    fontWeight:'bold',
    fontSize: 18,
    // backgroundColor: "blue"
},
FirstSeparator:{
    height: 35,
    backgroundColor:"#434343",
    flexDirection: 'row',
},
AlertDetailLabel:{
    // backgroundColor:"red",
    fontFamily:"Arial",
    fontSize: 14,
    color: "white",
    textAlignVertical:'center',
    paddingLeft: 10

},
DismissalLabel:{
    marginLeft: 'auto',
    fontFamily:"Arial",
    fontSize: 14,
    color: "white",
    textAlignVertical:'center',
    paddingRight: 10
}

});

export default HeaderBar;

好的,我可以通过在 App.js 中的视图上添加 flex:1 然后将高度设置为 AlertList.js

中父视图的 100% 来解决这个问题

App.js

<View style = {{ flex: 1}}>
    <AlertList allAlert={this.state.alerts}/>
  </View>

AlerList.js

 <View style  =  {{ height:"100%"}}>
  <HeaderBar/>
  <FlatList data={props.allAlert}
   renderItem = {this._renderItem}
  />
 </View>