SwipeList.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. import React, { Component } from 'react'
  2. import {
  3. StyleSheet,
  4. View,
  5. StatusBar,
  6. Text,
  7. TouchableOpacity,
  8. Dimensions,
  9. Animated,
  10. } from 'react-native'
  11. import { connect } from 'react-redux'
  12. import Icon from '../../components/Iconfont/Iconfont'
  13. import { NavigationActions, createAction } from '../../utils'
  14. import Interactable from 'react-native-interactable'
  15. import { AddAttentModal } from '../common/datamodel/dataModel'
  16. const Screen = Dimensions.get('window')
  17. @connect(({ shoppingcart }) => ({ ...shoppingcart }))
  18. export default class Row extends Component {
  19. constructor(props) {
  20. super(props)
  21. this._deltaX = new Animated.Value(0)
  22. this.state = {
  23. isMoving: false,
  24. position: 1,
  25. }
  26. this._this = []
  27. }
  28. render() {
  29. const activeOpacity = this.state.position !== 1 ? 0.5 : 1
  30. return (
  31. <View>
  32. <View
  33. style={{
  34. position: 'absolute',
  35. flexDirection: 'row',
  36. right: 0,
  37. }}
  38. >
  39. <TouchableOpacity onPress={this.onButtonPress.bind(this, 'trash')}>
  40. <Animated.View
  41. style={{
  42. justifyContent: 'center',
  43. alignItems: 'center',
  44. width: Screen.width * 0.16,
  45. paddingBottom: 40,
  46. paddingTop: 37,
  47. backgroundColor: '#FFBF00',
  48. overflow: 'hidden',
  49. // transform: [
  50. // {
  51. // scale: this._deltaX.interpolate({
  52. // inputRange: [
  53. // -Screen.width,
  54. // -Screen.width * 0.32,
  55. // -Screen.width * 0.16
  56. // ],
  57. // outputRange: [1, 1, 0]
  58. // })
  59. // }
  60. // ]
  61. }}
  62. >
  63. <Text
  64. style={{ flex: 1, fontSize: 14, lineHeight: 20, color: '#FFF' }}
  65. >
  66. 关注
  67. </Text>
  68. </Animated.View>
  69. </TouchableOpacity>
  70. <TouchableOpacity onPress={this.onButtonPress.bind(this, 'delete')}>
  71. <Animated.View
  72. style={{
  73. justifyContent: 'center',
  74. alignItems: 'center',
  75. width: Screen.width * 0.16,
  76. paddingBottom: 40,
  77. paddingTop: 37,
  78. backgroundColor: '#E14C46',
  79. // transform: [
  80. // {
  81. // scale: this._deltaX.interpolate({
  82. // inputRange: [-Screen.width, -Screen.width * 0.16, 0],
  83. // outputRange: [1, 1, 0]
  84. // })
  85. // }
  86. // ]
  87. }}
  88. >
  89. <Text
  90. style={{ flex: 1, fontSize: 14, lineHeight: 20, color: '#FFF' }}
  91. >
  92. 删除
  93. </Text>
  94. </Animated.View>
  95. </TouchableOpacity>
  96. </View>
  97. <Interactable.View
  98. boundaries={{ right: 0 }}
  99. ref={el => (this.interactableElem = el)}
  100. horizontalOnly={true}
  101. onAlert={e => {
  102. alert(e)
  103. }}
  104. snapPoints={[
  105. {
  106. x: 0,
  107. },
  108. {
  109. x: -Screen.width * 0.32,
  110. },
  111. ]}
  112. onSnap={this.onSnap.bind(this)}
  113. onDrag={this.onDrag.bind(this)}
  114. onStop={this.onStopMoving.bind(this)}
  115. dragToss={0.01}
  116. animatedValueX={this._deltaX}
  117. >
  118. <TouchableOpacity
  119. // onPress={this.onRowPress.bind(this)}
  120. activeOpacity={1}
  121. underlayColor={'#dddddd'}
  122. >
  123. <View
  124. style={{
  125. left: 0,
  126. right: 0,
  127. backgroundColor: 'white',
  128. }}
  129. >
  130. {this.props.children}
  131. </View>
  132. </TouchableOpacity>
  133. </Interactable.View>
  134. </View>
  135. )
  136. }
  137. onSnap({ nativeEvent }) {
  138. const { index } = nativeEvent
  139. this.setState({ position: index })
  140. if (index == 1) {
  141. this.props.addThis && this.props.addThis(this)
  142. }
  143. }
  144. onRowPress() {
  145. const { isMoving, position } = this.state
  146. }
  147. onDrag({ nativeEvent }) {
  148. const { state } = nativeEvent
  149. if (state === 'start') {
  150. this.setState({ isMoving: true })
  151. }
  152. }
  153. onStopMoving() {
  154. this.setState({ isMoving: false })
  155. }
  156. onButtonPress(name) {
  157. this.interactableElem.snapTo({ index: 0 })
  158. if (name == 'delete') {
  159. this.props
  160. .dispatch(
  161. createAction('shoppingcart/deleteShop')({
  162. params: {
  163. id: this.props.itemData,
  164. customer: this.props.customerId,
  165. },
  166. })
  167. )
  168. .finally(() => {
  169. if (this.props.isDelete) {
  170. this.props.deleteTouch()
  171. }
  172. })
  173. } else if (name == 'trash') {
  174. let returnData = AddAttentModal(
  175. this.props.item,
  176. CUSTOMERINFO.id,
  177. CUSTOMERINFO.customerRankCode
  178. )
  179. this.props.dispatch(createAction('attention/addAttention')(returnData))
  180. }
  181. }
  182. }