Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { PureComponent } from 'react';
  2. import { View, StyleSheet, Linking, Text, TouchableOpacity } from 'react-native';
  3. import FastImage from 'react-native-fast-image';
  4. import ParsedText from 'react-native-parsed-text';
  5. import * as _ from 'lodash';
  6. import UtilDate from '../../../utils/UtilDate';
  7. import UtiImage from '../../../utils/UtiImage';
  8. import { SCREEN } from '../../../utils/UtilDeviceInfo';
  9. import localization from '../../../localization';
  10. import ModalImageComment from './Modal/ModalImageComment';
  11.  
  12. export default class CommentItemChild extends PureComponent {
  13.   constructor(props) {
  14.     super(props);
  15.     this.state = {
  16.       isModalVisible: false,
  17.       urlViewImage: null,
  18.       visibleLoading: false,
  19.     };
  20.   }
  21.   closeModal = () => {
  22.     this.setState({ isModalVisible: false, visibleLoading:false});
  23.   }
  24.  
  25.   handleUrlPress(url) {
  26.     Linking.openURL(url);
  27.   }
  28.   renderText(matchingString, matches) {
  29.     let pattern = /\[(@[^:]+):([^\]]+)\]/i;
  30.     let match = matchingString.match(pattern);
  31.     match = (match[1] || '').substring(1);
  32.     return `${match}`;
  33.   }
  34.   handleNamePress(name) {}
  35.   handleEmailPress(email) {}
  36.   handlePhonePress(phone) {}
  37.   _handlerLongClick = () => {
  38.       const {onShowModalCommentChild} = this.props;
  39.       if(onShowModalCommentChild){
  40.         const { comment,commentParent } = this.props;
  41.         onShowModalCommentChild(comment,commentParent)
  42.       }
  43.   };
  44.   _onPressImage = (images) => {
  45.       let image = UtiImage.getUrlImageStream(images);
  46.       this.setState({
  47.         isModalVisible: true,
  48.         urlViewImage: image.uri
  49.       });
  50.   }
  51.   render() {
  52.     const { comment, onPressReplyChild = () => {}, commentParent, userIdCurrent } = this.props;
  53.     let text = _.get(comment.data, 'text', '');
  54.     text = text.trim();
  55.     //check quyền xoá comment
  56.     const userIdComment = _.get(comment.user, 'id');
  57.     return (
  58.       <View style={styles.container}>
  59.         <View style={styles.viewHeader}>
  60.           <TouchableOpacity
  61.             disabled={userIdCurrent === userIdComment ? false : true}
  62.             activeOpacity={0.6}
  63.             onLongPress={this._handlerLongClick}
  64.           >
  65.             <View style={{ flexDirection: 'row' }}>
  66.               <FastImage
  67.                 style={styles.imageView}
  68.                 resizeMode={FastImage.resizeMode.cover}
  69.                 source={
  70.                   _.get(comment.user, 'data.profileImage')
  71.                     ? UtiImage.getLink(comment.user.data.profileImage)
  72.                     : require('../../../assets/imgs/accnt_avatar_defaut.png')
  73.                 }
  74.               />
  75.               <View style={styles.viewAuthor}>
  76.                 <Text style={styles.commentAuthor}>{_.get(comment.user, 'data.name', '')} </Text>
  77.               </View>
  78.             </View>
  79.             {text && text !== '' ? (
  80.               <View style={styles.viewContain}>
  81.                 <ParsedText
  82.                   style={styles.text}
  83.                   parse={[
  84.                     { type: 'url', style: styles.url, onPress: this.handleUrlPress },
  85.                     { type: 'email', style: styles.email, onPress: this.handleEmailPress },
  86.                     {
  87.                       pattern: /\[(@[^:]+):([^\]]+)\]/i,
  88.                       style: styles.username,
  89.                       onPress: this.handleNamePress,
  90.                       renderText: this.renderText
  91.                     },
  92.                     { pattern: /#(\w+)/, style: styles.hashTag }
  93.                   ]}
  94.                 >
  95.                   {text}
  96.                 </ParsedText>
  97.               </View>
  98.             ) : null}
  99.             {(comment.data || {}).images && (comment.data || {}).images.length > 0 && (
  100.               <TouchableOpacity
  101.               onPress={() => this._onPressImage((comment.data || {}).images[0])}
  102.               tyle={[styles.touchImageComment]}>
  103.                 <FastImage
  104.                   style={{
  105.                     width: SCREEN.width - SIZE_IMAGE * 2 - 14 * 4,
  106.                     height: 180,
  107.                     marginLeft:SIZE_IMAGE + 10,
  108.                     marginTop:5,
  109.                   }}
  110.                   source={UtiImage.getUrlImageStream((comment.data || {}).images[0])}
  111.                 />
  112.               </TouchableOpacity>
  113.             )}
  114.           </TouchableOpacity>
  115.           <View style={styles.viewContain}>
  116.             <View style={styles.viewBottom}>
  117.               <Text style={styles.commentTime}>{UtilDate.humanizeTimestamp(comment.created_at)}</Text>
  118.               <TouchableOpacity
  119.                 onPress={() => onPressReplyChild(comment, commentParent)}
  120.                 style={styles.touchLabelChildren}
  121.               >
  122.                 <Text style={styles.labelChildrenCount}>{localization.t('comment_reply')}</Text>
  123.               </TouchableOpacity>
  124.             </View>
  125.           </View>
  126.         </View>
  127.  
  128.         <ModalImageComment
  129.                 comment={comment}
  130.                 userId={this.props.userId}
  131.                 isModalVisible={this.state.isModalVisible}
  132.                 urlViewImage={this.state.urlViewImage}
  133.                 closeModal={this.closeModal}
  134.                 visibleLoading={this.state.visibleLoading}
  135.         />
  136.       </View>
  137.     );
  138.   }
  139. }
  140. const SIZE_IMAGE = 25;
  141. const styles = StyleSheet.create({
  142.   container: {
  143.     flex: 1,
  144.     marginTop: 5
  145.   },
  146.   viewHeader: {},
  147.   imageView: {
  148.     width: SIZE_IMAGE,
  149.     height: SIZE_IMAGE,
  150.     borderRadius: SIZE_IMAGE / 2
  151.   },
  152.   viewContain: {
  153.     flex: 1,
  154.     marginHorizontal: 10,
  155.     marginLeft: SIZE_IMAGE + 10
  156.     // width:SCREEN.width - SIZE_IMAGE * 4,
  157.   },
  158.   touchImageComment:{
  159.     marginTop:10,
  160.     marginBottom:5,
  161.     // marginLeft:SIZE_IMAGE   + 10,
  162.   },
  163.   bottomModal: {
  164.     justifyContent: 'flex-end',
  165.     margin: 0
  166.   },
  167.   viewContainParse: {
  168.     flex: 1,
  169.     marginHorizontal: 10,
  170.     marginLeft: SIZE_IMAGE + 10,
  171.     width: SCREEN.width - SIZE_IMAGE - 20 * 2
  172.   },
  173.   touchLabelChildren: {
  174.     minHeight: 20,
  175.     minWidth: 36,
  176.     marginLeft: SIZE_IMAGE,
  177.     flexDirection: 'row'
  178.   },
  179.   commentAuthor: {
  180.     fontWeight: '500',
  181.     fontSize: 14,
  182.     fontFamily: 'SFCompactDisplay-Medium',
  183.     // marginBottom: 2,
  184.     color: 'rgb(34,43,69)'
  185.     // flex:1,
  186.     // width:SCREEN.width - SIZE_IMAGE * 4,
  187.   },
  188.   viewAuthor: {
  189.     justifyContent: 'center',
  190.     marginLeft: 10,
  191.     flex: 1
  192.   },
  193.   text: {
  194.     fontSize: 14,
  195.     fontFamily: 'SFCompactDisplay-Regular',
  196.     color: 'rgb(34,43,69)',
  197.     width: SCREEN.width - SIZE_IMAGE * 4
  198.   },
  199.   commentTime: {
  200.     fontSize: 13,
  201.     color: 'rgb(143,155,179)',
  202.     fontWeight: '500',
  203.     fontStyle: 'normal',
  204.     lineHeight: 16,
  205.     fontFamily: 'SFCompactDisplay-Medium',
  206.     marginBottom: 5
  207.   },
  208.   viewBottom: {
  209.     marginTop: 5,
  210.     flexDirection: 'row'
  211.     // width:SCREEN.width - SIZE_IMAGE * 4,
  212.   },
  213.   phone: {
  214.     color: 'blue',
  215.     textDecorationLine: 'underline'
  216.   },
  217.   name: {
  218.     color: 'red'
  219.   },
  220.  
  221.   username: {
  222.     fontFamily: 'SFCompactDisplay-Bold',
  223.     fontSize: 14,
  224.     fontWeight: 'bold',
  225.     color: 'rgb(34,43,69)'
  226.   },
  227.  
  228.   magicNumber: {
  229.     fontSize: 42,
  230.     color: 'pink'
  231.   },
  232.  
  233.   hashTag: {
  234.     color: '#157edc',
  235.     fontWeight: 'bold',
  236.     fontStyle: 'italic'
  237.   },
  238.   url: {
  239.     color: 'red',
  240.     textDecorationLine: 'underline'
  241.   },
  242.  
  243.   email: {
  244.     textDecorationLine: 'underline'
  245.   },
  246.   labelChildrenCount: {
  247.     fontFamily: 'SFCompactDisplay-Medium',
  248.     fontSize: 13,
  249.     fontWeight: '500',
  250.     lineHeight: 16,
  251.     letterSpacing: 0,
  252.     color: 'rgb(143,155,179)',
  253.     marginLeft: 10
  254.   }
  255. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement