From 180f5102e9ff96d6215289f163ee9c61c4a188e7 Mon Sep 17 00:00:00 2001 From: Ben Myers Date: Wed, 10 Aug 2022 19:08:52 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20iOS=20version=20bug=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xcschemes/xcschememanagement.plist | 4 +- Sources/ShinySwiftUI/Views/HoverView.swift | 37 ++++++++++++++++--- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/.swiftpm/xcode/xcuserdata/benmyers.xcuserdatad/xcschemes/xcschememanagement.plist b/.swiftpm/xcode/xcuserdata/benmyers.xcuserdatad/xcschemes/xcschememanagement.plist index 9d03f3c..1960745 100644 --- a/.swiftpm/xcode/xcuserdata/benmyers.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/.swiftpm/xcode/xcuserdata/benmyers.xcuserdatad/xcschemes/xcschememanagement.plist @@ -7,9 +7,9 @@ ShinySwiftUI.xcscheme_^#shared#^_ isShown - + orderHint - 1 + 4 SuppressBuildableAutocreation diff --git a/Sources/ShinySwiftUI/Views/HoverView.swift b/Sources/ShinySwiftUI/Views/HoverView.swift index 2d329f4..cd1def6 100644 --- a/Sources/ShinySwiftUI/Views/HoverView.swift +++ b/Sources/ShinySwiftUI/Views/HoverView.swift @@ -7,7 +7,7 @@ import SwiftUI -@available(macOS 11.0, *) +@available(macOS 11.0, iOS 14.0, *) public struct HoverView: View where Content: View { // MARK: - Public Wrapped Properties @@ -24,32 +24,59 @@ public struct HoverView: View where Content: View { /// The action to perform on click. public let action: () -> Void + /// The action to perform on hover. + public let onHover: (Bool) -> Void // MARK: - Public Body View public var body: some View { Button(action: action) { - content(hover, clicked).onHover { hover = $0 } + content(hover, clicked).onHover { + hover = $0 + onHover($0) + } } .buttonStyle(HoverButtonStyle(pressed: $clicked)) } // MARK: - Public Initalizers - public init(action: @escaping () -> Void = {}, content c: @escaping (Bool, Bool) -> Content) { + public init(action: @escaping () -> Void = {}, onHover: @escaping (Bool) -> Void = { _ in }, content c: @escaping (Bool, Bool) -> Content) { self.action = action + self.onHover = onHover self.content = c } - public init(action: @escaping () -> Void = {}, content c: @escaping (Bool) -> Content) { + public init(action: @escaping () -> Void = {}, onHover: @escaping (Bool) -> Void = { _ in }, content c: @escaping (Bool) -> Content) { self.action = action + self.onHover = onHover self.content = { (hover: Bool, click: Bool) in return c(hover) } } + + // MARK: - Public Methods + + /** + Animates the `hover` property of the view. + + - parameter animation: The Animation to use. + */ + public func animateHover(_ animation: Animation = .slickEaseOut) -> some View { + return self.animation(animation, value: hover) + } + + /** + Animates the `clicked` property of the view. + + - parameter animation: The Animation to use. + */ + public func animateClicked(_ animation: Animation = .slickEaseOut) -> some View { + return self.animation(animation, value: clicked) + } } -@available(macOS 11.0, *) +@available(macOS 11.0, iOS 14.0, *) fileprivate struct HoverButtonStyle: ButtonStyle { let pressed: Binding func makeBody(configuration: Configuration) -> some View {