diff --git a/Examples/Samples/Sources/AppDelegate.swift b/Examples/Samples/Sources/AppDelegate.swift index b7fd8891..b13e73d6 100644 --- a/Examples/Samples/Sources/AppDelegate.swift +++ b/Examples/Samples/Sources/AppDelegate.swift @@ -4,8 +4,18 @@ // import UIKit +import FloatingPanel @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? + + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool { + FloatingPanelSurfaceView.appearance().shadowHidden = false + FloatingPanelSurfaceView.appearance().cornerRadius = 6.0 + // FloatingPanelSurfaceView.appearance().backgroundColor = .lightGray + // FloatingPanelBackdropView.appearance().backgroundColor = .red + // GrabberHandleView.appearance().barColor = .red + return true + } } diff --git a/Examples/Samples/Sources/ViewController.swift b/Examples/Samples/Sources/ViewController.swift index 3826c0e3..9fd079d4 100644 --- a/Examples/Samples/Sources/ViewController.swift +++ b/Examples/Samples/Sources/ViewController.swift @@ -123,10 +123,6 @@ class SampleListViewController: UIViewController { mainPanelVC = FloatingPanelController() mainPanelVC.delegate = self - // Initialize FloatingPanelController and add the view - mainPanelVC.surfaceView.cornerRadius = 6.0 - mainPanelVC.surfaceView.shadowHidden = false - // Set a content view controller mainPanelVC.set(contentViewController: contentVC) diff --git a/Framework/Sources/FloatingPanel.swift b/Framework/Sources/FloatingPanel.swift index 1ca1f520..19a48717 100644 --- a/Framework/Sources/FloatingPanel.swift +++ b/Framework/Sources/FloatingPanel.swift @@ -68,10 +68,8 @@ class FloatingPanel: NSObject, UIGestureRecognizerDelegate, UIScrollViewDelegate viewcontroller = vc surfaceView = FloatingPanelSurfaceView() - surfaceView.backgroundColor = .white backdropView = FloatingPanelBackdropView() - backdropView.backgroundColor = .black backdropView.alpha = 0.0 self.layoutAdapter = FloatingPanelLayoutAdapter(surfaceView: surfaceView, diff --git a/Framework/Sources/FloatingPanelBackdropView.swift b/Framework/Sources/FloatingPanelBackdropView.swift index 93ad6b0f..1c752e40 100644 --- a/Framework/Sources/FloatingPanelBackdropView.swift +++ b/Framework/Sources/FloatingPanelBackdropView.swift @@ -6,4 +6,26 @@ import UIKit /// A view that presents a backdrop interface behind a floating panel. -public class FloatingPanelBackdropView: UIView { } +public class FloatingPanelBackdropView: UIView { + override init(frame: CGRect) { + super.init(frame: frame) + setUp() + } + + required public init?(coder aDecoder: NSCoder) { + super.init(coder: aDecoder) + setUp() + } + + private func setUp() { + layer.backgroundColor = UIColor.black.cgColor + } + + @objc dynamic public override var backgroundColor: UIColor? { + get { + guard let color = layer.backgroundColor else { return nil } + return UIColor(cgColor: color) + } + set { layer.backgroundColor = newValue?.cgColor } + } +} diff --git a/Framework/Sources/FloatingPanelSurfaceView.swift b/Framework/Sources/FloatingPanelSurfaceView.swift index 4ef1cb16..52855e90 100644 --- a/Framework/Sources/FloatingPanelSurfaceView.swift +++ b/Framework/Sources/FloatingPanelSurfaceView.swift @@ -15,7 +15,7 @@ public class FloatingPanelSurfaceView: UIView { public let grabberHandle: GrabberHandleView = GrabberHandleView() /// Offset of the grabber handle from the top - public var grabberTopPadding: CGFloat = 6.0 { didSet { + @objc dynamic public var grabberTopPadding: CGFloat = 6.0 { didSet { setNeedsUpdateConstraints() } } @@ -25,10 +25,10 @@ public class FloatingPanelSurfaceView: UIView { } /// Grabber view width and height - public var grabberHandleWidth: CGFloat = 36.0 { didSet { + @objc dynamic public var grabberHandleWidth: CGFloat = 36.0 { didSet { setNeedsUpdateConstraints() } } - public var grabberHandleHeight: CGFloat = 5.0 { didSet { + @objc dynamic public var grabberHandleHeight: CGFloat = 5.0 { didSet { setNeedsUpdateConstraints() } } @@ -48,7 +48,7 @@ public class FloatingPanelSurfaceView: UIView { private var color: UIColor? = .white { didSet { setNeedsLayout() } } var bottomOverflow: CGFloat = 0.0 // Must not call setNeedsLayout() - public override var backgroundColor: UIColor? { + @objc dynamic public override var backgroundColor: UIColor? { get { return color } set { color = newValue } } @@ -57,34 +57,34 @@ public class FloatingPanelSurfaceView: UIView { /// /// `self.contentView` is masked with the top rounded corners automatically on iOS 11 and later. /// On iOS 10, they are not automatically masked because of a UIVisualEffectView issue. See https://forums.developer.apple.com/thread/50854 - public var cornerRadius: CGFloat { + @objc dynamic public var cornerRadius: CGFloat { set { containerView.layer.cornerRadius = newValue; setNeedsLayout() } get { return containerView.layer.cornerRadius } } /// A Boolean indicating whether the surface shadow is displayed. - public var shadowHidden: Bool = false { didSet { setNeedsLayout() } } + @objc dynamic public var shadowHidden: Bool = false { didSet { setNeedsLayout() } } /// The color of the surface shadow. - public var shadowColor: UIColor = .black { didSet { setNeedsLayout() } } + @objc dynamic public var shadowColor: UIColor = .black { didSet { setNeedsLayout() } } /// The offset (in points) of the surface shadow. - public var shadowOffset: CGSize = CGSize(width: 0.0, height: 1.0) { didSet { setNeedsLayout() } } + @objc dynamic public var shadowOffset: CGSize = CGSize(width: 0.0, height: 1.0) { didSet { setNeedsLayout() } } /// The opacity of the surface shadow. - public var shadowOpacity: Float = 0.2 { didSet { setNeedsLayout() } } + @objc dynamic public var shadowOpacity: Float = 0.2 { didSet { setNeedsLayout() } } /// The blur radius (in points) used to render the surface shadow. - public var shadowRadius: CGFloat = 3 { didSet { setNeedsLayout() } } + @objc dynamic public var shadowRadius: CGFloat = 3 { didSet { setNeedsLayout() } } /// The width of the surface border. - public var borderColor: UIColor? { didSet { setNeedsLayout() } } + @objc dynamic public var borderColor: UIColor? { didSet { setNeedsLayout() } } /// The color of the surface border. - public var borderWidth: CGFloat = 0.0 { didSet { setNeedsLayout() } } + @objc dynamic public var borderWidth: CGFloat = 0.0 { didSet { setNeedsLayout() } } /// Offset of the container view from the top - public var containerTopInset: CGFloat = 0.0 { didSet { + @objc dynamic public var containerTopInset: CGFloat = 0.0 { didSet { setNeedsUpdateConstraints() } } diff --git a/Framework/Sources/GrabberHandleView.swift b/Framework/Sources/GrabberHandleView.swift index 865eebf5..c82b14e1 100644 --- a/Framework/Sources/GrabberHandleView.swift +++ b/Framework/Sources/GrabberHandleView.swift @@ -7,7 +7,9 @@ import UIKit public class GrabberHandleView: UIView { - public var barColor = UIColor(displayP3Red: 0.76, green: 0.77, blue: 0.76, alpha: 1.0) { didSet { backgroundColor = barColor } } + @objc dynamic public var barColor = UIColor(displayP3Red: 0.76, green: 0.77, blue: 0.76, alpha: 1.0) { + didSet { backgroundColor = barColor } + } required public init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder)