import React, {Component} from 'react'; import {Image, StyleSheet, Text, View, TouchableOpacity} from 'react-native'; import Ionicons from 'react-native-vector-icons/Ionicons'; import UserIcon from '../userIcon'; import Touchable from '../touchable'; import Color from '../../style/color'; export default class Notification extends Component { _onDeletePress(msg) { this.props.onDeletePress && this.props.onDeletePress(msg) } render() { let msg = this.props.msg; if(msg && msg.type) { if(msg.type == 1) { return this.renderComment(msg); } else if(msg.type == 2) { return this.renderFollow(msg); } else if(msg.type == 3) { return this.renderLike(msg); } } return null; } renderDeleteButton(msg) { return this.props.showDelete ? ( this._onDeletePress(msg)}> ) : null; } renderComment(msg) { const max = 5; const formatMsg = {}; let key = null; for (let i=0; i this.props.onCommentPress(msg)}> { Object.keys(formatMsg).map((it, index) => { if (index >= max) { return null; } return ( this.props.onUserIconPress(formatMsg[it])} /> ); }) } {Object.keys(formatMsg).length > max ? '等' : ''}回复了你 {this.renderDeleteButton(msg)} ) } renderFollow(msg) { const body = `${msg.content.user.name} 关注了你`; return ( this.props.onFollowPress(msg)}> {body} {this.renderDeleteButton(msg)} ) } renderLike(msg) { const userData = { userId: msg.content.user.id, userIcon: msg.link_user_icon, userName: msg.content.user.name, } return ( this.props.onLikePress(msg)}> this.props.onUserIconPress(userData)} /> 给了你一个OK绷 {this.renderDeleteButton(msg)} ) } } const localStyle = StyleSheet.create({ container: { padding: 20, borderColor: Color.line, borderBottomWidth: StyleSheet.hairlineWidth, flexDirection: 'row' }, icon: { marginRight: 10, marginTop: 1, lineHeight: 28 }, text: { flex: 1, lineHeight: 28 }, icon2: { width: 15, height: 15, marginRight: 10, marginTop: 7, }, delete: { lineHeight: 20, paddingHorizontal: 8, } });