-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9d338cc
commit e6aa32d
Showing
28 changed files
with
638 additions
and
115 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
115 changes: 115 additions & 0 deletions
115
Projects/Shared/DesignSystem/Example/Sources/Component/TooltipDetailView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
// | ||
// TooltipDetailView.swift | ||
// DesignSystemExample | ||
// | ||
// Created by devMinseok on 8/7/24. | ||
// Copyright © 2024 PomoNyang. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
|
||
import DesignSystem | ||
|
||
struct TooltipDetailView: View { | ||
@State var downDirectionTooltip: DownDirectionTooltip? | ||
@State var upDirectionTooltip: UpDirectionTooltip? | ||
@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_ | ||
} | ||
) | ||
.buttonStyle(.box(size: .large, color: .primary)) | ||
.setTooltipTarget(tooltip: downDirectionTooltip_) | ||
|
||
Button( | ||
title: "Direction: .up, Color: .black, dim: false", | ||
action: { | ||
upDirectionTooltip = upDirectionTooltip_ | ||
} | ||
) | ||
.buttonStyle(.box(size: .large, color: .primary)) | ||
.setTooltipTarget(tooltip: upDirectionTooltip_) | ||
|
||
Button( | ||
title: "Direction: .down, Color: .white, dim: true", | ||
action: { | ||
downDirectionWithDimTooltip = downDirectionWithDimTooltip_ | ||
} | ||
) | ||
.buttonStyle(.box(size: .large, color: .primary)) | ||
.setTooltipTarget(tooltip: downDirectionWithDimTooltip_) | ||
|
||
Button( | ||
title: "Direction: .up, Color: .black, dim: true", | ||
action: { | ||
upDirectionWithDimTooltip = upDirectionWithDimTooltip_ | ||
} | ||
) | ||
.buttonStyle(.box(size: .large, color: .primary)) | ||
.setTooltipTarget(tooltip: upDirectionWithDimTooltip_) | ||
} | ||
.frame(maxWidth: .infinity, maxHeight: .infinity) | ||
.background(.yellow) | ||
.tooltipDestination(tooltip: $downDirectionTooltip) | ||
.tooltipDestination(tooltip: $upDirectionTooltip) | ||
.tooltipDestination(tooltip: $downDirectionWithDimTooltip) | ||
.tooltipDestination(tooltip: $upDirectionWithDimTooltip) | ||
} | ||
} | ||
|
||
|
||
|
||
struct DownDirectionTooltip: Tooltip { | ||
var title: Text { Text("DownDirectionTooltip") } | ||
var color: TooltipColor { .white } | ||
var direction: TooltipDirection { .down } | ||
var targetCornerRadius: CGFloat? { Alias.BorderRadius.small } | ||
var dimEnabled: Bool { false } | ||
var padding: CGFloat { 12 } | ||
} | ||
|
||
struct UpDirectionTooltip: Tooltip { | ||
var title: Text { Text("UpDirectionTooltip") } | ||
var color: TooltipColor { .black } | ||
var direction: TooltipDirection { .up } | ||
var targetCornerRadius: CGFloat? { Alias.BorderRadius.small } | ||
var dimEnabled: Bool { false } | ||
var padding: CGFloat { 12 } | ||
} | ||
|
||
struct DownDirectionWithDimTooltip: Tooltip { | ||
var title: Text { Text("DownDirectionWithDimTooltip") } | ||
var color: TooltipColor { .white } | ||
var direction: TooltipDirection { .down } | ||
var targetCornerRadius: CGFloat? { Alias.BorderRadius.small } | ||
var dimEnabled: Bool { true } | ||
var padding: CGFloat { 12 } | ||
} | ||
|
||
struct UpDirectionWithDimTooltip: Tooltip { | ||
var title: Text { Text("UpDirectionWithDimTooltip") } | ||
var color: TooltipColor { .black } | ||
var direction: TooltipDirection { .up } | ||
var targetCornerRadius: CGFloat? { Alias.BorderRadius.small } | ||
var dimEnabled: Bool { true } | ||
var padding: CGFloat { 12 } | ||
} | ||
|
||
|
||
// Preview환경에서만 크래시 발생: | ||
// some View와 같은 제너릭 타입은 프리뷰에서 타입 추론에 문제가 생길 수 있습니다. 특히 프리뷰의 경우, 다양한 뷰가 서로 다른 타입으로 처리될 수 있어, 뷰의 타입이 명확하지 않은 경우 문제가 발생할 수 있습니다. | ||
//#Preview { | ||
// TooltipDetailView() | ||
//} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
Projects/Shared/DesignSystem/Sources/Component/Button/ButtonHuggingPriorityHorizontal.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// ButtonHuggingPriorityHorizontal.swift | ||
// DesignSystem | ||
// | ||
// Created by devMinseok on 8/10/24. | ||
// Copyright © 2024 PomoNyang. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
public enum ButtonHuggingPriorityHorizontal { | ||
case high | ||
case low | ||
} | ||
|
||
extension ButtonHuggingPriorityHorizontal { | ||
var width: CGFloat? { | ||
switch self { | ||
case .high: | ||
return nil | ||
case .low: | ||
return .infinity | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
Projects/Shared/DesignSystem/Sources/Component/Tooltip/ExcludeRoundedRectMask.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// ExcludeRoundedRectMask.swift | ||
// DesignSystem | ||
// | ||
// Created by devMinseok on 8/9/24. | ||
// Copyright © 2024 PomoNyang. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct ExcludeRoundedRectMask: View { | ||
let excludedRect: CGRect | ||
let cornerRadius: CGFloat | ||
|
||
var body: some View { | ||
GeometryReader { geometry in | ||
let fullRect = geometry.frame(in: .local) | ||
|
||
Path { path in | ||
path.addRect(fullRect) | ||
|
||
let roundedRect = RoundedRectangle(cornerRadius: cornerRadius) | ||
.path(in: excludedRect) | ||
path.addPath(roundedRect) | ||
} | ||
.fill(style: FillStyle(eoFill: true)) | ||
} | ||
.ignoresSafeArea() | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
Projects/Shared/DesignSystem/Sources/Component/Tooltip/FrameMeasurePreferenceKey.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// FrameMeasurePreferenceKey.swift | ||
// DesignSystem | ||
// | ||
// Created by devMinseok on 8/9/24. | ||
// Copyright © 2024 PomoNyang. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct FrameMeasurePreferenceKey: PreferenceKey { | ||
typealias Value = [AnyHashable: CGRect] | ||
|
||
static var defaultValue: Value = Value() | ||
|
||
static func reduce(value: inout Value, nextValue: () -> Value) { | ||
value.merge(nextValue()) { _, new in | ||
new | ||
} | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
Projects/Shared/DesignSystem/Sources/Component/Tooltip/OverlayWithOnPreferenceChange.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// | ||
// OverlayWithOnPreferenceChange.swift | ||
// DesignSystem | ||
// | ||
// Created by devMinseok on 8/9/24. | ||
// Copyright © 2024 PomoNyang. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct OverlayWithOnPreferenceChange< | ||
K, OverlayContent | ||
>: ViewModifier where K: PreferenceKey, K.Value: Equatable, OverlayContent: View { | ||
let preferenceKey: K.Type | ||
let contentForOverlay: (K.Value) -> OverlayContent | ||
@State var value: K.Value? | ||
|
||
init( | ||
preferenceKey: K.Type, | ||
@ViewBuilder contentForOverlay: @escaping (K.Value) -> OverlayContent | ||
) { | ||
self.preferenceKey = preferenceKey | ||
self.contentForOverlay = contentForOverlay | ||
} | ||
|
||
func body(content: Content) -> some View { | ||
content | ||
.overlay { | ||
if let value { | ||
contentForOverlay(value) | ||
} | ||
} | ||
.onPreferenceChange(preferenceKey) { value in | ||
self.value = value | ||
} | ||
} | ||
} | ||
|
||
extension View { | ||
func overlayWithOnPreferenceChange<K, Content>( | ||
_ key: K.Type, | ||
@ViewBuilder content: @escaping (K.Value) -> Content | ||
) -> some View where K: PreferenceKey, K.Value: Equatable, Content: View { | ||
modifier( | ||
OverlayWithOnPreferenceChange( | ||
preferenceKey: key, | ||
contentForOverlay: content | ||
) | ||
) | ||
} | ||
} |
Oops, something went wrong.