Skip to content

Commit c5da510

Browse files
committed
Enable to build it for iOS 12
1 parent 5fff51b commit c5da510

4 files changed

Lines changed: 24 additions & 6 deletions

File tree

Examples/SamplesSwiftUI/SamplesSwiftUI/UseCases/MainView.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import FloatingPanel
44
import SwiftUI
55
import UIKit
6+
import os.log
67

78
struct MainView: View {
89
@State private var panelLayout: FloatingPanelLayout? = MyFloatingPanelLayout()
@@ -20,6 +21,9 @@ struct MainView: View {
2021
.floatingPanelSurfaceAppearance(.transparent())
2122
.floatingPanelLayout(panelLayout)
2223
.floatingPanelState($panelState)
24+
.onChange(of: panelState) { newValue in
25+
Logger().debug("Panel state changed: \(newValue ?? .hidden)")
26+
}
2327

2428
VStack(spacing: 32) {
2529
Button("Move to full") {

FloatingPanel.xcodeproj/project.pbxproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@
523523
ENABLE_USER_SCRIPT_SANDBOXING = YES;
524524
INFOPLIST_FILE = Sources/Info.plist;
525525
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
526-
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
526+
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
527527
LD_RUNPATH_SEARCH_PATHS = (
528528
"$(inherited)",
529529
"@executable_path/Frameworks",
@@ -556,7 +556,7 @@
556556
ENABLE_USER_SCRIPT_SANDBOXING = YES;
557557
INFOPLIST_FILE = Sources/Info.plist;
558558
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
559-
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
559+
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
560560
LD_RUNPATH_SEARCH_PATHS = (
561561
"$(inherited)",
562562
"@executable_path/Frameworks",
@@ -694,7 +694,7 @@
694694
ENABLE_USER_SCRIPT_SANDBOXING = YES;
695695
INFOPLIST_FILE = Sources/Info.plist;
696696
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
697-
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
697+
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
698698
LD_RUNPATH_SEARCH_PATHS = (
699699
"$(inherited)",
700700
"@executable_path/Frameworks",

Sources/Core.swift

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright 2018-Present Shin Yamamoto. All rights reserved. MIT license.
22

3+
#if canImport(Combine)
34
import Combine
5+
#endif
46
import UIKit
57
import os.log
68

@@ -50,7 +52,13 @@ class Core: NSObject, UIGestureRecognizerDelegate {
5052
}
5153
}
5254
}
53-
private(set) var statePublisher: CurrentValueSubject<FloatingPanelState, Never> = .init(.hidden)
55+
56+
@available(iOS 13.0, *)
57+
private(set) var statePublisher: CurrentValueSubject<FloatingPanelState, Never>? {
58+
get { _statePublisher as? CurrentValueSubject<FloatingPanelState, Never> }
59+
set { _statePublisher = newValue }
60+
}
61+
private var _statePublisher: Any?
5462

5563
var panGestureRecognizer: FloatingPanelPanGestureRecognizer
5664
let panGestureDelegateRouter: FloatingPanelPanGestureRecognizer.DelegateRouter
@@ -100,6 +108,10 @@ class Core: NSObject, UIGestureRecognizerDelegate {
100108

101109
super.init()
102110

111+
if #available(iOS 13.0, *) {
112+
statePublisher = .init(.hidden)
113+
}
114+
103115
panGestureRecognizer.set(floatingPanel: self)
104116
surfaceView.addGestureRecognizer(panGestureRecognizer)
105117
panGestureRecognizer.addTarget(self, action: #selector(handle(panGesture:)))
@@ -262,7 +274,9 @@ class Core: NSObject, UIGestureRecognizerDelegate {
262274
layoutAdapter.activateLayout(for: target, forceLayout: true)
263275
backdropView.alpha = getBackdropAlpha(for: target)
264276
adjustScrollContentInsetIfNeeded()
265-
statePublisher.send(target)
277+
if #available(iOS 13.0, *) {
278+
statePublisher?.send(target)
279+
}
266280
}
267281

268282
private func getBackdropAlpha(for target: FloatingPanelState) -> CGFloat {

Sources/SwiftUI/FloatingPanelView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ extension FloatingPanelCoordinatorProxy {
235235

236236
/// Start observing ``FloatingPanelController/state`` through the `Core` object.
237237
func observeStateChanges() {
238-
controller.floatingPanel.statePublisher
238+
controller.floatingPanel.statePublisher?
239239
.sink { [weak self] state in
240240
guard let self = self else { return }
241241
// Needs to update the state binding value on the next run loop cycle to avoid this error.

0 commit comments

Comments
 (0)