Skip to content

Commit

Permalink
refactor #51: 폰트 정리
Browse files Browse the repository at this point in the history
  • Loading branch information
enebin committed Aug 18, 2023
1 parent ae9350d commit 42aaf55
Show file tree
Hide file tree
Showing 10 changed files with 212 additions and 47 deletions.
15 changes: 15 additions & 0 deletions Projects/Core/Sources/Utility/Function/Float + String.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// Float + String.swift
// Core
//
// Created by Young Bin on 2023/08/15.
// Copyright © 2023 team.humanwave. All rights reserved.
//

import Foundation

public extension Float {
func toString(floatingPoint: Int = 1) -> String {
String(format: "%.\(floatingPoint)f", self)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// CustomInteractiveSpringAnimation.swift
// Core
//
// Created by Young Bin on 2023/08/15.
// Copyright © 2023 team.humanwave. All rights reserved.
//

import SwiftUI

public extension Animation {
// 테스트하고프면 https://www.cssportal.com/css-cubic-bezier-generator/
static func customInteractiveSpring(duration: CGFloat = 0.5) -> Animation {
.timingCurve(0.175, 0.885, 0.32, 1.05, duration: 0.5) // default: 0.5
}
}
17 changes: 17 additions & 0 deletions Projects/DSKit/Sources/Font/DynamicText.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// DynamicText.swift
// DSKit
//
// Created by Young Bin on 2023/08/15.
// Copyright © 2023 team.humanwave. All rights reserved.
//

import SwiftUI

public extension Text {
static func keyme(_ text: String, font: Font.KeymeFont) -> Text {
Text(text)
.font(font.value)
.kerning(font.size * (font.kerning / 100))
}
}
2 changes: 1 addition & 1 deletion Projects/DSKit/Sources/MyPage/CircleContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public struct CircleContentView: View {
Text(metadata.keyword)
.font(.Keyme.body3Semibold)

Text(String(format: "%.1f", metadata.score))
Text(String(format: "%.1f", metadata.averageScore))
.font(.Score.mypage)
}
.matchedGeometryEffect(id: contentTextEffectID, in: namespace)
Expand Down
51 changes: 51 additions & 0 deletions Projects/DSKit/Sources/MyPage/Detail/ScoreAndPersonalityView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//
// ScoreAndPersonalityView.swift
// DSKit
//
// Created by Young Bin on 2023/08/15.
// Copyright © 2023 team.humanwave. All rights reserved.
//

import Domain
import SwiftUI

public struct ScoreAndPersonalityView: View {
private let title: String
private let score: Float

public init(circleData: CircleData) {
self.title = circleData.metadata.keyword
self.score = circleData.metadata.averageScore
}

public init(title: String, score: Float) {
self.title = title
self.score = score
}

public var body: some View {
// 상단에 점수표시
VStack(spacing: 4) {
Text.keyme(title, font: .body5)
.padding(.horizontal, 10)
.padding(.vertical, 5)
.overlay(
RoundedRectangle(cornerRadius: 16)
.fill(Color.white.opacity(0.2))
.overlay {
RoundedRectangle(cornerRadius: 16)
.stroke(.white, lineWidth: 0.5)
}
)
.foregroundColor(.white)

HStack(alignment: .bottom) {
Text.keyme(score.toString(), font: .detailPage)

Text.keyme("", font: .caption1)
.offset(y: -7)
}
.foregroundColor(DSKitAsset.Color.keymeWhite.swiftUIColor.opacity(0.6))
}
}
}
10 changes: 6 additions & 4 deletions Projects/Domain/Sources/Model/CirclePack/CircleMetadata.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ public struct CircleMetadata {
public let id = UUID()
public let icon: Image
public let keyword: String
public let score: Float
public let averageScore: Float
public let myScore: Float

public init(icon: Image, keyword: String, score: Float) {
public init(icon: Image, keyword: String, averageScore: Float, myScore: Float) {
self.icon = icon
self.keyword = keyword
self.score = score
self.averageScore = averageScore
self.myScore = myScore
}

public static var emptyData: CircleMetadata {
return CircleMetadata(icon: Image(""), keyword: "", score: 0.0)
return CircleMetadata(icon: Image(""), keyword: "", averageScore: 0.0, myScore: 0.0)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public struct CirclePackView<DetailView: View>: View {

@State private var showMorePersonalitySheet: Bool = false
@State private var focusedCircleData: CircleData?
@State private var isPersonalityCirclePressed = false

private let circleData: [CircleData]
private let option: CirclePackViewOption<DetailView>
Expand Down Expand Up @@ -141,8 +142,20 @@ public struct CirclePackView<DetailView: View>: View {
.onTapGesture(perform: onDismiss)

// 개별보기
VStack(alignment: .center) {
VStack(alignment: .center, spacing: 0) {
if let focusedCircleData {
Group {
if isPersonalityCirclePressed {
ScoreAndPersonalityView(
title: "나의 점수",
score: focusedCircleData.metadata.myScore)
} else {
ScoreAndPersonalityView(
circleData: focusedCircleData)
}
}
.transition(.move(edge: .top).combined(with: .opacity))

FocusedCircleView(
namespace: namespace,
shrinkageDistance: currentSheetOffset,
Expand All @@ -152,8 +165,14 @@ public struct CirclePackView<DetailView: View>: View {
circleData: focusedCircleData)
.onDragChanged(self.onDragChanged)
.onDragEnded(self.onDragEnded)
.padding(.top, 20)
.onLongPressStarted { _ in
isPersonalityCirclePressed = true
}
.onLongPressEnded { _ in
isPersonalityCirclePressed = false
}
.transition(.offset(x: 1, y: 1).combined(with: .opacity))
.padding(.vertical, 12)
// .transition(.offset(x: 1, y: 1)) // Magic line. 왠진 모르겠지만 돌아가는 중이니 건들지 말 것

VStack {
Expand Down Expand Up @@ -182,10 +201,13 @@ public struct CirclePackView<DetailView: View>: View {
.opacity(focusedCircleData == nil ? 1 : 0)
}
.animation(
customInteractiveSpringAnimation,
Animation.customInteractiveSpring(),
value: isPersonalityCirclePressed)
.animation(
Animation.customInteractiveSpring(),
value: focusedCircleData)
.animation(
customInteractiveSpringAnimation,
Animation.customInteractiveSpring(),
value: doneDragging)
.onChange(of: focusedCircleData) { _ in
animationEnded = false
Expand Down Expand Up @@ -251,11 +273,6 @@ private extension CirclePackView {
}

private extension CirclePackView {
// 테스트하고프면 https://www.cssportal.com/css-cubic-bezier-generator/
var customInteractiveSpringAnimation: Animation {
.timingCurve(0.175, 0.885, 0.32, 1.05, duration: 0.5) // default: 0.5
}

func onDragChanged(_ value: DragGesture.Value) {
doneDragging = false
currentSheetOffset =
Expand Down Expand Up @@ -372,31 +389,51 @@ struct CirclePackView_Previews: PreviewProvider {
xPoint: 0.2068919881427701,
yPoint: 0.7022698911578201,
radius: 0.14644660940672627,
metadata: CircleMetadata(icon: Image(systemName: "person.fill"), keyword: "표현력", score: 4.2)),
metadata: CircleMetadata(
icon: Image(systemName: "person.fill"),
keyword: "표현력",
averageScore: 4.2,
myScore: 4.2)),
CircleData(
color: .red,
xPoint: -0.20710678118654763,
yPoint: -0.4925857155047088,
radius: 0.20710678118654754,
metadata: CircleMetadata(icon: Image(systemName: "person.fill"), keyword: "표현력", score: 4.2)),
metadata: CircleMetadata(
icon: Image(systemName: "person.fill"),
keyword: "표현력",
averageScore: 4.2,
myScore: 3.5)),
CircleData(
color: .gray,
xPoint: -0.2218254069479773,
yPoint: 0.6062444788590935,
radius: 0.29289321881345254,
metadata: CircleMetadata(icon: Image(systemName: "person.fill"), keyword: "표현력", score: 4.2)),
metadata: CircleMetadata(
icon: Image(systemName: "person.fill"),
keyword: "표현력",
averageScore: 4.2,
myScore: 3.5)),
CircleData(
color: .cyan,
xPoint: -0.5857864376269051,
yPoint: 0.0,
radius: 0.4142135623730951,
metadata: CircleMetadata(icon: Image(systemName: "person.fill"), keyword: "표현력", score: 4.2)),
metadata: CircleMetadata(
icon: Image(systemName: "person.fill"),
keyword: "표현력",
averageScore: 4.2,
myScore: 3.5)),
CircleData(
color: .mint,
xPoint: 0.4142135623730951,
yPoint: 0.0,
radius: 0.5857864376269051,
metadata: CircleMetadata(icon: Image(systemName: "person.fill"), keyword: "표현력", score: 4.2))
metadata: CircleMetadata(
icon: Image(systemName: "person.fill"),
keyword: "표현력",
averageScore: 4.2,
myScore: 3.5)),
],
detailViewBuilder: { _ in
let scores = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ import Foundation

final class FocusedCircleViewOption {
typealias LongPressGestureValue = SequenceGesture<LongPressGesture, DragGesture>.Value
var onLongPressStarted: (LongPressGestureValue) -> Void
var onLongPressEnded: (LongPressGestureValue) -> Void
var onDragChanged: (DragGesture.Value) -> Void
var onDragEnded: (DragGesture.Value) -> Void

init(
onLongPressStarted: @escaping (LongPressGestureValue) -> Void = { _ in },
onLongPressEnded: @escaping (LongPressGestureValue) -> Void = { _ in },
onDragChanged: @escaping (DragGesture.Value) -> Void = { _ in },
onDragEnded: @escaping (DragGesture.Value) -> Void = { _ in }
) {
self.onLongPressStarted = onLongPressStarted
self.onLongPressEnded = onLongPressEnded
self.onDragChanged = onDragChanged
self.onDragEnded = onDragEnded
Expand Down Expand Up @@ -71,21 +74,24 @@ struct FocusedCircleView: View {
if circleData.isEmptyCircle {
emptyCircleView
} else {
outlineCircleView

innerCircleView(with: circleData)
.opacity(blinkCircle ? animatedOpacity : 1)
.opacity(isPressed ? 0.5 : 1)

if isPressed {
overlayingCircleView
.frame(width: 100)
.zIndex(1)
// 원
ZStack(alignment: .center) {
outlineCircleView

innerCircleView(with: circleData)
.opacity(blinkCircle ? animatedOpacity : 1)
.opacity(isPressed ? 0.5 : 1)

if isPressed {
overlayingCircleView
.frame(width: 100)
.zIndex(1)
}

circleContentView
.frame(width: 75, height: 75)
.zIndex(1.5)
}

circleContentView
.frame(width: 75, height: 75)
.zIndex(1.5)
}
}
.gesture(
Expand All @@ -95,14 +101,15 @@ struct FocusedCircleView: View {
switch value {
case .second(true, nil):
HapticManager.shared.homeButtonTouchDown()
option.onLongPressStarted(value)
state = true
default:
break
}
}
.onEnded { _ in
.onEnded { value in
HapticManager.shared.homeButtonTouchUp()

option.onLongPressEnded(value)
}
.simultaneously(
with: DragGesture(minimumDistance: 0, coordinateSpace: .global)
Expand All @@ -117,8 +124,8 @@ struct FocusedCircleView: View {
.frame(
width: calculatedOutlineCircleRaduis,
height: calculatedOutlineCircleRaduis)
.animation(customAnimation, value: showComponents)
.animation(.spring(), value: isPressed)
.animation(Animation.customInteractiveSpring(), value: showComponents)
.animation(Animation.customInteractiveSpring(), value: isPressed)
.onAppear {
startAnimation()
}
Expand Down Expand Up @@ -215,11 +222,6 @@ extension FocusedCircleView: GeometryAnimatableCircle {
}

var circleContentView: some View {
// circleData.metadata.icon
// .resizable()
// .frame(width: 100, height: 100)
// .foregroundColor(.white)
// .scaledToFit()
CircleContentView(namespace: namespace, metadata: circleData.metadata, showSubText: false)
.matchedGeometryEffect(
id: contentEffectID,
Expand Down Expand Up @@ -277,6 +279,11 @@ extension FocusedCircleView {
return self
}

func onLongPressStarted(_ action: @escaping (LongPressGestureValue) -> Void) -> FocusedCircleView {
option.onLongPressStarted = action
return self
}

func onLongPressEnded(_ action: @escaping (LongPressGestureValue) -> Void) -> FocusedCircleView {
option.onLongPressEnded = action
return self
Expand Down
Loading

0 comments on commit 42aaf55

Please sign in to comment.