-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathNESSuggestionPanelFeature.swift
More file actions
62 lines (58 loc) · 2 KB
/
NESSuggestionPanelFeature.swift
File metadata and controls
62 lines (58 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import ComposableArchitecture
import Foundation
import SwiftUI
@Reducer
public struct NESSuggestionPanelFeature {
@ObservableState
public struct State: Equatable {
static let baseFontSize: CGFloat = 13
static let defaultLineHeight: Double = 18
var nesContent: NESCodeSuggestionProvider? {
didSet { closeNotificationByUser = false }
}
var colorScheme: ColorScheme = .light
var firstLineIndent: Double = 0
var lineHeight: Double = Self.defaultLineHeight
var lineFontSize: Double {
Self.baseFontSize * fontSizeScale
}
var isPanelDisplayed: Bool = false
public var isPanelOutOfFrame: Bool = false
var closeNotificationByUser: Bool = false
// TODO: handle warnings
// var warningMessage: String?
// var warningURL: String?
var opacity: Double {
guard isPanelDisplayed else { return 0 }
if isPanelOutOfFrame { return 0 }
guard nesContent != nil else { return 0 }
return 1
}
var menuViewOpacity: Double {
guard nesContent != nil else { return 0 }
guard isPanelDisplayed else { return 0 }
return isPanelOutOfFrame ? 0 : 1
}
var diffViewOpacity: Double { menuViewOpacity }
var notificationViewOpacity: Double {
guard nesContent != nil else { return 0 }
guard isPanelDisplayed else { return 0 }
return isPanelOutOfFrame ? 1 : 0
}
var fontSizeScale: Double {
(lineHeight / Self.defaultLineHeight * 100).rounded() / 100
}
}
public enum Action: Equatable {
case onUserCloseNotification
}
public var body: some ReducerOf<Self> {
Reduce { state, action in
switch action {
case .onUserCloseNotification:
state.closeNotificationByUser = true
return .none
}
}
}
}