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 5, 2023
1 parent 6008762 commit 4323710
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,28 @@ extension AdaptiveModalManager {
let offset = percent > 1 ? abs(percent - 1) : 0;
return 1 - percent + offset;
};

static func setProperty<O: AnyObject, T>(
forObject object: O?,
forPropertyKey propertyKey: WritableKeyPath<O, T>,
withValue value: T?
) {
guard var object = object,
let value = value
else { return };

object[keyPath: propertyKey] = value;
};

static func setProperty<O, T>(
for valueType: inout O?,
forPropertyKey propertyKey: WritableKeyPath<O, T>,
withValue newValue: T?
) {
guard var valueType = valueType,
let newValue = newValue
else { return };

valueType[keyPath: propertyKey] = newValue;
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -678,45 +678,49 @@ class AdaptiveModalManager {
) {
guard let modalView = self.modalView else { return };

if let nextModalRect = self.interpolateModalRect(
self.modalFrame = self.interpolateModalRect(
forInputPercentValue: inputPercentValue
) {
self.modalFrame = nextModalRect;
};
);

if let nextModalTransform = self.interpolateModalTransform(
forInputPercentValue: inputPercentValue
) {
modalView.transform = nextModalTransform;
};
Self.setProperty(
forObject: modalView,
forPropertyKey: \.transform,
withValue: self.interpolateModalTransform(
forInputPercentValue: inputPercentValue
)
);

if let nextModalOpacity = self.interpolateOpacity(
forInputPercentValue: inputPercentValue
) {
modalView.alpha = nextModalOpacity;
};
Self.setProperty(
forObject: modalView,
forPropertyKey: \.alpha,
withValue: self.interpolateOpacity(
forInputPercentValue: inputPercentValue
)
);

if let nextModalRadius = self.interpolateModalBorderRadius(
forInputPercentValue: inputPercentValue
) {
modalView.layer.cornerRadius = nextModalRadius;
};
Self.setProperty(
forObject: modalView,
forPropertyKey: \.layer.cornerRadius,
withValue: self.interpolateModalBorderRadius(
forInputPercentValue: inputPercentValue
)
);

if let modalBgView = self.modalBackgroundView,
let nextModalBgOpacity = self.interpolateModalBackgroundOpacity(
forInputPercentValue: inputPercentValue
) {

modalBgView.alpha = nextModalBgOpacity;
};
Self.setProperty(
forObject: self.modalBackgroundView,
forPropertyKey: \.alpha,
withValue: self.interpolateModalBackgroundOpacity(
forInputPercentValue: inputPercentValue
)
);

if let bgDimmingView = self.backgroundDimmingView,
let nextBgOpacity = self.interpolateBackgroundOpacity(
forInputPercentValue: inputPercentValue
) {

bgDimmingView.alpha = nextBgOpacity;
};
Self.setProperty(
forObject: self.backgroundDimmingView,
forPropertyKey: \.alpha,
withValue: self.interpolateBackgroundOpacity(
forInputPercentValue: inputPercentValue
)
);

self.applyInterpolationToBackgroundVisualEffect(
forInputPercentValue: inputPercentValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import UIKit

enum AdaptiveModalConfigTestPresets: CaseIterable {

static let `default`: Self = .testModalTransform01;
static let `default`: Self = .test03;

case testModalTransform01;

Expand Down

0 comments on commit 4323710

Please sign in to comment.