Skip to content

Commit

Permalink
Merge pull request #234 from APP-iOS5th/Feature/LetterWriteDIContainer
Browse files Browse the repository at this point in the history
Feature/LetterWirteDIContainer
  • Loading branch information
jinwoong16 authored Nov 2, 2024
2 parents 3a55b22 + ac18995 commit 9299344
Show file tree
Hide file tree
Showing 14 changed files with 239 additions and 216 deletions.
71 changes: 71 additions & 0 deletions FontUtility.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//
// FontUtility.swift
// Kabinett
//
// Created by Song Kim on 10/24/24.
//

import Foundation
import UIKit
import SwiftUI

class FontUtility {
static let screenSize = UIScreen.main.bounds.width

static func selectedUIFont(font: String, size: CGFloat) -> UIFont {
if font == "SFMONO" {
return UIFont.monospacedSystemFont(ofSize: size, weight: .regular)
} else if font == "SFDisplay" {
return UIFont.systemFont(ofSize: size)
} else {
return UIFont(name: font, size: size) ?? UIFont.systemFont(ofSize: size)
}
}

static func selectedFont(font: String, size: CGFloat) -> Font {
if font == "SFMONO" {
return .system(size: size, design: .monospaced)
} else if font == "SFDisplay" {
return .system(size: size)
} else {
return .custom(font, size: size)
}
}

static func fontSize(font: String) -> CGFloat {
if font == "SourceHanSerifK-Regular" {
return screenSize * 0.0333
} else if font == "NanumMyeongjoOTF" {
return screenSize * 0.0392
} else if font == "Baskervville-Regular" {
return screenSize * 0.0369
} else if font == "Pecita" {
return screenSize * 0.037
}
return (screenSize * 0.0382)
}

static func lineSpacing(font: String) -> CGFloat {
if font == "Pecita" {
return screenSize * 0.0069
} else if font == "SFDisplay" {
return screenSize * 0.0013
} else if font == "goormSansOTF4" {
return screenSize * 0.0013
} else if font == "Baskervville-Regular" {
return screenSize * 0.002
}
return 0.0
}

static func kerning(font: String) -> CGFloat {
if font == "SFMONO" {
return -(screenSize * 0.0025)
} else if font == "SFDisplay" {
return (screenSize * 0.0005)
} else if font == "goormSansOTF4" {
return (screenSize * 0.001)
}
return 0.0
}
}
4 changes: 4 additions & 0 deletions Kabinett.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
57966BA42C7FF739008D650B /* PreviewLetterView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57966BA32C7FF738008D650B /* PreviewLetterView.swift */; };
57966BA62C81FD98008D650B /* PreviewLetterViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57966BA52C81FD98008D650B /* PreviewLetterViewModel.swift */; };
57A014FE2CA57E7100580883 /* NanumMyeongjo.otf in Resources */ = {isa = PBXBuildFile; fileRef = 57A014FD2CA57E7100580883 /* NanumMyeongjo.otf */; };
57C35C672CCA02130083A346 /* FontUtility.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57C35C662CCA02130083A346 /* FontUtility.swift */; };
57EBE5B02C69E5F2003ECD7F /* UserSelectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57EBE5AF2C69E5F2003ECD7F /* UserSelectionView.swift */; };
57EBE5B92C6B399C003ECD7F /* StationerySelectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57EBE5B82C6B399C003ECD7F /* StationerySelectionView.swift */; };
57ED94FA2C84AFAC00A6F187 /* LetterWriteModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57ED94F92C84AFAC00A6F187 /* LetterWriteModel.swift */; };
Expand Down Expand Up @@ -199,6 +200,7 @@
57966BA32C7FF738008D650B /* PreviewLetterView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreviewLetterView.swift; sourceTree = "<group>"; };
57966BA52C81FD98008D650B /* PreviewLetterViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreviewLetterViewModel.swift; sourceTree = "<group>"; };
57A014FD2CA57E7100580883 /* NanumMyeongjo.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = NanumMyeongjo.otf; sourceTree = "<group>"; };
57C35C662CCA02130083A346 /* FontUtility.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = FontUtility.swift; path = ../../../../FontUtility.swift; sourceTree = "<group>"; };
57EBE5AF2C69E5F2003ECD7F /* UserSelectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserSelectionView.swift; sourceTree = "<group>"; };
57EBE5B82C6B399C003ECD7F /* StationerySelectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StationerySelectionView.swift; sourceTree = "<group>"; };
57ED94F92C84AFAC00A6F187 /* LetterWriteModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = LetterWriteModel.swift; path = Kabinett/Presentation/ViewModel/WriteLetter/LetterWriteModel.swift; sourceTree = SOURCE_ROOT; };
Expand Down Expand Up @@ -588,6 +590,7 @@
8366B6F82C65ED0F0021FAE0 /* WriteLetter */ = {
isa = PBXGroup;
children = (
57C35C662CCA02130083A346 /* FontUtility.swift */,
57ED94F92C84AFAC00A6F187 /* LetterWriteModel.swift */,
57ED9CDD2C73698B00A4312C /* StationerySelectionViewModel.swift */,
57ED9CD62C72C8C900A4312C /* UserSelectionViewModel.swift */,
Expand Down Expand Up @@ -972,6 +975,7 @@
53A482D42C6B4E8600F00A9A /* LetterBoxView.swift in Sources */,
530C765A2C7638D9007E09C6 /* LetterBoxViewModel.swift in Sources */,
5359618D2C7488DD0031E181 /* TransparentBlurView.swift in Sources */,
57C35C672CCA02130083A346 /* FontUtility.swift in Sources */,
538150512C8AD5FB007B1E5A /* LayoutHelper.swift in Sources */,
535961912C74F5870031E181 /* CalendarView.swift in Sources */,
530C765C2C76CEFC007E09C6 /* LetterBoxUseCaseStub.swift in Sources */,
Expand Down
42 changes: 0 additions & 42 deletions Kabinett/Application/KabinettApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@ struct KabinettApp: App {
@StateObject private var imagePickerViewModel: ImagePickerViewModel
@StateObject private var customTabViewModel: CustomTabViewModel

// MARK: - LetterWrite Flow
@StateObject private var userSelectionViewModel: UserSelectionViewModel
@StateObject private var stationerySelectionViewModel: StationerySelectionViewModel
@StateObject private var fontSelectionViewModel: FontSelectionViewModel
@StateObject private var contentWriteViewModel: ContentWriteViewModel
@StateObject private var envelopStampSelectionViewModel: EnvelopeStampSelectionViewModel
@StateObject private var previewLetterViewModel: PreviewLetterViewModel

init() {
// Init Firebase App
FirebaseApp.configure()
Expand Down Expand Up @@ -106,34 +98,6 @@ struct KabinettApp: App {
_customTabViewModel = .init(
wrappedValue: CustomTabViewModel()
)

// MARK: - LetterWrite ViewModels
_userSelectionViewModel = .init(
wrappedValue: UserSelectionViewModel(
useCase: normalLetterUseCase
)
)
_stationerySelectionViewModel = .init(
wrappedValue: StationerySelectionViewModel(
useCase: normalLetterUseCase
)
)
_fontSelectionViewModel = .init(
wrappedValue: FontSelectionViewModel()
)
_contentWriteViewModel = .init(
wrappedValue: ContentWriteViewModel()
)
_envelopStampSelectionViewModel = .init(
wrappedValue: EnvelopeStampSelectionViewModel(
useCase: normalLetterUseCase
)
)
_previewLetterViewModel = .init(
wrappedValue: PreviewLetterViewModel(
useCase: normalLetterUseCase
)
)
}

var body: some Scene {
Expand All @@ -143,12 +107,6 @@ struct KabinettApp: App {
.environmentObject(signUpViewModel)
.environmentObject(imagePickerViewModel)
.environmentObject(customTabViewModel)
.environmentObject(userSelectionViewModel)
.environmentObject(stationerySelectionViewModel)
.environmentObject(fontSelectionViewModel)
.environmentObject(contentWriteViewModel)
.environmentObject(envelopStampSelectionViewModel)
.environmentObject(previewLetterViewModel)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct SmallEnvelopeCell: View {
.font(.custom("SFDisplay", size: LayoutHelper.shared.getSize(forSE: 0.006, forOthers: 0.006)))
.foregroundStyle(.contentPrimary)
Text(letter.fromUserName)
.font(fontViewModel.selectedFont(font: letter.fontString ?? "SFDisplay", size: LayoutHelper.shared.getSize(forSE: 0.0122, forOthers: 0.0122)))
.font(FontUtility.selectedFont(font: letter.fontString ?? "SFDisplay", size: LayoutHelper.shared.getSize(forSE: 0.0122, forOthers: 0.0122)))
.foregroundStyle(.contentPrimary)
.frame(maxWidth: LayoutHelper.shared.getWidth(forSE: 0.4, forOthers: 0.443), alignment: .leading)
}
Expand All @@ -46,7 +46,7 @@ struct SmallEnvelopeCell: View {
.font(.custom("SFDisplay", size: LayoutHelper.shared.getSize(forSE: 0.006, forOthers: 0.006)))
.foregroundStyle(.contentPrimary)
Text(letter.toUserName)
.font(fontViewModel.selectedFont(font: letter.fontString ?? "SFDisplay", size: LayoutHelper.shared.getSize(forSE: 0.0122, forOthers: 0.0122)))
.font(FontUtility.selectedFont(font: letter.fontString ?? "SFDisplay", size: LayoutHelper.shared.getSize(forSE: 0.0122, forOthers: 0.0122)))
.foregroundStyle(.contentPrimary)
.frame(maxWidth: LayoutHelper.shared.getWidth(forSE: 0.17, forOthers: 0.2), alignment: .leading)
.padding(.bottom, LayoutHelper.shared.getSize(forSE: 0.008, forOthers: 0.008))
Expand Down Expand Up @@ -77,7 +77,7 @@ struct LargeEnvelopeCell: View {
.font(.custom("SFDisplay", size: LayoutHelper.shared.getSize(forSE: 0.009, forOthers: 0.008)))
.foregroundStyle(.contentPrimary)
Text(letter.fromUserName)
.font(fontViewModel.selectedFont(font: letter.fontString ?? "SFDisplay", size: LayoutHelper.shared.getSize(forSE: 0.018, forOthers: 0.017)))
.font(FontUtility.selectedFont(font: letter.fontString ?? "SFDisplay", size: LayoutHelper.shared.getSize(forSE: 0.018, forOthers: 0.017)))
.foregroundStyle(.contentPrimary)
.frame(maxWidth: LayoutHelper.shared.getWidth(forSE: 0.57, forOthers: 0.57), alignment: .leading)
}
Expand All @@ -94,7 +94,7 @@ struct LargeEnvelopeCell: View {

HStack(alignment: .top) {
Text(letter.postScript ?? "")
.font(fontViewModel.selectedFont(font: letter.fontString ?? "SFDisplay", size: LayoutHelper.shared.getSize(forSE: 0.012, forOthers: 0.012)))
.font(FontUtility.selectedFont(font: letter.fontString ?? "SFDisplay", size: LayoutHelper.shared.getSize(forSE: 0.012, forOthers: 0.012)))
.foregroundStyle(.contentPrimary)
.frame(width: LayoutHelper.shared.getWidth(forSE: 0.4, forOthers: 0.4), alignment: .leading)

Expand All @@ -103,7 +103,7 @@ struct LargeEnvelopeCell: View {
.font(.custom("SFDisplay", size: LayoutHelper.shared.getSize(forSE: 0.008, forOthers: 0.008)))
.foregroundStyle(.contentPrimary)
Text(letter.toUserName)
.font(fontViewModel.selectedFont(font: letter.fontString ?? "SFDisplay", size: LayoutHelper.shared.getSize(forSE: 0.017, forOthers: 0.017)))
.font(FontUtility.selectedFont(font: letter.fontString ?? "SFDisplay", size: LayoutHelper.shared.getSize(forSE: 0.017, forOthers: 0.017)))
.foregroundStyle(.contentPrimary)
.frame(maxWidth: LayoutHelper.shared.getWidth(forSE: 0.26, forOthers: 0.26), alignment: .leading)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ struct ContentRectangleView: View {

VStack {
Text(toUserName)
.font(fontViewModel.selectedFont(font: fontString, size: 14))
.font(FontUtility.selectedFont(font: fontString, size: 14))
.foregroundStyle(.contentPrimary)
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.top, geometry.size.height * 0.2)
.padding(.leading, 10)
.opacity(currentPageIndex == 0 ? 1 : 0)

Text(letterContent.forceCharWrapping)
.font(fontViewModel.selectedFont(font: fontString, size: LayoutHelper.shared.getSize(forSE: 0.017, forOthers: 0.015)))
.font(FontUtility.selectedFont(font: fontString, size: LayoutHelper.shared.getSize(forSE: 0.017, forOthers: 0.015)))
.foregroundStyle(.contentPrimary)
.lineSpacing(8)
.frame(maxWidth: .infinity, alignment: .leading)
Expand All @@ -56,14 +56,14 @@ struct ContentRectangleView: View {
Spacer()

Text(formattedDate(date: date))
.font(fontViewModel.selectedFont(font: fontString, size: 14))
.font(FontUtility.selectedFont(font: fontString, size: 14))
.foregroundStyle(.contentPrimary)
.frame(maxWidth: .infinity, alignment: .trailing)
.padding(.bottom, 0.1)
.opacity(currentPageIndex == max(totalPages - 1, 0) ? 1 : 0)

Text(fromUserName)
.font(fontViewModel.selectedFont(font: fontString, size: 14))
.font(FontUtility.selectedFont(font: fontString, size: 14))
.foregroundStyle(.contentPrimary)
.frame(maxWidth: .infinity, alignment: .trailing)
.padding(.bottom, geometry.size.height * 0.2)
Expand Down
17 changes: 8 additions & 9 deletions Kabinett/Presentation/View/WriteLetter/ContentWriteView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import PhotosUI

struct ContentWriteView: View {
@Binding var letterContent: LetterWriteModel
@EnvironmentObject var viewModel: ContentWriteViewModel
@StateObject var viewModel = ContentWriteViewModel()
@EnvironmentObject var imageViewModel: ImagePickerViewModel
@EnvironmentObject var customViewModel: CustomTabViewModel

Expand Down Expand Up @@ -79,7 +79,7 @@ struct ContentWriteView: View {
.background(letterContent.photoContents.isEmpty ? Color(.primary300) : Color(.primary900))
.clipShape(Capsule())

ScrollableLetterView(letterContent: $letterContent, currentIndex: $viewModel.currentIndex)
ScrollableLetterView(letterContent: $letterContent, viewModel: viewModel, currentIndex: $viewModel.currentIndex)

Text("\(viewModel.currentIndex+1) / \(viewModel.texts.count)")
}
Expand All @@ -100,8 +100,7 @@ struct ContentWriteView: View {
// MARK: - ScrollableLetterView
struct ScrollableLetterView: View {
@Binding var letterContent: LetterWriteModel
@EnvironmentObject var viewModel: ContentWriteViewModel
@EnvironmentObject var fontViewModel: FontSelectionViewModel
@ObservedObject var viewModel: ContentWriteViewModel
@Binding var currentIndex: Int

var body: some View {
Expand Down Expand Up @@ -139,9 +138,9 @@ struct ScrollableLetterView: View {
text: $viewModel.texts[i],
maxWidth: geo.size.width,
maxHeight: geo.size.height,
font: fontViewModel.selectedUIFont(font: letterContent.fontString ?? "", size: fontViewModel.fontSize(font: letterContent.fontString ?? "")),
lineSpacing: fontViewModel.lineSpacing(font: letterContent.fontString ?? ""),
kerning: fontViewModel.kerning(font: letterContent.fontString ?? "")
font: FontUtility.selectedUIFont(font: letterContent.fontString ?? "", size: FontUtility.fontSize(font: letterContent.fontString ?? "")),
lineSpacing: FontUtility.lineSpacing(font: letterContent.fontString ?? ""),
kerning: FontUtility.kerning(font: letterContent.fontString ?? "")
)
}
.onChange(of: viewModel.texts[i]) {
Expand All @@ -166,7 +165,7 @@ struct ScrollableLetterView: View {
.frame(width: UIScreen.main.bounds.width * 0.88)
.id(i)
Spacer()
.anchorPreference(key: AnchorsKey.self, value: .trailing, transform: { [i: $0] })
.anchorPreference(key: AnchorsKey.self, value: .trailing, transform: { [i: $0] })
}
}
}
Expand All @@ -175,7 +174,7 @@ struct ScrollableLetterView: View {
.scrollTargetLayout()
}
.scrollTargetBehavior(.viewAligned)
.font(fontViewModel.selectedFont(font: letterContent.fontString ?? "", size: 15))
.font(FontUtility.selectedFont(font: letterContent.fontString ?? "", size: 15))
.onChange(of: viewModel.texts.count) {
withAnimation {
scrollViewProxy.scrollTo((currentIndex+1), anchor: .center)
Expand Down
Loading

0 comments on commit 9299344

Please sign in to comment.