Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React from 'react';
- import { KeyboardAvoidingView,Animated,RefreshControl, View,TouchableOpacity,Text, StyleSheet,Platform } from 'react-native';
- import { client } from '../../../utils/StreamConnect';
- import { KeyboardAccessoryView } from 'react-native-keyboard-accessory'
- import {
- SinglePost,
- Activity,
- } from 'react-native-activity-feed';
- import RepostList from '../component/RepostList';
- import _ from 'lodash';
- import AppConfig from '../../../AppConfig';
- import StreamAppClient from '../component/StreamAppClient';
- import { ReactionToggleLike } from '../component/ReactionToggleLike';
- import { ReactionToggleHeart } from '../component/ReactionToggleHeart';
- import { ReactionComment } from '../component/ReactionComment';
- import CommentBoxCustom from '../component/CommentBoxCustom';
- import ContentActivity from '../component/ContentActivity';
- import CommentItemCustom from '../component/CommentItemCustom';
- import LogicMessage from '../../../logic_app/LogicMessage';
- import ApiUrl from '../../../api'
- import TokenStream from '../storage/TokenStream';
- import HeaherActivity from '../component/HeaherActivity';
- import { Actions } from 'react-native-router-flux';
- import MyStatusBar from '../../../components/MyStatusBar';
- import { HEIGHT_DEFAULT_NAVBAR, SCREEN } from '../../../utils/UtilDeviceInfo';
- import localization from '../../../localization';
- import FastImage from 'react-native-fast-image';
- import Modal from 'react-native-modal';
- import ModalContent from '../component/ModalContent';
- import CommentList from '../component/Reaction/CommentList';
- import Modalize from 'react-native-modalize';
- import ModalContentToggle from '../component/Modal/ModalContentToggle'
- import LoadMoreButton from '../component/Reaction/LoadMoreButton';
- import TotalToggle from '../component/TotalToggle';
- export default class SinglePostScreen extends React.PureComponent {
- constructor(props) {
- super(props);
- this.state = {
- data : [],
- dataInit:[],
- paddingFocus:350,//default isFocus 350 , //not 50
- userId:undefined,
- user:undefined,
- comment:undefined,
- type:1,
- token:undefined,
- visibleModal:false,
- activityId:undefined,
- activity:undefined,
- isRefreshing:false,
- commentToggle:undefined,
- spinValue:new Animated.Value(0),
- isActivty:false
- };
- }
- componentDidMount() {
- this.setState({
- activity: this.props.activity || {}
- })
- this._fetchDatamention();
- this.fetchToken();
- }
- _onShowModallize = (comment,isActivty = false) => {
- if(this.modaLize){
- this.setState({commentToggle:comment,isActivty},() => {
- this.modaLize.open();
- })
- }
- }
- _onPressComment = props => {
- if(this.commentBox){
- this.commentBox.focus();
- }
- };
- async fetchToken(){
- try{
- let user = await TokenStream.getAuthStream();
- if( !_.isNil(user) && !_.isNil(user.data) ) {
- this.setState(
- {
- userId: (user.data || {})._id + '',
- token:user.tokenStream
- }
- )
- }
- }catch(e){
- }
- }
- async _fetchDatamention() {
- try{
- const dataResponse = await ApiUrl.getListUserMention();
- let data = dataResponse.data || {};
- if( LogicMessage.isSuccess(dataResponse,false) && _.isArray(data.data)){
- this.setState({ data: data.data, dataInit: data.data })
- }else{
- this.setState({ data: [] })
- }
- }catch(e){
- }
- }
- renderContent = props => (
- <ContentActivity {...props} />
- );
- renderHeader = props => {
- return <HeaherActivity {...props} onPressStation={this._onPressStation} isDetailPost= {false} onPressBack = { () => {
- Actions.pop();
- }}
- onPressAvatar={() => this._onPressAvatar(props)}
- />
- };
- _onPressEditComment = (comment,isCommentChild = false,commentChild) => {
- if( this.commentBox){
- this.commentBox.focusEdit(comment,isCommentChild,commentChild);
- }
- }
- _onPressCommentChild = (comment ,type = 1) => {
- if(type === 2 && this.commentBox){
- let userIdComment = _.get(comment, 'user_id');
- const isUserSefReply = userIdComment === this.state.userId ? true : false;
- this.commentBox.focus(comment,undefined,type,isUserSefReply);
- }
- }
- _onPressCommentChildParent = (comment ,commentParent,type = 3) => {
- if(this.commentBox){
- let userIdComment = _.get(comment, 'user_id');
- const isUserSefReply = userIdComment === this.state.userId ? true : false;
- this.commentBox.focus(comment,commentParent,type,isUserSefReply);
- }
- }
- _onPressAvatar = props => {};
- _updatePaddingFocus = (paddingTop) => {
- if(paddingTop && paddingTop !== this.state.paddingFocus){
- this.setState({paddingFocus: paddingTop})
- }
- if(this.commentBox && this.state.type !== 3 ){
- if(this.state.comment && this.state.type === 2 ){
- this.commentBox.focus(this.state.comment);
- }else{
- this.commentBox.focus();
- }
- }
- }
- _closeModal = () => {
- this.setState({visibleModal:false})
- }
- _renderSeparator = ()=>{
- return <View style={{height:1,marginLeft:40 + 10, backgroundColor:'rgb(237,241,247)'}}></View>;
- };
- _keyExtractor = (item, index)=> {
- return index;
- }
- _refreshControl = ()=>{
- return <RefreshControl
- refreshing={this.state.isRefreshing}
- // onRefresh={this.onRefresh.bind(this)}
- />
- };
- _onRefesh = () => {
- return null
- }
- _refeshActivity = async() => {
- //update activity
- let feedClient = await client();
- let userComment = await feedClient.feed(AppConfig.FEED_USER,this.state.userId,
- this.state.token
- );
- let activity = await userComment.get({ limit:1, id: this.state.activity.id });
- this.setState({activity:activity.results[0]},() => {this.forceUpdate()});
- }
- _onUpdateReaction =async (reactionId,data,isResetComment) => {
- try{
- let feedClient = await client();
- await feedClient.reactions.update(reactionId, data);
- isResetComment();
- this.setState({ isRefreshing: true },() => {
- this.forceUpdate();
- });
- }catch(e){
- }
- }
- _onPressStation = (item) => {
- Actions.Station({
- keyData: item._id,
- data: item
- });
- };
- render() {
- const activity = this.state.activity || {};
- let feedGroup = this.props.feedGroup || AppConfig.FEED_TIMELINE;
- return (
- <View style={styles.container}>
- <MyStatusBar>
- <View style={{ height: HEIGHT_DEFAULT_NAVBAR,flexDirection:'row', margin: 0, width: SCREEN.width, display: 'flex' }}>
- <TouchableOpacity
- style={styles.touchImageViewClose}
- onPress={ () => {Actions.pop() } }
- >
- <FastImage
- style={styles.imageViewClose}
- source={ require('../../../assets/imgs/m_1_t_back.png') }
- />
- </TouchableOpacity>
- <Text style={styles.HeaderTittle}>{localization.t('label_Comment')}</Text>
- </View>
- </MyStatusBar>
- <StreamAppClient isTimeline = {true}>
- <SinglePost
- activity={activity}
- feedGroup={feedGroup}
- userId={ this.state.userId}
- /**
- * withOwnChildren: true get children user comment
- */
- options={{ withOwnChildren: true }}//
- Activity={props => {
- return (
- <React.Fragment>
- <Activity
- {...props}
- styles={{
- container: {
- paddingTop: 10,
- paddingBottom: 0,
- borderBottomColor: 'rgb(237,241,247)',
- borderBottomWidth: 1
- }
- }}
- onPressAvatar={() => this._onPressAvatar(props)}
- Header={this.renderHeader(props)}
- Content={this.renderContent(props)}
- Footer={
- <View style={{ flexDirection: 'row', alignItems: 'center',justifyContent: 'space-between' }}>
- <View style={{ flexDirection: 'row', alignItems: 'center' }}>
- <ReactionToggleLike {...props} userId={this.state.userId} />
- <ReactionToggleHeart {...props} userId={this.state.userId} />
- <ReactionComment
- {...props}
- onPressActivity={this._onPressComment}
- />
- </View>
- {
- this.state.userId === _.get( props.activity , 'actor.id', '') &&
- <TouchableOpacity onPress = {
- () => this.setState({visibleModal:true,activity:props.activity , activityId: _.get( props.activity , 'id') })
- } style={[styles.touchMore]}>
- <FastImage
- style={styles.imageViewMore}
- source={require('../../../assets/imgs/timeline/moreHorizontal.png')}
- />
- </TouchableOpacity>
- }
- </View>
- }
- />
- {/* <RepostList activityId={(props.activity || {}).id} /> */}
- <TotalToggle onShowModallize={this._onShowModallize} {...props}/>
- <CommentList
- {...props}
- flatListProps={{
- style: {
- },
- ItemSeparatorComponent: this._renderSeparator,
- }}
- activityId={(props.activity || {}).id}
- reactions={(props.activity || {}).latest_reactions}
- reverseOrder
- noPagination={false}
- oldestToNewest ={false}
- infiniteScroll={false} //false: show ButtonLoadmore
- LoadMoreButton={(props) => <LoadMoreButton {...props} onPress={props.onPress}/>}
- CommentItem={({ comment }) => {
- return (
- <React.Fragment>
- <CommentItemCustom
- onShowModallize={this._onShowModallize}
- onPressCommentChild = {this._onPressCommentChild}
- onPressCommentChildParent = {this._onPressCommentChildParent}
- onPressEditComment = {this._onPressEditComment}
- onRemoveChildReaction = { (commentParent, idChildReaction) => {
- props.onRemoveChildReaction(AppConfig.VERB_COMMENT, commentParent, idChildReaction);
- }}
- props = {props}
- userIdCurrent= {this.state.userId}
- comment={comment} />
- </React.Fragment>
- );
- }}
- />
- <View style={styles.sectionHeader} />
- </React.Fragment>
- );
- }}
- Footer={props => {
- return (
- <CommentBoxCustom
- userId={ this.state.userId}
- ref = {c => this.commentBox = c}
- data={this.state.data || []}
- dataInit={this.state.dataInit || []}
- avatar={this.props.avatar}
- activity={activity}
- onAddReaction={async (comment, activityData, data,userId_Mention = [],isCommentChild = false,commentObject = {},isResetComment) => {
- try {
- let originUser = _.get(activity, 'actor.id');
- if(isCommentChild){
- props.onAddChildReaction(comment, commentObject, data, {targetFeeds: originUser !== this.state.userId ? userId_Mention.concat(['notification:' + originUser]) : userId_Mention });
- }else{
- props.onAddReaction(
- comment,
- activityData,
- data,
- {targetFeeds: originUser !== this.state.userId ? userId_Mention.concat(['notification:' + originUser]) : userId_Mention });
- }
- isResetComment();
- } catch (e) {}
- }}
- onUpdateReaction = {(reactionId,data,isResetComment) => {
- this._onUpdateReaction(reactionId,data,isResetComment);
- }}
- />
- );
- }}
- />
- </StreamAppClient>
- <Modal
- onBackdropPress={() => this.setState({ visibleModal: false })}
- isVisible={this.state.visibleModal}
- onSwipeComplete={() => this.setState({ visibleModal: false })}
- style={styles.bottomModal}
- >
- <KeyboardAvoidingView
- behavior="position"
- enabled
- >
- <ModalContent
- isDetailPost = {true}
- activity={this.state.activity}
- userId={this.state.userId}
- activityId={this.state.activityId}
- token={this.state.token}
- refeshActivity={this._refeshActivity}
- closeModal = {this._closeModal}/>
- </KeyboardAvoidingView>
- </Modal>
- <Modalize
- ref={ c => this.modaLize = c}
- modalStyle={{marginTop:HEIGHT_DEFAULT_NAVBAR + 20}}
- overlayStyle={{ backgroundColor: 'rgba(0,0,0,.3)' }}
- //modalHeight={SCREEN.height/2}
- snapPoint={SCREEN.height/2}
- >
- <ModalContentToggle
- isActivty = {this.state.isActivty}
- commentToggle={this.state.commentToggle}
- />
- </Modalize>
- </View>
- );
- }
- }
- const SIZE_ICON_CLOSE = 18;
- const styles = StyleSheet.create({
- container: {
- flex: 1,
- },
- imageViewMore:{
- width: 24,
- height: 24
- },
- touchMore:{
- minHeight:36,
- minWidth:36,
- justifyContent:'center',
- alignItems:'center',
- marginRight:10,
- },
- commentBox: {
- height: 60
- },
- HeaderTittle: {
- justifyContent: 'flex-start',
- alignItems: 'center',
- color: '#ffffff', //152935
- fontSize: 22,
- paddingLeft: 5,
- marginTop: 20,
- fontWeight: 'bold'
- },
- bottomModal: {
- justifyContent: 'flex-end',
- margin: 0
- },
- imageViewClose:{
- width: SIZE_ICON_CLOSE,
- height: SIZE_ICON_CLOSE,
- marginTop:10
- },
- touchImageViewClose:{
- minWidth: 30,
- minHeight: 36,
- justifyContent:'center',
- alignItems:'center',
- marginLeft:10,
- },
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement