Skip to content

Commit

Permalink
Added disable swipe function
Browse files Browse the repository at this point in the history
  • Loading branch information
zerobranch committed May 10, 2019
1 parent e29ccbf commit 66488ed
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ android {
dependencies {
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.github.ArmanSar:SwipeLayout:1.0.9'
implementation 'com.github.ArmanSar:SwipeLayout:1.0.10'
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ public class SwipeLayout extends FrameLayout {
*/
private boolean isTogether;

/**
* Is enabled Swipe
*/
private boolean isEnabledSwipe;

/**
* Swipe to the end of the screen.
* Can work without a secondary view {@link #staticLeftView} and {@link #staticRightView}
Expand Down Expand Up @@ -133,6 +138,7 @@ public SwipeLayout(Context context, AttributeSet attrs) {
isFreeHorizontalDrag = typedArray.getBoolean(R.styleable.SwipeLayout_isFreeHorizontalDrag, false);
isContinuousSwipe = typedArray.getBoolean(R.styleable.SwipeLayout_isContinuousSwipe, false);
isTogether = typedArray.getBoolean(R.styleable.SwipeLayout_isTogether, false);
isEnabledSwipe = typedArray.getBoolean(R.styleable.SwipeLayout_isEnabledSwipe, true);
staticLeftViewId = typedArray.getResourceId(R.styleable.SwipeLayout_leftItem, 0);
staticRightViewId = typedArray.getResourceId(R.styleable.SwipeLayout_rightItem, 0);
draggedViewId = typedArray.getResourceId(R.styleable.SwipeLayout_draggedItem, 0);
Expand Down Expand Up @@ -210,6 +216,10 @@ public boolean tryCaptureView(@NonNull View view, int pointerId) {

@Override
public int clampViewPositionHorizontal(@NonNull View child, int left, int dx) {
if (!isEnabledSwipe) {
return CLOSE_POSITION;
}

switch (currentDirection) {
case LEFT:
return clampLeftViewPosition(left);
Expand Down Expand Up @@ -588,8 +598,27 @@ private void moveTo(int x) {
ViewCompat.postInvalidateOnAnimation(this);
}

/**
* Is enabled Swipe
*
* @return True if swipe is enabled, false otherwise.
*/
public boolean isEnabledSwipe() {
return isEnabledSwipe;
}

/**
* Set the enabled swipe.
*
* @param enabledSwipe True if swipe is enabled, false otherwise.
*/
public void setEnabledSwipe(boolean enabledSwipe) {
this.isEnabledSwipe = enabledSwipe;
}

/**
* Performs manual swipe to the left
*
* @param animated - flag to animate opening
*/
public void openRight(boolean animated) {
Expand All @@ -609,6 +638,7 @@ public void openRight(boolean animated) {

/**
* Performs a full manual swipe to the left
*
* @param animated - flag to animate opening
*/
public void openRightCompletely(boolean animated) {
Expand All @@ -629,6 +659,7 @@ public void openRightCompletely(boolean animated) {

/**
* Performs manual swipe to the right
*
* @param animated - flag to animate opening
*/
public void openLeft(boolean animated) {
Expand All @@ -648,6 +679,7 @@ public void openLeft(boolean animated) {

/**
* Performs a full manual swipe to the right
*
* @param animated - flag to animate opening
*/
public void openLeftCompletely(boolean animated) {
Expand All @@ -668,6 +700,7 @@ public void openLeftCompletely(boolean animated) {

/**
* Performs manual close
*
* @param animated - flag to animate closing
*/
public void close(boolean animated) {
Expand Down
1 change: 1 addition & 0 deletions swipelayout/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<flag name="left" value="1"/>
<flag name="right" value="2"/>
</attr>
<attr name="isEnabledSwipe" format="boolean"/>
<attr name="isFreeDragAfterOpen" format="boolean"/>
<attr name="isFreeHorizontalDrag" format="boolean"/>
<attr name="isContinuousSwipe" format="boolean"/>
Expand Down

0 comments on commit 66488ed

Please sign in to comment.