I'm getting this error while using Compose in my fragment which works fine in case of XML
ViewTreeLifecycleOwner not found from androidx.fragment.app.FragmentContainerView
I'm using a single activity approach without using Jetpack Navigation component
Activity:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_nav)
supportFragmentManager.commit {
setReorderingAllowed(true)
add<InboxFragment>(R.id.nav_fragmentContainerView_appNav)
}
}
<androidx.fragment.app.FragmentContainerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/nav_fragmentContainerView_appNav"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
Fragment:
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
return ComposeView(requireContext()).apply {
setContent {
Text(text = "HELLO FRIEND!")
}
}
}
Dependencies:
def fragment_version = "1.3.3"
implementation("androidx.fragment:fragment-ktx:$fragment_version")
def compose_version = "1.0.0-beta06"
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.ui:ui-tooling:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.activity:activity-compose:1.3.0-alpha07"
classpath "com.android.tools.build:gradle:7.0.0-alpha15"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.30"
Since you are using an AppCompatActivity
, only the appcompat 1.3
versions populate the ViewTreeLifecycleOwner
.
Add:
implementation 'androidx.appcompat:appcompat:1.3.0'
None of these worked and there seems to be an open issue with BottomSheetDialog.
https://issuetracker.google.com/issues/261078350
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With