Skip to content

Instantly share code, notes, and snippets.

@nikolaDrljaca
Created December 13, 2021 13:24
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save nikolaDrljaca/75f3d078cdf25ae1358ba6b62c19892c to your computer and use it in GitHub Desktop.
class ListFragment : Fragment() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
exitTransition = Slide()
reenterTransition = Slide()
}
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
return ComposeView(requireContext()).apply {
id = R.id.compose_view_first
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
setContent {
MdcTheme {
FirstScreen {
findNavController().navigate(R.id.action_listFragment_to_detailFragment)
}
}
}
}
}
@Composable
fun FirstScreen(
onClick: () -> Unit
) {
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
Column {
Text(text = "This is the first screen")
Button(onClick = onClick) {
Text(text = "Navigate")
}
}
}
}
}
class DetailFragment : Fragment() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enterTransition = Fade()
exitTransition = Fade()
}
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
return ComposeView(requireContext()).apply {
id = R.id.compose_view_second
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
setContent {
MdcTheme {
Box(
modifier = Modifier
.fillMaxSize()
.padding(12.dp)
.background(color = Color.Red),
contentAlignment = Alignment.Center
) {
Text(text = "This is the second screen")
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment