Hello, I attached a crash report to this post I've received from a handful of users.
The stack-trace in the crash report doesn't point to any code in the app, rather, it indicates something happened in UIKitCore related to in progress animation state causing the app to crash.
I was able to track down where the crash is occurring via events tracked in the app. It appears to be happening when a sheet is presented. The sheet has a UIViewControllerRepresentable containing a UIViewUIPageViewController. The page view controller has three pages, each with a UIViewRepresentable containing a UITextView. The purpose of using a UITextView on these pages is to make the keyboard first responder as soon as the page changes.
I was unable to recreate this crash on any of my test devices, so I was wondering if someone has any insight into what might be causing this crash.
Below are some code snippets showing the implementation of each of the before-mentioned views.
Paging View
struct PageViewController: UIViewControllerRepresentable {
var controllers: [UIViewController]
@Binding var currPage: Int
@Binding var pageDirection: UIPageViewController.NavigationDirection
@Binding var isPageChanging: Bool
func makeCoordinator() -> Coordinator {
Coordinator(self)
}
func makeUIViewController(context: Context) -> UIPageViewController {
let pageViewController = UIPageViewController(transitionStyle: .scroll,
navigationOrientation: .horizontal)
if let scrollView = pageViewController.view.subviews.first(where: { $0 is UIScrollView }) as? UIScrollView {
scrollView.delegate = context.coordinator
}
pageViewController.setViewControllers([controllers[currPage]],
direction: pageDirection,
animated: true)
return pageViewController
}
func updateUIViewController(_ pageViewController: UIPageViewController, context: Context) {
if isPageChanging {
// Allow time for the keyboard to be dismissed
DispatchQueue.main.asyncAfter(deadline: .now() + 0.85) {
pageViewController.setViewControllers([controllers[currPage]],
direction: pageDirection,
animated: true)
}
}
}
class Coordinator: NSObject, UIScrollViewDelegate {
var parent: PageViewController
init(_ pageViewController: PageViewController) {
self.parent = pageViewController
}
func scrollViewDidEndScrollingAnimation(_ scrollView: UIScrollView) {
DispatchQueue.main.async { self.parent.isPageChanging = false }
}
}
}
Example of view used in Paging View
struct SamplePageInputView: View {
@Binding var isPageChanging: Bool
@Binding var currPage: Int
@State private var text = ""
var submitCallback: () -> Void
var body: some View {
GeometryReader { _ in
VStack {
Text("Title")
.font(.custom(Fonts.brandHeading.swiftUIFont, size: 32))
.foregroundColor(Color(ColorPalette.secondaryTint))
.padding(.bottom, 8)
Text("Subtitle")
.font(.custom(Fonts.brandBold.swiftUIFont, size: 18))
.foregroundColor(Color(ColorPalette.secondaryTint))
.padding(.bottom, 16)
FocusablePageableTextField(text: $text,
isFirstResponder: true,
placeholder: "placeholder",
textAlignment: .center,
autocapitalizationType: .words,
textContentType: .name,
autocorrectionType: .no,
activePage: 0,
isPageChanging: $isPageChanging,
currPage: $currPage,
showSpinner: .constant(false),
onReturnCallback: submit,
onButtonPressCallback: submit)
.frame(height: 40)
.padding([.leading, .trailing], 36)
.padding(.bottom, 8)
.disabled(isPageChanging || currPage != 0)
}
}
}
private func submit() {
// ....
submitCallback()
}
}
See comment below for remaining view code: