
/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 *
 * @format
 * @flow
 */

import React, { Component } from 'react';
import {
  StyleSheet,
  Image,
  View,
} from 'react-native';
import { WaterfallList } from 'react-native-largelist-v3';
import { compose } from 'redux';
import { connect } from 'react-redux';
import FastImage from 'react-native-fast-image';
import { push } from '../../BasicNavigator/actions';
import NavigationBar from '../../components/NavigationBar';
import BackButton from '../../components/BackButton';
import { ENV, resourceURLMapping } from '../../utils/constants';


const cookData = require('./data.json').data.list;

type Props = {};
const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#F5FCFF',
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});

class WaterList extends Component<Props> {
  state = { data: [...cookData, ...cookData, ...cookData, ...cookData, ...cookData] };

  _renderItem = item => (
    <FastImage
      style={{ flex: 1, margin: 5 }}
      source={{
        uri: item.showimg,
        priority: FastImage.priority.normal,
      }}
      resizeMode={FastImage.resizeMode.stretch}
    />
  );

  render() {
    return (
      <View style={styles.container}>
        <NavigationBar
          title="瀑布流"
          left={<BackButton />}
        />
        <WaterfallList
          data={this.state.data}
          heightForItem={item => global.SCREEN_WIDTH / Math.floor(global.SCREEN_HEIGHT / 150)
            * +item.showimg_height / +item.showimg_width}
          numColumns={2}
          // preferColumnWidth={150}
          renderItem={this._renderItem}
        />
      </View>
    );
  }
}

function actionMapping(dispatch) {
  return {
    push: compose(dispatch, push),
  };
}
export default connect(null, actionMapping)(WaterList);
