Simplify showing Xcode previews for sheets

This commit is contained in:
Elaine 2024-11-27 15:58:55 -07:00 committed by GitHub
parent 83a022efe3
commit 24f5916693
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 79 additions and 46 deletions

View File

@ -1680,6 +1680,7 @@
B99288002CF124AC000D62C4 /* Text+Links.swift in Sources */ = {isa = PBXBuildFile; fileRef = B99287FF2CF124AC000D62C4 /* Text+Links.swift */; };
B99B155D2A71BA5200E26DAC /* StoryContextViewState.swift in Sources */ = {isa = PBXBuildFile; fileRef = B99B155C2A71BA5200E26DAC /* StoryContextViewState.swift */; };
B9A0807A2B07D76A000FDB5B /* HomeTabViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9A080792B07D76A000FDB5B /* HomeTabViewController.swift */; };
B9A53B932CF7928A0000578B /* SheetPreviewViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9A53B922CF7928A0000578B /* SheetPreviewViewController.swift */; };
B9A87A362A9D1D25009FCA13 /* EditorSticker.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9A87A352A9D1D25009FCA13 /* EditorSticker.swift */; };
B9A87A382A9E34BD009FCA13 /* Hatsuishi-UPM800.otf in Resources */ = {isa = PBXBuildFile; fileRef = B9A87A372A9E34BD009FCA13 /* Hatsuishi-UPM800.otf */; };
B9B2AA942BC598B60060B56C /* ContactNoteSheet.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9B2AA932BC598B60060B56C /* ContactNoteSheet.swift */; };
@ -5509,6 +5510,7 @@
B99287FF2CF124AC000D62C4 /* Text+Links.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Text+Links.swift"; sourceTree = "<group>"; };
B99B155C2A71BA5200E26DAC /* StoryContextViewState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoryContextViewState.swift; sourceTree = "<group>"; };
B9A080792B07D76A000FDB5B /* HomeTabViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeTabViewController.swift; sourceTree = "<group>"; };
B9A53B922CF7928A0000578B /* SheetPreviewViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SheetPreviewViewController.swift; sourceTree = "<group>"; };
B9A87A352A9D1D25009FCA13 /* EditorSticker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditorSticker.swift; sourceTree = "<group>"; };
B9A87A372A9E34BD009FCA13 /* Hatsuishi-UPM800.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Hatsuishi-UPM800.otf"; sourceTree = "<group>"; };
B9B2AA932BC598B60060B56C /* ContactNoteSheet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContactNoteSheet.swift; sourceTree = "<group>"; };
@ -8119,6 +8121,7 @@
34A955AF271B53F500B05242 /* GroupManager+GroupInvites.swift */,
34A95507271B510400B05242 /* GroupViewUtils.swift */,
6605D5042A86EE50004DC345 /* MessageRecipientStatusUtils.swift */,
B9A53B922CF7928A0000578B /* SheetPreviewViewController.swift */,
C1D9B1522B7E949500D94595 /* SpamReportingUIUtils.swift */,
);
path = Utils;
@ -16273,6 +16276,7 @@
50597BBF2B97D629004681E1 /* SearchableNameFinder.swift in Sources */,
66FC638E29EDABAC00F00DAC /* SearchDisplayConfigurations.swift in Sources */,
66FBC4E328DA82AA00BD9E8B /* SelectMyStoryRecipientsViewController.swift in Sources */,
B9A53B932CF7928A0000578B /* SheetPreviewViewController.swift in Sources */,
3402AA3C271D9DCD0084CBAE /* SheetViewController.swift in Sources */,
B9E322E72CD170ED006DAF3B /* SignalList.swift in Sources */,
B9F817642BA263A900EAEE23 /* SignalSymbols.swift in Sources */,

View File

@ -184,30 +184,12 @@ class CallLinkApprovalRequestDetailsSheet: OWSTableSheetViewController {
#if DEBUG
@available(iOS 17.0, *)
#Preview {
class PreviewViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let button = OWSButton(title: "Present sheet") { [unowned self] in
self.sheet().present(from: self, animated: true)
}
view.addSubview(button)
button.autoCenterInSuperview()
button.setTitleColor(.ows_signalBlue, for: .normal)
view.backgroundColor = .black
}
override func viewDidAppear(_ animated: Bool) {
sheet().present(from: self, animated: false)
}
private func sheet() -> CallLinkApprovalRequestDetailsSheet {
return CallLinkApprovalRequestDetailsSheet(
approvalRequest: .init(aci: .init(fromUUID: UUID()), name: "Candice"),
approvalViewModel: CallLinkApprovalViewModel()
)
}
SheetPreviewViewController { viewController, animated in
CallLinkApprovalRequestDetailsSheet(
approvalRequest: .init(aci: .init(fromUUID: UUID()), name: "Candice"),
approvalViewModel: CallLinkApprovalViewModel()
)
.present(from: viewController, animated: animated)
}
return PreviewViewController()
}
#endif

View File

@ -535,23 +535,9 @@ private class RequestCell: UITableViewCell, ReusableTableViewCell {
// MARK: - Previews
#if DEBUG
private class PreviewViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let button = OWSButton(title: "Present sheet") { [unowned self] in
self.present(self.sheet(), animated: true)
}
view.addSubview(button)
button.autoCenterInSuperview()
button.setTitleColor(.ows_signalBlue, for: .normal)
view.backgroundColor = .black
}
override func viewDidAppear(_ animated: Bool) {
self.present(self.sheet(), animated: false)
}
private func sheet() -> UIViewController {
@available(iOS 17.0, *)
#Preview {
SheetPreviewViewController {
let viewModel = CallLinkApprovalViewModel()
viewModel.requests = [
.init(aci: .init(fromUUID: UUID()), name: "Candice"),
@ -566,9 +552,4 @@ private class PreviewViewController: UIViewController {
return CallLinkBulkApprovalSheet(viewModel: viewModel)
}
}
@available(iOS 17.0, *)
#Preview {
PreviewViewController()
}
#endif

View File

@ -0,0 +1,66 @@
//
// Copyright 2024 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
//
import UIKit
#if DEBUG
public class SheetPreviewViewController: UIViewController {
private let presentAction: PresentAction
private enum PresentAction {
case createSheet(() -> UIViewController)
case presentSheet((_ viewController: SheetPreviewViewController, _ animated: Bool) -> Void)
func present(from viewController: SheetPreviewViewController, animated: Bool) {
switch self {
case let .createSheet(createSheet):
let sheet = createSheet()
viewController.present(sheet, animated: animated)
case let .presentSheet(presentSheet):
presentSheet(viewController, animated)
}
}
}
public init(
presentSheet: @escaping (
_ viewController: SheetPreviewViewController,
_ animated: Bool
) -> Void
) {
self.presentAction = .presentSheet(presentSheet)
super.init(nibName: nil, bundle: nil)
}
public init(sheet: @escaping @autoclosure () -> UIViewController) {
self.presentAction = .createSheet(sheet)
super.init(nibName: nil, bundle: nil)
}
public init(createSheet: @escaping () -> UIViewController) {
self.presentAction = .createSheet(createSheet)
super.init(nibName: nil, bundle: nil)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
public override func viewDidLoad() {
super.viewDidLoad()
let button = OWSButton(title: "Present sheet") { [unowned self] in
self.presentAction.present(from: self, animated: true)
}
view.addSubview(button)
button.autoCenterInSuperview()
button.setTitleColor(UIColor.Signal.accent, for: .normal)
}
public override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
self.presentAction.present(from: self, animated: false)
}
}
#endif