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

Added a BottomSheetFragment to bottomsheet-commons that works like a DialogFragment. #79

Merged
merged 1 commit into from
Nov 21, 2015

Conversation

evant
Copy link
Contributor

@evant evant commented Nov 5, 2015

After trying a few things I believe this is the best solution to support fragments in a bottom sheet. Fragments have a more complex lifecycle so it's far simpler to handle everything in the fragment itself instead of trying to deal with it in a view or other helper component. This implementation actually follows very closely to the support lib's DialogFragment.

public static int getContainerId(Fragment fragment) {
return fragment.mContainerId;
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure the best way to handle this. DialogFragment makes use of this field that's not part of the public api to determine if it's showing in a dialog or normally. Other possible solutions are to use reflection or find some other way to obtain the same information without that field.

@evant evant mentioned this pull request Nov 5, 2015
@ZacSweers
Copy link
Contributor

Sorry about the delayed response, looking forward to reviewing this! Going to try to tonight.

@ZacSweers
Copy link
Contributor

I like this a lot. The code itself looks sound, but I'd like to propose investigating an alternative approach if you haven't already. Requiring the user to extend our own BottomSheetFragment isn't ideal, as many developers prefer to use their own base implementations for fragments. Sure, sheets are intended to be simple, but it would be understandable for them to still prefer their own base implementations anyway.

In light of this, could we take a similar approach to AppCompatDelegate? It seems like the main fragment inheritance requirements for for hooking into the lifecycle, which could be proxied through a delegate. We can still keep the BottomSheetFragment class for easy drop-in use, but I think it would be useful to make its underlying implementation rely on a delegate.

This would be two parts:

  • BottomSheetFragmentInterface
  • BottomSheetFragmentDelegate

I've written up an implementation of this based on your PR here: https://github.com/Flipboard/bottomsheet/tree/z/bottomsheetfragmentdelegate

Let me know what you think! You too @markrietveld

}

@Override
public void onSheetStateChanged(BottomSheetLayout.State state) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second thought, I think it would be better not to set this. Could be confusing if the user set a listener in their activity and finds out that it's never called! They can still do the same thing in the fragment with getBottomSheetLayout().setOnSheetStateChangeListener()

@evant
Copy link
Contributor Author

evant commented Nov 9, 2015

Providing a delegate seems completely reasonable. I didn't do it originally since I was staying close to DialogFragment, but we can be better than them.

@ZacSweers
Copy link
Contributor

Cool, pending @markrietveld's thoughts then

@ZacSweers ZacSweers merged commit b5500d5 into Flipboard:master Nov 21, 2015
@ZacSweers
Copy link
Contributor

Merged with the delgate approach. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants