mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-08-28 21:48:17 +00:00
ios: prevent app freezing in create group view (#6079)
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user