ios: prevent app freezing in create group view (#6079)

This commit is contained in:
Evgeny
2025-07-15 18:52:49 +01:00
committed by GitHub
parent e65ab2c80f
commit 64372f01a3
@@ -104,7 +104,9 @@ struct AddGroupView: View {
}
.foregroundColor(theme.colors.secondary)
.frame(maxWidth: .infinity, alignment: .leading)
.onTapGesture(perform: hideKeyboard)
.onTapGesture {
focusDisplayName = false
}
}
}
.onAppear() {
@@ -161,7 +163,8 @@ struct AddGroupView: View {
} else {
Image(systemName: "pencil").foregroundColor(theme.colors.secondary)
}
textField("Enter group name…", text: $profile.displayName)
TextField("Enter group name…", text: $profile.displayName)
.padding(.leading, 36)
.focused($focusDisplayName)
.submitLabel(.continue)
.onSubmit {
@@ -170,11 +173,6 @@ struct AddGroupView: View {
}
}
func textField(_ placeholder: LocalizedStringKey, text: Binding<String>) -> some View {
TextField(placeholder, text: text)
.padding(.leading, 36)
}
func sharedGroupProfileInfo(_ incognito: Bool) -> Text {
let name = ChatModel.shared.currentUser?.displayName ?? ""
return Text(
@@ -185,7 +183,7 @@ struct AddGroupView: View {
}
func createGroup() {
hideKeyboard()
focusDisplayName = false
do {
profile.displayName = profile.displayName.trimmingCharacters(in: .whitespaces)
profile.groupPreferences = GroupPreferences(history: GroupPreference(enable: .on))
@@ -217,6 +215,8 @@ struct AddGroupView: View {
}
}
// Using this method may freeze the app in some cases, so it should be avoided when possible, especially when combined with .focussed modifier.
// It also must only be called from background thread.
func hideKeyboard() {
UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
}