From 8185f66a24adad50e0ca396962be65c4ea5e2330 Mon Sep 17 00:00:00 2001 From: Bosco Ho Date: Tue, 10 Oct 2023 23:56:14 -0700 Subject: [PATCH] Fixed default sidebar avatars (#689) Commit: 1d83d194e551d59e55fb45df712ee354b70e39b4 [1d83d194] --- Mlem.xcodeproj/project.pbxproj | 46 +++++++++++------- Mlem/Enums/AvatarType.swift | 33 +++++++++++++ .../Shared/Avatars/DefaultAvatarView.swift | 21 +++++++++ Mlem/Views/Shared/Links/AvatarView.swift | 45 ++++-------------- .../Components/Sidebar Header Avatar.swift | 47 +++++++------------ .../Feeds/Components/Sidebar Header.swift | 22 ++++++--- .../Tabs/Feeds/Components/Sidebar View.swift | 3 +- Mlem/Views/Tabs/Profile/User View.swift | 3 +- 8 files changed, 128 insertions(+), 92 deletions(-) create mode 100644 Mlem/Enums/AvatarType.swift create mode 100644 Mlem/Views/Shared/Avatars/DefaultAvatarView.swift diff --git a/Mlem.xcodeproj/project.pbxproj b/Mlem.xcodeproj/project.pbxproj index 36e45a24e..aa39af684 100644 --- a/Mlem.xcodeproj/project.pbxproj +++ b/Mlem.xcodeproj/project.pbxproj @@ -11,15 +11,15 @@ 030AC0522A64666C00037155 /* UserSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 030AC0512A64666C00037155 /* UserSettingsView.swift */; }; 030D4AE62AA1273200A3393D /* ErrorDetails.swift in Sources */ = {isa = PBXBuildFile; fileRef = 030D4AE52AA1273200A3393D /* ErrorDetails.swift */; }; 030D4AE82AA1278400A3393D /* ErrorDetails+Mock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 030D4AE72AA1278400A3393D /* ErrorDetails+Mock.swift */; }; + 030E86392AC6B44B000283A6 /* DeletePictrsFile.swift in Sources */ = {isa = PBXBuildFile; fileRef = 030E86382AC6B44B000283A6 /* DeletePictrsFile.swift */; }; + 030E863B2AC6C3B1000283A6 /* PictrsRespository.swift in Sources */ = {isa = PBXBuildFile; fileRef = 030E863A2AC6C3B1000283A6 /* PictrsRespository.swift */; }; + 030E863D2AC6C49E000283A6 /* PictrsRepository+Dependency.swift in Sources */ = {isa = PBXBuildFile; fileRef = 030E863C2AC6C49E000283A6 /* PictrsRepository+Dependency.swift */; }; + 030E863F2AC6C5E9000283A6 /* PictrsImageModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 030E863E2AC6C5E9000283A6 /* PictrsImageModel.swift */; }; 030E86412AC6F692000283A6 /* SearchBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 030E86402AC6F692000283A6 /* SearchBar.swift */; }; 030E86442AC6F6D5000283A6 /* SearchBar+NavigationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 030E86432AC6F6D5000283A6 /* SearchBar+NavigationView.swift */; }; 030E86462AC6FC1B000283A6 /* DefaultTextInputType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 030E86452AC6FC1B000283A6 /* DefaultTextInputType.swift */; }; 030E86482AC6FD1D000283A6 /* _assignIfNotEqual.swift in Sources */ = {isa = PBXBuildFile; fileRef = 030E86472AC6FD1D000283A6 /* _assignIfNotEqual.swift */; }; 030E864C2AC7037F000283A6 /* SearchBarExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 030E864B2AC7037F000283A6 /* SearchBarExtensions.swift */; }; - 030E86392AC6B44B000283A6 /* DeletePictrsFile.swift in Sources */ = {isa = PBXBuildFile; fileRef = 030E86382AC6B44B000283A6 /* DeletePictrsFile.swift */; }; - 030E863B2AC6C3B1000283A6 /* PictrsRespository.swift in Sources */ = {isa = PBXBuildFile; fileRef = 030E863A2AC6C3B1000283A6 /* PictrsRespository.swift */; }; - 030E863D2AC6C49E000283A6 /* PictrsRepository+Dependency.swift in Sources */ = {isa = PBXBuildFile; fileRef = 030E863C2AC6C49E000283A6 /* PictrsRepository+Dependency.swift */; }; - 030E863F2AC6C5E9000283A6 /* PictrsImageModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 030E863E2AC6C5E9000283A6 /* PictrsImageModel.swift */; }; 031A93D62AC847DA0077030C /* UploadConfirmationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 031A93D52AC847DA0077030C /* UploadConfirmationView.swift */; }; 031BF9532AB24BAF00F4517F /* SiteVersion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 031BF9522AB24BAF00F4517F /* SiteVersion.swift */; }; 031BF9552AB25AFB00F4517F /* SiteVersionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 031BF9542AB25AFB00F4517F /* SiteVersionTests.swift */; }; @@ -46,23 +46,22 @@ 03B7AAF12ABE404300068B23 /* ContentModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03B7AAF02ABE404300068B23 /* ContentModel.swift */; }; 03B7AAF32ABEF85300068B23 /* UserModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03B7AAF22ABEF85200068B23 /* UserModel.swift */; }; 03B7AAF52ABEFA7A00068B23 /* UserResultView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03B7AAF42ABEFA7A00068B23 /* UserResultView.swift */; }; - 03BAA23A2A57DC1400D48252 /* TimestampView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03BAA2392A57DC1400D48252 /* TimestampView.swift */; }; + 03BAA23A2A57DC1400D48252 /* PublishedTimestampView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03BAA2392A57DC1400D48252 /* PublishedTimestampView.swift */; }; 03C897F62ABF49BD005F3403 /* Abbreviate Numbers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03C897F52ABF49BD005F3403 /* Abbreviate Numbers.swift */; }; 03C897F82ABF652D005F3403 /* SearchRoot.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03C897F72ABF652D005F3403 /* SearchRoot.swift */; }; 03C898012AC04EF9005F3403 /* SearchResultsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03C898002AC04EF9005F3403 /* SearchResultsView.swift */; }; 03C898032AC04F61005F3403 /* RecentSearchesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03C898022AC04F61005F3403 /* RecentSearchesView.swift */; }; - 03BAA23A2A57DC1400D48252 /* PublishedTimestampView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03BAA2392A57DC1400D48252 /* PublishedTimestampView.swift */; }; 03CB329E2A6D8E910021EF27 /* PostDetailEditorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03CB329D2A6D8E910021EF27 /* PostDetailEditorView.swift */; }; 03E0B9C82A61F0F400FED265 /* AdvancedSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03E0B9C72A61F0F400FED265 /* AdvancedSettingsView.swift */; }; 03E0B9CA2A62B4A400FED265 /* ContributorsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03E0B9C92A62B4A400FED265 /* ContributorsView.swift */; }; 03E0B9CC2A62CD5800FED265 /* ThemeSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03E0B9CB2A62CD5800FED265 /* ThemeSettingsView.swift */; }; + 03EA79C42AC0D92C00BCDC91 /* PostDetailEditorView+Logic.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03EA79C32AC0D92C00BCDC91 /* PostDetailEditorView+Logic.swift */; }; 03EC92952AC064AE007BBE7E /* SearchHomeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03EC92942AC064AE007BBE7E /* SearchHomeView.swift */; }; 03EC92972AC069CE007BBE7E /* SearchResultListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03EC92962AC069CE007BBE7E /* SearchResultListView.swift */; }; + 03EC92992AC0BF8A007BBE7E /* APIClient+Pictrs.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03EC92982AC0BF8A007BBE7E /* APIClient+Pictrs.swift */; }; 03EEEAF32AB8DCDF0087F8D8 /* CommunityResultView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03EEEAF22AB8DCDF0087F8D8 /* CommunityResultView.swift */; }; 03EEEAF72AB8ED3C0087F8D8 /* SearchTabPicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03EEEAF62AB8ED3C0087F8D8 /* SearchTabPicker.swift */; }; 03EEEAF92ABB985D0087F8D8 /* CommunityModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03EEEAF82ABB985D0087F8D8 /* CommunityModel.swift */; }; - 03EA79C42AC0D92C00BCDC91 /* PostDetailEditorView+Logic.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03EA79C32AC0D92C00BCDC91 /* PostDetailEditorView+Logic.swift */; }; - 03EC92992AC0BF8A007BBE7E /* APIClient+Pictrs.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03EC92982AC0BF8A007BBE7E /* APIClient+Pictrs.swift */; }; 500C168E2A66FAAB006F243B /* HapticManager+Dependency.swift in Sources */ = {isa = PBXBuildFile; fileRef = 500C168D2A66FAAB006F243B /* HapticManager+Dependency.swift */; }; 5016A2B12A67EB8600B257E8 /* UIViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5016A2B02A67EB8600B257E8 /* UIViewController.swift */; }; 5016A2B32A67EC0700B257E8 /* NotificationDisplayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5016A2B22A67EC0700B257E8 /* NotificationDisplayer.swift */; }; @@ -329,6 +328,8 @@ CD18DC6F2A5209C3002C56BC /* MarkPrivateMessageAsReadRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD18DC6E2A5209C3002C56BC /* MarkPrivateMessageAsReadRequest.swift */; }; CD18DC732A522A7C002C56BC /* CreatePrivateMessageRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD18DC722A522A7C002C56BC /* CreatePrivateMessageRequest.swift */; }; CD2053102AC878B50000AA38 /* UpdatedTimestampView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD20530F2AC878B50000AA38 /* UpdatedTimestampView.swift */; }; + CD2053142ACBAF150000AA38 /* AvatarType.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD2053132ACBAF150000AA38 /* AvatarType.swift */; }; + CD2053172ACBBB5A0000AA38 /* DefaultAvatarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD2053162ACBBB5A0000AA38 /* DefaultAvatarView.swift */; }; CD2BD6782A79F55800ECFF89 /* ImageSize.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD2BD6772A79F55800ECFF89 /* ImageSize.swift */; }; CD2E182B2A3B708500224F8A /* Settings Options.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD2E182A2A3B708500224F8A /* Settings Options.swift */; }; CD309C462A93FBD300988F95 /* Logo View.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD309C452A93FBD300988F95 /* Logo View.swift */; }; @@ -491,15 +492,15 @@ 030AC0512A64666C00037155 /* UserSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserSettingsView.swift; sourceTree = ""; }; 030D4AE52AA1273200A3393D /* ErrorDetails.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ErrorDetails.swift; sourceTree = ""; }; 030D4AE72AA1278400A3393D /* ErrorDetails+Mock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ErrorDetails+Mock.swift"; sourceTree = ""; }; + 030E86382AC6B44B000283A6 /* DeletePictrsFile.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeletePictrsFile.swift; sourceTree = ""; }; + 030E863A2AC6C3B1000283A6 /* PictrsRespository.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PictrsRespository.swift; sourceTree = ""; }; + 030E863C2AC6C49E000283A6 /* PictrsRepository+Dependency.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PictrsRepository+Dependency.swift"; sourceTree = ""; }; + 030E863E2AC6C5E9000283A6 /* PictrsImageModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PictrsImageModel.swift; sourceTree = ""; }; 030E86402AC6F692000283A6 /* SearchBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchBar.swift; sourceTree = ""; }; 030E86432AC6F6D5000283A6 /* SearchBar+NavigationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SearchBar+NavigationView.swift"; sourceTree = ""; }; 030E86452AC6FC1B000283A6 /* DefaultTextInputType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DefaultTextInputType.swift; sourceTree = ""; }; 030E86472AC6FD1D000283A6 /* _assignIfNotEqual.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = _assignIfNotEqual.swift; sourceTree = ""; }; 030E864B2AC7037F000283A6 /* SearchBarExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchBarExtensions.swift; sourceTree = ""; }; - 030E86382AC6B44B000283A6 /* DeletePictrsFile.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeletePictrsFile.swift; sourceTree = ""; }; - 030E863A2AC6C3B1000283A6 /* PictrsRespository.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PictrsRespository.swift; sourceTree = ""; }; - 030E863C2AC6C49E000283A6 /* PictrsRepository+Dependency.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PictrsRepository+Dependency.swift"; sourceTree = ""; }; - 030E863E2AC6C5E9000283A6 /* PictrsImageModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PictrsImageModel.swift; sourceTree = ""; }; 031A93D52AC847DA0077030C /* UploadConfirmationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UploadConfirmationView.swift; sourceTree = ""; }; 031BF9522AB24BAF00F4517F /* SiteVersion.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SiteVersion.swift; sourceTree = ""; }; 031BF9542AB25AFB00F4517F /* SiteVersionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SiteVersionTests.swift; sourceTree = ""; }; @@ -526,23 +527,22 @@ 03B7AAF02ABE404300068B23 /* ContentModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentModel.swift; sourceTree = ""; }; 03B7AAF22ABEF85200068B23 /* UserModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserModel.swift; sourceTree = ""; }; 03B7AAF42ABEFA7A00068B23 /* UserResultView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserResultView.swift; sourceTree = ""; }; - 03BAA2392A57DC1400D48252 /* TimestampView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimestampView.swift; sourceTree = ""; }; + 03BAA2392A57DC1400D48252 /* PublishedTimestampView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PublishedTimestampView.swift; sourceTree = ""; }; 03C897F52ABF49BD005F3403 /* Abbreviate Numbers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Abbreviate Numbers.swift"; sourceTree = ""; }; 03C897F72ABF652D005F3403 /* SearchRoot.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchRoot.swift; sourceTree = ""; }; 03C898002AC04EF9005F3403 /* SearchResultsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchResultsView.swift; sourceTree = ""; }; 03C898022AC04F61005F3403 /* RecentSearchesView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecentSearchesView.swift; sourceTree = ""; }; - 03BAA2392A57DC1400D48252 /* PublishedTimestampView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PublishedTimestampView.swift; sourceTree = ""; }; 03CB329D2A6D8E910021EF27 /* PostDetailEditorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostDetailEditorView.swift; sourceTree = ""; }; 03E0B9C72A61F0F400FED265 /* AdvancedSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdvancedSettingsView.swift; sourceTree = ""; }; 03E0B9C92A62B4A400FED265 /* ContributorsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContributorsView.swift; sourceTree = ""; }; 03E0B9CB2A62CD5800FED265 /* ThemeSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThemeSettingsView.swift; sourceTree = ""; }; + 03EA79C32AC0D92C00BCDC91 /* PostDetailEditorView+Logic.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PostDetailEditorView+Logic.swift"; sourceTree = ""; }; 03EC92942AC064AE007BBE7E /* SearchHomeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchHomeView.swift; sourceTree = ""; }; 03EC92962AC069CE007BBE7E /* SearchResultListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchResultListView.swift; sourceTree = ""; }; + 03EC92982AC0BF8A007BBE7E /* APIClient+Pictrs.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "APIClient+Pictrs.swift"; sourceTree = ""; }; 03EEEAF22AB8DCDF0087F8D8 /* CommunityResultView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommunityResultView.swift; sourceTree = ""; }; 03EEEAF62AB8ED3C0087F8D8 /* SearchTabPicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchTabPicker.swift; sourceTree = ""; }; 03EEEAF82ABB985D0087F8D8 /* CommunityModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommunityModel.swift; sourceTree = ""; }; - 03EA79C32AC0D92C00BCDC91 /* PostDetailEditorView+Logic.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PostDetailEditorView+Logic.swift"; sourceTree = ""; }; - 03EC92982AC0BF8A007BBE7E /* APIClient+Pictrs.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "APIClient+Pictrs.swift"; sourceTree = ""; }; 500C168D2A66FAAB006F243B /* HapticManager+Dependency.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "HapticManager+Dependency.swift"; sourceTree = ""; }; 5016A2B02A67EB8600B257E8 /* UIViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIViewController.swift; sourceTree = ""; }; 5016A2B22A67EC0700B257E8 /* NotificationDisplayer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationDisplayer.swift; sourceTree = ""; }; @@ -807,6 +807,8 @@ CD18DC6E2A5209C3002C56BC /* MarkPrivateMessageAsReadRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MarkPrivateMessageAsReadRequest.swift; sourceTree = ""; }; CD18DC722A522A7C002C56BC /* CreatePrivateMessageRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreatePrivateMessageRequest.swift; sourceTree = ""; }; CD20530F2AC878B50000AA38 /* UpdatedTimestampView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UpdatedTimestampView.swift; sourceTree = ""; }; + CD2053132ACBAF150000AA38 /* AvatarType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AvatarType.swift; sourceTree = ""; }; + CD2053162ACBBB5A0000AA38 /* DefaultAvatarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DefaultAvatarView.swift; sourceTree = ""; }; CD2BD6772A79F55800ECFF89 /* ImageSize.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageSize.swift; sourceTree = ""; }; CD2E182A2A3B708500224F8A /* Settings Options.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Settings Options.swift"; sourceTree = ""; }; CD309C452A93FBD300988F95 /* Logo View.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Logo View.swift"; sourceTree = ""; }; @@ -1862,6 +1864,7 @@ 6386E03E2A04570F006B3C1D /* Shared */ = { isa = PBXGroup; children = ( + CD2053152ACBBB490000AA38 /* Avatars */, CD2E147B2A6B2891004198DE /* Components */, 6332FDCD27EFDD0A0009A98A /* Accounts */, CD2E147A2A6B2871004198DE /* Comments */, @@ -1908,6 +1911,7 @@ CDDCF6522A677F45003DA3AC /* TabSelection.swift */, CDE9CE4E2A7B0B1B002B97DD /* Haptic.swift */, CDEBC3242A9A57D200518D9D /* Content Type.swift */, + CD2053132ACBAF150000AA38 /* AvatarType.swift */, ); path = Enums; sourceTree = ""; @@ -2032,6 +2036,14 @@ path = "View Modifiers"; sourceTree = ""; }; + CD2053152ACBBB490000AA38 /* Avatars */ = { + isa = PBXGroup; + children = ( + CD2053162ACBBB5A0000AA38 /* DefaultAvatarView.swift */, + ); + path = Avatars; + sourceTree = ""; + }; CD2E14782A6B283D004198DE /* Feeds */ = { isa = PBXGroup; children = ( @@ -2643,6 +2655,7 @@ CD863FBA2A6AEB5900A31ED9 /* TabSafeScrollView.swift in Sources */, 637218772A3A2AAD008C4816 /* APIRequest.swift in Sources */, 63A09B69285F53E9004F0032 /* Error View.swift in Sources */, + CD2053172ACBBB5A0000AA38 /* DefaultAvatarView.swift in Sources */, CD3FBCE72A4A8CE300B2063F /* Messages Feed View.swift in Sources */, 63344C582A07DB9A001BC616 /* Array - Move Elements Around.swift in Sources */, 03E0B9C82A61F0F400FED265 /* AdvancedSettingsView.swift in Sources */, @@ -2894,6 +2907,7 @@ 50A881282A71D66B003E3661 /* APIClient+Community.swift in Sources */, 6307378D2A1CEB7C00039852 /* My Vote.swift in Sources */, 50F830FA2A4C935C00D67099 /* FeedTracker.swift in Sources */, + CD2053142ACBAF150000AA38 /* AvatarType.swift in Sources */, CD69F55D2A400DF50028D4F7 /* UIUserInterfaceStyle - SettingsOption conformant.swift in Sources */, CDF1EF182A6C40C9003594B6 /* Menu Button.swift in Sources */, 6D91D4552A415994006B8F9A /* CommunityListSidebarEntry.swift in Sources */, diff --git a/Mlem/Enums/AvatarType.swift b/Mlem/Enums/AvatarType.swift new file mode 100644 index 000000000..fa4e7d19c --- /dev/null +++ b/Mlem/Enums/AvatarType.swift @@ -0,0 +1,33 @@ +// +// AvatarType.swift +// Mlem +// +// Created by Eric Andrews on 2023-10-02. +// + +import Foundation + +/// Enum of things that can have avatars +enum AvatarType { + case user, community +} + +extension AvatarType: AssociatedIcon { + var iconName: String { + switch self { + case .user: + return Icons.user + case .community: + return Icons.community + } + } + + var iconNameFill: String { + switch self { + case .user: + return Icons.userFill + case .community: + return Icons.communityFill + } + } +} diff --git a/Mlem/Views/Shared/Avatars/DefaultAvatarView.swift b/Mlem/Views/Shared/Avatars/DefaultAvatarView.swift new file mode 100644 index 000000000..141600942 --- /dev/null +++ b/Mlem/Views/Shared/Avatars/DefaultAvatarView.swift @@ -0,0 +1,21 @@ +// +// DefaultAvatarView.swift +// Mlem +// +// Created by Eric Andrews on 2023-10-02. +// + +import Foundation +import SwiftUI + +struct DefaultAvatarView: View { + let avatarType: AvatarType + + var body: some View { + Image(systemName: avatarType.iconNameFill) + .resizable() + .scaledToFill() + .background(.white) + .foregroundStyle(Color.gray.gradient) + } +} diff --git a/Mlem/Views/Shared/Links/AvatarView.swift b/Mlem/Views/Shared/Links/AvatarView.swift index 884c7b915..976d9cec2 100644 --- a/Mlem/Views/Shared/Links/AvatarView.swift +++ b/Mlem/Views/Shared/Links/AvatarView.swift @@ -10,8 +10,6 @@ struct AvatarView: View { // Don't clip the avatars of communities from these instances static let unclippedInstances = ["beehaw.org"] - enum AvatarType { case community, user } - let type: AvatarType let url: URL? let avatarSize: CGFloat @@ -48,21 +46,15 @@ struct AvatarView: View { return !unclippedInstances.contains(hostString) } - + var body: some View { - Group { - if let url { - CachedImage( - url: url.withIcon64Parameters, - shouldExpand: false, - fixedSize: CGSize(width: avatarSize, height: avatarSize), - imageNotFound: defaultAvatar, - contentMode: .fill - ) - } else { - defaultAvatar() - } - } + CachedImage( + url: url?.withIcon64Parameters, + shouldExpand: false, + fixedSize: CGSize(width: avatarSize, height: avatarSize), + imageNotFound: { AnyView(DefaultAvatarView(avatarType: type)) }, + contentMode: .fill + ) .frame(width: avatarSize, height: avatarSize) .accessibilityHidden(true) .blur(radius: blurAvatar ? 4 : 0) @@ -73,25 +65,4 @@ struct AvatarView: View { lineWidth: clipAvatar ? 1 : 0 )) } - - private func defaultAvatar() -> AnyView { - switch type { - case .community: - return AnyView( - Image(systemName: Icons.communityFill) - .resizable() - .scaledToFill() - .background(.white) - .foregroundStyle(Color.gray.gradient) - ) - case .user: - return AnyView( - Image(systemName: Icons.userFill) - .resizable() - .scaledToFill() - .background(.white) - .foregroundStyle(Color.gray.gradient) - ) - } - } } diff --git a/Mlem/Views/Tabs/Feeds/Components/Sidebar Header Avatar.swift b/Mlem/Views/Tabs/Feeds/Components/Sidebar Header Avatar.swift index 6f45485ca..2ec287ee8 100644 --- a/Mlem/Views/Tabs/Feeds/Components/Sidebar Header Avatar.swift +++ b/Mlem/Views/Tabs/Feeds/Components/Sidebar Header Avatar.swift @@ -9,38 +9,25 @@ import Foundation import SwiftUI -struct CommunitySidebarHeaderAvatar: View { +struct SidebarHeaderAvatar: View { @State var shouldClipAvatar: Bool = false @State var imageUrl: URL? - - var body: some View { - avatar - .frame(width: AppConstants.hugeAvatarSize, height: AppConstants.hugeAvatarSize) - .clipShape(Circle()) - .overlay(Circle() - .stroke(.secondary, lineWidth: shouldClipAvatar ? 2 : 0)) - .shadow(radius: 10) - .background(shouldClipAvatar ? Circle() - .foregroundColor(.systemBackground) : nil) - } + let avatarType: AvatarType - @ViewBuilder - var avatar: some View { - if let avatarURL = imageUrl { - CachedImage( - url: avatarURL, - shouldExpand: false, - fixedSize: CGSize(width: AppConstants.hugeAvatarSize, height: AppConstants.hugeAvatarSize), - contentMode: .fill - ) - } else { - VStack(alignment: .center) { - Spacer() - .frame(height: 20) - Image(systemName: Icons.user) - .font(.system(size: AppConstants.hugeAvatarSize)) // SF Symbols are apparently font - .foregroundColor(.secondary) - } - } + var body: some View { + CachedImage( + url: imageUrl, + shouldExpand: false, + fixedSize: CGSize(width: AppConstants.hugeAvatarSize, height: AppConstants.hugeAvatarSize), + imageNotFound: { AnyView(DefaultAvatarView(avatarType: avatarType)) }, + contentMode: .fill + ) + .frame(width: AppConstants.hugeAvatarSize, height: AppConstants.hugeAvatarSize) + .clipShape(Circle()) + .overlay(Circle() + .stroke(.secondary, lineWidth: shouldClipAvatar ? 2 : 0)) + .shadow(radius: 10) + .background(shouldClipAvatar ? Circle() + .foregroundColor(.systemBackground) : nil) } } diff --git a/Mlem/Views/Tabs/Feeds/Components/Sidebar Header.swift b/Mlem/Views/Tabs/Feeds/Components/Sidebar Header.swift index fb57c75bf..a2840c84a 100644 --- a/Mlem/Views/Tabs/Feeds/Components/Sidebar Header.swift +++ b/Mlem/Views/Tabs/Feeds/Components/Sidebar Header.swift @@ -19,6 +19,8 @@ struct CommunitySidebarHeader: View { var label1: String? var label2: String? + let avatarType: AvatarType + var body: some View { ZStack(alignment: .top) { // Banner @@ -38,9 +40,10 @@ struct CommunitySidebarHeader: View { } HStack(alignment: .top) { VStack(alignment: .leading) { - CommunitySidebarHeaderAvatar( + SidebarHeaderAvatar( shouldClipAvatar: AvatarView.shouldClipCommunityAvatar(url: avatarUrl), - imageUrl: avatarUrl + imageUrl: avatarUrl, + avatarType: avatarType ) Button { @@ -96,7 +99,8 @@ struct SidebarHeaderPreview: PreviewProvider { bannerURL: URL(string: "https://picsum.photos/seed/mlem-banner/2001/300"), avatarUrl: URL(string: "https://picsum.photos/seed/mlem-avatar/200"), label1: "Label 1", - label2: "Label 2" + label2: "Label 2", + avatarType: .community ) Divider() CommunitySidebarHeader( @@ -106,7 +110,8 @@ struct SidebarHeaderPreview: PreviewProvider { bannerURL: URL(string: "https://picsum.photos/seed/mlem-banner/200/300"), avatarUrl: URL(string: "https://picsum.photos/seed/mlem-avatar/200"), label1: "Label 1", - label2: "Label 2" + label2: "Label 2", + avatarType: .community ) Divider() CommunitySidebarHeader( @@ -116,7 +121,8 @@ struct SidebarHeaderPreview: PreviewProvider { bannerURL: URL(string: "https://picsum.photos/seed/mlem-banner/200/300"), avatarUrl: nil, label1: "Label 1", - label2: "Label 2" + label2: "Label 2", + avatarType: .community ) Divider() CommunitySidebarHeader( @@ -126,7 +132,8 @@ struct SidebarHeaderPreview: PreviewProvider { bannerURL: nil, avatarUrl: URL(string: "https://picsum.photos/seed/mlem-avatar/200"), label1: "Label 1", - label2: "Label 2" + label2: "Label 2", + avatarType: .community ) Divider() CommunitySidebarHeader( @@ -136,7 +143,8 @@ struct SidebarHeaderPreview: PreviewProvider { bannerURL: nil, avatarUrl: nil, label1: "Label 1", - label2: "Label 2" + label2: "Label 2", + avatarType: .community ) Spacer() } diff --git a/Mlem/Views/Tabs/Feeds/Components/Sidebar View.swift b/Mlem/Views/Tabs/Feeds/Components/Sidebar View.swift index 2908f5dfc..076cbeaee 100644 --- a/Mlem/Views/Tabs/Feeds/Components/Sidebar View.swift +++ b/Mlem/Views/Tabs/Feeds/Components/Sidebar View.swift @@ -69,7 +69,8 @@ struct CommunitySidebarView: View { avatarSubtext: .constant("Created \(getRelativeTime(date: communityDetails.communityView.community.published))"), bannerURL: shouldShowCommunityHeaders ? communityDetails.communityView.community.bannerUrl : nil, avatarUrl: communityDetails.communityView.community.iconUrl, - label1: "\(communityDetails.communityView.counts.subscribers) Subscribers" + label1: "\(communityDetails.communityView.counts.subscribers) Subscribers", + avatarType: .community ) Picker(selection: $selectionSection, label: Text("Profile Section")) { diff --git a/Mlem/Views/Tabs/Profile/User View.swift b/Mlem/Views/Tabs/Profile/User View.swift index 05c68addf..e4a86a7e2 100644 --- a/Mlem/Views/Tabs/Profile/User View.swift +++ b/Mlem/Views/Tabs/Profile/User View.swift @@ -104,7 +104,8 @@ struct UserView: View { bannerURL: shouldShowUserHeaders ? userDetails.person.bannerUrl : nil, avatarUrl: userDetails.person.avatarUrl, label1: "\(userDetails.counts.commentCount) Comments", - label2: "\(userDetails.counts.postCount) Posts" + label2: "\(userDetails.counts.postCount) Posts", + avatarType: .user ) }