Skip to content

Commit

Permalink
[refactor] #154 Device 관련 로직 Util로 이동
Browse files Browse the repository at this point in the history
  • Loading branch information
ShapeKim98 committed Nov 6, 2024
1 parent 84eb77c commit 49c523f
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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
Expand All @@ -216,7 +219,7 @@ private extension PokitSplitFeature {
return .none

case .링크추가및수정(.delegate(.dismiss)):
state.columnVisibility = .detailOnly
state.columnVisibility = .doubleColumn
return .none
case .링크추가및수정:
return .none
Expand Down
5 changes: 2 additions & 3 deletions Projects/App/Sources/Root/RootFeature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -50,7 +49,7 @@ public struct RootFeature {

guard let fcmToken = userDefaults.stringKey(.fcmToken) else {
await send(._sceneChange(
deviceClient.isPhone()
Device.isPhone
? .mainTab()
: .mainTabSplit())
)
Expand All @@ -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()
))
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
43 changes: 43 additions & 0 deletions Projects/Util/Sources/Device.swift
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit 49c523f

Please sign in to comment.