fix(scroll-view): android 'isScrollEnabled' will apply if changed while gesture is underway (#8695)

This commit is contained in:
DimitrisRK
2020-07-07 05:05:40 +03:00
committed by GitHub
parent 635f31f81f
commit 02ec7f104d
5 changed files with 35 additions and 2 deletions

View File

@@ -17,6 +17,7 @@ export function loadExamples() {
examples.set("safe-area-images", "scroll-view/safe-area-images-page");
examples.set("safe-area-images-overflow", "scroll-view/safe-area-images-overflow-page");
examples.set("layout-outside-scroll", "scroll-view/layout-outside-scroll-page");
examples.set("scroll-enabled", "scroll-view/scroll-enabled-page");
return examples;
}

View File

@@ -0,0 +1,25 @@
import { EventData as ObservableEventData } from "tns-core-modules/data/observable";
import { GestureStateTypes, PanGestureEventData } from "tns-core-modules/ui/gestures";
import { Page } from "tns-core-modules/ui/page";
export function pageLoaded(args: ObservableEventData) {
var page = <Page>args.object;
}
export function panLayout(args: PanGestureEventData)
{
const scrollView = args.object.parent;
if (args.state === GestureStateTypes.began) {
args.object.previousDeltaY = 0;
scrollView.isScrollEnabled = false;
}
else if (args.state === GestureStateTypes.changed) {
const diff = (args.deltaY - args.object.previousDeltaY);
args.object.translateY += diff;
args.object.previousDeltaY = args.deltaY;
}
else if (args.state === GestureStateTypes.ended) {
scrollView.isScrollEnabled = true;
}
}

View File

@@ -0,0 +1,7 @@
<Page xmlns="http://schemas.nativescript.org/tns.xsd" loaded="pageLoaded" class="page">
<ScrollView id="scroll-view" height="300">
<StackLayout height="500" backgroundColor="red" pan="panLayout">
<Label text="Move Me" color="#fff" fontSize="22"/>
</StackLayout>
</ScrollView>
</Page>

View File

@@ -70,7 +70,7 @@ public class HorizontalScrollView extends android.widget.HorizontalScrollView {
@Override
public boolean onTouchEvent(MotionEvent ev) {
if (!this.scrollEnabled && ev.getAction() == MotionEvent.ACTION_DOWN) {
if (!this.scrollEnabled && (ev.getAction() == MotionEvent.ACTION_DOWN || ev.getAction() == MotionEvent.ACTION_MOVE)) {
return false;
}

View File

@@ -70,7 +70,7 @@ public class VerticalScrollView extends ScrollView {
@Override
public boolean onTouchEvent(MotionEvent ev) {
if (!this.scrollEnabled && ev.getAction() == MotionEvent.ACTION_DOWN) {
if (!this.scrollEnabled && (ev.getAction() == MotionEvent.ACTION_DOWN || ev.getAction() == MotionEvent.ACTION_MOVE)) {
return false;
}