I am working with a UIKit app, which has an MKMapView in it, which displays a bunch of MKAnnotationViews. For each annotation view, I'm using a SwiftUI view to draw the detailAccessoryView
. This works, but whenever a keyboard is presented (even if it's in another view controller), I see a major memory spike in the app. For e.g., it goes from using 130MB to 600MB+ on an iPhone8 (the exact values don't matter of course). This explains a crash that seems to be happening with the same app in production as well, which I reported in this DevForums Thread
From what I can tell, whenever a keyboard is shown, the SwiftUI views seem go repeatedly resize or re-layout themselves, maybe trying to reconfigure their internal layout or something. If I reduce the number of views in my SwiftUI view, it reduces the memory spike; if I remove the SwiftUI view and just use a plain UIView, the spike completely disappears.
My question is: how can I get the SwiftUI views to ignore what's happening with the keyboard in some other view? I've read in some other threads that there is a 'keyboard avoidance' issue with iOS14 and above ... though in my SwiftUI view, there isn't any text field in it's own views. I've tried adding the modifier to the top-level SwiftUI view:
.ignoresSafeArea(.keyboard)
But it doesn't make a difference
Can anyone shed some light on this? Is there another way to avoid keyboard changes in a SwiftUI view?