I’m experiencing a lag in SwiftUI when dismissing the keyboard inside a ScrollView that’s within a NavigationStack. When the keyboard is opened and then dismissed, the view seems to lag as it resizes back to its original state. This issue occurs when the content is in a ScrollView.
I’m using iOS 17, and the resizing of the content feels choppy after the keyboard interaction. Here’s a simplified version of my code:
VStack {
NavigationStack {
ScrollView {
createAllForm
}
.onAppear {
if #available(iOS 17.0, *) {
Self.addTripOpen.sendDonation()
}
}
.toolbar {
ToolbarItem(placement: .topBarLeading) {
Button(action: {
presentationMode.wrappedValue.dismiss()
}, label: {
Image(systemName: IconsEnum.closeIcon).foregroundColor(.gray)
})
}
}
.toolbar {
ToolbarItem(placement: .topBarTrailing) {
Button(LocalizedText.create, action: {
focusedField = nil
withAnimation {
addTripViewModel.creatingTrip = true
addTripViewModel.addTripToFirebase(presentationMode: presentationMode)
}
}).disabled(addTripViewModel.disableCreate).foregroundColor(Color(addTripViewModel.disableCreate ? ColorsEnum.greyColor : ColorsEnum.tripBlue))
}
}
.navigationTitle(LocalizedText.createTrip)
.navigationBarTitleDisplayMode(.inline)
.isLoadingView(isLoading: addTripViewModel.creatingTrip)
.alert(addTripViewModel.alertMessage, isPresented: $addTripViewModel.showingAlert) {
Button(LocalizedText.acceptLabel, role: .cancel) { }
}
.onDisappear {
if addTripViewModel.isCreated {
processCompletedCount += 1
}
if let currentAppVersion = Bundle.currentAppVersion,
processCompletedCount >= 2,
currentAppVersion != lastVersionPromptedForReview,
addTripViewModel.isCreated {
presentReview()
lastVersionPromptedForReview = currentAppVersion
}
onDismiss(addTripViewModel.isCreated)
}
.sheet(isPresented: $addTripViewModel.showingAddUsers) {
AddUsers().environmentObject(addTripViewModel)
}
}
}