Skip to content

Commit bf15ba7

Browse files
committed
examples: fix animation glitch on iOS 26
1 parent c954ce3 commit bf15ba7

1 file changed

Lines changed: 50 additions & 47 deletions

File tree

Examples/Maps-SwiftUI/Maps/MapsApp.swift

Lines changed: 50 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2021 the FloatingPanel authors. All rights reserved. MIT license.
22

3-
import SwiftUI
43
import FloatingPanel
4+
import SwiftUI
55

66
@main
77
struct MapsApp: App {
@@ -24,12 +24,12 @@ struct MapsApp: App {
2424
final class MapPanelCoordinator: FloatingPanelCoordinator {
2525
enum Event {}
2626

27-
let action: (Event) -> ()
27+
let action: (Event) -> Void
2828
let proxy: FloatingPanelProxy
2929

3030
private lazy var delegate: FloatingPanelControllerDelegate? = self
3131

32-
init(action: @escaping (Event) -> ()) {
32+
init(action: @escaping (Event) -> Void) {
3333
self.action = action
3434
self.proxy = .init(controller: FloatingPanelController())
3535
}
@@ -42,51 +42,54 @@ final class MapPanelCoordinator: FloatingPanelCoordinator {
4242
contentHostingController.ignoresKeyboardSafeArea()
4343

4444
if #available(iOS 16, *) {
45-
// Set the delegate object
46-
controller.delegate = delegate
47-
48-
// Set up the content
49-
contentHostingController.view.backgroundColor = nil
50-
controller.set(contentViewController: contentHostingController)
51-
52-
// Show the panel
53-
controller.addPanel(toParent: mainHostingController, animated: false)
54-
} else {
55-
// NOTE: Fix floating panel content view constraints (#549)
56-
// This issue happens on iOS 15 or earlier.
57-
58-
// Set the delegate object
59-
controller.delegate = delegate
60-
61-
// Set up the content
62-
contentHostingController.view.backgroundColor = nil
63-
let contentWrapperViewController = UIViewController()
64-
contentWrapperViewController.view.addSubview(contentHostingController.view)
65-
contentWrapperViewController.addChild(contentHostingController)
66-
contentHostingController.didMove(toParent: contentWrapperViewController)
67-
controller.set(contentViewController: contentWrapperViewController)
68-
69-
// Show the panel
70-
controller.addPanel(toParent: mainHostingController, animated: false)
71-
72-
contentHostingController.view.translatesAutoresizingMaskIntoConstraints = false
73-
let bottomConstraint = contentHostingController.view.bottomAnchor.constraint(
74-
equalTo: contentWrapperViewController.view.bottomAnchor
75-
)
76-
bottomConstraint.priority = .defaultHigh
77-
NSLayoutConstraint.activate([
78-
contentHostingController.view.topAnchor.constraint(
79-
equalTo: contentWrapperViewController.view.topAnchor
80-
),
81-
contentHostingController.view.leadingAnchor.constraint(
82-
equalTo: contentWrapperViewController.view.leadingAnchor
83-
),
84-
contentHostingController.view.trailingAnchor.constraint(
85-
equalTo: contentWrapperViewController.view.trailingAnchor
86-
),
87-
bottomConstraint
88-
])
45+
if #unavailable(iOS 26) {
46+
// Set the delegate object
47+
controller.delegate = delegate
48+
49+
// Set up the content
50+
contentHostingController.view.backgroundColor = nil
51+
controller.set(contentViewController: contentHostingController)
52+
53+
// Show the panel
54+
controller.addPanel(toParent: mainHostingController, animated: false)
55+
return
56+
}
8957
}
58+
59+
// NOTE: Fix floating panel content view constraints (#549)
60+
// This issue happens on iOS 15 or earlier, and iOS 26 or later.
61+
62+
// Set the delegate object
63+
controller.delegate = delegate
64+
65+
// Set up the content
66+
contentHostingController.view.backgroundColor = nil
67+
let contentWrapperViewController = UIViewController()
68+
contentWrapperViewController.view.addSubview(contentHostingController.view)
69+
contentWrapperViewController.addChild(contentHostingController)
70+
contentHostingController.didMove(toParent: contentWrapperViewController)
71+
controller.set(contentViewController: contentWrapperViewController)
72+
73+
// Show the panel
74+
controller.addPanel(toParent: mainHostingController, animated: false)
75+
76+
contentHostingController.view.translatesAutoresizingMaskIntoConstraints = false
77+
let bottomConstraint = contentHostingController.view.bottomAnchor.constraint(
78+
equalTo: contentWrapperViewController.view.bottomAnchor
79+
)
80+
bottomConstraint.priority = .defaultHigh
81+
NSLayoutConstraint.activate([
82+
contentHostingController.view.topAnchor.constraint(
83+
equalTo: contentWrapperViewController.view.topAnchor
84+
),
85+
contentHostingController.view.leadingAnchor.constraint(
86+
equalTo: contentWrapperViewController.view.leadingAnchor
87+
),
88+
contentHostingController.view.trailingAnchor.constraint(
89+
equalTo: contentWrapperViewController.view.trailingAnchor
90+
),
91+
bottomConstraint,
92+
])
9093
}
9194

9295
func onUpdate<Representable>(

0 commit comments

Comments
 (0)