Post

Replies

Boosts

Views

Activity

Lag When Dismissing Keyboard in ScrollView Inside NavigationStack in SwiftUI
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) } } }
2
0
198
Sep ’24
Floating button changes position when keyboard is shown in iOS 16.4.1
I have a floating button that is created using the CGFloatingButton func in my iOS app. It is positioned at the bottom of the screen, and its position is defined using frame based on the view's bounds. It was working fine in previous versions of iOS, but after updating to iOS 16.4.1, I noticed that the button's position changes when the keyboard is shown, and it does not return to its original position after the keyboard is dismissed. I checked the constraints and they seem to be fine. However, when I looked at the debug view hierarchy, I noticed that the button appears to be outside its container, and the click only works within the original 65x65 container. I am using the following code to set up the button: let loginLater = UserDefaults.standard.bool(forKey: Constants.LOGIN_LATER) cgFloatingButton = CGFloatingButton(onTap: { self.gotoCheckandGo() }) cgFButtonHController = UIHostingController(rootView: cgFloatingButton) self.addChild(cgFButtonHController) var offset = CGPoint(x: (self.view.bounds.width * 0.5) - 32.5, y: (self.view.bounds.height) - 117) switch deviceType { case .iPhone8, .iPhone8Plus, .iPhoneSE: offset = CGPoint(x: (self.view.bounds.width * 0.5) - 32.5, y: (self.view.bounds.height) - 90) default: offset = CGPoint(x: (self.view.bounds.width * 0.5) - 32.5, y: (self.view.bounds.height) - 117) } let frame = CGRect(origin: offset, size: CGSize(width: 65, height: 65)) cgFButtonHController.view.frame = frame cgFButtonHController.view.autoresizingMask = [.flexibleWidth, .flexibleHeight] cgFButtonHController.view.backgroundColor = UIColor.clear cgFButtonHController.view.isHidden = true self.floatingTabBar.tabBarCheckAndGoButtonView.isHidden = true if loginLater == false { view.addSubview(cgFButtonHController.view) } else { self.floatingTabBar.isHidden = true } } This is the code in SwiftUI about cgFloatingButton var: struct CGFloatingButton: View { var onTap: () -> Void = { } var body: some View { Button(action: { onTap() }) { Image("cg_btn") .resizable() .frame(width: 65, height: 65) .background(Color.white) .foregroundColor(.white) .clipShape(Circle()) .shadow(radius: 2) }.ignoresSafeArea(.all) }} Has anyone else experienced this issue with a floating button or have any suggestions on how to fix it? Thanks in advance for your help!
0
0
367
Apr ’23