/** * 新闻信息列表 * @邠心vbe on 2023/08/17 */ import React, { Component } from 'react'; import { Text, FlatList, StyleSheet, RefreshControl, PixelRatio, View } from 'react-native'; import apiArticle from '../../api/apiArticle'; import { MyRefreshProps } from '../../components/ThemesConfig'; import { PageList } from '../Router'; import AlertUtil from './AlertUtil'; import ItemArticle from './ItemArticle'; import VbeSkeleton from '../../components/VbeSkeleton'; export default class ListNews extends Component { constructor(props) { super(props); this.state = { dataList: [], loading: true, refreshing: false, loadingList: ["", "", "", ""] }; this.isHide = false; } componentDidMount() { this.props.navigation.addListener('focus', () => { if (this.isHide) { this.isHide = false; this.getMessageList(); } }); this.props.navigation.addListener('blur', () => { this.isHide = true; }); setTimeout(() => { this.getMessageList(); }, 500); } toDetail(item={}) { if (item.articleId) { startPage(PageList.viewArticle, {id: item.articleId}); } } onRefresh() { this.setState({ refreshing: true }) this.getMessageList(); } getMessageList() { apiArticle.getArticleList().then(res => { if (res.data) { this.setState({ dataList: res.data }) } }).catch(err => { toastShort(err) }).finally(() => { this.setState({ loading: false, refreshing: false }) }) } getMessageListPage() { const count = AlertUtil.getNewsCount(); if (this.state.dataList.length > 0 && this.state.dataList.length < count) { const last = this.state.dataList[this.state.dataList.length-1] if (last.articleId) { apiArticle.getArticleList(last.articleId).then(res => { if (res.data) { const list = [ ...this.state.dataList, ] list.push(...res.data) this.setState({ dataList: list }) } }).catch(err => { toastShort(err) }) } } } listItem = (props) => { return ( this.toDetail(props.item)} /> ) } divideView = (props) => { return () } render() { if (this.state.loading) { return ( { this.state.loadingList.map((item, index) => )} ) } return ( item.articleId} onEndReached={() => this.getMessageListPage()} onEndReachedThreshold={0.3} refreshControl={ this.onRefresh()} /> } ListEmptyComponent={{$t('notification.empty')}} /> ); } } const styles = StyleSheet.create({ listView: { flex: 1 }, noData: { color: textPlacehoder, fontSize: 14, padding: 20, textAlign: 'center' }, loadingView: { padding: 16, flexDirection: 'row' }, iconImage: { width: 85, height: 85, borderRadius: 6, marginRight: 16, marginBottom: 8 } })