ContentListView.js 5.38 KB
/**
 * Created by zzz on 2019/3/5.
 */
'use strict';
import React, {Component} from "react";
import ReactNative, {View, Text, Image, ListView, StyleSheet, Dimensions, TouchableOpacity, Platform, RefreshControl, NativeModules
} from 'react-native';

import YH_PtrRefresh from '../../../common/components/YH_PtrRefresh';
import LoadMoreIndicator from '../../../common/components/LoadMoreIndicator';

import ContentLikedListCell from './ContentLikedListCell'
import ContentFansListCell from './ContentFansListCell'

export default class ContentListView extends Component {
    constructor(props) {
        super(props);

        this._renderRow = this._renderRow.bind(this);
        this.dataSource = new ListView.DataSource({
            rowHasChanged: (r1, r2) => !Immutable.is(r1, r2),
        });
    }

    _renderRow(rowData, sectionID, rowID) {

        return (

          <View>

            { this.props.contentListId === '1' ?
              <ContentLikedListCell
                  key={'row'+ rowID}
                  data={rowData}
              />

              :

              <ContentFansListCell
                  key={'row'+ rowID}
                  data={rowData}
                  updateAttentionAction={this.props.updateAttentionAction}
              />
            }

            </View>

        );
    }

    componentDidMount() {

    }

    componentWillReceiveProps(nextProps) {

    }

    render() {

      let listsData = this.props.contentList;
      // let {isFetching, endReached, list, shouldShowEmpty, pageCount} = this.props.data;
      // let isLoadingMore = list.size != 0 && !endReached && pageCount != 1;
      // let isShowLoading = list.size == 0 && isFetching;
      //
      // if (shouldShowEmpty) {
      //       return (
      //           <View style={styles.container}>
      //               <EmptyContent
      //                   // listId={listId}
      //               />
      //           </View>
      //       );
      //   }

      return (
          <View style={styles.container}>
          {
              Platform.OS === 'ios' ?
              <ListView
                  ref={(c) => {
                      this.listView = c;
                  }}
                  contentContainerStyle={styles.contentContainer}
                  dataSource={this.dataSource.cloneWithRows(listsData)}
                  renderRow={this._renderRow}
                  enableEmptySections={true}
                  enablePullToRefresh={true}
                  // isOnPullToRefresh={isPullToRefresh}
                  onRefreshData={() => {
                      this.props.onRefresh && this.props.onRefresh();
                  }}
                  // onEndReached={() => {
                  //     if (list.size !== 0) {
                  //         this.props.onEndReached && this.props.onEndReached();
                  //     }
                  // }}
                  // renderFooter={() => {
                  //       if (endReached) {
                  //           return <LoadMoreIndicator
                  //                   isVisible={true}
                  //                   text={'暂无更多'}
                  //               />;
                  //       } else {
                  //           return <LoadMoreIndicator
                  //                   isVisible={isLoadingMore}
                  //                   animating={true}
                  //               />;
                  //       }
                  // }}
              />
              :
              <ListView
                  ref={(c) => {
                      this.listView = c;
                  }}
                  contentContainerStyle={styles.contentContainer}
                  dataSource={this.dataSource.cloneWithRows(listsData)}
                  renderRow={this._renderRow}
                  enableEmptySections={true}
                  enablePullToRefresh={true}
                  // refreshControl={
                  //         <YH_PtrRefresh
                  //             refreshing={isPullToRefresh}
                  //             onRefresh={() => {
                  //                 this.props.onRefresh && this.props.onRefresh();
                  //             }}
                  //             colors={['#000000', '#ff0000']}
                  //             progressBackgroundColor="#ffffff"
                  //         />
                  //   }
                    // onEndReached={() => {
                    //     if (list.size !== 0) {
                    //         this.props.onEndReached && this.props.onEndReached();
                    //     }
                    // }}
                    // renderFooter={() => {
                    //       if (endReached) {
                    //           return <LoadMoreIndicator
                    //                   isVisible={true}
                    //                   text={'暂无更多'}
                    //               />;
                    //       } else {
                    //           return <LoadMoreIndicator
                    //                   isVisible={isLoadingMore}
                    //                   animating={true}
                    //               />;
                    //       }
                    // }}
              />
          }
          </View>
      );
    }
}

let styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: 'white',
    },
    contentContainer: {
    },
})