Share Username dialog body; make BasicTextField cursor visible in dark mode
- New: shared/ui/UsernameDialogContent.kt (material-free) - Android: use UsernameDialogContent for title/message/input; keep platform buttons - Fix: pass cursorColor (Material color) to shared content so caret is visible in dark theme
This commit is contained in:
@@ -148,6 +148,7 @@ import app.klottr.ui.LoginRequiredContent
|
||||
import app.klottr.ui.NearbyContent // Delat material-fritt innehåll för Närliggande
|
||||
import app.klottr.ui.NearbyDialogContent
|
||||
import app.klottr.ui.SettingsContent // Delad material-fri UI för inställningar
|
||||
import app.klottr.ui.UsernameDialogContent
|
||||
import app.klottr.ui.WikiDetailContent // Ny: delad Wiki-layout
|
||||
import app.klottr.ui.WriteDocContent // Använd delad, material-fri formulär-UI
|
||||
import app.klottr.util.Auth
|
||||
@@ -1573,37 +1574,38 @@ private fun UsernameDialog(
|
||||
modifier = Modifier.padding(20.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(12.dp)
|
||||
) {
|
||||
Text("Välj användarnamn", style = MaterialTheme.typography.titleLarge)
|
||||
Text(
|
||||
"Du måste välja ett användarnamn för att fortsätta.",
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||
)
|
||||
|
||||
OutlinedTextField(
|
||||
value = input,
|
||||
onValueChange = {
|
||||
UsernameDialogContent(
|
||||
titleText = "Välj användarnamn",
|
||||
messageText = "Du måste välja ett användarnamn för att fortsätta.",
|
||||
input = input,
|
||||
onInputChange = {
|
||||
input = it
|
||||
validateLocal(it)
|
||||
// display uppdateras i validateLocal
|
||||
validateLocal(it) // Uppdaterar även 'display'
|
||||
},
|
||||
label = { Text("Användarnamn") },
|
||||
singleLine = true,
|
||||
isError = localErr != null || remoteErr != null,
|
||||
supportingText = {
|
||||
val msg = localErr ?: remoteErr
|
||||
if (checking && msg == null) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
CircularProgressIndicator(modifier = Modifier.size(16.dp), strokeWidth = 2.dp)
|
||||
Text("Kontrollerar …")
|
||||
}
|
||||
} else if (msg != null) {
|
||||
Text(msg, color = MaterialTheme.colorScheme.error)
|
||||
} else if (okRemote && display.isNotBlank()) {
|
||||
Text("Namnet är ledigt.")
|
||||
}
|
||||
placeholder = "Användarnamn",
|
||||
titleStyle = MaterialTheme.typography.titleLarge.copy(
|
||||
color = MaterialTheme.colorScheme.onSurface
|
||||
),
|
||||
messageStyle = MaterialTheme.typography.bodyMedium.copy(
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||
),
|
||||
inputTextStyle = MaterialTheme.typography.bodyMedium.copy(
|
||||
color = MaterialTheme.colorScheme.onSurface
|
||||
),
|
||||
statusText = when {
|
||||
checking && localErr == null && remoteErr == null -> "Kontrollerar …"
|
||||
localErr != null -> localErr
|
||||
remoteErr != null -> remoteErr
|
||||
okRemote && display.isNotBlank() -> "Namnet är ledigt."
|
||||
else -> null
|
||||
},
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
statusStyle = when {
|
||||
localErr != null || remoteErr != null ->
|
||||
MaterialTheme.typography.bodySmall.copy(color = MaterialTheme.colorScheme.error)
|
||||
else ->
|
||||
MaterialTheme.typography.bodySmall.copy(color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||
},
|
||||
cursorColor = MaterialTheme.colorScheme.primary // Ny: tydlig markör i både ljust/mörkt läge
|
||||
)
|
||||
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(12.dp)) {
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package app.klottr.ui
|
||||
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.text.BasicText
|
||||
import androidx.compose.foundation.text.BasicTextField
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.SolidColor
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
||||
/**
|
||||
* Material-fri dialogkropp för "Välj användarnamn".
|
||||
* - Android/iOS skickar in färger/typografi via TextStyle så natt/dag blir rätt.
|
||||
* - Knappar (Spara/Logga ut) ligger kvar i plattformslagret.
|
||||
*/
|
||||
@Composable
|
||||
fun UsernameDialogContent(
|
||||
titleText: String,
|
||||
messageText: String,
|
||||
input: String,
|
||||
onInputChange: (String) -> Unit,
|
||||
placeholder: String,
|
||||
titleStyle: TextStyle,
|
||||
messageStyle: TextStyle,
|
||||
inputTextStyle: TextStyle,
|
||||
statusText: String?, // "Kontrollerar …" eller fel/OK-rad
|
||||
statusStyle: TextStyle, // Färg väljs av plattformen (error/neutral)
|
||||
cursorColor: Color // Markörfärg (dag/natt från plattform)
|
||||
) {
|
||||
Column(verticalArrangement = Arrangement.spacedBy(12.dp)) {
|
||||
BasicText(titleText, style = titleStyle)
|
||||
BasicText(messageText, style = messageStyle)
|
||||
|
||||
// Enkel material-fri textinmatning
|
||||
Column(verticalArrangement = Arrangement.spacedBy(6.dp)) {
|
||||
// Etikett
|
||||
BasicText(placeholder, style = messageStyle)
|
||||
// Fält
|
||||
BasicTextField(
|
||||
value = input,
|
||||
onValueChange = onInputChange,
|
||||
textStyle = inputTextStyle,
|
||||
cursorBrush = SolidColor(cursorColor), // Gör markören synlig i mörkt läge
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(vertical = 2.dp)
|
||||
)
|
||||
}
|
||||
|
||||
if (!statusText.isNullOrBlank()) {
|
||||
BasicText(statusText, style = statusStyle)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user