Last active
April 15, 2025 22:10
-
-
Save hgarciaalberto/1bae880237f7d5998906c3f3ceb2e7d1 to your computer and use it in GitHub Desktop.
Live Templates for Compose in Android Studio
This file contains hidden or 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
// ////// | |
// Screen | |
// ////// | |
import androidx.compose.runtime.getValue | |
import androidx.compose.runtime.setValue | |
@androidx.compose.runtime.Composable | |
fun $NAME$ScreenRoot( | |
viewModel: $NAME$ViewModel = viewModel { $NAME$ViewModel() }, | |
) { | |
val state by viewModel.state.collectAsStateWithLifecycle() | |
$NAME$Screen(state)$END$ | |
} | |
@androidx.compose.runtime.Composable | |
fun $NAME$Screen( | |
state: $NAME$State, | |
) { | |
$NAME$Content()$END$ | |
} | |
@androidx.compose.runtime.Composable | |
fun $NAME$Content(modifier: androidx.compose.ui.Modifier = androidx.compose.ui.Modifier) { | |
Column( | |
modifier = modifier.fillMaxSize(), | |
verticalArrangement = Arrangement.Center, | |
horizontalAlignment = Alignment.CenterHorizontally, | |
) { | |
Text("Text") | |
}$END$ | |
} | |
@Preview | |
@androidx.compose.runtime.Composable | |
fun $NAME$ContentPreview(modifier: androidx.compose.ui.Modifier = androidx.compose.ui.Modifier) { | |
MaterialTheme { | |
$NAME$Screen( | |
state = $NAME$State().copy( | |
isLoading = false, | |
) | |
) | |
}$END$ | |
} | |
// ///////// | |
// ViewModel | |
// ///////// | |
import kotlinx.coroutines.flow.MutableStateFlow | |
import kotlinx.coroutines.flow.asStateFlow | |
import org.koin.core.component.KoinComponent | |
class $NAME$ViewModel : ViewModel(), KoinComponent { | |
private val _state = MutableStateFlow<$NAME$State>($NAME$State()) | |
val state = _state.asStateFlow() | |
} | |
// ///////// | |
// Preview | |
// ///////// | |
@androidx.compose.ui.tooling.preview.Preview(showBackground = true, showSystemUi = true) | |
@androidx.compose.runtime.Composable | |
private fun $NAME$() { | |
MaterialTheme { | |
$NAME$Screen( | |
state = $NAME$State().copy( | |
isLoading = false, | |
), | |
) | |
}$END$ | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment