StreamlineSignInDefaultViewModel
A view model for the default implementation of a streamline sign-in screen.
It checks if there is a user already signed in, and emits the appropriate states through the uiState property.
Samples
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.size
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Android
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavHostController
import androidx.wear.compose.material.Icon
import androidx.wear.compose.material.Text
import com.google.android.horologist.auth.sample.R
import com.google.android.horologist.auth.ui.common.screens.streamline.StreamlineSignInDefaultScreen
import com.google.android.horologist.auth.ui.common.screens.streamline.StreamlineSignInDefaultViewModel
import com.google.android.horologist.compose.layout.ScalingLazyColumnState
import com.google.android.horologist.compose.material.Confirmation
import com.google.android.horologist.compose.material.util.DECORATIVE_ELEMENT_CONTENT_DESCRIPTION
fun main() {
//sampleStart
var showNoAccountsAvailableDialog by rememberSaveable { mutableStateOf(false) }
StreamlineSignInDefaultScreen(
onSignedInConfirmationDialogDismissOrTimeout = { navController.popBackStack() },
onNoAccountsAvailable = { showNoAccountsAvailableDialog = true },
columnState = columnState,
viewModel = viewModel,
) {
Box(
modifier = modifier.fillMaxSize(),
contentAlignment = Alignment.Center,
) {
Icon(
modifier = Modifier.size(48.dp),
imageVector = Icons.Default.Android,
contentDescription = DECORATIVE_ELEMENT_CONTENT_DESCRIPTION,
)
}
}
if (showNoAccountsAvailableDialog) {
Confirmation(
onTimeout = navController::popBackStack,
) {
Text(
modifier = Modifier.align(Alignment.CenterHorizontally),
textAlign = TextAlign.Center,
text = stringResource(id = R.string.common_screens_streamline_no_accounts_message),
)
}
}
//sampleEnd
}Functions
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Indicate that the screen has observed the idle state and that the view model can start its work.