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

[CAT-286] 앱 전체 Rive 파일 적용 #44

Merged
merged 7 commits into from
Aug 20, 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
12 changes: 8 additions & 4 deletions Projects/Domain/CatService/Interface/Model/CatFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public struct AnyCat: CatFactoryProtocol, Identifiable, Equatable {
public var keyword: String { base.keyword }
public var keywordImage: Image { base.keywordImage }
public var catImage: Image { base.catImage }
public var selectCatRivTrigger: String { base.selectCatRivTrigger }
public var rivTriggerName: String { base.rivTriggerName }
public var rivInputName: String { base.rivInputName }
public var focusEndPushTitle: String { base.focusEndPushTitle }
public var restEndPushTitle: String { base.restEndPushTitle }
public var disturbPushTitle: String { base.disturbPushTitle }
Expand All @@ -50,7 +51,8 @@ public struct CheeseCat: CatFactoryProtocol {
public var keyword: String = "응원"
public var keywordImage: Image = DesignSystemAsset.Image._16Star.swiftUIImage
public var catImage: Image = Image(systemName: "star.fill")
public var selectCatRivTrigger: String = "Click_Cheese Cat"
public var rivTriggerName: String = "Click_Cheese Cat"
public var rivInputName: String = "cheeseCat"
public var focusEndPushTitle: String = "집중이 끝났다냥! 이제 나랑 놀아달라냥"
public var restEndPushTitle: String = "이제 다시 집중해볼까냥?"
public var disturbPushTitle: String = "날 두고 어디갔냥.."
Expand All @@ -69,7 +71,8 @@ public struct BlackCat: CatFactoryProtocol {
public var keyword: String = "긍정"
public var keywordImage: Image = DesignSystemAsset.Image._16Heart.swiftUIImage
public var catImage: Image = Image(systemName: "star")
public var selectCatRivTrigger: String = "Click_Black Cat"
public var rivTriggerName: String = "Click_Black Cat"
public var rivInputName: String = "blackCat"
public var focusEndPushTitle: String = "집중이 끝났다냥! 이제 나랑 놀아달라냥"
public var restEndPushTitle: String = "이제 다시 집중해볼까냥?"
public var disturbPushTitle: String = "날 두고 어디갔냥.."
Expand All @@ -88,7 +91,8 @@ public struct ThreeColorCat: CatFactoryProtocol {
public var keyword: String = "자극"
public var keywordImage: Image = DesignSystemAsset.Image._16Focus.swiftUIImage
public var catImage: Image = Image(systemName: "star.fill")
public var selectCatRivTrigger: String = "Click_Calico Cat"
public var rivTriggerName: String = "Click_Calico Cat"
public var rivInputName: String = "calicoCat"
public var focusEndPushTitle: String = "집중이 끝났다냥! 원하는 만큼 집중했냥?"
public var restEndPushTitle: String = "집중할 시간이다냥! 빨리 들어오라냥"
public var disturbPushTitle: String = "지금 뭐하고 있냥? 내가 감시하고 있다냥"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public protocol CatFactoryProtocol {
var keyword: String { get }
var keywordImage: Image { get } // 키워드에 따른 아이콘 이미지
var catImage: Image { get }
var selectCatRivTrigger: String { get }
var rivTriggerName: String { get }
var rivInputName: String { get }
var focusEndPushTitle: String { get }
var restEndPushTitle: String { get }
var disturbPushTitle: String { get }
Expand Down
14 changes: 12 additions & 2 deletions Projects/Feature/CatFeature/Sources/NamingCat/NamingCatCore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
import UserDefaultsClientInterface
import APIClientInterface
import CatServiceInterface
import DesignSystem

import ComposableArchitecture
import RiveRuntime

@Reducer
public struct NamingCatCore {
Expand All @@ -26,9 +28,11 @@ public struct NamingCatCore {
var text: String = ""
var inputFieldError: NamingCatError?
var tooltip: DownDirectionTooltip? = .init()
var catRiv: RiveViewModel = Rive.catSelectRiv(stateMachineName: "State Machine_selectCat")
}

public enum Action: BindableAction {
case onAppear
case namedButtonTapped
case moveToHome
case setTooltip(DownDirectionTooltip?)
Expand Down Expand Up @@ -57,11 +61,17 @@ public struct NamingCatCore {
let isOnboardedKey = "mohanyang_userdefaults_isOnboarded"

switch action {
case .onAppear:
state.catRiv.stop()
state.catRiv.triggerInput(state.selectedCat.rivTriggerName)
return .none

case .namedButtonTapped:
return .run { [text = state.text] send in
let catName = state.text == "" ? state.selectedCat.name : state.text
return .run { send in
_ = try await catService.changeCatName(
apiClient: apiClient,
name: text
name: catName
)
await send(._setNextAction)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import SwiftUI
import DesignSystem

import ComposableArchitecture
import RiveRuntime

public struct NamingCatView: View {
@Bindable var store: StoreOf<NamingCatCore>
Expand All @@ -30,7 +31,7 @@ public struct NamingCatView: View {
ZStack {
Rectangle()
.foregroundStyle(Alias.Color.Background.secondary)
store.selectedCat.catImage
store.catRiv.view()
.setTooltipTarget(tooltip: DownDirectionTooltip.self)
}
.frame(maxHeight: 240)
Expand All @@ -56,7 +57,7 @@ public struct NamingCatView: View {
store.send(.namedButtonTapped)
}
.buttonStyle(.box(level: .primary, size: .large, width: .low))
.disabled(store.inputFieldError != nil || store.text == "")
.disabled(store.inputFieldError != nil)
.padding(.bottom, Alias.Spacing.small)
}
.padding(.horizontal, Alias.Spacing.xLarge)
Expand All @@ -66,5 +67,8 @@ public struct NamingCatView: View {
.ignoresSafeArea()
}
.tooltipDestination(tooltip: $store.tooltip.sending(\.setTooltip))
.onAppear {
store.send(.onAppear)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ public struct DownDirectionTooltip: Tooltip {
public var direction: TooltipDirection { .down }
public var targetCornerRadius: CGFloat? { Alias.BorderRadius.small }
public var dimEnabled: Bool { false }
public var padding: CGFloat { 12 }
public var padding: CGFloat { -20 }
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public struct SelectCatCore {
var route: Route
var catList: [AnyCat] = []
var selectedCat: AnyCat?
var catRiv: RiveViewModel = Rive.catSelectMotionRiv
var catRiv: RiveViewModel = Rive.catSelectRiv(stateMachineName: "State Machine_selectCat")
@Presents var namingCat: NamingCatCore.State?
}

Expand Down Expand Up @@ -80,7 +80,7 @@ public struct SelectCatCore {

case .setRivTrigger:
if let selectedCat = state.selectedCat {
state.catRiv.triggerInput(selectedCat.selectCatRivTrigger)
state.catRiv.triggerInput(selectedCat.rivTriggerName)
} else {
state.catRiv.play()
}
Expand All @@ -89,7 +89,7 @@ public struct SelectCatCore {
case .selectButtonTapped:
guard let selectedCat = state.selectedCat else { return .none }
return .run { send in
_ = try await userService.selectCat(no: selectedCat.no, apiClient: apiClient)
_ = try await userService.selectCat(selectedCat.no, apiClient)
await send(._setNextAction)
}

Expand Down Expand Up @@ -120,7 +120,7 @@ public struct SelectCatCore {

case ._fetchCatListRequest:
return .run { send in
let response = try await catService.fetchCatLists(apiClient: apiClient)
let response = try await catService.fetchCatLists(apiClient)
await send(._fetchCatListResponse(response))
}

Expand Down
69 changes: 36 additions & 33 deletions Projects/Feature/CatFeature/Sources/SelectCat/SelectCatView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public struct SelectCatView: View {
style: .navigation
) {
VStack(spacing: 0) {
Spacer(minLength: Alias.Spacing.xLarge)
Spacer(minLength: Alias.Spacing.large)

HStack {
VStack(spacing: Alias.Spacing.xSmall) {
Expand All @@ -48,27 +48,28 @@ public struct SelectCatView: View {
ZStack {
Rectangle()
.foregroundStyle(Alias.Color.Background.secondary)
.frame(maxHeight: .infinity)
store.catRiv.view()
}
.frame(maxHeight: 240)
}

Spacer()
Spacer(minLength: Alias.Spacing.large)

HStack {
ForEach(store.catList) { cat in
Button(
title: LocalizedStringKey(cat.name),
subtitle: LocalizedStringKey(cat.keyword),
rightIcon: cat.keywordImage,
action: { store.send(.selectCat(cat)) }
)
.buttonStyle(.select(isSelected: cat == store.selectedCat))
.frame(height: 80)
}
HStack {
ForEach(store.catList) { cat in
Button(
title: LocalizedStringKey(cat.name),
subtitle: LocalizedStringKey(cat.keyword),
rightIcon: cat.keywordImage,
action: { store.send(.selectCat(cat)) }
)
.buttonStyle(.select(isSelected: cat == store.selectedCat))
.frame(height: 80)
}
}
.padding(.bottom, Alias.Spacing.medium)

Spacer(minLength: Alias.Spacing.large)
Spacer(minLength: Alias.Spacing.xLarge)

Button(title: "이 고양이와 함께하기") {
store.send(.selectButtonTapped)
Expand Down Expand Up @@ -102,27 +103,29 @@ struct CatPushNotificationExampleView: View {

if let selectedCat = selectedCat {
HStack(spacing: 10){
Image(systemName: "star.fill")
VStack(spacing: 0) {
HStack {
Text("모하냥")
.font(Typography.bodyR)
.foregroundStyle(Alias.Color.Text.primary)
Spacer()
Text("지금")
.font(Typography.subBodyR)
.foregroundStyle(Alias.Color.Text.secondary)
}
HStack {
Text(selectedCat.disturbPushTitle)
.font(Typography.subBodyR)
.foregroundStyle(Alias.Color.Text.primary)
Spacer()
}
DesignSystemAsset.Image.appIconExample.swiftUIImage
.cornerRadius(8.5, corners: .allCorners)

VStack(alignment: .leading, spacing: .zero) {
Text("모하냥")
.font(Typography.bodySB)
.foregroundStyle(Alias.Color.Text.primary)
Text(selectedCat.disturbPushTitle)
.font(Typography.subBodyR)
.foregroundStyle(Alias.Color.Text.primary)
}

Spacer()

VStack(alignment: .trailing, spacing: .zero) {
Text("지금")
.font(Typography.captionR)
.foregroundStyle(Alias.Color.Text.primary)
Spacer()
}
.padding(.trailing, Alias.Spacing.small)
}
.padding(.all, Alias.Spacing.medium)
.padding(.all, Alias.Spacing.large)
} else {
Text("고양이를 선택하면\n딴 짓 방해알림 예시를 보여드려요")
.font(Typography.bodyR)
Expand Down
11 changes: 9 additions & 2 deletions Projects/Feature/HomeFeature/Sources/Home/HomeCore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import UserNotifications

import PomodoroFeature
import PushService
import CatServiceInterface
import PomodoroServiceInterface
import UserDefaultsClientInterface
import DatabaseClientInterface
Expand All @@ -18,6 +19,7 @@ import MyPageFeature
import DesignSystem

import ComposableArchitecture
import RiveRuntime

@Reducer
public struct HomeCore {
Expand All @@ -28,10 +30,14 @@ public struct HomeCore {
var homeTimeGuideTooltip: HomeTimeGuideTooltip?

var selectedCategory: PomodoroCategory?

// 저장된 고양이 불러오고나서 이 state에 저장하면 될듯합니다
var selectedCat: AnyCat = CatFactory.makeCat(type: .threeColor, no: 0, name: "치즈냥")

var toast: DefaultToast?
var dialog: DefaultDialog?


var catRiv: RiveViewModel = Rive.catHomeRiv(stateMachineName: "State Machine_Home")

@Presents var categorySelect: CategorySelectCore.State?
@Presents var timeSelect: TimeSelectCore.State?
@Presents var focusPomodoro: FocusPomodoroCore.State?
Expand Down Expand Up @@ -101,6 +107,7 @@ public struct HomeCore {
}

case .onAppear:
state.catRiv.setInput(state.selectedCat.rivInputName, value: true)
return .run { send in
await send(.syncCategory)
}
Expand Down
16 changes: 12 additions & 4 deletions Projects/Feature/HomeFeature/Sources/Home/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,18 @@ public struct HomeView: View {
) {
VStack(spacing: 40) {
VStack(spacing: Alias.Spacing.xLarge) {
Rectangle()
.fill(Alias.Color.Background.secondary)
.frame(width: 240, height: 240)
.setTooltipTarget(tooltip: HomeCatDialogueTooltip.self)

ZStack {
Rectangle()
.fill(Alias.Color.Background.secondary)
store.catRiv.view()
.setTooltipTarget(tooltip: HomeCatDialogueTooltip.self)
.onTapGesture {
store.catRiv.triggerInput(store.selectedCat.rivTriggerName)
}
}
.frame(width: 240, height: 240)

Text("치즈냥")
.font(Typography.header4)
.foregroundStyle(Alias.Color.Text.tertiary)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
// Copyright © 2024 PomoNyang. All rights reserved.
//

import CatServiceInterface
import PomodoroServiceInterface
import UserDefaultsClientInterface
import DatabaseClientInterface
import DesignSystem

import ComposableArchitecture
import RiveRuntime

@Reducer
public struct FocusPomodoroCore {
Expand All @@ -21,7 +24,12 @@ public struct FocusPomodoroCore {
var overTimeBySeconds: Int = 0

var timer: TimerCore.State = .init(interval: .seconds(1), mode: .continuous)


// 저장된 고양이 불러오고나서 이 state에 저장하면 될듯합니다
var selectedCat: AnyCat = CatFactory.makeCat(type: .threeColor, no: 0, name: "치즈냥")

var catRiv: RiveViewModel = Rive.catFocusRiv(stateMachineName: "State Machine_Focus")

@Presents var restWaiting: RestWaitingCore.State?

public init() {}
Expand All @@ -34,6 +42,7 @@ public struct FocusPomodoroCore {
}

public enum Action: BindableAction {
case onAppear
case binding(BindingAction<State>)
case task

Expand Down Expand Up @@ -66,6 +75,10 @@ public struct FocusPomodoroCore {

private func core(state: inout State, action: Action) -> EffectOf<Self> {
switch action {
case .onAppear:
state.catRiv.setInput(state.selectedCat.rivInputName, value: true)
return .none

case .binding:
return .none

Expand Down
Loading
Loading