From f815d4e2e4bec0600fb16cef67acbb802081ad02 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Thu, 22 Dec 2022 18:03:32 -0500 Subject: [PATCH] Replace VisualEffectImageButton with ProfileHeaderButton --- Tusker.xcodeproj/project.pbxproj | 8 +-- .../Profile Header/ProfileHeaderButton.swift | 25 +++++++ .../Profile Header/ProfileHeaderView.swift | 31 ++++---- .../Profile Header/ProfileHeaderView.xib | 29 ++++---- Tusker/Views/VisualEffectImageButton.swift | 72 ------------------- 5 files changed, 55 insertions(+), 110 deletions(-) create mode 100644 Tusker/Views/Profile Header/ProfileHeaderButton.swift delete mode 100644 Tusker/Views/VisualEffectImageButton.swift diff --git a/Tusker.xcodeproj/project.pbxproj b/Tusker.xcodeproj/project.pbxproj index 2f74a483..76c4ab65 100644 --- a/Tusker.xcodeproj/project.pbxproj +++ b/Tusker.xcodeproj/project.pbxproj @@ -117,7 +117,6 @@ D63CC7122911F57C000E19DE /* StatusBarTappableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D63CC7112911F57C000E19DE /* StatusBarTappableViewController.swift */; }; D63D8DF42850FE7A008D95E1 /* ViewTags.swift in Sources */ = {isa = PBXBuildFile; fileRef = D63D8DF32850FE7A008D95E1 /* ViewTags.swift */; }; D63F9C6E241D2D85004C03CF /* CompositionAttachment.swift in Sources */ = {isa = PBXBuildFile; fileRef = D63F9C6D241D2D85004C03CF /* CompositionAttachment.swift */; }; - D6403CC224A6B72D00E81C55 /* VisualEffectImageButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6403CC124A6B72D00E81C55 /* VisualEffectImageButton.swift */; }; D640D76922BAF5E6004FBE69 /* DomainBlocks.plist in Resources */ = {isa = PBXBuildFile; fileRef = D640D76822BAF5E6004FBE69 /* DomainBlocks.plist */; }; D6412B0324AFF6A600F5412E /* TabBarScrollableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6412B0224AFF6A600F5412E /* TabBarScrollableViewController.swift */; }; D6412B0924B0291E00F5412E /* MyProfileViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6412B0824B0291E00F5412E /* MyProfileViewController.swift */; }; @@ -219,6 +218,7 @@ D6969E9E240C81B9002843CE /* NSTextAttachment+Emoji.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6969E9D240C81B9002843CE /* NSTextAttachment+Emoji.swift */; }; D6969EA0240C8384002843CE /* EmojiLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6969E9F240C8384002843CE /* EmojiLabel.swift */; }; D6A00B1D26379FC900316AD4 /* PollOptionsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6A00B1C26379FC900316AD4 /* PollOptionsView.swift */; }; + D6A3A380295515550036B6EF /* ProfileHeaderButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6A3A37F295515550036B6EF /* ProfileHeaderButton.swift */; }; D6A3BC7C232195C600FD64D5 /* ActionNotificationGroupTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6A3BC7A232195C600FD64D5 /* ActionNotificationGroupTableViewCell.swift */; }; D6A3BC7D232195C600FD64D5 /* ActionNotificationGroupTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = D6A3BC7B232195C600FD64D5 /* ActionNotificationGroupTableViewCell.xib */; }; D6A3BC802321B7E600FD64D5 /* FollowNotificationGroupTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6A3BC7E2321B7E600FD64D5 /* FollowNotificationGroupTableViewCell.swift */; }; @@ -498,7 +498,6 @@ D63CC7112911F57C000E19DE /* StatusBarTappableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusBarTappableViewController.swift; sourceTree = ""; }; D63D8DF32850FE7A008D95E1 /* ViewTags.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewTags.swift; sourceTree = ""; }; D63F9C6D241D2D85004C03CF /* CompositionAttachment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CompositionAttachment.swift; sourceTree = ""; }; - D6403CC124A6B72D00E81C55 /* VisualEffectImageButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VisualEffectImageButton.swift; sourceTree = ""; }; D640D76822BAF5E6004FBE69 /* DomainBlocks.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = DomainBlocks.plist; sourceTree = ""; }; D6412B0224AFF6A600F5412E /* TabBarScrollableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabBarScrollableViewController.swift; sourceTree = ""; }; D6412B0824B0291E00F5412E /* MyProfileViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyProfileViewController.swift; sourceTree = ""; }; @@ -602,6 +601,7 @@ D6969E9D240C81B9002843CE /* NSTextAttachment+Emoji.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSTextAttachment+Emoji.swift"; sourceTree = ""; }; D6969E9F240C8384002843CE /* EmojiLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiLabel.swift; sourceTree = ""; }; D6A00B1C26379FC900316AD4 /* PollOptionsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PollOptionsView.swift; sourceTree = ""; }; + D6A3A37F295515550036B6EF /* ProfileHeaderButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileHeaderButton.swift; sourceTree = ""; }; D6A3BC7A232195C600FD64D5 /* ActionNotificationGroupTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionNotificationGroupTableViewCell.swift; sourceTree = ""; }; D6A3BC7B232195C600FD64D5 /* ActionNotificationGroupTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ActionNotificationGroupTableViewCell.xib; sourceTree = ""; }; D6A3BC7E2321B7E600FD64D5 /* FollowNotificationGroupTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FollowNotificationGroupTableViewCell.swift; sourceTree = ""; }; @@ -1113,6 +1113,7 @@ D6412B0A24B0D4C600F5412E /* ProfileHeaderView.xib */, D6412B0C24B0D4CF00F5412E /* ProfileHeaderView.swift */, D651C5B32915B00400236EF6 /* ProfileFieldsView.swift */, + D6A3A37F295515550036B6EF /* ProfileHeaderButton.swift */, ); path = "Profile Header"; sourceTree = ""; @@ -1345,7 +1346,6 @@ D620483723D38190008A63EF /* StatusContentTextView.swift */, 04ED00B021481ED800567C53 /* SteppedProgressView.swift */, D6093FB625BE0CF3004811E6 /* TrendHistoryView.swift */, - D6403CC124A6B72D00E81C55 /* VisualEffectImageButton.swift */, D686BBE224FBF8110068E6AA /* WrappedProgressView.swift */, D627944623A6AC9300D38C68 /* BasicTableViewCell.xib */, D6A3BC872321F78000FD64D5 /* Account Cell */, @@ -1938,7 +1938,6 @@ 04DACE8E212CC7CC009840C4 /* ImageCache.swift in Sources */, D6BEA249291C6118002F4D01 /* DraftsView.swift in Sources */, D61F75AD293AF39000C0B37F /* Filter+Helpers.swift in Sources */, - D6403CC224A6B72D00E81C55 /* VisualEffectImageButton.swift in Sources */, D6531DEE246B81C9000F9538 /* GifvAttachmentView.swift in Sources */, D673ACCE2919E74200D6F8B0 /* MenuPicker.swift in Sources */, D6370B9C24421FF30092A7FF /* Tusker.xcdatamodeld in Sources */, @@ -2116,6 +2115,7 @@ D6A6C10525B6138A00298D0F /* StatusTablePrefetching.swift in Sources */, D6C82B4125C5BB7E0017F1E6 /* ExploreViewController.swift in Sources */, D6B053A423BD2C8100A066FA /* AssetCollectionsListViewController.swift in Sources */, + D6A3A380295515550036B6EF /* ProfileHeaderButton.swift in Sources */, D623A543263634100095BD04 /* PollOptionCheckboxView.swift in Sources */, D68A76E829527884001DA1B3 /* PinnedTimelinesView.swift in Sources */, D690797324A4EF9700023A34 /* UIBezierPath+Helpers.swift in Sources */, diff --git a/Tusker/Views/Profile Header/ProfileHeaderButton.swift b/Tusker/Views/Profile Header/ProfileHeaderButton.swift new file mode 100644 index 00000000..6d0c09a7 --- /dev/null +++ b/Tusker/Views/Profile Header/ProfileHeaderButton.swift @@ -0,0 +1,25 @@ +// +// ProfileHeaderButton.swift +// Tusker +// +// Created by Shadowfacts on 12/22/22. +// Copyright © 2022 Shadowfacts. All rights reserved. +// + +import UIKit + +class ProfileHeaderButton: UIButton { + + override func updateConfiguration() { + guard var config = self.configuration else { + return + } + config.baseForegroundColor = .label + config.cornerStyle = .capsule + var backgroundConfig = UIBackgroundConfiguration.clear() + backgroundConfig.visualEffect = UIBlurEffect(style: .systemThickMaterial) + config.background = backgroundConfig + self.configuration = config + } + +} diff --git a/Tusker/Views/Profile Header/ProfileHeaderView.swift b/Tusker/Views/Profile Header/ProfileHeaderView.swift index f3110b16..1cb33ece 100644 --- a/Tusker/Views/Profile Header/ProfileHeaderView.swift +++ b/Tusker/Views/Profile Header/ProfileHeaderView.swift @@ -31,8 +31,8 @@ class ProfileHeaderView: UIView { @IBOutlet weak var headerImageView: UIImageView! @IBOutlet weak var avatarContainerView: UIView! @IBOutlet weak var avatarImageView: UIImageView! - @IBOutlet weak var moreButton: VisualEffectImageButton! - @IBOutlet weak var followButton: UIButton! + @IBOutlet weak var moreButton: ProfileHeaderButton! + @IBOutlet weak var followButton: ProfileHeaderButton! @IBOutlet weak var displayNameLabel: EmojiLabel! @IBOutlet weak var usernameLabel: UILabel! @IBOutlet weak var lockImageView: UIImageView! @@ -50,7 +50,10 @@ class ProfileHeaderView: UIView { private var isGrayscale = false private var followButtonMode = FollowButtonMode.follow { didSet { - followButton.configuration = followButtonMode.makeConfig(showsActivityIndicator: false) + var config = followButton.configuration! + followButtonMode.updateConfig(&config) + config.showsActivityIndicator = false + followButton.configuration = config } } @@ -72,12 +75,15 @@ class ProfileHeaderView: UIView { headerImageView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(headerPressed))) headerImageView.isUserInteractionEnabled = true - moreButton.layer.cornerRadius = 16 - moreButton.layer.masksToBounds = true + var config = UIButton.Configuration.plain() + config.image = UIImage(systemName: "ellipsis") + moreButton.configuration = config + moreButton.setNeedsUpdateConfiguration() moreButton.addInteraction(UIPointerInteraction(delegate: self)) moreButton.showsMenuAsPrimaryAction = true moreButton.isContextMenuInteractionEnabled = true + followButton.setNeedsUpdateConfiguration() followButton.addInteraction(UIPointerInteraction(delegate: self)) displayNameLabel.font = UIFontMetrics(forTextStyle: .title1).scaledFont(for: .systemFont(ofSize: 24, weight: .semibold)) @@ -323,7 +329,7 @@ class ProfileHeaderView: UIView { case .blocked: return } - followButton.configuration = followButtonMode.makeConfig(showsActivityIndicator: true) + followButton.configuration!.showsActivityIndicator = true followButton.isEnabled = false Task { do { @@ -332,7 +338,7 @@ class ProfileHeaderView: UIView { // don't need to update the button, since the relationship observer will do so anyways } catch { followButton.isEnabled = true - followButton.configuration = followButtonMode.makeConfig(showsActivityIndicator: false) + followButton.configuration!.showsActivityIndicator = false if let toastable = delegate?.toastableViewController { let config = ToastConfiguration(from: error, with: "Error \(action)", in: toastable) { toast in toast.dismissToast(animated: true) @@ -350,15 +356,7 @@ extension ProfileHeaderView { enum FollowButtonMode { case follow, unfollow, cancelRequest, blocked - func makeConfig(showsActivityIndicator: Bool) -> UIButton.Configuration { - var config = UIButton.Configuration.plain() - config.showsActivityIndicator = showsActivityIndicator - config.baseForegroundColor = .label - config.imagePadding = 4 - config.cornerStyle = .capsule - var backgroundConfig = UIBackgroundConfiguration.clear() - backgroundConfig.visualEffect = UIBlurEffect(style: .systemThickMaterial) - config.background = backgroundConfig + func updateConfig(_ config: inout UIButton.Configuration) { switch self { case .follow: config.title = "Follow" @@ -373,7 +371,6 @@ extension ProfileHeaderView { config.title = "Blocked" config.image = UIImage(systemName: "circle.slash") } - return config } } } diff --git a/Tusker/Views/Profile Header/ProfileHeaderView.xib b/Tusker/Views/Profile Header/ProfileHeaderView.xib index aca7aaab..f4621adc 100644 --- a/Tusker/Views/Profile Header/ProfileHeaderView.xib +++ b/Tusker/Views/Profile Header/ProfileHeaderView.xib @@ -45,21 +45,16 @@ - + +