Created
December 13, 2021 13:24
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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