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 4323710 commit a9f46c8
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ struct AdaptiveModalAnimationConfig {
let modalMaskedCorners: CACornerMask?;

let modalBackgroundVisualEffect: UIVisualEffect?;
let modalBackgroundVisualEffectOpacity: CGFloat?;
let modalBackgroundVisualEffectIntensity: CGFloat?;

let backgroundColor: UIColor?;
Expand All @@ -45,6 +46,7 @@ struct AdaptiveModalAnimationConfig {
modalCornerRadius: CGFloat? = nil,
modalMaskedCorners: CACornerMask? = nil,
modalBackgroundVisualEffect: UIVisualEffect? = nil,
modalBackgroundVisualEffectOpacity: CGFloat? = nil,
modalBackgroundVisualEffectIntensity: CGFloat? = nil,
backgroundColor: UIColor? = nil,
backgroundOpacity: CGFloat? = nil,
Expand All @@ -67,6 +69,7 @@ struct AdaptiveModalAnimationConfig {
self.modalMaskedCorners = modalMaskedCorners;

self.modalBackgroundVisualEffect = modalBackgroundVisualEffect;
self.modalBackgroundVisualEffectOpacity = modalBackgroundVisualEffectOpacity;
self.modalBackgroundVisualEffectIntensity = modalBackgroundVisualEffectIntensity;

self.backgroundColor = backgroundColor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ struct AdaptiveModalInterpolationPoint: Equatable {
let modalMaskedCorners: CACornerMask;

let modalBackgroundVisualEffect: UIVisualEffect?;
let modalBackgroundVisualEffectOpacity: CGFloat;
let modalBackgroundVisualEffectIntensity: CGFloat;

//let backgroundColor: UIColor;
Expand Down Expand Up @@ -164,6 +165,10 @@ struct AdaptiveModalInterpolationPoint: Equatable {
self.modalBackgroundVisualEffect = keyframeCurrent?.modalBackgroundVisualEffect
?? keyframePrev?.modalBackgroundVisualEffect;

self.modalBackgroundVisualEffectOpacity = keyframeCurrent?.modalBackgroundVisualEffectOpacity
?? keyframePrev?.modalBackgroundVisualEffectOpacity
?? 1;

self.modalBackgroundVisualEffectIntensity = keyframeCurrent?.modalBackgroundVisualEffectIntensity
?? keyframePrev?.modalBackgroundVisualEffectIntensity
?? 1;
Expand Down Expand Up @@ -244,8 +249,8 @@ struct AdaptiveModalInterpolationPoint: Equatable {
modalBgView?.alpha = self.modalBackgroundOpacity;
};

func apply(toBackgroundEffectView effectView: UIVisualEffectView?){
effectView?.effect = self.backgroundVisualEffect;
func apply(toModalBackgroundEffectView effectView: UIVisualEffectView?){
effectView?.alpha = self.modalBackgroundVisualEffectOpacity;
};

func apply(toBackgroundView bgView: UIView?){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ class AdaptiveModalManager {
return nextTransform;
};

func interpolateOpacity(
func interpolateModalOpacity(
forInputPercentValue inputPercentValue: CGFloat
) -> CGFloat? {

Expand All @@ -559,6 +559,16 @@ class AdaptiveModalManager {
);
};

func interpolateModalBackgroundVisualEffectOpacity(
forInputPercentValue inputPercentValue: CGFloat
) -> CGFloat? {

return self.interpolate(
inputValue: inputPercentValue,
rangeOutputKey: \.modalBackgroundVisualEffectOpacity
);
};

func interpolateModalBorderRadius(
forInputPercentValue inputPercentValue: CGFloat
) -> CGFloat? {
Expand Down Expand Up @@ -693,7 +703,7 @@ class AdaptiveModalManager {
Self.setProperty(
forObject: modalView,
forPropertyKey: \.alpha,
withValue: self.interpolateOpacity(
withValue: self.interpolateModalOpacity(
forInputPercentValue: inputPercentValue
)
);
Expand All @@ -714,6 +724,14 @@ class AdaptiveModalManager {
)
);

Self.setProperty(
forObject: self.modalBackgroundVisualEffectView,
forPropertyKey: \.alpha,
withValue: self.interpolateModalBackgroundVisualEffectOpacity(
forInputPercentValue: inputPercentValue
)
);

Self.setProperty(
forObject: self.backgroundDimmingView,
forPropertyKey: \.alpha,
Expand Down Expand Up @@ -843,6 +861,8 @@ class AdaptiveModalManager {
interpolationPoint.apply(toDummyModalView: self.dummyModalView);
interpolationPoint.apply(toModalBackgroundView: self.modalBackgroundView);
interpolationPoint.apply(toBackgroundView: self.backgroundDimmingView);

interpolationPoint.apply(toModalBackgroundEffectView: self.modalBackgroundVisualEffectView)
};

if let completion = completion {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ enum AdaptiveModalConfigTestPresets: CaseIterable {
.layerMinXMaxYCorner,
.layerMaxXMaxYCorner
],
modalBackgroundVisualEffectOpacity: 0.9,
modalBackgroundVisualEffectIntensity: 0.6,
backgroundOpacity: 0.1,
backgroundVisualEffectIntensity: 0.075
Expand Down

0 comments on commit a9f46c8

Please sign in to comment.