Skip to content

Commit

Permalink
fix alert controller presentation
Browse files Browse the repository at this point in the history
  • Loading branch information
dypme committed Jan 3, 2023
1 parent 05ee2ec commit ef7af4a
Show file tree
Hide file tree
Showing 12 changed files with 339 additions and 479 deletions.
33 changes: 13 additions & 20 deletions iOStarter.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,8 @@
E2FD8DD827FECB5C003F5BA4 /* AlertAppearance.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2FD8DD727FECB5C003F5BA4 /* AlertAppearance.swift */; };
E2FD8DDA27FECB5C003F5BA4 /* AlertController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2FD8DD927FECB5C003F5BA4 /* AlertController.swift */; };
E2FD8DDC27FECB5C003F5BA4 /* AlertSheetController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2FD8DDB27FECB5C003F5BA4 /* AlertSheetController.swift */; };
E2FD8DE327FECB5C003F5BA4 /* AlertView.xib in Resources */ = {isa = PBXBuildFile; fileRef = E2FD8DE227FECB5C003F5BA4 /* AlertView.xib */; };
E2FD8DE527FECB5C003F5BA4 /* AlertSheetView.xib in Resources */ = {isa = PBXBuildFile; fileRef = E2FD8DE427FECB5C003F5BA4 /* AlertSheetView.xib */; };
E2FD8DE727FECB5C003F5BA4 /* ConfirmAlertView.xib in Resources */ = {isa = PBXBuildFile; fileRef = E2FD8DE627FECB5C003F5BA4 /* ConfirmAlertView.xib */; };
E2FD8DE927FECB5C003F5BA4 /* ConfirmAlertSheetView.xib in Resources */ = {isa = PBXBuildFile; fileRef = E2FD8DE827FECB5C003F5BA4 /* ConfirmAlertSheetView.xib */; };
E2FD8DE727FECB5C003F5BA4 /* AlertView.xib in Resources */ = {isa = PBXBuildFile; fileRef = E2FD8DE627FECB5C003F5BA4 /* AlertView.xib */; };
E2FD8DE927FECB5C003F5BA4 /* AlertSheetView.xib in Resources */ = {isa = PBXBuildFile; fileRef = E2FD8DE827FECB5C003F5BA4 /* AlertSheetView.xib */; };
E2FD8DEC27FECB5C003F5BA4 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E2FD8DEB27FECB5C003F5BA4 /* LaunchScreen.storyboard */; };
E2FD8DEE27FECB5C003F5BA4 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E2FD8DED27FECB5C003F5BA4 /* Main.storyboard */; };
E2FD8DF027FECB5C003F5BA4 /* Menu.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E2FD8DEF27FECB5C003F5BA4 /* Menu.storyboard */; };
Expand Down Expand Up @@ -187,10 +185,8 @@
E2FD8DD727FECB5C003F5BA4 /* AlertAppearance.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlertAppearance.swift; sourceTree = "<group>"; };
E2FD8DD927FECB5C003F5BA4 /* AlertController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlertController.swift; sourceTree = "<group>"; };
E2FD8DDB27FECB5C003F5BA4 /* AlertSheetController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlertSheetController.swift; sourceTree = "<group>"; };
E2FD8DE227FECB5C003F5BA4 /* AlertView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = AlertView.xib; sourceTree = "<group>"; };
E2FD8DE427FECB5C003F5BA4 /* AlertSheetView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = AlertSheetView.xib; sourceTree = "<group>"; };
E2FD8DE627FECB5C003F5BA4 /* ConfirmAlertView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ConfirmAlertView.xib; sourceTree = "<group>"; };
E2FD8DE827FECB5C003F5BA4 /* ConfirmAlertSheetView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ConfirmAlertSheetView.xib; sourceTree = "<group>"; };
E2FD8DE627FECB5C003F5BA4 /* AlertView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = AlertView.xib; sourceTree = "<group>"; };
E2FD8DE827FECB5C003F5BA4 /* AlertSheetView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = AlertSheetView.xib; sourceTree = "<group>"; };
E2FD8DEB27FECB5C003F5BA4 /* LaunchScreen.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = LaunchScreen.storyboard; sourceTree = "<group>"; };
E2FD8DED27FECB5C003F5BA4 /* Main.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Main.storyboard; sourceTree = "<group>"; };
E2FD8DEF27FECB5C003F5BA4 /* Menu.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Menu.storyboard; sourceTree = "<group>"; };
Expand Down Expand Up @@ -515,14 +511,14 @@
isa = PBXGroup;
children = (
E2FD8DD627FECB5C003F5BA4 /* Alert */,
E2FD8DE127FECB5C003F5BA4 /* AlertView */,
);
path = View;
sourceTree = "<group>";
};
E2FD8DD627FECB5C003F5BA4 /* Alert */ = {
isa = PBXGroup;
children = (
E2FD8DE127FECB5C003F5BA4 /* UI */,
634E92542963EA0000100E3D /* AlertAnimation.swift */,
634E92562963EA9A00100E3D /* AlertSheetAnimation.swift */,
E2FD8DD727FECB5C003F5BA4 /* AlertAppearance.swift */,
Expand All @@ -532,16 +528,15 @@
path = Alert;
sourceTree = "<group>";
};
E2FD8DE127FECB5C003F5BA4 /* AlertView */ = {
E2FD8DE127FECB5C003F5BA4 /* UI */ = {
isa = PBXGroup;
children = (
E2FD8DE227FECB5C003F5BA4 /* AlertView.xib */,
E2FD8DE427FECB5C003F5BA4 /* AlertSheetView.xib */,
E2FD8DE627FECB5C003F5BA4 /* ConfirmAlertView.xib */,
E2FD8DE827FECB5C003F5BA4 /* ConfirmAlertSheetView.xib */,
E2FD8DE627FECB5C003F5BA4 /* AlertView.xib */,
E2FD8DE827FECB5C003F5BA4 /* AlertSheetView.xib */,
);
path = AlertView;
sourceTree = "<group>";
name = UI;
path = iOStarter/View/Alert/UI;
sourceTree = SOURCE_ROOT;
};
E2FD8DEA27FECB5C003F5BA4 /* Storyboard */ = {
isa = PBXGroup;
Expand Down Expand Up @@ -690,22 +685,20 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
E2FD8DE327FECB5C003F5BA4 /* AlertView.xib in Resources */,
E2FD8D7C27FECB5B003F5BA4 /* user.json in Resources */,
E2FD8DF027FECB5C003F5BA4 /* Menu.storyboard in Resources */,
E2FD8D6727FECB5B003F5BA4 /* Settings.bundle in Resources */,
E2FD8DEE27FECB5C003F5BA4 /* Main.storyboard in Resources */,
E2FD8D5F27FECB5B003F5BA4 /* GoogleService-Info.plist in Resources */,
E2FD8DF227FECB5C003F5BA4 /* Auth.storyboard in Resources */,
E2FD8DE927FECB5C003F5BA4 /* ConfirmAlertSheetView.xib in Resources */,
E2FD8DE927FECB5C003F5BA4 /* AlertSheetView.xib in Resources */,
E2FD8D8027FECB5B003F5BA4 /* Colors.xcassets in Resources */,
E2FD8D7A27FECB5B003F5BA4 /* items.json in Resources */,
E2FD8D7E27FECB5B003F5BA4 /* Assets.xcassets in Resources */,
E2FD8DE527FECB5C003F5BA4 /* AlertSheetView.xib in Resources */,
E2FD8DF427FECB5C003F5BA4 /* Profile.storyboard in Resources */,
E2FD8DF927FECB5C003F5BA4 /* Localizable.strings in Resources */,
E2FD8DEC27FECB5C003F5BA4 /* LaunchScreen.storyboard in Resources */,
E2FD8DE727FECB5C003F5BA4 /* ConfirmAlertView.xib in Resources */,
E2FD8DE727FECB5C003F5BA4 /* AlertView.xib in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
59 changes: 59 additions & 0 deletions iOStarter/View/Alert/AlertAnimation.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//
// AlertAnimation.swift
// iOStarter
//
// Created by MBP2022_1 on 03/01/23.
// Copyright © 2023 dypme. All rights reserved.
//

import Foundation
import UIKit

class AlertPresentAnimationController: NSObject, UIViewControllerAnimatedTransitioning {
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
0.24
}

func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
guard let alertController = transitionContext.viewController(forKey: .to) as? AlertController else { return }

let containerView = transitionContext.containerView
let view = alertController.view!
view.frame = containerView.frame
containerView.addSubview(view)

let animationDuration = transitionDuration(using: transitionContext)

alertController.alertView.transform = CGAffineTransform(scaleX: 1.23, y: 1.23)
view.alpha = 0
UIView.animate(withDuration: animationDuration, animations: {
alertController.view.alpha = 1
alertController.alertView.transform = CGAffineTransform(scaleX: 1.0, y: 1.0)
}, completion: { _ in
transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
})
}
}

class AlertDismissAnimationController: NSObject, UIViewControllerAnimatedTransitioning {
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
0.2
}

func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
guard let alertController = transitionContext.viewController(forKey: .from) as? AlertController else { return }

let containerView = transitionContext.containerView
let view = alertController.view!
view.frame = containerView.frame
containerView.addSubview(view)

let animationDuration = transitionDuration(using: transitionContext)

UIView.animate(withDuration: animationDuration, animations: {
alertController.view.alpha = 0
}, completion: { (finished) in
transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
})
}
}
12 changes: 7 additions & 5 deletions iOStarter/View/Alert/AlertAppearance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ class AlertAppearance {
var cancelText = L10n.Alert.cancelButton
var cancelTextColor = UIColor(red: 0, green: 122/255, blue: 255/255, alpha: 1)
var cancelColor = UIColor.white
var actionText = L10n.Alert.actionButton
var actionTextColor = UIColor(red: 0, green: 122/255, blue: 255/255, alpha: 1)
var actionColor = UIColor.white
var isCancelButtonHidden = false
var submitText = L10n.Alert.actionButton
var submitTextColor = UIColor(red: 0, green: 122/255, blue: 255/255, alpha: 1)
var submitColor = UIColor.white
var isSubmitButtonHidden = false
var buttonFont = UIFont.systemFont(ofSize: 17)
var backgroundColor = UIColor.white
var overlayColor = UIColor.black.withAlphaComponent(0.4)
var alertColor = UIColor.white
var overlayColor = UIColor.black.withAlphaComponent(0.5)
var isBlurContainer = false
}
Loading

0 comments on commit ef7af4a

Please sign in to comment.