Giter Club home page Giter Club logo

Comments (14)

miguelhincapie avatar miguelhincapie commented on May 18, 2024 1

ohhh I get it!
I have same problem in a big project... I was thinking it was something wrong in my code (I'm using deep link) to open some views with this lib and I'm facing same problem.

I know about some bugs related to resizing original bottomsheet and the works around it, but I have not found anything for this one you are showing.

If you take a look when the components get "refreshed", you will see its happening when you hide/unhide any item.
Next code is what I'm using when I'm changing the content of the bottomsheet cuz a weird bug related to original BottomSheet.

        ViewTreeObserver observer = bottom_sheet_principal_container.getViewTreeObserver();
        observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                fixBottomSheetHeight();
                if (bottom_sheet_principal_container == null)
                    return;
                bottom_sheet_sucursal_principal_container.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            }
        });
private void fixBottomSheetHeight() {
        if (reciclerview == null)
            return;
        Display display = getActivity().getWindowManager().getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);
        int height = size.y;

        ViewGroup.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) reciclerview.getLayoutParams();

        if (bottom_sheet_principal_container.getHeight() < height)
            p.setMargins(p.leftMargin, p.topMargin, p.rightMargin, p.bottomMargin + (height - bottom_sheet_principal_container.getHeight()));
        else
            p.setMargins(p.leftMargin, p.topMargin, p.rightMargin, getResources().getDimensionPixelSize(R.dimen.term_cond_text_margin));

        reciclerview.requestLayout();
    }

Let's find whats going on xD.

from custombottomsheetbehavior.

ZherebtsovAlexandr avatar ZherebtsovAlexandr commented on May 18, 2024 1

This hack works http://stackoverflow.com/a/35804525/1890996

I using now

I click button for showing bottom sheet

btnShowBottomSheet.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                FragmentManager fragmentManager = getSupportFragmentManager();

                if (fragmentManager.getBackStackEntryCount() > 0) {
                    fragmentManager.popBackStackImmediate();
                    fragmentManager
                            .beginTransaction()
                            .replace(R.id.bottom_sheet_fragment, TestFragment.newInstance("From runtime"))
                            .addToBackStack(null)
                            .commit();
                } else {
                    fragmentManager
                            .beginTransaction()
                            .replace(R.id.bottom_sheet_fragment, TestFragment.newInstance("From runtime"))
                            .commit();
                }


                behavior.setState(BottomSheetBehaviorGoogleMapsLike.STATE_COLLAPSED);
            }
        });

And mannually call onLayoutChild in callback :

 behavior.addBottomSheetCallback(new BottomSheetBehaviorGoogleMapsLike.BottomSheetCallback() {
            @Override
            public void onStateChanged(@NonNull View bottomSheet, int newState) {
                switch (newState) {
                     ...
                    case BottomSheetBehaviorGoogleMapsLike.STATE_COLLAPSED:
                        Log.d("bottomsheet-", "STATE_COLLAPSED");
                        bottomSheet.requestLayout();
                        behavior.onLayoutChild(coordinatorLayout, bottomSheet, ViewCompat.LAYOUT_DIRECTION_LTR);
                        break;
                     ...
                }
            }

        });

from custombottomsheetbehavior.

miguelhincapie avatar miguelhincapie commented on May 18, 2024

Hello,
We wanted to keep sample project easy to understand how to use the lib, but in real life you usually use a Fragment like you are trying.

You can use something like this:

            android:id="@+id/bottom_sheet_fragment"
            android:name="xx.xxx.BottomSheetFragment_"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            tools:layout="@layout/bottom_sheet_content" />

the _ at the end of xx.xxx.BottomSheetFragment is because I took it from a real project in where I'm using Android Annotations.

from custombottomsheetbehavior.

ZherebtsovAlexandr avatar ZherebtsovAlexandr commented on May 18, 2024

@miguelhincapie thank you for quick answer! Do yo mean use:

<fragment
            android:id="@+id/bottom_sheet_fragment"
            android:name="xx.xxx.BottomSheetFragment_"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            tools:layout="@layout/bottom_sheet_content" />

But how can I pass some parameters to the fragment, for example?

BottomSheetFragment.newInstance(param1, param2)

from custombottomsheetbehavior.

miguelhincapie avatar miguelhincapie commented on May 18, 2024

Yeah! you can handle the fragment like any simple fragment, this Lib doesn't care about or don't touch anything about the content inside "include" or "fragment". I mean this library only cares about 3 things:

  1. BottomSheet got anchor_point state
  2. Parallax effect in the backdrop (image, view, viewpager, etc)
  3. The 2 appbarlayout the app shows depends on the current bottomsheet's state.

You can do what you said before: .replace(R.id.bottom_sheet_content, TestFragment.newInstance());

If you get stuck trying it I can upload a more detailed sample to the project showing it... but I trusth you can do it ;)

from custombottomsheetbehavior.

ZherebtsovAlexandr avatar ZherebtsovAlexandr commented on May 18, 2024

Thank you!
I'll try to make a fork of the library and show the problem. I think it is not related with the BottomSheetBehaviorGoogleMapsLike. The problem is that if NestedScrollView will be created with an empty View (container for fragment) and after add fragment to the View (by button click) then will not works correct (View doesn't render fragment content). But if add fragment in onViewCreated method then all works correct.

from custombottomsheetbehavior.

ZherebtsovAlexandr avatar ZherebtsovAlexandr commented on May 18, 2024

I created fork and reproduced problem described above you can see my code to understand the problem.

Code:
https://github.com/ZherebtsovAlexandr/CustomBottomSheetBehavior/blob/master/app/src/main/java/co/com/parsoniisolutions/custombottomsheetbehavior/sample/MainActivity.java#L108

See short giff:

device-2017-01-16-011608

from custombottomsheetbehavior.

miguelhincapie avatar miguelhincapie commented on May 18, 2024

By the way, have you tried using

.post(new Runnable() {...

when you are swiping/adding new fragment?

from custombottomsheetbehavior.

ZherebtsovAlexandr avatar ZherebtsovAlexandr commented on May 18, 2024

@miguelhincapie not tried, I added fragment in main thread. What give this?

from custombottomsheetbehavior.

ZherebtsovAlexandr avatar ZherebtsovAlexandr commented on May 18, 2024

Issue related with onLayoutChild method, i have noticed that parent.onLayoutChild(child, layoutDirection); doesn't call after added fragment.

from custombottomsheetbehavior.

miguelhincapie avatar miguelhincapie commented on May 18, 2024

Well being hack or not if it works I will use it too hahahaha. I need it for the current app I'm finishing.

from custombottomsheetbehavior.

miguelhincapie avatar miguelhincapie commented on May 18, 2024

Have you seen Recent Support Library Revisions? they are talking about Fragment transactions. I'm gonna take a look at it to see if that can help us

from custombottomsheetbehavior.

MelnykovOleksii avatar MelnykovOleksii commented on May 18, 2024

Place this solution in the example! This will greatly help those who will use this library.

from custombottomsheetbehavior.

miguelhincapie avatar miguelhincapie commented on May 18, 2024

At this I'm full time with some personal project, I will do it when I can or if you can do it, I appreciate it.

from custombottomsheetbehavior.

Related Issues (20)

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.