daimajia / daimajia/AndroidSwipeLayout

onTouchEvent exits prematurely if the SwipeLayout is not the root AdapterView item

Open
#54 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
12.3k
Forks
2.6k
PR merge metrics
No merged PRs in 30d

Description

Inside **SwipeLayout.onTouchEvent()** there is a check called **isEnabledInAdapterView()** which will return false if the SwipeLayout instance is inside an **AdapterView**.

``` java
public boolean onTouchEvent(MotionEvent event)
{
if(!isEnabledInAdapterView() || !isEnabled())
return true;
...
```

This is because inside i_sEnabledInAdapterView()_, _getPositionForView()_ will be looking for
a direct child of the list; it expects the SwipeLayout instance to be the root element which is not always the case.

``` java
private boolean isEnabledInAdapterView(){
AdapterView adapterView = getAdapterView();
boolean enable = true;
if(adapterView != null){
Adapter adapter = adapterView.getAdapter();
if(adapter != null){
int p = adapterView.getPositionForView(SwipeLayout.this);
if(adapter instanceof BaseAdapter){
enable = ((BaseAdapter) adapter).isEnabled(p);
}else if(adapter instanceof ListAdapter){
enable = ((ListAdapter) adapter).isEnabled(p);
}
}
}
return enable;
}
```

Simply returning **true** always here solves the problem. It is also going to make touch events faster, because there is no recursive calls to find the parent (which occurs for every touch!).

Right now we have a "hard" patch to just return _true_ for **isEnabledInAdapterView()**. It would be useful if all private methods could be protected instead so that behavior can be customized when needed. Thanks for the great library!

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.