Skip to content

[RTM] Removed dependency on setScrollableView**() #636

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
3 changes: 1 addition & 2 deletions demo/res/layout/activity_demo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
sothree:umanoShadowHeight="4dp"
sothree:umanoParallaxOffset="100dp"
sothree:umanoDragView="@+id/dragView"
sothree:umanoOverlay="true"
sothree:umanoScrollableView="@+id/list">
sothree:umanoOverlay="true">

<!-- MAIN CONTENT -->
<FrameLayout
Expand Down
1 change: 0 additions & 1 deletion library/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
<attr name="umanoFadeColor" format="color" />
<attr name="umanoFlingVelocity" format="integer" />
<attr name="umanoDragView" format="reference" />
<attr name="umanoScrollableView" format="reference" />
<attr name="umanoOverlay" format="boolean"/>
<attr name="umanoClipPanel" format="boolean"/>
<attr name="umanoAnchorPoint" format="float" />
Expand Down
63 changes: 0 additions & 63 deletions library/src/com/sothree/slidinguppanel/ScrollableViewHelper.java

This file was deleted.

54 changes: 21 additions & 33 deletions library/src/com/sothree/slidinguppanel/SlidingUpPanelLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,6 @@ public class SlidingUpPanelLayout extends ViewGroup {
*/
private int mDragViewResId = -1;

/**
* If provided, the panel will transfer the scroll from this view to itself when needed.
*/
private View mScrollableView;
private int mScrollableViewResId;
private ScrollableViewHelper mScrollableViewHelper = new ScrollableViewHelper();

/**
* The child view that can slide, if any.
*/
Expand Down Expand Up @@ -327,7 +320,6 @@ public SlidingUpPanelLayout(Context context, AttributeSet attrs, int defStyle) {
mCoveredFadeColor = ta.getColor(R.styleable.SlidingUpPanelLayout_umanoFadeColor, DEFAULT_FADE_COLOR);

mDragViewResId = ta.getResourceId(R.styleable.SlidingUpPanelLayout_umanoDragView, -1);
mScrollableViewResId = ta.getResourceId(R.styleable.SlidingUpPanelLayout_umanoScrollableView, -1);

mOverlayContent = ta.getBoolean(R.styleable.SlidingUpPanelLayout_umanoOverlay, DEFAULT_OVERLAY_FLAG);
mClipPanel = ta.getBoolean(R.styleable.SlidingUpPanelLayout_umanoClipPanel, DEFAULT_CLIP_PANEL_FLAG);
Expand Down Expand Up @@ -383,9 +375,6 @@ protected void onFinishInflate() {
if (mDragViewResId != -1) {
setDragView(findViewById(mDragViewResId));
}
if (mScrollableViewResId != -1) {
setScrollableView(findViewById(mScrollableViewResId));
}
}

public void setGravity(int gravity) {
Expand Down Expand Up @@ -570,24 +559,6 @@ public void setDragView(int dragViewResId) {
setDragView(findViewById(dragViewResId));
}

/**
* Set the scrollable child of the sliding layout. If set, scrolling will be transfered between
* the panel and the view when necessary
*
* @param scrollableView The scrollable view
*/
public void setScrollableView(View scrollableView) {
mScrollableView = scrollableView;
}

/**
* Sets the current scrollable view helper. See ScrollableViewHelper description for details.
* @param helper
*/
public void setScrollableViewHelper(ScrollableViewHelper helper) {
mScrollableViewHelper = helper;
}

/**
* Set an anchor point where the panel can stop during sliding
*
Expand Down Expand Up @@ -974,17 +945,16 @@ public boolean dispatchTouchEvent(@NonNull MotionEvent ev) {
float dy = y - mPrevMotionY;
mPrevMotionY = y;

// If the scroll view isn't under the touch, pass the
// event along to the dragView.
if (!isViewUnder(mScrollableView, (int) mInitialMotionX, (int) mInitialMotionY)) {
// If the slidable view isn't under the touch, pass the event.
if (!isViewUnder(mSlideableView, (int) mInitialMotionX, (int) mInitialMotionY)) {
return super.dispatchTouchEvent(ev);
}

// Which direction (up or down) is the drag moving?
if (dy * (mIsSlidingUp ? 1 : -1) > 0) { // Collapsing
// Is the child less than fully scrolled?
// Then let the child handle it.
if (mScrollableViewHelper.getScrollableViewScrollPosition(mScrollableView, mIsSlidingUp) > 0) {
if (canScrollVertically(mSlideableView, mInitialMotionX, mInitialMotionY, mIsSlidingUp ? -1 : 1)) {
mIsScrollableViewHandlingTouch = true;
return super.dispatchTouchEvent(ev);
}
Expand Down Expand Up @@ -1035,6 +1005,24 @@ public boolean dispatchTouchEvent(@NonNull MotionEvent ev) {
return super.dispatchTouchEvent(ev);
}

private boolean canScrollVertically(View view, float x, float y, int direction) {
if (view instanceof ViewGroup) {
ViewGroup vg = (ViewGroup) view;
for (int i = 0; i < vg.getChildCount(); i++) {
View child = vg.getChildAt(i);
int childLeft = child.getLeft();
int childTop = child.getTop();
int childRight = child.getRight();
int childBottom = child.getBottom();
boolean intersects = x > childLeft && x < childRight && y > childTop && y < childBottom;
if (intersects && canScrollVertically(child, x - childLeft, y - childTop, direction)) {
return true;
}
}
}
return ViewCompat.canScrollVertically(view, direction);
}

private boolean isViewUnder(View view, int x, int y) {
if (view == null) return false;
int[] viewLocation = new int[2];
Expand Down