Skip to content

Commit

Permalink
🔨 iOS version bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
benlmyers committed Aug 11, 2022
1 parent d7480bf commit 180f510
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
<key>ShinySwiftUI.xcscheme_^#shared#^_</key>
<dict>
<key>isShown</key>
<false/>
<true/>
<key>orderHint</key>
<integer>1</integer>
<integer>4</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
Expand Down
37 changes: 32 additions & 5 deletions Sources/ShinySwiftUI/Views/HoverView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import SwiftUI

@available(macOS 11.0, *)
@available(macOS 11.0, iOS 14.0, *)
public struct HoverView<Content>: View where Content: View {

// MARK: - Public Wrapped Properties
Expand All @@ -24,32 +24,59 @@ public struct HoverView<Content>: 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<Bool>
func makeBody(configuration: Configuration) -> some View {
Expand Down

0 comments on commit 180f510

Please sign in to comment.