Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TIMOB-11820: Android: ScrollableView in ScrollView is not working #3558

Merged
merged 4 commits into from
Jan 31, 2013
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@

import android.content.Context;
import android.graphics.Canvas;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -40,26 +38,16 @@ public class TiUIScrollView extends TiUIView
private boolean setInitialOffset = false;
private boolean mScrollingEnabled = true;

private class TiScrollViewLayout extends TiCompositeLayout
public class TiScrollViewLayout extends TiCompositeLayout
{
private static final int AUTO = Integer.MAX_VALUE;
private int parentWidth = 0;
private int parentHeight = 0;
private boolean canCancelEvents = true;
private GestureDetector gestureDetector;

public TiScrollViewLayout(Context context, LayoutArrangement arrangement)
{
super(context, arrangement, proxy);
gestureDetector = new GestureDetector(new SimpleOnGestureListener()
{
@Override
public void onLongPress(MotionEvent e)
{
// Only do this for long presses to match iOS behavior
requestDisallowInterceptTouchEvent(true);
}
});
}

public void setParentWidth(int width)
Expand All @@ -81,10 +69,11 @@ public void setCanCancelEvents(boolean value)
public boolean dispatchTouchEvent(MotionEvent ev)
{
// If canCancelEvents is false, then we want to prevent the scroll view from canceling the touch
// events of the child view by calling requestDisallowInterceptTouchEvent(true)
// events of the child view
if (!canCancelEvents) {
gestureDetector.onTouchEvent(ev);
requestDisallowInterceptTouchEvent(true);
}

return super.dispatchTouchEvent(ev);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.appcelerator.titanium.view.TiUIView;

import ti.modules.titanium.ui.ScrollableViewProxy;
import ti.modules.titanium.ui.widget.TiUIScrollView.TiScrollViewLayout;
import android.app.Activity;
import android.content.Context;
import android.os.Parcelable;
Expand Down Expand Up @@ -538,6 +539,27 @@ public boolean onTrackballEvent(MotionEvent event)
return super.onTrackballEvent(event);
}

@Override
public boolean dispatchTouchEvent(MotionEvent ev)
{
// If the parent is a scroll view, then we prevent the scroll view from intercepting touch events
if (this.getParent() instanceof TiScrollViewLayout) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should probably just call getParent().

int action = ev.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
requestDisallowInterceptTouchEvent(true);
break;

case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
requestDisallowInterceptTouchEvent(false);
break;

}
}
return super.dispatchTouchEvent(ev);
}

@Override
public boolean dispatchKeyEvent(KeyEvent event)
{
Expand Down
10 changes: 7 additions & 3 deletions apidoc/Titanium/UI/ScrollView.yml
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,13 @@ events:

properties:
- name: canCancelEvents
summary: |
Determines whether this scroll view can cancel subview touches in order to scroll instead.
description: Set to `false` to ensure that subview touches always take effect.
summary: Determines whether this scroll view can cancel subview touches in order to scroll instead.
description: |
On iOS, this property maps to the native `canCancelContentTouches` property which controls
whether touches in the content view always lead to tracking. See [UIScrollView](http://developer.apple.com/library/ios/#documentation/uikit/reference/UIScrollView_Class/Reference/UIScrollView.html) for more details.

On Android, setting this property to false prevents the scroll view from intercepting
any touch events from its subviews. Note that this behavior may be slightly different from iOS.
type: Boolean
default: true
platforms: [android, iphone, ipad]
Expand Down