From 94eb6fd88049e7e02b7e4a3b1f81a4ffa32ce698 Mon Sep 17 00:00:00 2001 From: "Evgeny @ SimpleX Chat" <259188159+evgeny-simplex@users.noreply.github.com> Date: Sat, 11 Jul 2026 17:07:07 +0000 Subject: [PATCH] name UI --- .../Views/UserSettings/UserAddressView.swift | 92 ++++++++++++------- .../views/usersettings/SetSimplexNameView.kt | 57 ++++++++---- .../commonMain/resources/MR/base/strings.xml | 1 + 3 files changed, 99 insertions(+), 51 deletions(-) diff --git a/apps/ios/Shared/Views/UserSettings/UserAddressView.swift b/apps/ios/Shared/Views/UserSettings/UserAddressView.swift index ef38e3c092..c7079b669d 100644 --- a/apps/ios/Shared/Views/UserSettings/UserAddressView.swift +++ b/apps/ios/Shared/Views/UserSettings/UserAddressView.swift @@ -757,6 +757,17 @@ struct SetSimplexDomainView: View { @State private var saving = false @State private var original = "" @State private var didSave = false + @State private var editing = false + + init(title: LocalizedStringKey, footer: LocalizedStringKey, prompt: String, simplexName: String, save: @escaping (String?) async -> Bool) { + self.title = title + self.footer = footer + self.prompt = prompt + self._simplexName = State(initialValue: simplexName) + self.save = save + self._original = State(initialValue: simplexName) + self._editing = State(initialValue: simplexName.isEmpty) + } private var changed: Bool { normalized(simplexName) != normalized(original) @@ -770,14 +781,28 @@ struct SetSimplexDomainView: View { var body: some View { List { Section { - ZStack(alignment: .trailing) { - TextField(prompt, text: $simplexName) - .autocorrectionDisabled(true) - .textInputAutocapitalization(.never) - .padding(.trailing, isValid ? 0 : 20) - if !isValid { - Image(systemName: "exclamationmark.circle") - .foregroundColor(.red) + if editing { + ZStack(alignment: .trailing) { + TextField(prompt, text: $simplexName) + .autocorrectionDisabled(true) + .textInputAutocapitalization(.never) + .padding(.trailing, isValid ? 0 : 20) + if !isValid { + Image(systemName: "exclamationmark.circle") + .foregroundColor(.red) + } + } + } else { + Button { + UIPasteboard.general.string = simplexName + } label: { + HStack { + Text(simplexName) + .foregroundColor(theme.colors.onBackground) + Spacer() + Image(systemName: "doc.on.doc") + .foregroundColor(theme.colors.secondary) + } } } } header: { @@ -786,37 +811,40 @@ struct SetSimplexDomainView: View { Text(footer).foregroundColor(theme.colors.secondary) } Section { - Button { - openBrowserAlert(uri: "https://github.com/simplex-chat/simplex-chat/blob/master/docs/guide/register-simplex-name.md") - } label: { - Text("Register a test name") - } - if !original.isEmpty { - Button("Remove") { - simplexName = "" - } - } - Button { - saving = true - Task { - let ok = await save(normalized(simplexName)) - await MainActor.run { - saving = false - if ok { - didSave = true - dismiss() - } + if editing { + if simplexName.isEmpty { + Button { + openBrowserAlert(uri: "https://github.com/simplex-chat/simplex-chat/blob/master/docs/guide/register-simplex-name.md") + } label: { + Text("Register a test name") } } - } label: { - Text("Save") + Button { + saving = true + Task { + let ok = await save(normalized(simplexName)) + await MainActor.run { + saving = false + if ok { + didSave = true + dismiss() + } + } + } + } label: { + Text("Save") + } + .disabled(saving || !isValid || !changed) + } else { + Button("Remove name") { + simplexName = "" + editing = true + } } - .disabled(saving || !isValid || !changed) } } .navigationTitle(title) .navigationBarTitleDisplayMode(.large) - .onAppear { original = simplexName } .onDisappear { if !didSave, changed, isValid { let domain = normalized(simplexName) diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/usersettings/SetSimplexNameView.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/usersettings/SetSimplexNameView.kt index 405faec824..4e42b15f91 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/usersettings/SetSimplexNameView.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/usersettings/SetSimplexNameView.kt @@ -3,6 +3,7 @@ package chat.simplex.common.views.usersettings import SectionBottomSpacer import SectionDividerSpaced import SectionItemView +import SectionItemViewSpaceBetween import SectionTextFooter import SectionView import androidx.compose.foundation.layout.* @@ -10,13 +11,16 @@ import androidx.compose.material.* import androidx.compose.runtime.* import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalClipboardManager import androidx.compose.ui.platform.LocalUriHandler +import androidx.compose.ui.text.AnnotatedString import chat.simplex.common.platform.* import chat.simplex.common.ui.theme.* import chat.simplex.common.views.* import chat.simplex.common.views.chat.item.openBrowserAlert import chat.simplex.common.views.helpers.* import chat.simplex.res.MR +import dev.icerock.moko.resources.compose.painterResource import dev.icerock.moko.resources.compose.stringResource import kotlinx.coroutines.* @@ -40,7 +44,9 @@ fun SetSimplexDomainView( ) { val name = rememberSaveable { mutableStateOf(simplexName) } val saving = remember { mutableStateOf(false) } + val editing = rememberSaveable { mutableStateOf(simplexName.isBlank()) } val uriHandler = LocalUriHandler.current + val clipboard = LocalClipboardManager.current fun addSimplexTLD(s: String): String { return if (s.contains(".")) s else "$s.simplex" @@ -123,31 +129,44 @@ fun SetSimplexDomainView( ColumnWithScrollBar { AppBarTitle(title) SectionView { - Box(Modifier.padding(horizontal = DEFAULT_PADDING)) { - ProfileNameField( - name, - placeholder, - isValid = { isValidName(it) }, - onInvalidTap = { AlertManager.shared.showAlertMsg(title = generalGetString(MR.strings.invalid_name)) } - ) + if (editing.value) { + Box(Modifier.padding(horizontal = DEFAULT_PADDING)) { + ProfileNameField( + name, + placeholder, + isValid = { isValidName(it) }, + onInvalidTap = { AlertManager.shared.showAlertMsg(title = generalGetString(MR.strings.invalid_name)) } + ) + } + } else { + SectionItemViewSpaceBetween(click = { + clipboard.setText(AnnotatedString(name.value)) + showToast(generalGetString(MR.strings.copied)) + }) { + Text(name.value) + Icon(painterResource(MR.images.ic_content_copy), stringResource(MR.strings.copy_verb), tint = MaterialTheme.colors.secondary) + } } } SectionTextFooter(footer) SectionDividerSpaced() SectionView { - SectionItemView({ openBrowserAlert("https://github.com/simplex-chat/simplex-chat/blob/master/docs/guide/register-simplex-name.md", uriHandler) }) { - Text(stringResource(MR.strings.register_test_name), color = MaterialTheme.colors.primary) - } - if (simplexName.isNotBlank()) { - SectionItemView({ name.value = "" }) { - Text(stringResource(MR.strings.remove_verb), color = MaterialTheme.colors.primary) + if (editing.value) { + if (name.value.isBlank()) { + SectionItemView({ openBrowserAlert("https://github.com/simplex-chat/simplex-chat/blob/master/docs/guide/register-simplex-name.md", uriHandler) }) { + Text(stringResource(MR.strings.register_test_name), color = MaterialTheme.colors.primary) + } + } + SectionItemView({ doSave(close) }, disabled = unchanged || saving.value || !isValid) { + Text( + stringResource(MR.strings.save_verb), + color = if (unchanged || saving.value || !isValid) MaterialTheme.colors.secondary else MaterialTheme.colors.primary + ) + } + } else { + SectionItemView({ name.value = ""; editing.value = true }) { + Text(stringResource(MR.strings.remove_name), color = MaterialTheme.colors.primary) } - } - SectionItemView({ doSave(close) }, disabled = unchanged || saving.value || !isValid) { - Text( - stringResource(MR.strings.save_verb), - color = if (unchanged || saving.value || !isValid) MaterialTheme.colors.secondary else MaterialTheme.colors.primary - ) } } SectionBottomSpacer() diff --git a/apps/multiplatform/common/src/commonMain/resources/MR/base/strings.xml b/apps/multiplatform/common/src/commonMain/resources/MR/base/strings.xml index 1265621f4c..86d845760a 100644 --- a/apps/multiplatform/common/src/commonMain/resources/MR/base/strings.xml +++ b/apps/multiplatform/common/src/commonMain/resources/MR/base/strings.xml @@ -398,6 +398,7 @@ Get SimpleX name (BETA) Channel SimpleX name Register a test name + Remove name Save Edit Info