Weird blank area showing up after cancelling when using EKEventEditViewController in SwiftUI

Viewed 132

What I am trying to do: I am writing a time/date program for iOS and MacOS that does things which Apple’s programs do not do. My program allows using, creating, and editing the same events one sees in Calendar.app, so my code uses EventKit and EventKitUI. And since my UI is written using SwiftUI, I have wrappers around EventKitUI classes. Mostly this works, but something weird is happening with EKEventEditViewController (used for creating new events).

Event view

We start off in the event view and press the “Add external event” (הוסף אירוע חיצוני) button.

EKEventEditViewController

EKEventEditViewController is shown in a popup.

EKEventEditViewController 2

We press the “Cancel” (ביטול) button and are asked if we want to cancel changes or continue editing. We affirm that we want to cancel. And then, as EKEventEditViewController disappears, something weird happens.

Edit view 2

There is this weird blank space which will not go away. It even shows up in other tabs. And it does not seem to be anything laid over the bottom of my events list. According to Xcode, the bottom of the list is just… gone.

Xcode view hierarchy dissection

Note: I have not seen this problem in other contexts (adding an event, editing an event, other wrapped EventKitUI view controllers). It also only happens in iOS, not in macOS.

The code for my EKEventEditViewController wrapper:

import EventKit
import EventKitUI
import Foundation
import SwiftUI

struct ASAEKEventEditView:  UIViewControllerRepresentable {
    @Binding var action:  EKEventEditViewAction?
    @Environment(\.presentationMode) var presentationMode

    func makeCoordinator() -> Coordinator {
        return Coordinator(self)
    } // func makeCoordinator() -> Coordinator
    
    var event:  EKEvent?
    var eventStore:  EKEventStore
    
    func makeUIViewController(context: Context) -> EKEventEditViewController {
        let eventEditViewController = EKEventEditViewController()
        eventEditViewController.eventStore = eventStore
        if let event = event {
            eventEditViewController.event = event
        }
        eventEditViewController.delegate = context.coordinator
        eventEditViewController.editViewDelegate = context.coordinator
        return eventEditViewController
    } // func makeUIViewController(context: Context) -> EKEventEditViewController
    
    func updateUIViewController(_ uiViewController: EKEventEditViewController, context: Context) {

    } // func updateUIViewController(_ uiViewController: EKEventEditViewController, context: Context)

    class Coordinator:  NSObject, EKEventEditViewDelegate, UINavigationControllerDelegate {
        var parent:  ASAEKEventEditView
        
        init(_ parent: ASAEKEventEditView) {
            self.parent = parent
        } // init(_ parent: ASAEKEventEditView)
        
        func eventEditViewController(_ controller: EKEventEditViewController, didCompleteWith action: EKEventEditViewAction) {
            switch action {
            case .canceled:
                debugPrint(#file, #function, "Canceled")

            case .saved:
                debugPrint(#file, #function, "Saved")
                
            case .deleted:
                debugPrint(#file, #function, "Deleted")
                
            @unknown default:
                debugPrint(#file, #function, "Unknown default")
            } // switch action
            
            parent.action = action

            parent.presentationMode.wrappedValue.dismiss()
        } // func eventEditViewController(_ controller: EKEventEditViewController, didCompleteWith action: EKEventEditViewAction)

        func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {
            debugPrint(#file, #function, navigationController, viewController, animated)
        }

        func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) {
            debugPrint(#file, #function, navigationController, viewController, animated)
        }
    } // class Coordinator

} // struct ASAEKEventEditView

The code for showing the wrapped view controller (referencing some variables and constants):

                    Button(action:
                            {
                                self.showingEventEditView = true
                            }, label:  {
                                Text(NSLocalizedString(ADD_EXTERNAL_EVENT_STRING, comment: ""))
                            })
                        .popover(isPresented:  $showingEventEditView, arrowEdge: .top) {
                            ASAEKEventEditView(action: self.$action, event: nil, eventStore: self.eventManager.eventStore).frame(minWidth:  FRAME_MIN_WIDTH, minHeight:  FRAME_MIN_HEIGHT)
                        }
                        .foregroundColor(.accentColor)

Does anyone have any idea what is going wrong or what the weird blank space is? Thanks in advance for any help anyone can provide in getting rid of it.

0 Answers
Related