Comments (14)
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.
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.
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.
@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.
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:
- BottomSheet got anchor_point state
- Parallax effect in the backdrop (image, view, viewpager, etc)
- 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.
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.
I created fork and reproduced problem described above you can see my code to understand the problem.
See short giff:
from custombottomsheetbehavior.
By the way, have you tried using
.post(new Runnable() {...
when you are swiping/adding new fragment?
from custombottomsheetbehavior.
@miguelhincapie not tried, I added fragment in main thread. What give this?
from custombottomsheetbehavior.
Issue related with onLayoutChild method, i have noticed that parent.onLayoutChild(child, layoutDirection); doesn't call after added fragment.
from custombottomsheetbehavior.
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.
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.
Place this solution in the example! This will greatly help those who will use this library.
from custombottomsheetbehavior.
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)
- NullPointerException at 288 line in BottomSheetBehaviorGoogleMapsLike HOT 20
- How to prevent STATE_COLLAPSED and STATE_HIDDEN? HOT 3
- main status bar color HOT 2
- crash with compile sdk version HOT 6
- The view is not associated with BottomSheetBehaviorGoogleMapsLike
- FATAL error on Viewdragger helper HOT 1
- How do I change MargedAppBarLayout's TitleTextColor?
- to vit001: How do I use your CustomBottomSheetBehavior custom lib (with your own viewpager)? HOT 4
- Parallax effect and Merged AppBar problems HOT 7
- Wrong behavior when the keyboard is shown
- What to do if PeekHeight > ToolbarHeight + StatusBarHeight
- crash with sdk 28 HOT 2
- Backdrop View is not showing properly in some cases, it doesn't animate to Anchor point.
- Header card should completely hide behind Toolbar
- Use in Kotlin has an error
- how to add custom view Toolbar when set STATE_EXPANDED
- Anchor Point state is not proper when it is set to 156dp
- Disable dragging on BackdropBottomSheetBehavior
- Clashing in defaultState attribute naming with ConstraintLayout 2.0 HOT 2
- Could not find com.mahc.custombottomsheetbehavior:googlemaps-like:0.9.4. in Gradle 7.2 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from custombottomsheetbehavior.