Colton Idle
05/14/2021, 9:07 PMsetContent{ }
? In order to do this it looks like I'll have to use AndroidView
to host a FragmentContainerView
. Or does this all seem like a bad idea and should I just keep my 10 lines of xml for the activity layout. 😅Ian Lake
05/14/2021, 9:10 PMAndroidViewBinding
to inflate the layout; that works fine with FragmentContainerView
inflated fragmentsColton Idle
05/14/2021, 9:17 PMoverride fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
AndroidView(
factory = { context ->
FragmentContainerView(context).apply {
//Figure out how to set these programatically
// android:name="androidx.navigation.fragment.NavHostFragment"
// android:id="@+id/nav_host_fragment"
// app:defaultNavHost="true"
// app:navGraph="@navigation/nav_graph"
}
}
)
}
}
Not sure where AndroidViewBinding fits into it.Ian Lake
05/14/2021, 9:27 PMAndroidViewBinding
from the ui-viewbinding
artifact: https://developer.android.com/jetpack/compose/interop/interop-apis#views-in-compose (the last example of that section)Colton Idle
05/14/2021, 9:32 PMsetContent {
AndroidView(
factory = { context ->
LayoutInflater.from(context).inflate(R.layout.only_my_fragment_container_view, null)
}
)
}
Ian Lake
05/14/2021, 9:39 PMAndroidViewBinding
has specific fixes around hosting a fragment in Compose (cleaning up the fragment if you remove it from your Compose hierarchy, etc), so you might get away with that super basic usage of a single static fragment, but it wouldn't work as well for a more complicated use caseIan Lake
05/14/2021, 9:40 PMAndroidViewBinding
handles correctly)Colton Idle
05/14/2021, 9:41 PMColton Idle
05/14/2021, 9:42 PMIan Lake
05/14/2021, 9:45 PMColton Idle
05/14/2021, 10:01 PMval navHostFragment =
supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment
navController = navHostFragment.navController
I don't actually think I need navController, but I guess off the cuff, am I walking into any trouble if I need to grab my navcontroller?Ian Lake
05/14/2021, 10:31 PMallan.conda
05/15/2021, 5:02 AMallan.conda
05/15/2021, 5:04 AMColton Idle
05/15/2021, 5:25 AMallan.conda
05/15/2021, 5:59 AMallan.conda
05/15/2021, 6:01 AMColton Idle
05/15/2021, 12:52 PMallan.conda
05/15/2021, 12:53 PMIan Lake
05/15/2021, 1:23 PMAndroidViewBinding
for inflating your fragments, embedding fragments in Compose works well enough to be a good transitional stepColton Idle
05/15/2021, 2:54 PMColton Idle
05/15/2021, 7:37 PMoverride fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
MaterialTheme {
AndroidViewBinding(MyFragmentContainerViewBinding::inflate) {}
}
}
val navHostFragment =
supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment
val navController = navHostFragment.navController
}
This crashes on findFragmentById. I'm assuming I'm doing something very wrong here?Ian Lake
05/15/2021, 8:21 PMsetContent
doesn't execute its lambda immediately; you'd want to do that work in that empty lambda of the AndroidViewBinding
Colton Idle
05/15/2021, 8:31 PMIan Lake
07/21/2021, 5:41 PMbrandonmcansh
07/21/2021, 5:42 PMbrandonmcansh
07/21/2021, 5:42 PMbrandonmcansh
07/21/2021, 5:43 PMbrandonmcansh
07/21/2021, 5:43 PMIan Lake
07/21/2021, 5:45 PMbrandonmcansh
07/21/2021, 5:47 PMbrandonmcansh
07/21/2021, 5:47 PM@Composable
fun Grid() {
AndroidViewBinding(FragmentPlanoGridBinding::inflate) {
// binding.something.setOnClickListener { }
}
}
would still need to be done here im assuming?Ian Lake
07/21/2021, 7:14 PM