-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
💫 Update: Exp -
swift-programmatic-modal
- Loading branch information
1 parent
971602b
commit 27a26b9
Showing
10 changed files
with
430 additions
and
296 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalAnimationConfig.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// | ||
// AdaptiveModalAnimationConfig.swift | ||
// swift-programmatic-modal | ||
// | ||
// Created by Dominic Go on 5/23/23. | ||
// | ||
|
||
import UIKit | ||
|
||
struct AdaptiveModalAnimationConfig { | ||
let modalRotation: CGFloat?; | ||
|
||
let modalScaleX: CGFloat?; | ||
let modalScaleY: CGFloat?; | ||
|
||
let modalTranslateX: CGFloat?; | ||
let modalTranslateY: CGFloat?; | ||
|
||
let modalBackgroundColor: UIColor?; | ||
let modalBackgroundOpacity: CGFloat?; | ||
|
||
let modalBlurEffectStyle: UIBlurEffect.Style?; | ||
let modalBlurEffectIntensity: CGFloat?; | ||
|
||
let backgroundColor: UIColor?; | ||
let backgroundOpacity: CGFloat?; | ||
|
||
let backgroundBlurEffectStyle: UIBlurEffect.Style?; | ||
let backgroundBlurEffectIntensity: CGFloat?; | ||
|
||
init( | ||
modalRotation: CGFloat? = nil, | ||
modalScaleX: CGFloat? = nil, | ||
modalScaleY: CGFloat? = nil, | ||
modalTranslateX: CGFloat? = nil, | ||
modalTranslateY: CGFloat? = nil, | ||
modalBackgroundColor: UIColor? = nil, | ||
modalBackgroundOpacity: CGFloat? = nil, | ||
modalBlurEffectStyle: UIBlurEffect.Style? = nil, | ||
modalBlurEffectIntensity: CGFloat? = nil, | ||
backgroundColor: UIColor? = nil, | ||
backgroundOpacity: CGFloat? = nil, | ||
backgroundBlurEffectStyle: UIBlurEffect.Style? = nil, | ||
backgroundBlurEffectIntensity: CGFloat? = nil | ||
) { | ||
self.modalRotation = modalRotation; | ||
self.modalScaleX = modalScaleX; | ||
self.modalScaleY = modalScaleY; | ||
self.modalTranslateX = modalTranslateX; | ||
self.modalTranslateY = modalTranslateY; | ||
self.modalBackgroundColor = modalBackgroundColor; | ||
self.modalBackgroundOpacity = modalBackgroundOpacity; | ||
self.modalBlurEffectStyle = modalBlurEffectStyle; | ||
self.modalBlurEffectIntensity = modalBlurEffectIntensity; | ||
self.backgroundColor = backgroundColor; | ||
self.backgroundOpacity = backgroundOpacity; | ||
self.backgroundBlurEffectStyle = backgroundBlurEffectStyle; | ||
self.backgroundBlurEffectIntensity = backgroundBlurEffectIntensity; | ||
}; | ||
}; |
21 changes: 21 additions & 0 deletions
21
experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalConfig.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// AdaptiveModalConfig.swift | ||
// swift-programmatic-modal | ||
// | ||
// Created by Dominic Go on 5/23/23. | ||
// | ||
|
||
import UIKit | ||
|
||
struct AdaptiveModalConfig { | ||
enum Direction { | ||
case horizontal; | ||
case vertical; | ||
case floating; | ||
}; | ||
|
||
let snapPoints: [AdaptiveModalSnapPointConfig]; | ||
let snapDirection: Direction; | ||
|
||
let entranceConfig: AdaptiveModalEntranceConfig; | ||
}; |
13 changes: 13 additions & 0 deletions
13
experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalEntranceConfig.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// AdaptiveModalEntranceConfig.swift | ||
// swift-programmatic-modal | ||
// | ||
// Created by Dominic Go on 5/24/23. | ||
// | ||
|
||
import Foundation | ||
|
||
struct AdaptiveModalEntranceConfig { | ||
let initialSnapPoint: AdaptiveModalSnapPointPreset; | ||
let initialAnimationKeyFrame: AdaptiveModalAnimationConfig; | ||
}; |
13 changes: 13 additions & 0 deletions
13
experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalSnapPoint.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// AdaptiveModalSnapPoint.swift | ||
// swift-programmatic-modal | ||
// | ||
// Created by Dominic Go on 5/23/23. | ||
// | ||
|
||
import UIKit | ||
|
||
struct AdaptiveModalSnapPointConfig { | ||
let snapPoint: RNILayout; | ||
let animationKeyframe: AdaptiveModalAnimationConfig?; | ||
}; |
16 changes: 16 additions & 0 deletions
16
experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalSnapPointPreset.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// AdaptiveModalInitialSnapPoint.swift | ||
// swift-programmatic-modal | ||
// | ||
// Created by Dominic Go on 5/23/23. | ||
// | ||
|
||
import UIKit | ||
|
||
enum AdaptiveModalSnapPointPreset { | ||
case offscreenBottom, offscreenTop; | ||
case offscreenLeft, offscreenRight; | ||
case center; | ||
|
||
case layoutConfig(_ config: RNILayout); | ||
}; |
168 changes: 168 additions & 0 deletions
168
experiments/swift-programmatic-modal/Test/BlurEffectTestViewController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
// | ||
// BlurEffectTestViewController.swift | ||
// swift-programmatic-modal | ||
// | ||
// Created by Dominic Go on 5/22/23. | ||
// | ||
|
||
import UIKit | ||
|
||
|
||
|
||
|
||
|
||
class BlurEffectIntensityManager { | ||
|
||
var animator: UIViewPropertyAnimator?; | ||
var onDisplayLinkUpdateBlock: (() -> Void)? = nil; | ||
|
||
|
||
func setBlur( | ||
forBlurEffectView blurEffectView: UIVisualEffectView, | ||
intensity: CGFloat = 1, | ||
blurEffectStyle: UIBlurEffect.Style = .systemMaterial, | ||
duration: CGFloat = 0, | ||
curve: UIView.AnimationCurve = .easeIn | ||
) { | ||
guard self.animator == nil else { return }; | ||
|
||
let animator = UIViewPropertyAnimator(duration: duration, curve: curve); | ||
self.animator = animator; | ||
|
||
|
||
|
||
animator.addAnimations { | ||
blurEffectView.effect = UIBlurEffect(style: blurEffectStyle); | ||
blurEffectView.alpha = intensity; | ||
}; | ||
|
||
if duration == 0 { | ||
animator.fractionComplete = intensity; | ||
animator.stopAnimation(true); | ||
self.animator = nil; | ||
|
||
} else { | ||
animator.startAnimation(); | ||
|
||
let displayLink = CADisplayLink( | ||
target: self, | ||
selector: #selector(self.onDisplayLinkUpdate) | ||
); | ||
|
||
displayLink.add(to: .current, forMode: .common) | ||
|
||
self.onDisplayLinkUpdateBlock = { | ||
guard animator.fractionComplete >= intensity else { return }; | ||
animator.stopAnimation(true); | ||
|
||
self.animator = nil; | ||
self.onDisplayLinkUpdateBlock = nil; | ||
}; | ||
}; | ||
}; | ||
|
||
@objc func onDisplayLinkUpdate() { | ||
self.onDisplayLinkUpdateBlock?(); | ||
}; | ||
}; | ||
|
||
|
||
class BlurEffectTestViewController: UIViewController { | ||
|
||
lazy var blurEffectView = UIVisualEffectView(); | ||
|
||
let blurManager = BlurEffectIntensityManager(); | ||
var isBlurred = false; | ||
|
||
var boxView: UIView { | ||
let view = UIView(); | ||
|
||
view.backgroundColor = UIColor( | ||
hue: CGFloat(Int.random(in: 0...360)) / 360, | ||
saturation: 50 / 100, | ||
brightness: 100 / 100, | ||
alpha: 1.0 | ||
); | ||
|
||
view.translatesAutoresizingMaskIntoConstraints = false; | ||
|
||
NSLayoutConstraint.activate([ | ||
view.heightAnchor.constraint(equalToConstant: 100), | ||
view.widthAnchor.constraint(equalToConstant: 100), | ||
]); | ||
|
||
|
||
return view; | ||
}; | ||
|
||
override func loadView() { | ||
let view = UIView(); | ||
view.backgroundColor = .white; | ||
|
||
self.view = view; | ||
|
||
let blurEffectView = self.blurEffectView; | ||
|
||
blurEffectView.addGestureRecognizer( | ||
UITapGestureRecognizer( | ||
target: self, | ||
action: #selector(self.onPressBlurView(_:)) | ||
) | ||
); | ||
|
||
let stackView = UIStackView(arrangedSubviews: [ | ||
self.boxView, | ||
self.boxView, | ||
self.boxView, | ||
self.boxView | ||
]); | ||
|
||
stackView.alignment = .center; | ||
|
||
view.addSubview(stackView); | ||
stackView.translatesAutoresizingMaskIntoConstraints = false; | ||
|
||
view.addSubview(blurEffectView); | ||
blurEffectView.translatesAutoresizingMaskIntoConstraints = false; | ||
|
||
NSLayoutConstraint.activate([ | ||
stackView.topAnchor.constraint(equalTo: view.topAnchor), | ||
stackView.leftAnchor.constraint(equalTo: view.leftAnchor), | ||
stackView.rightAnchor.constraint(equalTo: view.rightAnchor), | ||
stackView.bottomAnchor.constraint(equalTo: view.bottomAnchor), | ||
|
||
blurEffectView.widthAnchor.constraint(equalTo: view.widthAnchor), | ||
blurEffectView.heightAnchor.constraint(equalTo: view.heightAnchor), | ||
blurEffectView.centerYAnchor.constraint(equalTo: view.centerYAnchor), | ||
blurEffectView.centerXAnchor.constraint(equalTo: view.centerXAnchor), | ||
]) | ||
}; | ||
|
||
override func viewDidLoad() { | ||
self.blurManager.setBlur( | ||
forBlurEffectView: self.blurEffectView, | ||
intensity: 1 | ||
); | ||
}; | ||
|
||
@objc func onPressBlurView(_ sender: UITapGestureRecognizer){ | ||
if isBlurred { | ||
self.blurManager.setBlur( | ||
forBlurEffectView: self.blurEffectView, | ||
intensity: 0, | ||
duration: 1, | ||
curve: .easeIn | ||
); | ||
|
||
} else { | ||
self.blurManager.setBlur( | ||
forBlurEffectView: self.blurEffectView, | ||
intensity: 0.5, | ||
duration: 1, | ||
curve: .easeIn | ||
); | ||
}; | ||
|
||
self.isBlurred.toggle(); | ||
}; | ||
}; |
Oops, something went wrong.