Skip to content

Commit

Permalink
💫 Update: Exp - AdaptiveModal
Browse files Browse the repository at this point in the history
Summary: Update experiment/test - `swift-programmatic-modal/AdaptiveModal`.
  • Loading branch information
dominicstop committed Jun 18, 2023
1 parent b70b76e commit 9ce06dd
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import UIKit

class TestModalViewController: UIViewController, AdaptiveModalEventNotifiable {
fileprivate class TestModalViewController: UIViewController, AdaptiveModalEventNotifiable {

weak var modalManager: AdaptiveModalManager?;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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),
]);
};

Expand All @@ -151,4 +191,9 @@ class AdaptiveModalPresentationTestViewController : UIViewController {
presentingViewController: self
);
};

@objc func onPressButtonNextConfig(_ sender: UIButton) {
self.currentModalConfigPresetIndex += 1;
self.adaptiveModalManager.modalConfig = self.currentModalConfigPreset.config;
};
};

0 comments on commit 9ce06dd

Please sign in to comment.