Sign Up
Sign Up Screen
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.text.ClickableText
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Checkbox
import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.material3.minimumInteractiveComponentSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.focus.FocusDirection
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.unit.dp
@Composable
fun ScreenSignUp() {
var fullname by remember { mutableStateOf("Matias Duarte") }
var username by remember { mutableStateOf("[email protected]") }
var password by remember { mutableStateOf("duartesStrongPassword") }
var errorMessage by remember { mutableStateOf("") }
var acceptedTerms by remember { mutableStateOf(true) }
val focus = LocalFocusManager.current
val keyboardController = LocalSoftwareKeyboardController.current
val onSubmit: () -> Unit = {
TODO("Handle onSubmit")
}
@Composable
fun TermsAndConditions(onClick: () -> Unit) {
val fullText = "I accept the Terms & Conditions"
val clickableText = "Terms & Conditions"
val tag = "terms-and-conditions"
val annotatedString = buildAnnotatedString {
append(fullText)
val start = fullText.indexOf(clickableText)
val end = start + clickableText.length
addStyle(
style = SpanStyle(color = MaterialTheme.colorScheme.primary, fontWeight = FontWeight.SemiBold),
start = start,
end = end
)
addStringAnnotation(tag = tag, annotation = "https://www.composables.com", start = start, end = end)
}
val uriHandler = LocalUriHandler.current
ClickableText(
style = MaterialTheme.typography.bodyMedium.copy(color = LocalContentColor.current),
text = annotatedString,
onClick = { offset ->
val string = annotatedString.getStringAnnotations(tag, offset, offset).firstOrNull()
if (string != null) {
uriHandler.openUri(string.item)
} else {
onClick()
}
})
}
Scaffold { padding ->
BoxWithConstraints(modifier = Modifier.fillMaxSize().padding(padding)) {
val centered = maxWidth >= 840.dp
Box(
modifier = Modifier.fillMaxSize().verticalScroll(rememberScrollState(0)),
contentAlignment = Alignment.TopCenter
) {
Column(
modifier = Modifier.widthIn(max = 600.dp).padding(horizontal = 16.dp).padding(vertical = 32.dp),
horizontalAlignment = if (centered) Alignment.CenterHorizontally else Alignment.Start
) {
Text("Create Free Account", style = MaterialTheme.typography.headlineLarge)
Spacer(Modifier.height(12.dp))
Text(
text = "Gain access to the full Composables catalog",
style = MaterialTheme.typography.bodyMedium
)
Spacer(Modifier.height(24.dp))
OutlinedTextField(
modifier = Modifier.fillMaxWidth(),
value = fullname,
label = { Text("Full name") },
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Text, imeAction = ImeAction.Next),
keyboardActions = KeyboardActions(onNext = {
focus.moveFocus(FocusDirection.Next)
}),
onValueChange = { fullname = it },
singleLine = true
)
Spacer(Modifier.height(8.dp))
OutlinedTextField(
modifier = Modifier.fillMaxWidth(),
value = username,
label = { Text("E-mail") },
keyboardOptions = KeyboardOptions(
keyboardType = KeyboardType.Email,
imeAction = ImeAction.Next
),
keyboardActions = KeyboardActions(onNext = {
focus.moveFocus(FocusDirection.Next)
}),
onValueChange = { username = it },
singleLine = true
)
Spacer(Modifier.height(8.dp))
OutlinedTextField(
modifier = Modifier.fillMaxWidth(),
label = { Text("Password") },
isError = errorMessage.isNotBlank(),
supportingText = {
Text(errorMessage)
},
value = password,
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Text, imeAction = ImeAction.Done),
keyboardActions = KeyboardActions(onNext = {
focus.clearFocus()
keyboardController?.hide()
onSubmit()
}),
visualTransformation = PasswordVisualTransformation(),
onValueChange = {
password = it
},
singleLine = true
)
Spacer(Modifier.height(16.dp))
Row(
modifier = Modifier.fillMaxWidth().clip(MaterialTheme.shapes.small)
.clickable { acceptedTerms = acceptedTerms.not() }.minimumInteractiveComponentSize()
.padding(horizontal = 2.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(12.dp)
) {
Checkbox(
checked = acceptedTerms,
onCheckedChange = null,
)
TermsAndConditions(onClick = { acceptedTerms = acceptedTerms.not() })
}
Spacer(Modifier.height(16.dp))
Column(Modifier.padding(horizontal = 16.dp)) {
Button(
enabled = acceptedTerms && fullname.isNotBlank() && username.isNotBlank() && password.isNotBlank(),
onClick = onSubmit,
modifier = Modifier.fillMaxWidth()
) {
Text("Sign Up")
}
Spacer(Modifier.height(8.dp))
TextButton(
modifier = Modifier.align(Alignment.CenterHorizontally),
onClick = { /*TODO*/ },
colors = ButtonDefaults.textButtonColors(
contentColor = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.66f)
)
) {
Text("Already have an account? Sign in")
}
}
}
}
}
}
}
Explore other Jetpack Compose Blocks

Accordions
3 blocks

Autocomplete
4 blocks
Avatars
3 blocks

Bottom sheets
4 blocks

Button Groups
4 blocks

Buttons
7 blocks

Cards
11 blocks

Checkboxes
2 blocks

Chips
4 blocks

Date Pickers
5 blocks

Dialogs
4 blocks

Dropdown Menus
1 blocks

Expandable Lists
2 blocks

Feeds
2 blocks

Form Inputs
0 blocks

Forms
4 blocks

Grids
7 blocks

Horizontal Lists
2 blocks

Lists
6 blocks

Modal Bottom sheets
4 blocks

Music Playback
2 blocks

Radio Groups
2 blocks

Responsive Layouts
5 blocks

Search Bars
2 blocks

Social Share
1 blocks

Tables
8 blocks

Tabs
7 blocks

Text Fields
6 blocks

Toggles
3 blocks

Utilities
4 blocks

Accept Privacy
1 blocks

Chat
1 blocks

Forgot Password
1 blocks

Onboarding
3 blocks

Profile Details
6 blocks

Request Permission
1 blocks

Search
1 blocks

Settings
2 blocks

Sign In
1 blocks

Sign Up
1 blocks

Checkout Forms
2 blocks

Product Details
2 blocks

Product Filters
3 blocks

Product Lists
3 blocks

Product Reviews
5 blocks

Shopping Cart
3 blocks