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 3803207 commit 1b3e88d
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 43 deletions.
3 changes: 2 additions & 1 deletion Projects/DSKit/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import ProjectDescriptionHelpers
let project = Project.makeModule(
name: "DSKit",
internalDependencies: [
.Core
.Core,
.Domain
],
hasResource: true,
resourceSynthesizers: [
Expand Down
37 changes: 29 additions & 8 deletions Projects/DSKit/Sources/MyPage/CircleContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,20 @@ import Domain
import SwiftUI

public struct CircleContentView: View {
var showSubText: Bool
private let namespace: Namespace.ID
private let metadata: CircleMetadata

public init(metadata: CircleMetadata) {
public init(namespace: Namespace.ID, metadata: CircleMetadata, showSubText: Bool) {
self.namespace = namespace
self.metadata = metadata
self.showSubText = showSubText
}

public init(namespace: Namespace.ID, metadata: CircleMetadata) {
self.namespace = namespace
self.metadata = metadata
self.showSubText = true
}

public var body: some View {
Expand All @@ -22,15 +32,26 @@ public struct CircleContentView: View {
.resizable()
.frame(width: 48, height: 48)
.scaledToFit()

VStack(spacing: 0) {
Text(metadata.keyword)
.font(.Keyme.body3Semibold)

Text(String(format: "%.1f", metadata.score))
.font(.Score.mypage)
.matchedGeometryEffect(id: contentIconEffectID, in: namespace)

if showSubText {
VStack(spacing: 0) {
Text(metadata.keyword)
.font(.Keyme.body3Semibold)

Text(String(format: "%.1f", metadata.score))
.font(.Score.mypage)
}
.matchedGeometryEffect(id: contentTextEffectID, in: namespace)
.transition(.opacity)
}
}
.foregroundColor(.white)
}
}

extension CircleContentView: GeometryAnimatableCircle {
public var id: String {
metadata.id.uuidString
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,13 @@
// Copyright © 2023 team.humanwave. All rights reserved.
//

import Domain
import SwiftUI

protocol GeometryAnimatableCircle {
var circleData: CircleData { get }
public protocol GeometryAnimatableCircle {
var id: String { get }
}

extension GeometryAnimatableCircle {
var id: String {
circleData.id.uuidString
}

public extension GeometryAnimatableCircle {
var innerCircleEffectID: String {
id + "innerCircle"
}
Expand All @@ -29,4 +24,12 @@ extension GeometryAnimatableCircle {
var contentEffectID: String {
id + "content"
}

var contentIconEffectID: String {
id + "contentIcon"
}

var contentTextEffectID: String {
id + "contentText"
}
}
9 changes: 7 additions & 2 deletions Projects/Domain/Sources/Model/CirclePack/CircleData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
import SwiftUI
import Foundation

public struct CircleData: Identifiable {
public struct CircleData {
public let isEmptyCircle: Bool

public let id = UUID()
public let color: Color
public let xPoint: CGFloat
public let yPoint: CGFloat
Expand Down Expand Up @@ -57,3 +56,9 @@ extension CircleData: Equatable {
lhs.id == rhs.id
}
}

extension CircleData: Identifiable {
public var id: UUID {
metadata.id
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import SwiftUI
import Foundation

public struct CircleMetadata {
public let id = UUID()
public let icon: Image
public let keyword: String
public let score: Float
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ 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) // 0.5
.timingCurve(0.175, 0.885, 0.32, 1.05, duration: 3) // 0.5
}

func onDragChanged(_ value: DragGesture.Value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ struct FocusedCircleView: View {
private let option: FocusedCircleViewOption

private let namespace: Namespace.ID
private let id: String

private let shrinkageDistance: CGFloat
private let maxShrinkageDistance: CGFloat
Expand All @@ -57,9 +56,7 @@ struct FocusedCircleView: View {
circleData: CircleData
) {
self.option = option

self.namespace = namespace
self.id = circleData.id.uuidString

self.shrinkageDistance = shrinkageDistance
self.maxShrinkageDistance = maxShrinkageDistance
Expand Down Expand Up @@ -129,12 +126,8 @@ struct FocusedCircleView: View {
}

extension FocusedCircleView: GeometryAnimatableCircle {
var icon: Image {
Image("")
}

var character: String {
"RRR"
var id: String {
circleData.id.uuidString
}

func startAnimation() {
Expand Down Expand Up @@ -222,17 +215,16 @@ extension FocusedCircleView: GeometryAnimatableCircle {
}

var circleContentView: some View {
VStack {
Image(systemName: "person.fill")
.foregroundColor(isPressed ? .white : .black.opacity(0.4))
Text("인싸력")
.foregroundColor(isPressed ? .white : .black.opacity(0.4))
.font(.system(size: 14))
}
.matchedGeometryEffect(
id: contentEffectID,
in: namespace,
anchor: .center)
// circleData.metadata.icon
// .resizable()
// .frame(width: 100, height: 100)
// .foregroundColor(.white)
// .scaledToFit()
CircleContentView(namespace: namespace, metadata: circleData.metadata, showSubText: false)
.matchedGeometryEffect(
id: contentEffectID,
in: namespace,
anchor: .center)
}

var innerCircleEffectID: String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import Foundation
/// 마이페이지 들어가자 마자 나오는 CirclePack 그래프를 이루는 원을 만들 때 쓰는 뷰
struct SubCircleView: View {
private let namespace: Namespace.ID
private let id: String

private let outboundLength: CGFloat
let circleData: CircleData
Expand All @@ -31,7 +30,6 @@ struct SubCircleView: View {
onTapGesture: @escaping () -> Void
) {
self.namespace = namespace
self.id = circleData.id.uuidString

self.outboundLength = outboundLength
self.circleData = circleData
Expand Down Expand Up @@ -61,6 +59,10 @@ struct SubCircleView: View {
}

extension SubCircleView: GeometryAnimatableCircle {
var id: String {
circleData.id.uuidString
}

var designedCircleShape: some View {
Circle()
.fill(circleData.color)
Expand All @@ -80,7 +82,7 @@ extension SubCircleView: GeometryAnimatableCircle {
}

var circleContentView: some View {
CircleContentView(metadata: circleData.metadata)
CircleContentView(namespace: namespace, metadata: circleData.metadata)
.matchedGeometryEffect(
id: contentEffectID,
in: namespace,
Expand Down

0 comments on commit 1b3e88d

Please sign in to comment.