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 ComposeRenderer( | |
private val activity: ComponentActivity | |
) { | |
suspend fun render( | |
content: @Composable () -> Unit | |
): Result<Bitmap> { | |
val completableBitmap = CompletableDeferred<Result<Bitmap>>() | |
activity.awaitWindowToken() | |
val wm = activity.getSystemService(Context.WINDOW_SERVICE) as WindowManager |
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
// Just as an example of something you might want to send to some destinations | |
val scaffoldState = rememberScaffoldState() | |
DestinationsNavHost( | |
navGraph = NavGraphs.root | |
) { | |
composable(SomeScreenDestination) { //this: DestinationScope<SomeScreenDestination.NavArgs> | |
SomeScreen( | |
arg1 = navArgs.arg1, // navArgs is a lazily evaluated `SomeScreenDestination.NavArgs` instance, field of `DestinationScope` | |
navigator = destinationsNavigator, // destinationsNavigator is a `DestinationsNavigator` (also lazily evaluated) |
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
@Destination(start = true) | |
@Composable | |
fun LoginScreen( | |
navigator: DestinationsNavigator | |
) { | |
/*...*/ | |
Button (onClick = { navigator.navigate(HomeScreenDestination) } | |
/*...*/ | |
} |
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
sealed class UiText { | |
class DynamicText(val text: String) : UiText() | |
class ResourceText(@StringRes val stringRes: Int) : UiText() | |
} | |
fun UiText.getString(context: Context) = when (this) { | |
is UiText.DynamicText -> text | |
is UiText.ResourceText -> context.getString(stringRes) |
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
//region Screen Composables | |
@Destination(route = "profile") | |
@Composable | |
fun ProfileScreen( | |
id: String, | |
isEditable: Boolean = false | |
) {/*...*/} | |
@Destination(route = "login", start = true) | |
@Composable |