123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- import React, {Component} from 'react';
- import StorageUtil from '../utils/StorageUtil';
- import Utils from '../utils/Utils';
- import Toast from '@remobile/react-native-toast';
- import {
- Dimensions,
- Image,
- Modal,
- PixelRatio,
- StyleSheet,
- Text,
- TouchableOpacity,
- View
- } from 'react-native';
- const {width, height} = Dimensions.get('window');
- export default class MomentMenuView extends Component {
- constructor(props) {
- super(props);
- this.state = {
- show: false,
- pageX: 0,
- pageY: 0,
- height: 0
- };
- StorageUtil.get('username', (error, object) => {
- if (!error && object != null) {
- this.setState({username: object.username});
- }
- });
- }
- render() {
- return (
- <View style={[styles.modalContainer, {height: this.state.height}]}>
- <Modal transparent={true}
- visible={this.state.show}
- onRequestClose={() => this.closeModal()}>
- <TouchableOpacity style={[styles.modalContainer, {height: this.state.height}]}
- onPress={() => this.closeModal()}>
- <View style={[styles.container, {left: this.state.pageX - 200, top: this.state.pageY - 20}]}>
- <TouchableOpacity onPress={() => this.doFavor()}>
- <View style={styles.menuItemContainer}>
- <Image style={styles.menuItemImg} source={require('../../images/ic_moment_favor.png')}/>
- <Text style={styles.menuItemText}> 赞 </Text>
- </View>
- </TouchableOpacity>
- <View style={styles.divider}/>
- <TouchableOpacity onPress={() => this.doComment()}>
- <View style={styles.menuItemContainer}>
- <Image style={styles.menuItemImg} source={require('../../images/ic_moment_comment.png')}/>
- <Text style={styles.menuItemText}>评论</Text>
- </View>
- </TouchableOpacity>
- </View>
- </TouchableOpacity>
- </Modal>
- </View>
- );
- }
- doComment() {
- let callback2 = this.state.callback2;
- if (!Utils.isEmpty(callback2)) {
- callback2(this.state.momentId, this.state.momentUsername);
- }
- this.closeModal();
- }
- doFavor() {
- let momentId = this.state.momentId;
- if (!Utils.isEmpty(momentId)) {
- let url = 'http://app.yubo725.top/favor';
- let username = this.state.username;
- let formData = new FormData();
- formData.append('username', username);
- formData.append('momentId', momentId);
- fetch(url, {method: 'POST', body: formData}).then((res) => res.json())
- .then((json) => {
- if (!Utils.isEmpty(json)) {
- if (json.code == 1) {
- // 需要刷新页面
- let callback1 = this.state.callback1;
- if (!Utils.isEmpty(callback1)) {
- callback1(json.msg);
- }
- } else {
- Toast.showShortCenter(json.msg);
- }
- }
- }).catch((e) => {
- Toast.showShortCenter(e.toString());
- })
- }
- this.closeModal();
- }
- closeModal() {
- this.setState({show: false, height: 0});
- }
- showModal(pageX, pageY, momentId, momentUsername, callback1, callback2) {
- this.setState({
- pageX: pageX,
- pageY: pageY,
- height: height,
- show: true,
- momentId: momentId,
- momentUsername: momentUsername,
- callback1: callback1,
- callback2: callback2
- });
- }
- }
- const styles = StyleSheet.create({
- modalContainer: {
- width: width,
- },
- container: {
- backgroundColor: '#393A3E',
- borderRadius: 2,
- flexDirection: 'row',
- justifyContent: 'center',
- alignItems: 'center',
- width: 180,
- padding: 5,
- height: 35,
- position: 'absolute',
- left: 230,
- top: 500
- },
- divider: {
- width: 1 / PixelRatio.get(),
- marginLeft: 20,
- marginRight: 20,
- height: 25,
- backgroundColor: '#DDDDDD'
- },
- menuItemContainer: {
- flex: 1,
- flexDirection: 'row',
- alignItems: 'center',
- justifyContent: 'center',
- },
- menuItemImg: {
- width: 20,
- height: 20,
- marginTop: 10,
- marginBottom: 10,
- },
- menuItemText: {
- color: '#FFFFFF',
- fontSize: 15
- }
- })
|