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 251c212 commit dbbc54f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ struct AdaptiveModalAnimationConfig {
let backgroundOpacity: CGFloat?;

let backgroundVisualEffect: UIVisualEffect?;
let backgroundVisualEffectOpacity: CGFloat?;
let backgroundVisualEffectIntensity: CGFloat?;

init(
Expand All @@ -51,6 +52,7 @@ struct AdaptiveModalAnimationConfig {
backgroundColor: UIColor? = nil,
backgroundOpacity: CGFloat? = nil,
backgroundVisualEffect: UIVisualEffect? = nil,
backgroundVisualEffectOpacity: CGFloat? = nil,
backgroundVisualEffectIntensity: CGFloat? = nil
) {
self.modalRotation = modalRotation;
Expand All @@ -76,6 +78,7 @@ struct AdaptiveModalAnimationConfig {
self.backgroundOpacity = backgroundOpacity;

self.backgroundVisualEffect = backgroundVisualEffect;
self.backgroundVisualEffectOpacity = backgroundVisualEffectOpacity;
self.backgroundVisualEffectIntensity = backgroundVisualEffectIntensity;
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ struct AdaptiveModalInterpolationPoint: Equatable {
let backgroundOpacity: CGFloat;

let backgroundVisualEffect: UIVisualEffect?;
let backgroundVisualEffectOpacity: CGFloat;
let backgroundVisualEffectIntensity: CGFloat;

// MARK: - Computed Properties
Expand Down Expand Up @@ -180,6 +181,10 @@ struct AdaptiveModalInterpolationPoint: Equatable {
self.backgroundVisualEffect = keyframeCurrent?.backgroundVisualEffect
?? keyframePrev?.backgroundVisualEffect;

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

self.backgroundVisualEffectIntensity = keyframeCurrent?.backgroundVisualEffectIntensity
?? keyframePrev?.backgroundVisualEffectIntensity
?? 1;
Expand Down Expand Up @@ -256,6 +261,10 @@ struct AdaptiveModalInterpolationPoint: Equatable {
func apply(toBackgroundView bgView: UIView?){
bgView?.alpha = self.backgroundOpacity;
};

func apply(toBackgroundVisualEffectView effectView: UIView?){
effectView?.alpha = self.backgroundVisualEffectOpacity;
};
};

extension AdaptiveModalInterpolationPoint {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,15 @@ class AdaptiveModalManager {
)
);

Self.setProperty(
forObject: self.backgroundVisualEffectView,
forPropertyKey: \.alpha,
withValue: self.interpolate(
inputValue: inputPercentValue,
rangeOutputKey: \.backgroundVisualEffectOpacity
)
);

self.applyInterpolationToBackgroundVisualEffect(
forInputPercentValue: inputPercentValue
);
Expand Down Expand Up @@ -826,7 +835,8 @@ class AdaptiveModalManager {
interpolationPoint.apply(toModalBackgroundView: self.modalBackgroundView);
interpolationPoint.apply(toBackgroundView: self.backgroundDimmingView);

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

if let completion = completion {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ enum AdaptiveModalConfigTestPresets: CaseIterable {
backgroundVisualEffectIntensity: 0
)
),

// Snap Point 2
AdaptiveModalSnapPointConfig(
snapPoint: RNILayout(
Expand Down Expand Up @@ -249,6 +250,7 @@ enum AdaptiveModalConfigTestPresets: CaseIterable {
backgroundVisualEffectIntensity: 0.075
)
),

// Snap Point 3
AdaptiveModalSnapPointConfig(
snapPoint: RNILayout(
Expand All @@ -274,9 +276,12 @@ enum AdaptiveModalConfigTestPresets: CaseIterable {
],
modalBackgroundVisualEffectIntensity: 1,
backgroundOpacity: 0,
//backgroundVisualEffectOpacity: 0.5,
backgroundVisualEffectIntensity: 0.5
)
),

// Snap Point 4
AdaptiveModalSnapPointConfig(
snapPoint: RNILayout(
horizontalAlignment: .center,
Expand Down

0 comments on commit dbbc54f

Please sign in to comment.