Skip to content

Commit 68b759f

Browse files
zql602263131祝乔林
andauthored
react-native-pull鸿蒙化 (#1)
Co-authored-by: 祝乔林 <zhuqiaolin2@h-partners.com>
1 parent eb8fef1 commit 68b759f

File tree

13 files changed

+548
-103
lines changed

13 files changed

+548
-103
lines changed

.idea/.gitignore

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/react-native-pull.iml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

PullList.js

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,10 @@
11
'use strict';
22

33
import React, { Component } from 'react';
4-
import { ListView } from 'react-native';
4+
import { FlatList } from 'react-native';
55

66
import Pullable from './Pullable';
77

8-
/**
9-
支持android&ios可以下拉刷新的PullList组件
10-
Demo:
11-
import {PullList} from 'react-native-pullview';
12-
13-
<PullList onPulling={} onPullOk={} onPullRelease={} isPullEnd={true}
14-
topIndicatorRender={({pulling, pullok, pullrelease}) => {}} topIndicatorHeight={60}
15-
{...ListView.props}
16-
>
17-
18-
Demo2:
19-
topIndicatorRender(pulling, pullok, pullrelease) {
20-
return <View style={{flex: 1, flexDirection: 'row', justifyContent: 'center', alignItems: 'center', height: 60}}>
21-
<ActivityIndicator size="small" color="gray" />
22-
{pulling ? <Text>下拉刷新2...</Text> : null}
23-
{pullok ? <Text>松开刷新2......</Text> : null}
24-
{pullrelease ? <Text>玩命刷新中2......</Text> : null}
25-
</View>;
26-
}
27-
<PullList onPullRelease={this.props.onRefresh} topIndicatorRender={this.topIndicatorRender} topIndicatorHeight={60} {...ListView.props} />
28-
*/
29-
308
export default class extends Pullable {
319

3210
constructor(props) {
@@ -41,6 +19,7 @@ export default class extends Pullable {
4119
}
4220

4321
scrollTo(...args) {
22+
console.log(...args);
4423
this.scroll.scrollTo(...args);
4524
}
4625

@@ -50,7 +29,7 @@ export default class extends Pullable {
5029

5130
getScrollable() {
5231
return (
53-
<ListView ref={(c) => {this.scroll = c;}} onScroll={this.onScroll} {...this.props} />
32+
<FlatList ref={(c) => {this.scroll = c;}} scrollEnabled={this.state.scrollEnabled} onScroll={this.onScroll} {...this.props} />
5433
);
5534
}
5635
}

PullView.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export default class extends Pullable {
6565

6666
getScrollable(refreshControl) {
6767
return (
68-
<ScrollView ref={(c) => {this.scroll = c;}} refreshControl={refreshControl} onScroll={this.onScroll}>
68+
<ScrollView ref={(c) => {this.scroll = c;}} scrollEnabled={this.state.scrollEnabled} refreshControl={refreshControl} onScroll={this.onScroll}>
6969
{this.props.children}
7070
</ScrollView>
7171
);

Pullable.js

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
import React, { Component } from 'react';
3+
import React, { Component, useRef } from 'react';
44
import {
55
View,
66
Text,
@@ -58,42 +58,62 @@ export default class extends Component {
5858
this.renderTopIndicator = this.renderTopIndicator.bind(this);
5959
this.defaultTopIndicatorRender = this.defaultTopIndicatorRender.bind(this);
6060
this.panResponder = PanResponder.create({
61-
onStartShouldSetPanResponder: this.onShouldSetPanResponder.bind(this),
62-
onMoveShouldSetPanResponder: this.onShouldSetPanResponder.bind(this),
61+
onStartShouldSetPanResponder: this.onStartShouldSetPanResponder.bind(this),
62+
onMoveShouldSetPanResponder: this.onMoveShouldSetPanResponder.bind(this),
6363
onPanResponderGrant: () => { },
6464
onPanResponderMove: this.onPanResponderMove.bind(this),
6565
onPanResponderRelease: this.onPanResponderRelease.bind(this),
6666
onPanResponderTerminate: this.onPanResponderRelease.bind(this),
6767
});
6868
this.setFlag(defaultFlag);
6969
}
70-
71-
onShouldSetPanResponder(e, gesture) {
70+
onStartShouldSetPanResponder(e, gesture) {
71+
console.log('onStartShouldSetPanResponder----------->', gesture.dy)
72+
}
73+
onMoveShouldSetPanResponder(e, gesture) {
74+
console.log('onMoveShouldSetPanResponder----------->', gesture.dy)
75+
if( gesture.dy>0){
76+
this.setState({
77+
scrollEnabled: false,
78+
});
79+
}else{
80+
this.setState({
81+
scrollEnabled: true,
82+
});
83+
}
7284
if (!this.pullable || !isVerticalGesture(gesture.dx, gesture.dy)) { // 不使用pullable,或非向上 或向下手势不响应
7385
return false;
7486
}
75-
7687
if (!this.state.scrollEnabled) {
7788
this.lastY = this.state.pullPan.y._value;
7889
return gesture.dy >= 0;
90+
this.setState({
91+
scrollEnabled: true,
92+
});
7993
} else {
8094
return false;
8195
}
8296
}
8397

8498
onPanResponderMove(e, gesture) {
99+
console.log('onPanResponderMove----------->', gesture.dy)
85100
this.gesturePosition = {
86101
x: this.defaultXY.x,
87102
y: gesture.dy
88103
};
89-
90104
if (isUpGesture(gesture.dx, gesture.dy)) { //向上滑动
105+
this.setState({
106+
scrollEnabled: true,
107+
});
91108
if (this.isPullState()) {
92109
this.resetDefaultXYHandler();
93110
} else if (this.props.onPushing) {
94111
this.props.onPushing(this.gesturePosition)
95112
}
96113
} else if (isDownGesture(gesture.dx, gesture.dy)) { //下拉
114+
this.setState({
115+
scrollEnabled: false,
116+
});
97117
this.state.pullPan.setValue({
98118
x: this.defaultXY.x,
99119
y: this.lastY + gesture.dy / 2
@@ -107,14 +127,15 @@ export default class extends Component {
107127
}
108128

109129
this.setFlag(flagPulling);
110-
} else { //下拉到位
111-
if (!this.state.pullok) {
130+
} else if (gesture.dy >= this.topIndicatorHeight + this.pullOkMargin){ //下拉到位
131+
if (!this.flag.pullok) {
112132
if (this.props.onPullOk) {
113133
this.props.onPullOk();
114134
}
135+
this.setFlag(flagPullok);
115136
}
116137

117-
this.setFlag(flagPullok);
138+
118139
}
119140
}
120141
}
@@ -136,7 +157,8 @@ export default class extends Component {
136157
Animated.timing(this.state.pullPan, {
137158
toValue: { x: 0, y: 0 },
138159
easing: Easing.linear,
139-
duration: this.duration
160+
duration: this.duration,
161+
useNativeDriver:false
140162
}).start();
141163
}
142164
}
@@ -177,7 +199,8 @@ export default class extends Component {
177199
Animated.timing(this.state.pullPan, {
178200
toValue: this.defaultXY,
179201
easing: Easing.linear,
180-
duration: this.duration
202+
duration: this.duration,
203+
useNativeDriver:false
181204
}).start();
182205
}
183206

0 commit comments

Comments
 (0)