Skip to content

Commit 309d6b5

Browse files
committed
细节优化
1 parent f4ce74d commit 309d6b5

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

src/SpringScrollView.js

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export class SpringScrollView extends React.PureComponent<SpringScrollViewPropTy
5050
_scrollEventAttachment;
5151
_nativeOffset;
5252
_touching = false;
53+
_sizeChangeInterval = 0;
5354

5455
constructor(props) {
5556
super(props);
@@ -227,7 +228,10 @@ export class SpringScrollView extends React.PureComponent<SpringScrollViewPropTy
227228

228229
scroll(offset: Offset, animated: boolean = true) {
229230
return this.scrollTo(
230-
{ x: offset.x, y: offset.y + this._contentOffset.y },
231+
{
232+
x: offset.x + this._contentOffset.x,
233+
y: offset.y + this._contentOffset.y,
234+
},
231235
animated
232236
);
233237
}
@@ -283,11 +287,12 @@ export class SpringScrollView extends React.PureComponent<SpringScrollViewPropTy
283287
}
284288

285289
_onKeyboardWillShow = (evt) => {
290+
this._touching = false;
286291
this.props.textInputRefs.every((input) => {
287292
if (idx(() => input.current.isFocused())) {
288-
input.current.measure((x, y, w, h, l, t) => {
293+
input.current.measureInWindow((x, y, w, h, l, t) => {
289294
this._keyboardHeight =
290-
t + h - evt.endCoordinates.screenY + this.props.inputToolBarHeight;
295+
-evt.endCoordinates.screenY + this.props.inputToolBarHeight + y + h;
291296
this._keyboardHeight > 0 &&
292297
this.scroll({ x: 0, y: this._keyboardHeight });
293298
});
@@ -503,11 +508,7 @@ export class SpringScrollView extends React.PureComponent<SpringScrollViewPropTy
503508
this.props.onSizeChange && this.props.onSizeChange({ width, height });
504509
this._height = height;
505510
this._width = width;
506-
if (!this._contentHeight) return;
507-
if (this._contentHeight < this._height) this._contentHeight = height;
508-
if (this._contentOffset.y > this._contentHeight - this._height)
509-
this.scrollToEnd();
510-
this.forceUpdate();
511+
this._startSizeChangeInterval();
511512
}
512513
};
513514

@@ -521,7 +522,14 @@ export class SpringScrollView extends React.PureComponent<SpringScrollViewPropTy
521522
this.props.onContentSizeChange({ width, height });
522523
this._contentHeight = height;
523524
this._contentWidth = width;
524-
if (!this._height) return;
525+
this._startSizeChangeInterval();
526+
}
527+
};
528+
529+
_startSizeChangeInterval = () => {
530+
if (this._sizeChangeInterval) clearInterval(this._sizeChangeInterval);
531+
this._sizeChangeInterval = setInterval(() => {
532+
if (!this._height || !this._contentHeight) return;
525533
if (this._contentHeight < this._height)
526534
this._contentHeight = this._height;
527535
let { x: maxX, y: maxY } = this._contentOffset;
@@ -537,7 +545,9 @@ export class SpringScrollView extends React.PureComponent<SpringScrollViewPropTy
537545
Platform.OS === "android" && this.scrollTo({ x: maxX, y: maxY }, false);
538546
}
539547
this.forceUpdate();
540-
}
548+
clearInterval(this._sizeChangeInterval);
549+
this._sizeChangeInterval = 0;
550+
}, Platform.select({ ios: 10, android: 30 }));
541551
};
542552

543553
_onTouchBegin = (e) => {

src/android/src/main/java/com/bolan9999/SpringScrollView.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
127127
if (!dragging) sendEvent("onCustomTouchEnd", null);
128128
break;
129129
}
130-
return dragging;
130+
return dragging || super.onInterceptTouchEvent(ev);
131131
}
132132

133133
private boolean shouldChildrenInterceptTouchEvent(ViewGroup parent, MotionEvent ev) {

0 commit comments

Comments
 (0)