From 49c523f14ada5397fd6d5b38685f129e1d37b769 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=8F=84=ED=98=95?= <108233361+ShapeKim98@users.noreply.github.com> Date: Sat, 26 Oct 2024 21:34:48 +0900 Subject: [PATCH] =?UTF-8?q?[refactor]=20#154=20Device=20=EA=B4=80=EB=A0=A8?= =?UTF-8?q?=20=EB=A1=9C=EC=A7=81=20Util=EB=A1=9C=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Pokit/PokitSplitFeature.swift | 7 ++- Projects/App/Sources/Root/RootFeature.swift | 5 +-- .../DeviceClient/DeviceClient+LiveKey.swift | 39 ----------------- .../Client/DeviceClient/DeviceClient.swift | 16 ------- .../ContentSettingFeature.swift | 6 +-- Projects/Util/Sources/Device.swift | 43 +++++++++++++++++++ 6 files changed, 52 insertions(+), 64 deletions(-) delete mode 100644 Projects/CoreKit/Sources/Data/Client/DeviceClient/DeviceClient+LiveKey.swift delete mode 100644 Projects/CoreKit/Sources/Data/Client/DeviceClient/DeviceClient.swift create mode 100644 Projects/Util/Sources/Device.swift diff --git a/Projects/App/Sources/MainTabSplit/Pokit/PokitSplitFeature.swift b/Projects/App/Sources/MainTabSplit/Pokit/PokitSplitFeature.swift index 47cbc2be..8daae15e 100644 --- a/Projects/App/Sources/MainTabSplit/Pokit/PokitSplitFeature.swift +++ b/Projects/App/Sources/MainTabSplit/Pokit/PokitSplitFeature.swift @@ -26,7 +26,7 @@ public struct PokitSplitFeature { /// - State @ObservableState public struct State: Equatable { - var columnVisibility: NavigationSplitViewVisibility = UIDevice.current.orientation == .portrait ? .detailOnly : .all + var columnVisibility: NavigationSplitViewVisibility = Device.isPortrait ? .doubleColumn : .all var 포킷: PokitRootFeature.State = .init() var 카테고리상세: CategoryDetailFeature.State? @@ -205,6 +205,9 @@ private extension PokitSplitFeature { switch action { case let .포킷(.delegate(.categoryTapped(category))): state.categoryId = category.id + if Device.isPortrait { + state.columnVisibility = .detailOnly + } return .send(.inner(.카테고리_상세_활성화(category))) case .포킷(.delegate(.카테고리_삭제)): state.카테고리상세 = nil @@ -216,7 +219,7 @@ private extension PokitSplitFeature { return .none case .링크추가및수정(.delegate(.dismiss)): - state.columnVisibility = .detailOnly + state.columnVisibility = .doubleColumn return .none case .링크추가및수정: return .none diff --git a/Projects/App/Sources/Root/RootFeature.swift b/Projects/App/Sources/Root/RootFeature.swift index bc00cbc4..51c7dedb 100644 --- a/Projects/App/Sources/Root/RootFeature.swift +++ b/Projects/App/Sources/Root/RootFeature.swift @@ -16,7 +16,6 @@ import Util public struct RootFeature { @Dependency(UserDefaultsClient.self) var userDefaults @Dependency(UserClient.self) var userClient - @Dependency(DeviceClient.self) var deviceClient @Reducer(state: .equatable) public enum Destination { @@ -50,7 +49,7 @@ public struct RootFeature { guard let fcmToken = userDefaults.stringKey(.fcmToken) else { await send(._sceneChange( - deviceClient.isPhone() + Device.isPhone ? .mainTab() : .mainTabSplit()) ) @@ -62,7 +61,7 @@ public struct RootFeature { await userDefaults.setString(user.token, .fcmToken) await userDefaults.setString("\(user.userId)", .userId) await send(._sceneChange( - deviceClient.isPhone() + Device.isPhone ? .mainTab() : .mainTabSplit() )) diff --git a/Projects/CoreKit/Sources/Data/Client/DeviceClient/DeviceClient+LiveKey.swift b/Projects/CoreKit/Sources/Data/Client/DeviceClient/DeviceClient+LiveKey.swift deleted file mode 100644 index 1fc062f7..00000000 --- a/Projects/CoreKit/Sources/Data/Client/DeviceClient/DeviceClient+LiveKey.swift +++ /dev/null @@ -1,39 +0,0 @@ -// -// DeviceClient+LiveKey.swift -// CoreKit -// -// Created by 김도형 on 10/25/24. -// - -import SwiftUI - -import Dependencies - -extension DeviceClient: DependencyKey { - public static let liveValue: Self = { -#if os(iOS) - let device = UIDevice.current.userInterfaceIdiom -#endif - - return Self( - isPhone: { -#if os(macOS) - return false -#endif - return device == .phone - }, - isPad: { -#if os(macOS) - return false -#endif - return device == .pad - }, - isMac: { -#if os(macOS) - return true -#endif - return false - } - ) - }() -} diff --git a/Projects/CoreKit/Sources/Data/Client/DeviceClient/DeviceClient.swift b/Projects/CoreKit/Sources/Data/Client/DeviceClient/DeviceClient.swift deleted file mode 100644 index f508ebc4..00000000 --- a/Projects/CoreKit/Sources/Data/Client/DeviceClient/DeviceClient.swift +++ /dev/null @@ -1,16 +0,0 @@ -// -// DeviceClient.swift -// CoreKit -// -// Created by 김도형 on 10/25/24. -// - -import Foundation -import DependenciesMacros - -@DependencyClient -public struct DeviceClient: Sendable { - public var isPhone: @Sendable () -> Bool = { false } - public var isPad: @Sendable () -> Bool = { false } - public var isMac: @Sendable () -> Bool = { false } -} diff --git a/Projects/Feature/FeatureContentSetting/Sources/ContentSetting/ContentSettingFeature.swift b/Projects/Feature/FeatureContentSetting/Sources/ContentSetting/ContentSettingFeature.swift index 617c4ae8..d12acf65 100644 --- a/Projects/Feature/FeatureContentSetting/Sources/ContentSetting/ContentSettingFeature.swift +++ b/Projects/Feature/FeatureContentSetting/Sources/ContentSetting/ContentSettingFeature.swift @@ -26,8 +26,6 @@ public struct ContentSettingFeature { private var contentClient @Dependency(CategoryClient.self) private var categoryClient - @Dependency(DeviceClient.self) - private var deviceClient /// - State @ObservableState public struct State: Equatable { @@ -214,7 +212,7 @@ private extension ContentSettingFeature { return .send(.delegate(.포킷추가하기)) case .뒤로가기_버튼_눌렀을때: - guard deviceClient.isPhone() else { + guard Device.isPhone else { return .send(.delegate(.dismiss)) } return state.isShareExtension @@ -318,7 +316,7 @@ private extension ContentSettingFeature { } return .none case .선택한_포킷_인메모리_삭제: - guard deviceClient.isPhone() else { return .none } + guard Device.isPhone else { return .none } state.selectedPokit = nil return .none } diff --git a/Projects/Util/Sources/Device.swift b/Projects/Util/Sources/Device.swift new file mode 100644 index 00000000..714c3171 --- /dev/null +++ b/Projects/Util/Sources/Device.swift @@ -0,0 +1,43 @@ +// +// Device.swift +// Util +// +// Created by 김도형 on 10/26/24. +// + +import SwiftUI + +public struct Device { +#if os(iOS) + static private let device = UIDevice.current.userInterfaceIdiom +#endif + + public static var isPhone: Bool { +#if os(macOS) + return false +#endif + return device == .phone + } + + public static var isPad: Bool { +#if os(macOS) + return false +#endif + return device == .pad + } + + public static var isMac: Bool { +#if os(macOS) + return true +#endif + return device == .mac + } + + public static var isPortrait: Bool { +#if os(macOS) + return false +#endif + return UIDevice.current.orientation == .portrait + || UIDevice.current.orientation == .portraitUpsideDown + } +}