From 9ce06dddd808491114039272c7f615cf70fb5834 Mon Sep 17 00:00:00 2001 From: Dominic Go <18517029+dominicstop@users.noreply.github.com> Date: Mon, 19 Jun 2023 00:34:30 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=AB=20Update:=20Exp=20-=20`AdaptiveMod?= =?UTF-8?q?al`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: Update experiment/test - `swift-programmatic-modal/AdaptiveModal`. --- .../AdaptiveModal/AdaptiveModalManager.swift | 6 +- ...eModalPresentationTestViewController.swift | 57 +++++++++++++++++-- 2 files changed, 55 insertions(+), 8 deletions(-) diff --git a/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalManager.swift b/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalManager.swift index adedc2fc..19c23fed 100644 --- a/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalManager.swift +++ b/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalManager.swift @@ -1426,7 +1426,8 @@ class AdaptiveModalManager: NSObject { func prepareForPresentation( modalView: UIView? = nil, - targetView: UIView? = nil + targetView: UIView? = nil, + shouldForceReset: Bool = false ) { guard let modalView = modalView ?? self.modalView, let targetView = targetView ?? self.targetView @@ -1435,7 +1436,8 @@ class AdaptiveModalManager: NSObject { let didViewsChange = modalView !== self.modalView || targetView !== self.targetView; - let shouldReset = !self.didTriggerSetup || didViewsChange; + let shouldReset = + !self.didTriggerSetup || didViewsChange || shouldForceReset; if shouldReset { self.cleanup(); diff --git a/experiments/swift-programmatic-modal/Test/AdaptiveModalPresentationTestViewController.swift b/experiments/swift-programmatic-modal/Test/AdaptiveModalPresentationTestViewController.swift index af4dbe9f..6cd63b8a 100644 --- a/experiments/swift-programmatic-modal/Test/AdaptiveModalPresentationTestViewController.swift +++ b/experiments/swift-programmatic-modal/Test/AdaptiveModalPresentationTestViewController.swift @@ -7,7 +7,7 @@ import UIKit -class TestModalViewController: UIViewController, AdaptiveModalEventNotifiable { +fileprivate class TestModalViewController: UIViewController, AdaptiveModalEventNotifiable { weak var modalManager: AdaptiveModalManager?; @@ -88,9 +88,21 @@ class TestModalViewController: UIViewController, AdaptiveModalEventNotifiable { class AdaptiveModalPresentationTestViewController : UIViewController { lazy var adaptiveModalManager = AdaptiveModalManager( - modalConfig: AdaptiveModalConfigTestPresets.default.config + modalConfig: self.currentModalConfigPreset.config ); + let modalConfigs: [AdaptiveModalConfigTestPresets] = [ + .demo01, + .demo02, + .demo03 + ]; + + var currentModalConfigPresetIndex = 0; + + var currentModalConfigPreset: AdaptiveModalConfigTestPresets { + self.modalConfigs[self.currentModalConfigPresetIndex % self.modalConfigs.count]; + }; + override func viewDidLoad() { self.view.backgroundColor = .white; @@ -126,12 +138,40 @@ class AdaptiveModalPresentationTestViewController : UIViewController { return button; }(); - self.view.addSubview(presentButton); - presentButton.translatesAutoresizingMaskIntoConstraints = false; + let nextConfigButton: UIButton = { + let button = UIButton(); + button.setTitle("Next Modal Config", for: .normal); + + button.addTarget( + self, + action: #selector(self.onPressButtonNextConfig(_:)), + for: .touchUpInside + ); + + return button; + }(); + + + let stackView: UIStackView = { + let stack = UIStackView(); + + stack.axis = .vertical; + stack.distribution = .equalSpacing; + stack.alignment = .center; + stack.spacing = 7; + + stack.addArrangedSubview(presentButton); + stack.addArrangedSubview(nextConfigButton); + + return stack; + }(); + + stackView.translatesAutoresizingMaskIntoConstraints = false; + self.view.addSubview(stackView); NSLayoutConstraint.activate([ - presentButton.centerXAnchor.constraint(equalTo: self.view.centerXAnchor), - presentButton.centerYAnchor.constraint(equalTo: self.view.centerYAnchor) + stackView.centerXAnchor.constraint(equalTo: self.view.centerXAnchor), + stackView.centerYAnchor.constraint(equalTo: self.view.centerYAnchor), ]); }; @@ -151,4 +191,9 @@ class AdaptiveModalPresentationTestViewController : UIViewController { presentingViewController: self ); }; + + @objc func onPressButtonNextConfig(_ sender: UIButton) { + self.currentModalConfigPresetIndex += 1; + self.adaptiveModalManager.modalConfig = self.currentModalConfigPreset.config; + }; };