Coder Social home page Coder Social logo

miguelhincapie / custombottomsheetbehavior Goto Github PK

View Code? Open in Web Editor NEW
910.0 23.0 186.0 8.07 MB

Custom BottomSheetBehavior for Android that mimic Google Maps behavior

License: Apache License 2.0

Java 100.00%
android bottomsheetbehavior parallax-image google-maps stackoverflow

custombottomsheetbehavior's People

Contributors

akan44 avatar bmc08gt avatar hannesaa2 avatar jesusdmedinac avatar manufunk avatar michael-rapp avatar miguelhincapie avatar prat-z avatar veerenmandalia avatar vit001 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

custombottomsheetbehavior's Issues

The best way dynamically add fragment to NestedScrollView?

For example, instead

   <include
                layout="@layout/bottom_sheet_content"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true" />

Use

            <FrameLayout
                 android:id="@+id/bottom_sheet_content"
                 android:layout_width="match_parent"
                 android:layout_height="match_parent"
                 android:fitsSystemWindows="true" />

and commit fragment, for example by button click

TestFragment testFragment = (TestFragment) getSupportFragmentManager()
                        .findFragmentById(R.id.bottom_sheet_content);

                FragmentTransaction transaction = getSupportFragmentManager()
                        .beginTransaction()
                        .replace(R.id.bottom_sheet_content, TestFragment.newInstance());

                transaction.commit();

Right now in sample it works incorrect.

BackdropBottomSheetBehavior.onDependentViewChanged return value bug

I have seen a rare bug where the Backdrop freezes and doesn't scroll along with the bottom sheet. I believe the bug has to do with the return value of the BackdropBottomSheetBehavior.onDependentViewChanged.
Per docs: "If the Behavior changes the child view's size or position, it should return true. The default implementation returns false."
The implementation in this lib returns true if the size or position DO NOT change, and false with the DO change.

SecondAppBarLayoutBehavior improvement

I re-developed the SecondAppBarLayoutBehavior to mimic the exact Google behavior. I'll clean the code and push it as soon as possible. Here is a preview.
2016_07_27_17_49_54_17_51_11

Very sensitive scroll when use anchor point

When set anchor point - it has very sensitive scroll. It's easy to scroll to expanded state without stoping on anchored. Can I make it less sensitive or stop when use scroll to anchored state?

Sliding down from STATE_COLLAPSED does not hide the bottomsheet

Hi, I would like to know how I can fix this problem.
If my bottomsheet is currently STATE_COLLAPSED, scrolling down does NOT hide it.
If my bottomsheet is currently STATE_ANCHOR_POINT, scrolling down ON THE VIEWPAGER will hide it.

I cloned this sample project and it seems that is has the same issue, even if the bottomsheet is hideable (app:behavior_hideable="true"), on scrolling down by TOUCHING THE VIEWPAGER will hide the bottomsheet.

Bottom Sheet should have touchSlop

To mimic Google Maps behavior, the Bottom Sheet should have touch slop as provided by ViewConfiguration.getTouchSlop(). Currently, there is zero touchSlop which makes the scroll behavior too sensitive and jittery.

I am stumped by this one - anyone have ideas?

Scrolling down view pager is scrolling the bottomsheet as well, how ?

@miguelhincapie How is it that when scrolling down the sliding view pager, the bottomsheet scrolls aswell ?
I'm working on a project that is using a very similar bottomsheet and in my case, scrolling the backdrop view down is not affecting my bottom sheet.
I do not understand how it works in your case, could you explain it ? Is the "scrollable part" of the bottom sheet extended or something like this ?

Thank you for your answer.

TODO

TODO:

  1. MergedAppBarLayoutBehavior still not showing properly when
    BottomSheet starts in EXPANDED mode.

  2. ScrollingAppBarLayoutBehavior not showing properly the status bar if
    you start the BottomSheet in STATE_COLLAPSED.

  3. If BottomSheet content’s height is smaller than screen height, when
    you scroll the BottomSheet (going to expand mode) you can see the
    map/background behind BottomSheet element.

Allow dragging BottomSheet by grabbing FAB

It should be possible to grab the upper half of the Floating Action Button and drag the BottomSheet with it, in order to match Google Maps app behavior. Right now it is possible to grab the lower half of the FAB only.

Allow dragging BottomSheet by grabbing Backdrop

Google Maps allows you to scroll the BottomSheet vertically by grabbing and dragging the Backdrop. Lib is missing this functionality. What do you figure is the best way to implement this?

mLastStableState was not set on setState

Hi, thank you so much for this project.

I had a issue when setting state directly with setState, and it seems the mLastStableState was not set on this line: https://github.com/miguelhincapie/CustomBottomSheetBehavior/blob/master/app/src/main/java/co/com/parsoniisolutions/custombottomsheetbehavior/lib/BottomSheetBehaviorGoogleMapsLike.java#L563

What happens is when we set the state directly from expand to collapse, and starting dragging again, the bottom sheet makes a "hard jump" expanding like crazy, this happens on the sample project when we press the navigation close icon.

I've solved by moving the assignment out of the if (mViewRef == null) statement, but i'm still not sure about that, i just would like to point that, and hear this from you, and others who having this issue.

i am currently integrating this awesome project with react-native (react-native-bottom-sheet-behavior), but this isn't related though.

Thank you.

License?

This project is a great example!

Could you please add an open-source license to the project?

I'd prefer Apache 2.0 if possible. Thanks!

How can I hide ButtomSheet

Hi,
How can I hide ButtomSheet in activity?I used this code

behavior.setState(BottomSheetBehaviorGoogleMapsLike.STATE_HIDDEN);

But does not change it..thanks

How to prevent STATE_COLLAPSED and STATE_HIDDEN?

Hi, I want to only have STATE_ANCHOR_POINT and STATE_EXPANDED. Means the STATE_ANCHOR_POINT is my default state and I want users to only scroll up to STATE_EXPANDED and back again to STATE_ANCHOR_POINT.

Is there any way to achieve this?

main status bar color

hi

you seem to be changing the color of the system status bar to blue. How do I disable that? Why would the library want to do that anyway?

Viewpageer behavior wrong when set state is STATE_HIDDEN

I want to hide bottom sheet when activity create, so I set state as STATE_HIDDEN in onCreate() function
CoordinatorLayout coordinatorLayout = (CoordinatorLayout) findViewById(R.id.coordinatorlayout);
View bottomSheet = coordinatorLayout.findViewById(R.id.bottom_sheet);
behavior = BottomSheetBehaviorGoogleMapsLike.from(bottomSheet);
behavior.setState(BottomSheetBehaviorGoogleMapsLike.STATE_HIDDEN);
But I got the this issue. Check out image : https://goo.gl/M8bKpk
When I set state as STATE_COLLAPSED onCreate() funtion, it works fine.

BottomSheet collapse bug

Hi - great lib!!
I ran into the following bug:

  1. Fully expand the bottom sheet
  2. Scroll the bottom sheet up
  3. Collapse the bottom sheet using the X toolbar icon
    Bug: the Bottom sheet doesn't scroll to the top. Please see video: https://vimeo.com/200454784

In some real devices MergedAppBarLayoutBehavior doesn't work properly

Is a weird case when the MergedAppBarLayoutBehavior can't complete or animate through Y. I mean, when you are in the setToolbarVisible() method you set child.setY(-child.getHeight()/3), the animations update the Y value but visually you see the AppBarLayout still in child.setY(-child.getHeight()/3) position.
Work around: comment child.setY(-child.getHeight()/3); line of code.

Fix for bottom sheet fling/snap/settle bugs

There are several bugs related to snapping back to the anchor state:

  1. In Google Maps the anchor state is sticky - the Backdrop Element needs to be pulled down at least 50% before the Bottom Sheet collapses. If it is pulled less than 50% the Bottom Sheet snaps back to the anchor. The behavior of the lib is different - as soon as the Backdrop Element is pulled down even a tiny amount and released, the Bottom Sheet collapses rather than snapping back. Please see video:
    https://vimeo.com/200534893

  2. Similarly to 1), going from anchor state to expanded should require making the Backdrop half-way shut. Currently dragging up from anchor state by an infinitesimal amount and the lifting the finger is enough to expand the Bottom Sheet. Please see video:
    https://vimeo.com/200536226

  3. Current lib behavior does not take fling velocity into account.

  4. Current lib behavior does not force stop at anchor state.

Pull request for all fixes here. Please let me know if you come across any bug with this.
#27

Could not inflate behaviour subclass

I am using this library in my project and when I run my application then got this error.

Could not inflate behaviour subclass package name...

please help me to solve this error

Content does not display correctly after changing the text

Hi, Thank for sharing this

I have a problem changing the default text. After changing the text, it appears that it does not display it correctly with wrap_content not updating to the correct size and the default cheese image does not appear. Do you have any idea?

FATAL error on Viewdragger helper

I have got an exception : Attempt to invoke virtual method 'void android.support.v4.widget.ViewDragHelper.processTouchEvent(android.view.MotionEvent)' on a null object reference

Do you have any suggestion to solve this problem?

Shows wrong content position after close button click (STATE_EXPANDED to STATE_COLLAPSED)

I have a lot of text inside the content part and if I open the bottom part to STATE_EXPANDED, scroll to some lower lines of the text and then click the close (back) button in toolbar the view changes it's state to STATE_COLLAPSED but I don't see buttons at the top. Instead I see my text. See attached video.

I tried to catch STATE_COLLAPSED in onStateChanged and scoll manually by nestedScrollView.post(() -> nestedScrollView.fullScroll(View.FOCUS_UP)); but it not always work.
Instead if I use this in STATE_SETTLING it works well every time but very slows down the graphics and hangs the animation as well.

https://www.dropbox.com/s/uba3vokrlnypgma/CustomBottomSheetBehavior_bug.mp4?dl=0

crash with compile sdk version

I get this crash when i updated compile sdk version.

java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v4.widget.ViewDragHelper.processTouchEvent(android.view.MotionEvent)' on a null object reference
        at com.mahc.custombottomsheetbehavior.BottomSheetBehaviorGoogleMapsLike.onTouchEvent(BottomSheetBehaviorGoogleMapsLike.java:288)
        at android.support.design.widget.CoordinatorLayout.resetTouchBehaviors(CoordinatorLayout.java:396)
        at android.support.design.widget.CoordinatorLayout.onAttachedToWindow(CoordinatorLayout.java:238)
        at android.view.View.dispatchAttachedToWindow(View.java:16718)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3151)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3158)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3158)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3158)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3158)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3158)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1823)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1537)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7183)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:959)
        at android.view.Choreographer.doCallbacks(Choreographer.java:734)
        at android.view.Choreographer.doFrame(Choreographer.java:670)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:945)
        at android.os.Handler.handleCallback(Handler.java:751)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6776)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1518)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)

Additional bugfixes for fling

Issue: We track fling velocity in BottomSheetBehaviorGoogleMapsLike.onInterceptTouchEvent.

Problem: BottomSheetBehaviorGoogleMapsLike.onInterceptTouchEvent will stop being called after a child of BottomSheet consumes any scroll (e.g. main content listview), until the next MotionEvent.ACTION_DOWN, so we loose track of fling. onNestedScroll continues to be called.

Solution: Track fling in onNestedPreScroll. (onNestedPreFling doesn't work, as it doesn't get called if fling is initiated from child in expanded state. This is a known design lib bug.)


Separate issue: BottomSheet didn't work properly in a scrolling parent (like a horizontal view pager), due to MotionEvent.ACTION_CANCEL potentially triggering a state change. Fixed this as well.

Pull Request: #29

Achieving the same behavior in a fragment?

I have a navigation drawer with fragments where one of the fragments inflates a Google Maps fragment.

Is it possible to achieve the same behaviour when using the same setup as i do?

Achieve as a seprate activity

Hi,
I noticed that If I want to use this view I have to use it in a new activity, Is there any way to run it on existing activity?I mean if we have an existing activity when our new activiry with Bottonsheet behaviour runs it covers other activity, even when it is collapesed. Here I want that this activiy runs and we can out back activity too.Is it possible?

Google Map View does not adapt/scale

Is it normal that the bottom sheet just slides over the google maps v2 view, and that the map does not adapt/scale on slide? My map stays always the same size and so when sliding the bottom sheet up I only see a fraction of the map.
Bug? or issue on my side?

Bad position for backdrop image when starting in STATE_ANCHOR_POINT state

Sup @akaN44,
I'm implementing our developer in another project and I found this issue:
Lets say I have 2 activities, A and B. In B I implemented the CustomBottomSheetBehavior, so if I start activity B from A setting the state (setState(BottomSheetBehaviorGoogleMapsLike.STATE_ANCHOR_POINT)) the backdrop image doesn't start in the correct position. It's starting like if it was in STATE_COLLAPSED state.

I will give a look at this soon or late because I need it for the app that I'm developing but if you can give me a hand with this I will appreciate it so much!

Using in Scroling Activity and an empty space behind toolbar

Hi,
I have a problem. in an scrooling activity I face this problem.
photo514363939500435620

As you can see behind toolbar is empty. This is because I have added some margin top to make my list's top visable. Is there any way t connect list's margin top to the amount of moving bottomsheet and when It moves up decrease margin value to and when it moves down increase it?or is there any better way ?
thanks

How to disable third step (STATE_EXPANDED)?

Hi,

I don't need the feature to have three steps. I want to stop at STATE_ANCHOR_POINT step without another scrolling step to STATE_EXPANDED status.
Is there a quick way how to disable it?

Regards,
Manu

Give shadow to top edge of collapsed bottom sheet

The Google Maps app has a shadow above the bottom sheet when it is in collapsed state. Any ideas on how to implement it? I tried the obvious - setting elevation in xml, but without success (shadow is only cast downwards below the bottom sheet, not above). Also no success with ShadowLayout (it cannot paint over the main content behind the bottom sheet.

NullPointerException at 288 line in BottomSheetBehaviorGoogleMapsLike

hi, i just want to test your app without adding code, but i get this error:

FATAL EXCEPTION: main
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v4.widget.ViewDragHelper.processTouchEvent(android.view.MotionEvent)' on a null object reference
at com.mahc.custombottomsheetbehavior.BottomSheetBehaviorGoogleMapsLike.onTouchEvent(BottomSheetBehaviorGoogleMapsLike.java:288)
at android.support.design.widget.CoordinatorLayout.resetTouchBehaviors(CoordinatorLayout.java:389)
at android.support.design.widget.CoordinatorLayout.onAttachedToWindow(CoordinatorLayout.java:235)
at android.view.View.dispatchAttachedToWindow(View.java:15509)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2916)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2923)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2923)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2923)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2923)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2923)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1526)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1254)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6337)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:874)
at android.view.Choreographer.doCallbacks(Choreographer.java:686)
at android.view.Choreographer.doFrame(Choreographer.java:621)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:860)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.