import React, { Component } from “react”;

import {

ScrollView,

StyleSheet,

Dimensions,

ActivityIndicator,

View,

Text

} from “react-native”;

import { getData } from “…/comm/Fetch”;

import ReplyItem from “./ReplyItem”;

import ReplyTextarea from “./ReplyTextarea”;

import HTML from “react-native-render-html”;

export default class Xiangqing extends Component {

static navigationOptions = ({ navigation }) => {

return {

title: navigation.getParam(“title”)

};

};

constructor(props) {

super(props);

this.state = {

loaded: false,

replies: [],

content: “” //初始化为空

};

}

requestData = async () => {

try {

let url = “/topic/” + this.props.navigation.getParam(“id”);

let data = await getData(url); //网络获取的

data = data.data; //网络里面的data属性

this.setState({

content: data.content,

replies: data.replies,

loaded: true

});

} catch (err) {

console.error(err);

}

};

componentDidMount() {

this.requestData();

}

render() {

return (

{this.state.loaded ? (

html={this.state.content}

imagesMaxWidth={Dimensions.get(“window”).width - 20} //减去二十是因为padding边框是10

/>

{this.state.replies.length}

条评论

{this.state.replies.map(item => (

))}

) : (

)}

);

}

}

const style = StyleSheet.create({

box: {

flex: 1

},

replyTitle: {

backgroundColor: “#FFF”,

color: “#666”,

padding: 10,

fontSize: 16,

marginTop: 10

},

padding10: {

padding: 10

}

});

Logo

开源鸿蒙跨平台开发社区汇聚开发者与厂商,共建“一次开发,多端部署”的开源生态,致力于降低跨端开发门槛,推动万物智联创新。

更多推荐