details.js 4.86 KB
import React, { Component } from "react";
import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  ScrollView,
  TouchableOpacity,
  Image
} from "react-native";

export default class Details extends Component {
  constructor(props) {
    super(props);
    this.state = {
      data: this.props.data
    };
  }
  componentWillMount() {
    console.log("详情页", this);
  }

  render() {
    const { data } = this.state;
    return (
      <View style={styles.container}>
        <ScrollView automaticallyAdjustContentInsets={false}>
          <Text style={styles.titleText} numberOfLines={3}>
            {data.title}
          </Text>
          {/* 个人信息 */}
          <View style={styles.personContainer}>
            <Image style={styles.personImg} source={data.image} />
            <View style={styles.personRightContainer}>
              <View style={styles.personRTContainer}>
                <Text style={styles.personRTName}>{data.name}</Text>
                <Text style={styles.personRTIdentity}>{data.identity}</Text>
              </View>
              <Text style={styles.personRB}>{data.time}</Text>
            </View>
          </View>
          {/* 正文 */}
          <Text style={styles.content}>{data.content}</Text>
          <Text style={styles.copyright}>本文版权归 {data.name} 所有</Text>
          {/* 评论 */}
          <View style={styles.commentsContainer}>
            <View style={styles.commentsHeader}>
              <Text style={styles.commentsHeaderL}>评论</Text>
              <Text style={styles.commentsHeaderR}>
                ( {data.comments.length} )
              </Text>
            </View>
            {data.comments.map((item, index) => {
              return (
                <View style={styles.itemContainer} key={index}>
                  <Image style={styles.itemIcon} source={item.replayicon} />
                  <View style={styles.itemRightContainer}>
                    <View style={styles.itemRightTop}>
                      <View style={styles.itemRightTopLeft}>
                        <Text style={styles.itemReplyer}>{item.replyer}</Text>
                        <Text style={styles.itemWord}>回复</Text>
                        <Text style={styles.itemBeenreplyer}>{item.beenreplyer}</Text>
                        <Text style={styles.itemTime}>{item.time}</Text>
                      </View>
                      <Image
                        style={styles.itemRightTopRight}
                        source={require("../../assets/tabbar/ic_circle_n.png")}
                      />
                    </View>
                    <Text style={styles.itemRightBottom}>{item.content}</Text>
                  </View>
                </View>
              );
            })}
          </View>
        </ScrollView>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: "flex-start",
    alignItems: "stretch",
    backgroundColor: "white",
    paddingTop: 64
  },
  titleText: {
    marginTop: 21,
    marginLeft: 20,
    marginRight: 20,
    fontSize: 24,
    lineHeight: 30
  },
  personContainer: {
    marginTop: 16,
    marginLeft: 20,
    marginRight: 20,
    flexDirection: "row",
    justifyContent: "flex-start",
    alignItems: "center"
  },
  personImg: {
    width: 42,
    height: 42
  },
  personRightContainer: {
    marginLeft: 10
  },
  personRTContainer: {
    flexDirection: "row",
    justifyContent: "flex-start",
    alignItems: "center"
  },
  personRTName: {
    fontSize: 16,
    color: "#242424"
  },
  personRTIdentity: {
    fontSize: 14,
    color: "#3F3F3F",
    marginLeft: 5
  },
  personRB: {
    fontSize: 13,
    color: "#999999"
  },
  content: {
    marginLeft: 25,
    marginRight: 25,
    marginTop: 35,
    marginBottom: 25,
    fontSize: 15,
    lineHeight: 22,
    color: "#555555"
  },
  copyright: {
    textAlign: "center",
    fontSize: 12,
    color: "#999999",
    marginBottom: 20
  },
  commentsContainer: {
    borderTopWidth: 10,
    borderColor: "#EFEFEF",
    borderStyle: "solid",
    paddingLeft: 13,
    paddingRight: 13
  },
  commentsHeader: {
    flexDirection: "row",
    justifyContent: "flex-start",
    alignItems: "center",
    height: 45
  },
  commentsHeaderL: {
    fontSize: 15,
    color: "#242424",
    marginRight: 5
  },
  commentsHeaderR: {
    fontSize: 15,
    color: "#242424"
  },
  itemContainer: {
    paddingTop: 16,
    paddingBottom: 16,
    flexDirection: "row",
    justifyContent: "flex-start",
  },
  itemIcon: {
    width: 32,
    height: 32,
  },
  itemRightContainer: {
    flex: 1,
    marginLeft: 10
  },
  itemRightTop: {
    flexDirection: "row",
    justifyContent: "space-between",
    marginBottom: 7,
  },
  itemRightTopLeft: {
    flexDirection: "row",
    justifyContent: "flex-start",
    alignItems: "center",
  },
  itemRightTopRight: {},
  itemRightBottom: {
    fontSize: 15,
    lineHeight: 21,
    color: "#242424",
  },
});