maxkeppeler / sheets

⭐ ‎‎‎‏‏‎ ‎Offers a range of beautiful sheets (dialogs & bottom sheets) for quick use in your project. Includes many ways to customize sheets.
https://maxkeppeler.github.io/sheets/
Apache License 2.0
921 stars 77 forks source link

Error using hilt #17

Closed puntogris closed 3 years ago

puntogris commented 3 years ago

I'm getting : java.lang.IllegalStateException: Context has no window attached. at com.maxkeppeler.bottomsheets.core.BottomSheet.show(BottomSheet.kt:412) at com.maxkeppeler.bottomsheets.time_clock.ClockTimeSheet.show(ClockTimeSheet.kt:120)

when using ClockTimeSheet().show(requireContext()){... with Hilt in a PreferenceFragmentCompat

Library Version: 1.0.6

Additional context When not using hilt on the PreferenceFragmentCompat it works fine.

maxkeppeler commented 3 years ago

Right now it gets the fragment manager of a FragmentActivity, AppCompatActivity and Fragment. AppCompatActivity is not added. If you only build(requireContext())and then use the BottomSheetDialogFragment method show(fragmentManager), then it works, or? But then I wonder why it works without Hilt - I didn't have time to learn Hilt yet and therefore can't tell you anything. Can I checkout your code or could you build a small sample with hilt and this library?

puntogris commented 3 years ago

I tried it like you suggested and it works now, thanks a lot!

maxkeppeler commented 3 years ago

You are welcome! Will think about adding it through just the context with the default show method.

maxkeppeler commented 3 years ago

I added the preference library, and added PreferenceFragmentCompat so it can take the fragment manager directly through the context, which is used for the custom show + build method. Should work with the next version too then.