From 068af1136d22cc391affed260c426803b6bcddd4 Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Fri, 4 Aug 2023 13:49:38 +1000 Subject: [PATCH] customise UIHostingViewController --- Session.xcodeproj/project.pbxproj | 4 ++ .../ConversationVC+Interaction.swift | 1 - .../MessageInfoView.swift | 44 +++++++++----- .../Shared/SessionHostingViewController.swift | 59 +++++++++++++++++++ 4 files changed, 91 insertions(+), 17 deletions(-) create mode 100644 Session/Shared/SessionHostingViewController.swift diff --git a/Session.xcodeproj/project.pbxproj b/Session.xcodeproj/project.pbxproj index 1a831740f..0a381d866 100644 --- a/Session.xcodeproj/project.pbxproj +++ b/Session.xcodeproj/project.pbxproj @@ -125,6 +125,7 @@ 7B81682828B310D50069F315 /* _007_HomeQueryOptimisationIndexes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B81682728B310D50069F315 /* _007_HomeQueryOptimisationIndexes.swift */; }; 7B81682A28B6F1420069F315 /* ReactionResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B81682928B6F1420069F315 /* ReactionResponse.swift */; }; 7B81682C28B72F480069F315 /* PendingChange.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B81682B28B72F480069F315 /* PendingChange.swift */; }; + 7B8914772A7CAAE200A4C627 /* SessionHostingViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B8914762A7CAAE200A4C627 /* SessionHostingViewController.swift */; }; 7B8C44C528B49DDA00FBE25F /* NewConversationVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B8C44C428B49DDA00FBE25F /* NewConversationVC.swift */; }; 7B8D5FC428332600008324D9 /* VisibleMessage+Reaction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B8D5FC328332600008324D9 /* VisibleMessage+Reaction.swift */; }; 7B93D06A27CF173D00811CB6 /* MessageRequestsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B93D06927CF173D00811CB6 /* MessageRequestsViewController.swift */; }; @@ -1238,6 +1239,7 @@ 7B81682728B310D50069F315 /* _007_HomeQueryOptimisationIndexes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = _007_HomeQueryOptimisationIndexes.swift; sourceTree = ""; }; 7B81682928B6F1420069F315 /* ReactionResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReactionResponse.swift; sourceTree = ""; }; 7B81682B28B72F480069F315 /* PendingChange.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PendingChange.swift; sourceTree = ""; }; + 7B8914762A7CAAE200A4C627 /* SessionHostingViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SessionHostingViewController.swift; sourceTree = ""; }; 7B8C44C428B49DDA00FBE25F /* NewConversationVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewConversationVC.swift; sourceTree = ""; }; 7B8D5FC328332600008324D9 /* VisibleMessage+Reaction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "VisibleMessage+Reaction.swift"; sourceTree = ""; }; 7B93D06927CF173D00811CB6 /* MessageRequestsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MessageRequestsViewController.swift; sourceTree = ""; }; @@ -2684,6 +2686,7 @@ 7B3A39312980D02B002FE4AC /* SessionCarouselView.swift */, 7B2561C329874851005C086C /* SessionCarouselView+Info.swift */, 7B3A3933298882D6002FE4AC /* SessionCarouselViewDelegate.swift */, + 7B8914762A7CAAE200A4C627 /* SessionHostingViewController.swift */, ); path = Shared; sourceTree = ""; @@ -6051,6 +6054,7 @@ 7B7037432834B81F000DCF35 /* ReactionContainerView.swift in Sources */, 7BBBDC462875600700747E59 /* DocumentTitleViewController.swift in Sources */, FD71163F28E2C82C00B47552 /* SessionHeaderView.swift in Sources */, + 7B8914772A7CAAE200A4C627 /* SessionHostingViewController.swift in Sources */, B877E24226CA12910007970A /* CallVC.swift in Sources */, 7BA6890D27325CCC00EFC32F /* SessionCallManager+CXCallController.swift in Sources */, C374EEEB25DA3CA70073A857 /* ConversationTitleView.swift in Sources */, diff --git a/Session/Conversations/ConversationVC+Interaction.swift b/Session/Conversations/ConversationVC+Interaction.swift index bca74436d..187328416 100644 --- a/Session/Conversations/ConversationVC+Interaction.swift +++ b/Session/Conversations/ConversationVC+Interaction.swift @@ -1649,7 +1649,6 @@ extension ConversationVC: actions: actions, messageViewModel: cellViewModel ) - messageInfoViewController.title = "message_info_title".localized() navigationController?.pushViewController(messageInfoViewController, animated: true) } diff --git a/Session/Media Viewing & Editing/MessageInfoView.swift b/Session/Media Viewing & Editing/MessageInfoView.swift index ea04f528c..c42c62bb5 100644 --- a/Session/Media Viewing & Editing/MessageInfoView.swift +++ b/Session/Media Viewing & Editing/MessageInfoView.swift @@ -367,22 +367,27 @@ struct MessageInfoView: View { id: \.self ) { index in let tintColor: ThemeValue = actions[index].isDestructive ? .danger : .textPrimary - HStack(spacing: 24) { - Image(uiImage: actions[index].icon!.withRenderingMode(.alwaysTemplate)) - .resizable() - .scaledToFit() - .foregroundColor(themeColor: tintColor) - .frame(width: 26, height: 26) - Text(actions[index].title) - .bold() - .font(.system(size: 18)) - .foregroundColor(themeColor: tintColor) - } + Button( + action: { + actions[index].work() + dismiss?() + }, + label: { + HStack(spacing: 24) { + Image(uiImage: actions[index].icon!.withRenderingMode(.alwaysTemplate)) + .resizable() + .scaledToFit() + .foregroundColor(themeColor: tintColor) + .frame(width: 26, height: 26) + Text(actions[index].title) + .bold() + .font(.system(size: 18)) + .foregroundColor(themeColor: tintColor) + } + .frame(width: .infinity) + } + ) .frame(width: .infinity, height: 60) - .onTapGesture { - actions[index].work() - dismiss?() - } if index < (actions.count - 1) { Divider() @@ -444,7 +449,7 @@ struct InfoBlock: View where Content: View { } } -final class MessageInfoViewController: UIHostingController { +final class MessageInfoViewController: SessionHostingViewController { init(actions: [ContextMenuVC.Action], messageViewModel: MessageViewModel) { let messageInfoView = MessageInfoView( actions: actions, @@ -459,6 +464,13 @@ final class MessageInfoViewController: UIHostingController { fatalError("init(coder:) has not been implemented") } + override func viewDidLoad() { + super.viewDidLoad() + + let customTitleFontSize = Values.largeFontSize + setNavBarTitle("message_info_title".localized(), customFontSize: customTitleFontSize) + } + func dismiss() { self.navigationController?.popViewController(animated: true) } diff --git a/Session/Shared/SessionHostingViewController.swift b/Session/Shared/SessionHostingViewController.swift new file mode 100644 index 000000000..8c04d6a8e --- /dev/null +++ b/Session/Shared/SessionHostingViewController.swift @@ -0,0 +1,59 @@ +// Copyright © 2023 Rangeproof Pty Ltd. All rights reserved. + +import SwiftUI +import SessionUIKit + +public class SessionHostingViewController: UIHostingController where Content : View { + public override var preferredStatusBarStyle: UIStatusBarStyle { + return ThemeManager.currentTheme.statusBarStyle + } + + lazy var navBarTitleLabel: UILabel = { + let result = UILabel() + result.font = .boldSystemFont(ofSize: Values.veryLargeFontSize) + result.themeTextColor = .textPrimary + result.textAlignment = .center + result.alpha = 1 + + return result + }() + + lazy var crossfadeLabel: UILabel = { + let result = UILabel() + result.font = .boldSystemFont(ofSize: Values.veryLargeFontSize) + result.themeTextColor = .textPrimary + result.textAlignment = .center + result.alpha = 0 + + return result + }() + + public override func viewDidLoad() { + super.viewDidLoad() + + navigationItem.backButtonTitle = "" + view.themeBackgroundColor = .backgroundPrimary + ThemeManager.applyNavigationStylingIfNeeded(to: self) + + setNeedsStatusBarAppearanceUpdate() + } + + internal func setNavBarTitle(_ title: String, customFontSize: CGFloat? = nil) { + let container = UIView() + navBarTitleLabel.text = title + crossfadeLabel.text = title + + if let customFontSize = customFontSize { + navBarTitleLabel.font = .boldSystemFont(ofSize: customFontSize) + crossfadeLabel.font = .boldSystemFont(ofSize: customFontSize) + } + + container.addSubview(navBarTitleLabel) + container.addSubview(crossfadeLabel) + + navBarTitleLabel.pin(to: container) + crossfadeLabel.pin(to: container) + + navigationItem.titleView = container + } +}