Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WEAV-136] ToolTip AttibutedString 적용 #42

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,4 @@ Derived/
Tuist/.build
Projects/Core/CoreKit/Sources/Secret.swift
graph.png
OpenApiGenerator/.build
64 changes: 45 additions & 19 deletions Projects/DesignSystem/DesignCore/Sources/Tooltip/ToolTip.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,63 @@
import SwiftUI

extension View {
public func tooltip(message: String, offset: CGFloat) -> some View {
public func tooltip(message: String?, offset: CGFloat) -> some View {
return modifier(ToolTipViewModifier(message: message, offset: offset))
}

public func tooltip(message: AttributedString?, offset: CGFloat) -> some View {
return modifier(ToolTipViewModifier(message: message, offset: offset))
}
}

struct ToolTipViewModifier: ViewModifier {
let message: String
let message: AttributedString?
let offset: CGFloat

init(
message: AttributedString?,
offset: CGFloat
) {
self.message = message
self.offset = offset
}

init(
message: String?,
offset: CGFloat
) {
if let message {
self.message = .init(stringLiteral: message)
} else {
self.message = nil
}
self.offset = offset
}

func body(content: Content) -> some View {
content
.overlay {
Text(message)
.padding(.horizontal, 20)
.padding(.vertical, 10)
.typography(.regular_12)
.foregroundStyle(.white)
.multilineTextAlignment(.center)
.background {
ZStack {
RoundedRectangle(cornerRadius: 6)
.fill(DesignCore.Colors.grey400)
VStack {
Spacer()
InvertedTriangle()
if let message {
Text(message)
.padding(.horizontal, 20)
.padding(.vertical, 10)
.typography(.regular_12)
.foregroundStyle(.white)
.multilineTextAlignment(.center)
.background {
ZStack {
RoundedRectangle(cornerRadius: 6)
.fill(DesignCore.Colors.grey400)
VStack {
Spacer()
InvertedTriangle()
}
.offset(y: 12)
}
.offset(y: 12)
}
}
.frame(width: 300)
.offset(y: -offset)
// .frame(width: 300)
.offset(y: -offset)
}
}
}
}
Expand Down
7 changes: 2 additions & 5 deletions Projects/Features/Home/UnitTest/WidgetUnitTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,15 @@ struct WidgetUnitTest {
self.selectionState = WidgetSelectionModel()
self.selectionIntent = WidgetSelectionIntent(
model: selectionState,
input: .init(successHandler: {})
input: .init()
)

self.writeState = WidgetWritingModel()
self.writeIntent = WidgetWritingIntent(
model: writeState,
input: .init(
widgetType: .body,
content: nil,
successHandler: {

}
content: nil
),
service: ProfileServiceMock()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ extension AuthProfileAgeInputIntent {
func onFocusChanged(_ value: Bool)
func onTapNextButton(_ year: String)
func onYearChanged(_ year: String)
func toggleToolTip()

// default
func onAppear()
Expand Down Expand Up @@ -75,4 +76,7 @@ extension AuthProfileAgeInputIntent: AuthProfileAgeInputIntent.Intentable {
)
}
}
func toggleToolTip() {
model?.toggleToolTip()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ final class AuthProfileAgeInputModel: ObservableObject {
var isFocused: Bool { get }
var isValidated: Bool { get }
var targetGender: GenderType { get }
var isShowToolTip: Bool { get }

// default
var isLoading: Bool { get }
Expand All @@ -37,6 +38,7 @@ final class AuthProfileAgeInputModel: ObservableObject {
@Published var birthYear = String()
@Published var isFocused: Bool = false
@Published var targetGender: GenderType = .female
@Published var isShowToolTip: Bool = false

// default
@Published var isLoading: Bool = false
Expand All @@ -55,6 +57,7 @@ protocol AuthProfileAgeInputModelActionable: AnyObject {
func setFocuse(_ value: Bool)
func setValidation(value: Bool)
func setTargetGender(_ gender: GenderType)
func toggleToolTip()

// default
func setLoading(status: Bool)
Expand All @@ -79,6 +82,9 @@ extension AuthProfileAgeInputModel: AuthProfileAgeInputModelActionable {
func setTargetGender(_ gender: GenderType) {
targetGender = gender
}
func toggleToolTip() {
isShowToolTip.toggle()
}
// default
func setLoading(status: Bool) {
isLoading = status
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,32 @@ public struct AuthProfileAgeInputView: View {
self._container = StateObject(wrappedValue: container)
}

private var tooltipMessage: AttributedString {
let text = """
2024년 기준으로 2004년생(만 20살)부터
1989년생(만 35살)까지 가입할 수 있어요
"""

var attributedString = AttributedString(text)
let boldRanges = [
text.range(of: "2004년생(만 20살)부터"),
text.range(of: "1989년생(만 35살)")
].compactMap { $0 }

boldRanges.forEach { range in
let attributedRange = attributedString.range(of: text[range])!
attributedString[attributedRange].inlinePresentationIntent = .stronglyEmphasized
}

return attributedString
}

public var body: some View {
VStack {
ProfileInputTemplatedView(
currentPage: 2,
maxPage: 5,
subMessage: "좋은 \(state.targetGender) 소개시켜 드릴께요!",
subMessage: "좋은 \(state.targetGender.name)분 소개시켜 드릴께요!",
mainMessage: "당신의 나이는 무엇인가요?"
) {
VStack {
Expand Down Expand Up @@ -82,7 +102,9 @@ public struct AuthProfileAgeInputView: View {
.frame(height: 92)

Button(action: {

withAnimation {
intent.toggleToolTip()
}
}, label: {
HStack(spacing: 4) {
DesignCore.Images.iconInformation.image
Expand All @@ -94,6 +116,7 @@ public struct AuthProfileAgeInputView: View {
.padding(.top, 20)
}
.padding(.top, 8)
.tooltip(message: state.isShowToolTip ? tooltipMessage : nil, offset: 0)
}

Spacer()
Expand All @@ -118,6 +141,11 @@ public struct AuthProfileAgeInputView: View {

}
.setLoading(state.isLoading)
.onTapGesture {
if state.isShowToolTip {
intent.toggleToolTip()
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,17 @@ public enum GenderType: String, CaseIterable {
case male
case female

var toDto: Components.Schemas.Gender {
public var toDto: Components.Schemas.Gender {
switch self {
case .male: .MALE
case .female: .FEMALE
}
}

public var name: String {
switch self {
case .male: "남성"
case .female: "여성"
}
}
}
Loading