Skip to content

Commit

Permalink
reafactor: 툴팁 개선
Browse files Browse the repository at this point in the history
  • Loading branch information
devMinseok committed Aug 12, 2024
1 parent ea0ef95 commit 585b358
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,12 @@ struct TooltipDetailView: View {
@State var downDirectionWithDimTooltip: DownDirectionWithDimTooltip?
@State var upDirectionWithDimTooltip: UpDirectionWithDimTooltip?

let downDirectionTooltip_ = DownDirectionTooltip()
let upDirectionTooltip_ = UpDirectionTooltip()
let downDirectionWithDimTooltip_ = DownDirectionWithDimTooltip()
let upDirectionWithDimTooltip_ = UpDirectionWithDimTooltip()


var body: some View {
VStack {
Button(
title: "Direction: .down, Color: .white, dim: false",
action: {
downDirectionTooltip = downDirectionTooltip_
downDirectionTooltip = .init()
}
)
.buttonStyle(.box(size: .large, color: .primary))
Expand All @@ -36,7 +30,7 @@ struct TooltipDetailView: View {
Button(
title: "Direction: .up, Color: .black, dim: false",
action: {
upDirectionTooltip = upDirectionTooltip_
upDirectionTooltip = .init()
}
)
.buttonStyle(.box(size: .large, color: .primary))
Expand All @@ -45,7 +39,7 @@ struct TooltipDetailView: View {
Button(
title: "Direction: .down, Color: .white, dim: true",
action: {
downDirectionWithDimTooltip = downDirectionWithDimTooltip_
downDirectionWithDimTooltip = .init()
}
)
.buttonStyle(.box(size: .large, color: .primary))
Expand All @@ -54,7 +48,7 @@ struct TooltipDetailView: View {
Button(
title: "Direction: .up, Color: .black, dim: true",
action: {
upDirectionWithDimTooltip = upDirectionWithDimTooltip_
upDirectionWithDimTooltip = .init()
}
)
.buttonStyle(.box(size: .large, color: .primary))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import SwiftUI

public protocol Tooltip: Hashable {
public protocol Tooltip: Equatable {
var title: Text { get }
var color: TooltipColor { get }
var direction: TooltipDirection { get }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ struct TooltipTarget: View {
}

extension View {
public func setTooltipTarget(tooltip: some Tooltip) -> some View {
public func setTooltipTarget<T: Tooltip>(tooltip: T.Type) -> some View {
return self
.background(
TooltipTarget(identifier: tooltip)
TooltipTarget(identifier: ObjectIdentifier(tooltip))
)
}

public func tooltipDestination(tooltip: Binding<(some Tooltip)?>) -> some View {
public func tooltipDestination<T: Tooltip>(tooltip: Binding<T?>) -> some View {
return self
.overlayWithOnPreferenceChange(FrameMeasurePreferenceKey.self) { value in
if let content = tooltip.wrappedValue, let position = value[content] {
if let content = tooltip.wrappedValue, let position = value[ObjectIdentifier(type(of: content))] {
TooltipView(content: content, position: position)
.transition(.opacity.animation(.easeInOut))
.onTapGesture {
Expand Down

0 comments on commit 585b358

Please sign in to comment.