import React, {Component} from 'react'; import {StyleSheet, Text, View, ScrollView, InteractionManager, Alert} from 'react-native'; import {Avatar, Button} from "react-native-elements"; import moment from 'moment'; import Color from '../style/color'; import Api from '../util/api'; import Msg from '../util/msg'; import UserIcon from './userIcon'; import Loading from './loading'; export default class UserIntro extends Component { constructor(props) { super(props); this.state = { user: props.user, followed: 0, isLoading: true }; } componentDidMount() { InteractionManager.runAfterInteractions(() => { this.refresh(); }); } _onAddFollow() { Api.addFollow(this.state.user.id) .then(() => { this.setState({ followed: 1 }); Alert.alert('已关注'); }) .catch(e => { Alert.alert('关注失败'); }) } _onDeleteFollow() { Api.deleteFollow(this.state.user.id) .then(() => { this.setState({ followed: -1, }); Alert.alert('已取消关注'); }) .catch(e => { Alert.alert('取消关注失败'); }) } refresh(userId) { let targetId = userId; if(!targetId) { targetId = this.state.user ? this.state.user.id : null; } if(targetId) { Api.getUserInfo(targetId) .then(user => { this.setState({ user: user }); }) .catch(e => { Msg.showMsg('用户信息加载失败'); }) .finally(() => { this.setState({ isLoading: false }) }); } } refreshFollowed(followed = 0) { if(followed) { this.setState({ followed: followed }); } } render() { if(this.state.isLoading) { return ; } const user = this.state.user; const followed = this.state.followed; return user ? ( { followed < 0 ?