66 */
77
88import React from 'react'
9- import { TouchableOpacity , View , FlatList , Text } from 'react-native'
9+ import {
10+ TouchableOpacity ,
11+ View ,
12+ FlatList ,
13+ Text ,
14+ PanResponder ,
15+ } from 'react-native'
16+ import { scaleSize , screen } from '../../utils'
1017import styles from './styles'
18+
19+ const LEFT_MIN_WIDTH = scaleSize ( 240 )
1120export default class LinkageList extends React . Component {
1221 props : {
1322 language : String ,
@@ -16,6 +25,11 @@ export default class LinkageList extends React.Component {
1625 onLeftPress ?: ( ) => { } , //左侧点击
1726 onRightPress ?: ( ) => { } , //右侧点击
1827 styles ?: Object , //样式
28+ adjustmentWidth ?: boolean ,
29+ }
30+
31+ static defaultProps = {
32+ adjustmentWidth : false ,
1933 }
2034
2135 constructor ( props ) {
@@ -28,6 +42,21 @@ export default class LinkageList extends React.Component {
2842 this . styles = this . props . styles
2943 ? Object . assign ( styles , this . props . styles )
3044 : styles
45+
46+ if ( props . adjustmentWidth ) {
47+ this . _panBtnStyles = {
48+ style : {
49+ width : LEFT_MIN_WIDTH ,
50+ } ,
51+ }
52+ this . _panResponder = PanResponder . create ( {
53+ onStartShouldSetPanResponder : this . _handleStartShouldSetPanResponder ,
54+ onMoveShouldSetPanResponder : this . _handleMoveShouldSetPanResponder ,
55+ onPanResponderMove : this . _handlePanResponderMove ,
56+ onPanResponderRelease : this . _handlePanResponderEnd ,
57+ onPanResponderTerminate : this . _handlePanResponderEnd ,
58+ } )
59+ }
3160 }
3261
3362 componentDidUpdate ( prevProps ) {
@@ -41,6 +70,46 @@ export default class LinkageList extends React.Component {
4170 }
4271 }
4372
73+ _handleStartShouldSetPanResponder = ( ) => {
74+ // evt, gestureState
75+ return true
76+ }
77+
78+ _handleMoveShouldSetPanResponder = ( ) => {
79+ // evt, gestureState
80+ return true
81+ }
82+
83+ _handlePanResponderMove = ( evt , gestureState ) => {
84+ this . _panBtnStyles . style . width = gestureState . moveX
85+ if ( this . _panBtnStyles . style . width < LEFT_MIN_WIDTH ) {
86+ this . _panBtnStyles . style . width = LEFT_MIN_WIDTH
87+ } else if (
88+ this . _panBtnStyles . style . width >
89+ screen . getScreenWidth ( ) - LEFT_MIN_WIDTH
90+ ) {
91+ this . _panBtnStyles . style . width = screen . getScreenWidth ( ) - LEFT_MIN_WIDTH
92+ }
93+ this . _updateNativeStyles ( )
94+ }
95+
96+ _handlePanResponderEnd = ( evt , gestureState ) => {
97+ this . _panBtnStyles . style . width = gestureState . moveX
98+ if ( this . _panBtnStyles . style . width < LEFT_MIN_WIDTH ) {
99+ this . _panBtnStyles . style . width = LEFT_MIN_WIDTH
100+ } else if (
101+ this . _panBtnStyles . style . width >
102+ screen . getScreenWidth ( ) - LEFT_MIN_WIDTH
103+ ) {
104+ this . _panBtnStyles . style . width = screen . getScreenWidth ( ) - LEFT_MIN_WIDTH
105+ }
106+ this . _updateNativeStyles ( )
107+ }
108+
109+ _updateNativeStyles = ( ) => {
110+ this . leftList && this . leftList . setNativeProps ( this . _panBtnStyles )
111+ }
112+
44113 onLeftPress = ( { item, index } ) => {
45114 if ( this . props . onLeftPress ) return this . props . onLeftPress ( { item, index } )
46115 this . setState ( {
@@ -77,7 +146,9 @@ export default class LinkageList extends React.Component {
77146 } }
78147 >
79148 { this . state . selected === index && < View style = { styles . leftSelectTag } /> }
80- < Text style = { this . styles . leftItem } > { item . title } </ Text >
149+ < Text style = { this . styles . leftItem } numberOfLines = { 1 } >
150+ { item . title }
151+ </ Text >
81152 </ TouchableOpacity >
82153 )
83154 }
@@ -90,15 +161,24 @@ export default class LinkageList extends React.Component {
90161 this . onRightPress ( { item, index } )
91162 } }
92163 >
93- < Text style = { this . styles . rightItem } > { item . title } </ Text >
164+ < Text style = { this . styles . rightItem } numberOfLines = { 1 } >
165+ { item . title }
166+ </ Text >
94167 </ TouchableOpacity >
95168 )
96169 }
97170
98171 render ( ) {
172+ let panHandlers = { }
173+ if ( this . _panResponder && this . _panResponder . panHandlers ) {
174+ panHandlers = this . _panResponder . panHandlers
175+ }
99176 return (
100177 < View style = { this . styles . container } >
101- < View style = { this . styles . leftFlatListContainer } >
178+ < View
179+ ref = { ref => ( this . leftList = ref ) }
180+ style = { this . styles . leftFlatListContainer }
181+ >
102182 < View style = { this . styles . headContainer } >
103183 < Text style = { this . styles . menuTitle } > { this . props . titles [ 0 ] } </ Text >
104184 </ View >
@@ -110,6 +190,9 @@ export default class LinkageList extends React.Component {
110190 keyExtractor = { ( item , index ) => item + index }
111191 />
112192 </ View >
193+ { this . props . adjustmentWidth && (
194+ < View style = { styles . moveSeparator } { ...panHandlers } />
195+ ) }
113196 < View style = { this . styles . rightFlatListContainer } >
114197 < View style = { this . styles . headContainer } >
115198 < View style = { styles . shortLine1 } />
0 commit comments