Fixed
Status Update
Comments
il...@google.com <il...@google.com>
jb...@google.com <jb...@google.com> #2
Another option is to provide a setContent
like API specifically for Fragments.
E.g., an extension like:
fun Fragment.content(content: @Composable () -> Unit): ComposeView {
return ComposeView(requireContext()).apply {
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
setContent(content)
}
}
which would let you write a Fragment like:
class ExampleFragment : Fragment() {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
) = content {
// Write your @Composable content here
val viewModel: ExampleViewModel = viewModel()
// or extract it into a separate, testable method
ExampleComposable(viewModel)
}
}
Description
Component used: Fragment
Version used: 1.5.0
Devices/Android versions reproduced on: N/A lint only
In newer versions of lint (seemingly 30.4.x, but possibly 30.3.x), there was an API change that breaks the DialogFragmentCallbacksDetector lint. This commit fixes it and the fix (
(node.sourcePsi as? KtClassOrObject)
) is backward compatible. It would be great if this could be backported to a patch release for 1.5.x.