import React, { Component } from 'react' import { StyleSheet, View, StatusBar, Text, TouchableOpacity, Dimensions, Animated, } from 'react-native' import { connect } from 'react-redux' import Icon from '../../components/Iconfont/Iconfont' import { NavigationActions, createAction } from '../../utils' import Interactable from 'react-native-interactable' import { AddAttentModal } from '../common/datamodel/dataModel' const Screen = Dimensions.get('window') @connect(({ shoppingcart }) => ({ ...shoppingcart })) export default class Row extends Component { constructor(props) { super(props) this._deltaX = new Animated.Value(0) this.state = { isMoving: false, position: 1, } this._this = [] } render() { const activeOpacity = this.state.position !== 1 ? 0.5 : 1 return ( 关注 删除 (this.interactableElem = el)} horizontalOnly={true} onAlert={e => { alert(e) }} snapPoints={[ { x: 0, }, { x: -Screen.width * 0.32, }, ]} onSnap={this.onSnap.bind(this)} onDrag={this.onDrag.bind(this)} onStop={this.onStopMoving.bind(this)} dragToss={0.01} animatedValueX={this._deltaX} > {this.props.children} ) } onSnap({ nativeEvent }) { const { index } = nativeEvent this.setState({ position: index }) if (index == 1) { this.props.addThis && this.props.addThis(this) } } onRowPress() { const { isMoving, position } = this.state } onDrag({ nativeEvent }) { const { state } = nativeEvent if (state === 'start') { this.setState({ isMoving: true }) } } onStopMoving() { this.setState({ isMoving: false }) } onButtonPress(name) { this.interactableElem.snapTo({ index: 0 }) if (name == 'delete') { this.props .dispatch( createAction('shoppingcart/deleteShop')({ params: { id: this.props.itemData, customer: this.props.customerId, }, }) ) .finally(() => { if (this.props.isDelete) { this.props.deleteTouch() } }) } else if (name == 'trash') { let returnData = AddAttentModal( this.props.item, CUSTOMERINFO.id, CUSTOMERINFO.customerRankCode ) this.props.dispatch(createAction('attention/addAttention')(returnData)) } } }