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

TopGravityModifier checks improper values #30

Closed
abuttlemur opened this issue Feb 13, 2017 · 2 comments · May be fixed by #44
Closed

TopGravityModifier checks improper values #30

abuttlemur opened this issue Feb 13, 2017 · 2 comments · May be fixed by #44
Labels

Comments

@abuttlemur
Copy link

Hi
I have a app I've been playing with and had this library on 0.2.3, I just attempted to update to the latest 0.3.7, and receive a crash.

I experience this when I set:

setGravityResolver(new IChildGravityResolver() {
                    @Override
                    public int getItemGravity(int position) { 
                        return Gravity.TOP;
                    }
                })

Using other Gravitys work fine (BOTTOM, CENTER)

From looking in the source i see that the TopGravityModifier class was modified to check the left/right edges of the rect against the minStart and minEnd, whereas the BOTTOM layout checks the top and bottom, and I do not experience the issue using BOTTOM.

class TopGravityModifier implements IGravityModifier {
    TopGravityModifier() {
    }

    public Rect modifyChildRect(int minStart, int maxEnd, Rect childRect) {
        if(childRect.**left** < minStart) {
            throw new IllegalArgumentException("top point of input rect can\'t be lower than minTop");
        } else if(childRect.**right** > maxEnd) {
            throw new IllegalArgumentException("bottom point of input rect can\'t be bigger than maxTop");
        } else {
            childRect = new Rect(childRect);
            if(childRect.top > minStart) {
                childRect.bottom -= childRect.top - minStart;
                childRect.top = minStart;
            }

            return childRect;
        }
    }
}
class BottomGravityModifier implements IGravityModifier {
    BottomGravityModifier() {
    }

    public Rect modifyChildRect(int minStart, int maxEnd, Rect childRect) {
        if(childRect.**top** < minStart) {
            throw new IllegalArgumentException("top point of input rect can\'t be lower than minTop");
        } else if(childRect.**bottom** > maxEnd) {
            throw new IllegalArgumentException("bottom point of input rect can\'t be bigger than maxTop");
        } else {
            Rect modified = new Rect(childRect);
            if(modified.bottom < maxEnd) {
                modified.top += maxEnd - modified.bottom;
                modified.bottom = maxEnd;
            }

            return modified;
        }
    }
}

I'm not certain that this is a mistake, but it looks fishy. Eitherway something changed and I can't seem to figure out how to use Gravity.TOP again.

The crash I see when using Gravity.TOP is as follows:

FATAL EXCEPTION: main Process: com.foo, PID: 22659 java.lang.IllegalArgumentException: bottom point of input rect can't be bigger than maxTop at com.beloo.widget.chipslayoutmanager.gravity.TopGravityModifier.modifyChildRect(TopGravityModifier.java:13) at com.beloo.widget.chipslayoutmanager.layouter.AbstractLayouter.applyChildGravity(AbstractLayouter.java:277) at com.beloo.widget.chipslayoutmanager.layouter.AbstractLayouter.layoutRow(AbstractLayouter.java:250) at com.beloo.widget.chipslayoutmanager.ChipsLayoutManager.fillWithLayouter(ChipsLayoutManager.java:893) at com.beloo.widget.chipslayoutmanager.ChipsLayoutManager.fill(ChipsLayoutManager.java:821) at com.beloo.widget.chipslayoutmanager.ChipsLayoutManager.onLayoutChildren(ChipsLayoutManager.java:719) at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3535) at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3264) at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3796) at android.view.View.layout(View.java:16694) at android.view.ViewGroup.layout(ViewGroup.java:5481) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336) at android.widget.FrameLayout.onLayout(FrameLayout.java:273) at android.view.View.layout(View.java:16694) at android.view.ViewGroup.layout(ViewGroup.java:5481) at android.support.v4.view.ViewPager.onLayout(ViewPager.java:1795) at android.view.View.layout(View.java:16694) at android.view.ViewGroup.layout(ViewGroup.java:5481) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586) at android.widget.LinearLayout.onLayout(LinearLayout.java:1495) at android.view.View.layout(View.java:16694) at android.view.ViewGroup.layout(ViewGroup.java:5481) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336) at android.widget.FrameLayout.onLayout(FrameLayout.java:273) at android.view.View.layout(View.java:16694) at android.view.ViewGroup.layout(ViewGroup.java:5481) at com.android.internal.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:493) at android.view.View.layout(View.java:16694) at android.view.ViewGroup.layout(ViewGroup.java:5481) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336) at android.widget.FrameLayout.onLayout(FrameLayout.java:273) at com.android.internal.policy.PhoneWindow$DecorView.onLayout(PhoneWindow.java:2697) at android.view.View.layout(View.java:16694) at android.view.ViewGroup.layout(ViewGroup.java:5481) at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2228) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1981) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1140) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6232) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858) at android.view.Choreographer.doCallbacks(Choreographer.java:670) at android.view.Choreographer.doFrame(Choreographer.java:606) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5551) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)

@BelooS BelooS added the bug label Feb 20, 2017
@magneticflux-
Copy link

magneticflux- commented Jun 19, 2017

I encountered the same problem using version 0.3.7.

@BelooS
Copy link
Owner

BelooS commented Aug 28, 2017

A silly mistake and have been staying for so long. Will be released soon according to magneticflux pr.

@BelooS BelooS closed this as completed Aug 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants