-
Notifications
You must be signed in to change notification settings - Fork 594
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
FragmentSheet #46
Comments
As a workaround, I'm giving the bottom sheet a view that's just a FrameLayout with an id. And then adding a fragment to the fragment manager with that id. |
That sounds right. That should be the canonical solution |
Actually, can you reopen this? Fragment support has turned out to be nontrivial. In addition to knowing how to add the fragment correctly for the bottom sheet to measure correctly, you need to save and restore state across rotation in order to not have the app crash when trying to re-attach the fragment to a now missing id. |
Sure |
Also, handling the Back button press. I tried adding a fragment to the Bottom Sheet, and pressing Back did not cause the bottom sheet to be dismissed, but caused the Activity to get finished. |
Thats how I do it in my code for now: private void doShowBottomSheet(final Fragment fragment) {
View view = new FrameLayout(getContext());
view.setId(R.id.bottom_sheet_fragment);
view.setBackgroundResource(R.color.background);
BottomSheetLayout layout = getBase().getBottomSheetLayout();
layout.setOnSheetStateChangeListener(state -> {
if (state == BottomSheetLayout.State.PREPARING) {
FragmentManager fm = getActivity().getSupportFragmentManager();
fm.beginTransaction()
.replace(view.getId(), fragment)
.commit();
}
switch (state) {
case PEEKED:
sheetShown = true;
sheetExpanded = false;
break;
case EXPANDED:
sheetShown = true;
sheetExpanded = true;
break;
default:
sheetShown = false;
sheetExpanded = false;
break;
}
});
layout.showWithSheetView(view, null, bottomSheetLayout -> {
FragmentManager fm = getActivity().getSupportFragmentManager();
fm.beginTransaction()
.remove(fragment)
.commit();
});
} But there is an annoying problem that at the first attempt the fragment is not showing. Only second time and so on. :( I'm sorry for my bad english. I did my best to explain the situation :) |
That's probably because |
@evant Well, if I use |
Oh right you have to do it after the view is attached to the window. If I get some time, I'll write up a proper way to do this. We are doing it in our app but I'm not particularly happy with the solution. |
Ok, created a pull request with a solution that's based on DialogFragment #79 |
@evant I think you have done a great job! I look forward when the PR will be accepted. |
Done via #79 |
This commons component should take a fragment and show it in the bottomsheet.
The text was updated successfully, but these errors were encountered: