Skip to content

Commit

Permalink
fix(Sheet): Fix dismissal bug and TestUI in Sheet
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandroruizponce authored Oct 11, 2022
1 parent 669d73d commit 427d1dd
Show file tree
Hide file tree
Showing 98 changed files with 690 additions and 654 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ extension UICatalogSheetViewController: UITableViewDataSource, UITableViewDelega
print("\tAction:\(sheetResponse.action)")
print("\tSelected ids:\(sheetResponse.selectedIds)")
}
viewController.delegate = sheetTransitioningDelegate
viewController.transitioningDelegate = sheetTransitioningDelegate
viewController.modalPresentationStyle = .custom

Expand All @@ -201,15 +202,18 @@ extension UICatalogSheetViewController: UITableViewDataSource, UITableViewDelega

private extension UICatalogSheetViewController {
var sheetTitle: String? {
titleCell.textField.text
guard let title = titleCell.textField.text, !title.isEmpty else { return nil }
return title
}

var sheetSubtitle: String? {
subtitleCell.textField.text
guard let subtitle = subtitleCell.textField.text, !subtitle.isEmpty else { return nil }
return subtitle
}

var sheetDescription: String? {
descriptionCell.textField.text
guard let description = descriptionCell.textField.text, !description.isEmpty else { return nil }
return description
}

var sheetNumElements: Int {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//
// SheetPresentationAnimator.swift
//
// Made with ❤️ by Novum
//
// Copyright © Telefonica. All rights reserved.
//

import UIKit

/**
Basically the animator will animate the new View Controller showing it from the bottom.
It will be dismissed in the opposite direction.
*/
class SheetPresentationAnimator: NSObject {
private let isPresentation: Bool
init(isPresentation: Bool) {
self.isPresentation = isPresentation
}
}

extension SheetPresentationAnimator: UIViewControllerAnimatedTransitioning {
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
UIView.defaultAnimationDuration
}

func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
let key = isPresentation ? UITransitionContextViewControllerKey.to : UITransitionContextViewControllerKey.from
guard let controller = transitionContext.viewController(forKey: key) else { return }
let animationDuration = transitionDuration(using: transitionContext)

let presentedFrame = transitionContext.finalFrame(for: controller)
var dismissedFrame = presentedFrame
dismissedFrame.origin.y = transitionContext.containerView.frame.size.height

let initialFrame: CGRect
let finalFrame: CGRect
let options: UIView.AnimationOptions

if isPresentation {
transitionContext.containerView.addSubview(controller.view)
initialFrame = dismissedFrame
finalFrame = presentedFrame
options = .curveEaseOut
} else {
initialFrame = presentedFrame
finalFrame = dismissedFrame
options = .curveEaseIn
}

controller.view.frame = initialFrame
UIView.animate(withDuration: animationDuration, delay: 0, options: options, animations: {
controller.view.frame = finalFrame
}) { _ in
transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
}
}
}
Loading

0 comments on commit 427d1dd

Please sign in to comment.