mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
feat(android-scrollview): add isScrollEnabled property (#150)
This commit is contained in:
@@ -8,6 +8,7 @@ import android.graphics.Rect;
|
|||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.ViewParent;
|
import android.view.ViewParent;
|
||||||
@@ -26,6 +27,7 @@ public class HorizontalScrollView extends android.widget.HorizontalScrollView {
|
|||||||
private int scrollableLength = 0;
|
private int scrollableLength = 0;
|
||||||
private SavedState mSavedState;
|
private SavedState mSavedState;
|
||||||
private boolean isFirstLayout = true;
|
private boolean isFirstLayout = true;
|
||||||
|
private boolean scrollEnabled = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* True when the layout has changed but the traversal has not come through yet.
|
* True when the layout has changed but the traversal has not come through yet.
|
||||||
@@ -48,6 +50,33 @@ public class HorizontalScrollView extends android.widget.HorizontalScrollView {
|
|||||||
return this.scrollableLength;
|
return this.scrollableLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean getScrollEnabled() {
|
||||||
|
return this.scrollEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setScrollEnabled(boolean value) {
|
||||||
|
this.scrollEnabled = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
||||||
|
// Do nothing with intercepted touch events if we are not scrollable
|
||||||
|
if (!this.scrollEnabled) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.onInterceptTouchEvent(ev);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onTouchEvent(MotionEvent ev) {
|
||||||
|
if (!this.scrollEnabled && ev.getAction() == MotionEvent.ACTION_DOWN) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.onTouchEvent(ev);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void requestLayout() {
|
public void requestLayout() {
|
||||||
this.mIsLayoutDirty = true;
|
this.mIsLayoutDirty = true;
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import android.content.Context;
|
|||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
@@ -26,6 +27,7 @@ public class VerticalScrollView extends ScrollView {
|
|||||||
private int scrollableLength = 0;
|
private int scrollableLength = 0;
|
||||||
private SavedState mSavedState;
|
private SavedState mSavedState;
|
||||||
private boolean isFirstLayout = true;
|
private boolean isFirstLayout = true;
|
||||||
|
private boolean scrollEnabled = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* True when the layout has changed but the traversal has not come through yet.
|
* True when the layout has changed but the traversal has not come through yet.
|
||||||
@@ -48,6 +50,33 @@ public class VerticalScrollView extends ScrollView {
|
|||||||
return this.scrollableLength;
|
return this.scrollableLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean getScrollEnabled() {
|
||||||
|
return this.scrollEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setScrollEnabled(boolean value) {
|
||||||
|
this.scrollEnabled = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
||||||
|
// Do nothing with intercepted touch events if we are not scrollable
|
||||||
|
if (!this.scrollEnabled) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.onInterceptTouchEvent(ev);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onTouchEvent(MotionEvent ev) {
|
||||||
|
if (!this.scrollEnabled && ev.getAction() == MotionEvent.ACTION_DOWN) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.onTouchEvent(ev);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void requestLayout() {
|
public void requestLayout() {
|
||||||
this.mIsLayoutDirty = true;
|
this.mIsLayoutDirty = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user