mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-11-26 10:11:00 +00:00
Fix theme not being applied live on status row close #961
This commit is contained in:
parent
2508f98ce1
commit
e7fffa07d4
7 changed files with 43 additions and 42 deletions
|
@ -240,13 +240,13 @@ struct IceCubesApp: App {
|
|||
CommandGroup(replacing: .textFormatting) {
|
||||
Menu("menu.font") {
|
||||
Button("menu.font.bigger") {
|
||||
if userPreferences.fontSizeScale < 1.5 {
|
||||
userPreferences.fontSizeScale += 0.1
|
||||
if theme.fontSizeScale < 1.5 {
|
||||
theme.fontSizeScale += 0.1
|
||||
}
|
||||
}
|
||||
Button("menu.font.smaller") {
|
||||
if userPreferences.fontSizeScale > 0.5 {
|
||||
userPreferences.fontSizeScale -= 0.1
|
||||
if theme.fontSizeScale > 0.5 {
|
||||
theme.fontSizeScale -= 0.1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,20 +44,20 @@ struct DisplaySettingsView: View {
|
|||
|
||||
Section("settings.display.section.font") {
|
||||
Picker("settings.display.font", selection: .init(get: { () -> FontState in
|
||||
if userPreferences.chosenFont?.fontName == "OpenDyslexic-Regular" {
|
||||
if theme.chosenFont?.fontName == "OpenDyslexic-Regular" {
|
||||
return FontState.openDyslexic
|
||||
} else if userPreferences.chosenFont?.fontName == "AtkinsonHyperlegible-Regular" {
|
||||
} else if theme.chosenFont?.fontName == "AtkinsonHyperlegible-Regular" {
|
||||
return FontState.hyperLegible
|
||||
}
|
||||
return userPreferences.chosenFontData != nil ? FontState.custom : FontState.system
|
||||
return theme.chosenFontData != nil ? FontState.custom : FontState.system
|
||||
}, set: { newValue in
|
||||
switch newValue {
|
||||
case .system:
|
||||
userPreferences.chosenFont = nil
|
||||
theme.chosenFont = nil
|
||||
case .openDyslexic:
|
||||
userPreferences.chosenFont = UIFont(name: "OpenDyslexic", size: 1)
|
||||
theme.chosenFont = UIFont(name: "OpenDyslexic", size: 1)
|
||||
case .hyperLegible:
|
||||
userPreferences.chosenFont = UIFont(name: "Atkinson Hyperlegible", size: 1)
|
||||
theme.chosenFont = UIFont(name: "Atkinson Hyperlegible", size: 1)
|
||||
case .custom:
|
||||
isFontSelectorPresented = true
|
||||
}
|
||||
|
@ -68,12 +68,12 @@ struct DisplaySettingsView: View {
|
|||
}
|
||||
.navigationDestination(isPresented: $isFontSelectorPresented, destination: { FontPicker() })
|
||||
|
||||
Toggle("settings.display.font.rounded", isOn: $userPreferences.useSFRoundedFont)
|
||||
.disabled(userPreferences.chosenFont != nil)
|
||||
Toggle("settings.display.font.rounded", isOn: $theme.useSFRoundedFont)
|
||||
.disabled(theme.chosenFont != nil)
|
||||
|
||||
VStack {
|
||||
Slider(value: $userPreferences.fontSizeScale, in: 0.5 ... 1.5, step: 0.1)
|
||||
Text("settings.display.font.scaling-\(String(format: "%.1f", userPreferences.fontSizeScale))")
|
||||
Slider(value: $theme.fontSizeScale, in: 0.5 ... 1.5, step: 0.1)
|
||||
Text("settings.display.font.scaling-\(String(format: "%.1f", theme.fontSizeScale))")
|
||||
.font(.scaledBody)
|
||||
}
|
||||
.alignmentGuide(.listRowSeparatorLeading) { d in
|
||||
|
|
|
@ -15,15 +15,15 @@ public extension Font {
|
|||
private static let onMac = ProcessInfo.processInfo.isiOSAppOnMac
|
||||
|
||||
private static func customFont(size: CGFloat, relativeTo textStyle: TextStyle) -> Font {
|
||||
if let chosenFont = UserPreferences.shared.chosenFont {
|
||||
if let chosenFont = Theme.shared.chosenFont {
|
||||
return .custom(chosenFont.fontName, size: size, relativeTo: textStyle)
|
||||
}
|
||||
|
||||
return .system(size: size, design: UserPreferences.shared.useSFRoundedFont ? .rounded : .default)
|
||||
return .system(size: size, design: Theme.shared.useSFRoundedFont ? .rounded : .default)
|
||||
}
|
||||
|
||||
private static func customUIFont(size: CGFloat) -> UIFont {
|
||||
if let chosenFont = UserPreferences.shared.chosenFont {
|
||||
if let chosenFont = Theme.shared.chosenFont {
|
||||
return chosenFont.withSize(size)
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ public extension Font {
|
|||
}
|
||||
|
||||
private static func userScaledFontSize(baseSize: CGFloat) -> CGFloat {
|
||||
UIFontMetrics.default.scaledValue(for: baseSize * UserPreferences.shared.fontSizeScale)
|
||||
UIFontMetrics.default.scaledValue(for: baseSize * Theme.shared.fontSizeScale)
|
||||
}
|
||||
|
||||
static var scaledTitle: Font {
|
||||
|
|
|
@ -16,7 +16,7 @@ public struct FontPicker: UIViewControllerRepresentable {
|
|||
}
|
||||
|
||||
public func fontPickerViewControllerDidPickFont(_ viewController: UIFontPickerViewController) {
|
||||
UserPreferences.shared.chosenFont = UIFont(descriptor: viewController.selectedFontDescriptor!, size: 0)
|
||||
Theme.shared.chosenFont = UIFont(descriptor: viewController.selectedFontDescriptor!, size: 0)
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -84,6 +84,24 @@ public class Theme: ObservableObject {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public var chosenFont: UIFont? {
|
||||
get {
|
||||
guard let chosenFontData,
|
||||
let font = try? NSKeyedUnarchiver.unarchivedObject(ofClass: UIFont.self, from: chosenFontData) else { return nil }
|
||||
|
||||
return font
|
||||
}
|
||||
set {
|
||||
if let font = newValue,
|
||||
let data = try? NSKeyedArchiver.archivedData(withRootObject: font, requiringSecureCoding: false)
|
||||
{
|
||||
chosenFontData = data
|
||||
} else {
|
||||
chosenFontData = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@AppStorage("is_previously_set") public var isThemePreviouslySet: Bool = false
|
||||
@AppStorage(ThemeKey.selectedScheme.rawValue) public var selectedScheme: ColorScheme = .dark
|
||||
|
@ -98,6 +116,9 @@ public class Theme: ObservableObject {
|
|||
@AppStorage(ThemeKey.statusDisplayStyle.rawValue) public var statusDisplayStyle: StatusDisplayStyle = .large
|
||||
@AppStorage(ThemeKey.followSystemColorSchme.rawValue) public var followSystemColorScheme: Bool = true
|
||||
@AppStorage(ThemeKey.displayFullUsernameTimeline.rawValue) public var displayFullUsername: Bool = true
|
||||
@AppStorage("font_size_scale") public var fontSizeScale: Double = 1
|
||||
@AppStorage("chosen_font") public private(set) var chosenFontData: Data?
|
||||
@AppStorage("font_use_sf_rounded") public var useSFRoundedFont = false
|
||||
|
||||
@Published public var avatarPosition: AvatarPosition = .top
|
||||
@Published public var avatarShape: AvatarShape = .rounded
|
||||
|
|
|
@ -13,7 +13,6 @@ public class UserPreferences: ObservableObject {
|
|||
@AppStorage("remote_local_timeline") public var remoteLocalTimelines: [String] = []
|
||||
@AppStorage("preferred_browser") public var preferredBrowser: PreferredBrowser = .inAppSafari
|
||||
@AppStorage("draft_posts") public var draftsPosts: [String] = []
|
||||
@AppStorage("font_size_scale") public var fontSizeScale: Double = 1
|
||||
@AppStorage("show_translate_button_inline") public var showTranslateButton: Bool = true
|
||||
@AppStorage("is_open_ai_enabled") public var isOpenAIEnabled: Bool = true
|
||||
|
||||
|
@ -26,7 +25,6 @@ public class UserPreferences: ObservableObject {
|
|||
@AppStorage("app_default_post_visibility") public var appDefaultPostVisibility: Models.Visibility = .pub
|
||||
@AppStorage("app_default_posts_sensitive") public var appDefaultPostsSensitive = false
|
||||
@AppStorage("autoplay_video") public var autoPlayVideo = true
|
||||
@AppStorage("chosen_font") public private(set) var chosenFontData: Data?
|
||||
|
||||
@AppStorage("suppress_dupe_reblogs") public var suppressDupeReblogs: Bool = false
|
||||
|
||||
|
@ -48,8 +46,6 @@ public class UserPreferences: ObservableObject {
|
|||
@AppStorage("swipeactions-use-theme-color") public var swipeActionsUseThemeColor = false
|
||||
@AppStorage("swipeactions-icon-style") public var swipeActionsIconStyle: SwipeActionsIconStyle = .iconWithText
|
||||
|
||||
@AppStorage("font_use_sf_rounded") public var useSFRoundedFont = false
|
||||
|
||||
@AppStorage("requested_review") public var requestedReview = false
|
||||
|
||||
public enum SwipeActionsIconStyle: String, CaseIterable {
|
||||
|
@ -112,25 +108,7 @@ public class UserPreferences: ObservableObject {
|
|||
}
|
||||
return count
|
||||
}
|
||||
|
||||
public var chosenFont: UIFont? {
|
||||
get {
|
||||
guard let chosenFontData,
|
||||
let font = try? NSKeyedUnarchiver.unarchivedObject(ofClass: UIFont.self, from: chosenFontData) else { return nil }
|
||||
|
||||
return font
|
||||
}
|
||||
set {
|
||||
if let font = newValue,
|
||||
let data = try? NSKeyedArchiver.archivedData(withRootObject: font, requiringSecureCoding: false)
|
||||
{
|
||||
chosenFontData = data
|
||||
} else {
|
||||
chosenFontData = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Published public var serverPreferences: ServerPreferences?
|
||||
|
||||
private init() {}
|
||||
|
|
|
@ -3,6 +3,8 @@ import Models
|
|||
import SwiftUI
|
||||
|
||||
struct StatusRowTextView: View {
|
||||
@EnvironmentObject private var theme: Theme
|
||||
|
||||
let status: AnyStatus
|
||||
let viewModel: StatusRowViewModel
|
||||
|
||||
|
|
Loading…
Reference in a new issue