diff --git a/apps/ios/Shared/Views/NewChat/AddGroupView.swift b/apps/ios/Shared/Views/NewChat/AddGroupView.swift index 433d06b9d7..901b2deeab 100644 --- a/apps/ios/Shared/Views/NewChat/AddGroupView.swift +++ b/apps/ios/Shared/Views/NewChat/AddGroupView.swift @@ -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) -> 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) }