Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[[ Bug 22907 ]] Implement canCancelTouches property of android scroller
This patch implements the `canCancelTouches` property for android scrollers.
Additionally it resolves a regression causing `scrollerBeginDrag` and
`scrollerEndDrag` messages not to be sent.
  • Loading branch information
montegoulding committed Sep 15, 2020
commit 673efea83f7a485bd118599775d5fcb92e0d6f90
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class ScrollerControl extends NativeControl
private boolean m_touch_canceled;
private boolean m_dragging;
private boolean m_tracking;
private boolean m_can_cancel_touches;

public ScrollerControl(NativeControlModule p_module)
{
Expand All @@ -54,6 +55,7 @@ public ScrollerControl(NativeControlModule p_module)
m_dragging = false;
m_tracking = false;
m_touch_canceled = false;
m_can_cancel_touches = false;

m_scrolling_enabled = true;
}
Expand All @@ -80,12 +82,6 @@ public void onScrollChanged(int l, int t, int oldl, int oldt)
ScrollerControl.this.updateScroll(m_dispatching ? m_new_left : m_left, t);
super.onScrollChanged(l, t, oldl, oldt);
}

@Override
public boolean onInterceptTouchEvent (MotionEvent ev)
{
return true;
}
};
m_hscroll = new HorizontalScrollView(p_context) {
@Override
Expand All @@ -95,12 +91,6 @@ public void onScrollChanged(int l, int t, int oldl, int oldt)
ScrollerControl.this.updateScroll(l, m_dispatching ? m_new_top : m_top);
super.onScrollChanged(l, t, oldl, oldt);
}

@Override
public boolean onInterceptTouchEvent (MotionEvent ev)
{
return true;
}
};

m_inner_hview = new View(p_context) {
Expand Down Expand Up @@ -166,7 +156,10 @@ public boolean dispatchTouchEvent(MotionEvent e)
m_dragging = true;
m_tracking = false;
onScrollBeginDrag();
e.setAction(MotionEvent.ACTION_CANCEL);
if (m_can_cancel_touches)
{
e.setAction(MotionEvent.ACTION_CANCEL);
}
}
else
{
Expand All @@ -183,6 +176,11 @@ public boolean dispatchTouchEvent(MotionEvent e)
m_tracking = false;
onScrollEndDrag();
}

if (!m_can_cancel_touches)
{
NativeControlModule.getEngine().onTouchEvent(e);
}
}

return t_hdispatch || t_vdispatch;
Expand Down Expand Up @@ -307,6 +305,16 @@ public void setScrollingEnabled(boolean p_enabled)
{
m_scrolling_enabled = p_enabled;
}

public boolean getCanCancelTouches()
{
return m_can_cancel_touches;
}

public void setCanCancelTouches(boolean p_can_cancel_touches)
{
m_can_cancel_touches = p_can_cancel_touches;
}

public boolean isDragging()
{
Expand Down
20 changes: 19 additions & 1 deletion engine/src/mblandroidscroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ class MCAndroidScrollerControl: public MCAndroidControl
void GetShowHorizontalIndicator(MCExecContext& ctxt, bool& r_value);
void SetShowVerticalIndicator(MCExecContext& ctxt, bool p_value);
void GetShowVerticalIndicator(MCExecContext& ctxt, bool& r_value);
void SetCanCancelTouches(MCExecContext& ctxt, bool p_value);
void GetCanCancelTouches(MCExecContext& ctxt, bool& r_value);

void GetTracking(MCExecContext& ctxt, bool& r_value);
void GetDragging(MCExecContext& ctxt, bool& r_value);
Expand Down Expand Up @@ -109,6 +111,7 @@ MCPropertyInfo MCAndroidScrollerControl::kProperties[] =
DEFINE_RW_CTRL_PROPERTY(P_SHOW_VERTICAL_INDICATOR, Bool, MCAndroidScrollerControl, ShowVerticalIndicator)
DEFINE_RO_CTRL_PROPERTY(P_TRACKING, Bool, MCAndroidScrollerControl, Tracking)
DEFINE_RO_CTRL_PROPERTY(P_DRAGGING, Bool, MCAndroidScrollerControl, Dragging)
DEFINE_RW_CTRL_PROPERTY(P_CAN_CANCEL_TOUCHES, Bool, MCAndroidScrollerControl, CanCancelTouches)
};

MCObjectPropertyTable MCAndroidScrollerControl::kPropertyTable =
Expand Down Expand Up @@ -254,7 +257,22 @@ void MCAndroidScrollerControl::GetScrollingEnabled(MCExecContext& ctxt, bool& r_
if (t_view)
MCAndroidObjectRemoteCall(t_view, "getScrollingEnabled", "b", &r_value);
}

void MCAndroidScrollerControl::SetCanCancelTouches(MCExecContext& ctxt, bool p_value)
{
jobject t_view;
t_view = GetView();

if (t_view)
MCAndroidObjectRemoteCall(t_view, "setCanCancelTouches", "vb", nil, p_value);
}
void MCAndroidScrollerControl::GetCanCancelTouches(MCExecContext& ctxt, bool& r_value)
{
jobject t_view;
t_view = GetView();

if (t_view)
MCAndroidObjectRemoteCall(t_view, "getCanCancelTouches", "b", &r_value);
}
void MCAndroidScrollerControl::SetShowHorizontalIndicator(MCExecContext& ctxt, bool p_value)
{
jobject t_view;
Expand Down