Skip to content

Commit b0bc594

Browse files
committed
LiknageList新增可拖动改变两个列表宽度的功能
1 parent 6746674 commit b0bc594

3 files changed

Lines changed: 95 additions & 6 deletions

File tree

‎src/components/LinkageList/LinkageList.js‎

Lines changed: 87 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,17 @@
66
*/
77

88
import 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'
1017
import styles from './styles'
18+
19+
const LEFT_MIN_WIDTH = scaleSize(240)
1120
export 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} />

‎src/components/LinkageList/styles.js‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@ export default StyleSheet.create({
2525
fontSize: size.fontSize.fontSizeLg,
2626
},
2727
leftFlatListContainer: {
28-
flex: 1,
28+
// flex: 1,
29+
width: scaleSize(240),
2930
flexDirection: 'column',
3031
justifyContent: 'flex-start',
3132
},
3233
rightFlatListContainer: {
33-
flex: 2,
34+
flex: 1,
3435
flexDirection: 'column',
3536
backgroundColor: color.bgW,
3637
borderLeftWidth: 1,
@@ -89,4 +90,8 @@ export default StyleSheet.create({
8990
marginLeft: scaleSize(28),
9091
marginRight: scaleSize(40),
9192
},
93+
moveSeparator: {
94+
width: scaleSize(20),
95+
backgroundColor: color.separateColorGray,
96+
},
9297
})

‎src/containers/analystView/pages/localAnalystView/LocalAnalystView.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ export default class LocalAnalystView extends Component {
258258
<LinkageList
259259
language={this.props.language}
260260
// data={this.state.dataSourceAndSets}
261+
adjustmentWidth={true}
261262
data={this.props.userUdbAndDs}
262263
titles={[
263264
getLanguage(this.props.language).Analyst_Labels.DATA_SOURCE,

0 commit comments

Comments
 (0)