Skip to content

Commit

Permalink
🛹 HoverView
Browse files Browse the repository at this point in the history
  • Loading branch information
benlmyers committed Aug 10, 2022
1 parent d3d9b50 commit de48592
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public extension View {
}
return Group {
if UserDefaults.standard.bool(forKey: ShinySwiftUI.shortcutTooltipDefaultsKey) {
HoverView(button: self.keyboardShortcut(shortcut), string: str, symbols: symbols)
_HoverView(button: self.keyboardShortcut(shortcut), string: str, symbols: symbols)
} else {
self.keyboardShortcut(shortcut)
}
Expand All @@ -74,7 +74,7 @@ public extension View {

@available(macOS 11.0, iOS 13.4, *)
@available(watchOS, unavailable)
private struct HoverView<T>: View where T: View {
private struct _HoverView<T>: View where T: View {

@State var hover: Bool = false

Expand Down
31 changes: 31 additions & 0 deletions Sources/ShinySwiftUI/Views/HoverView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// SwiftUIView.swift
//
//
// Created by Ben Myers on 8/10/22.
//

import SwiftUI

public struct HoverView<Content>: View where Content: View {

// MARK: - Public Wrapped Properties

/// The content to display.
@ViewBuilder public let content: (Bool) -> Content

/// Whether the view is hovered.
@State public var hover: Bool = false

// MARK: - Public Body View

public var body: some View {
content(hover).onHover { hover = $0 }
}

// MARK: - Public Initalizers

public init(content: @escaping (Bool) -> Content) {
self.content = content
}
}

0 comments on commit de48592

Please sign in to comment.