Skip to content

Commit

Permalink
allow user to decide if avatar is shown in the tab bar
Browse files Browse the repository at this point in the history
  • Loading branch information
mormaer committed Sep 10, 2023
1 parent 6b938e3 commit 994a1de
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
10 changes: 10 additions & 0 deletions Mlem/App State.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class AppState: ObservableObject {

@AppStorage("defaultAccountId") var defaultAccountId: Int?
@AppStorage("profileTabLabel") var profileTabLabel: ProfileTabLabel = .username
@AppStorage("showUserAvatarOnProfileTab") var showUserAvatar: Bool = true

@Published private(set) var currentActiveAccount: SavedAccount?

Expand All @@ -36,6 +37,15 @@ class AppState: ObservableObject {
}
}

/// A variable representing the remote location to load the user profile avatar from if applicable
var profileTabRemoteSymbolUrl: URL? {
guard profileTabLabel != .anonymous, showUserAvatar else {
return nil
}

return currentActiveAccount?.avatarUrl
}

/// A method to set the current active account, any changes to the account will be propogated to the persistence layer
/// - Important: If you wish to _clear_ the current active account please use the `\.setAppFlow` method available via the environment to reset to our `.onboarding` flow
/// - Parameter account: The `SavedAccount` which should become the active account
Expand Down
2 changes: 1 addition & 1 deletion Mlem/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ struct ContentView: View {
symbolConfiguration: .init(
symbol: FancyTabBarLabel.SymbolConfiguration.profile.symbol,
activeSymbol: FancyTabBarLabel.SymbolConfiguration.profile.activeSymbol,
remoteSymbolUrl: appState.currentActiveAccount?.avatarUrl
remoteSymbolUrl: appState.profileTabRemoteSymbolUrl
)
)
.simultaneousGesture(accountSwitchLongPress)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ struct TabBarSettingsView: View {
@AppStorage("profileTabLabel") var profileTabLabel: ProfileTabLabel = .username
@AppStorage("showTabNames") var showTabNames: Bool = true
@AppStorage("showInboxUnreadBadge") var showInboxUnreadBadge: Bool = true
@AppStorage("showUserAvatarOnProfileTab") var showUserAvatar: Bool = true

@EnvironmentObject var appState: AppState

Expand Down Expand Up @@ -71,6 +72,14 @@ struct TabBarSettingsView: View {
settingName: "Show Unread Count",
isTicked: $showInboxUnreadBadge
)

SwitchableSettingsItem(
settingPictureSystemName: "person.fill.questionmark",
settingName: "Show User Avatar",
// if `.anonymous` is selected the toggle here should always be false
isTicked: profileTabLabel == .anonymous ? .constant(false) : $showUserAvatar
)
.disabled(profileTabLabel == .anonymous)
}
}
.fancyTabScrollCompatible()
Expand Down

0 comments on commit 994a1de

Please sign in to comment.