diff --git a/solutions/devsprint-leonardo-santos-5/bruno-alves/AnimationsShowcase/Assets.xcassets/backCard.imageset/Contents.json b/solutions/devsprint-leonardo-santos-5/bruno-alves/AnimationsShowcase/Assets.xcassets/backCard.imageset/Contents.json new file mode 100644 index 0000000..2003985 --- /dev/null +++ b/solutions/devsprint-leonardo-santos-5/bruno-alves/AnimationsShowcase/Assets.xcassets/backCard.imageset/Contents.json @@ -0,0 +1,15 @@ +{ + "images" : [ + { + "filename" : "backCard.png", + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + }, + "properties" : { + "preserves-vector-representation" : true + } +} diff --git a/solutions/devsprint-leonardo-santos-5/bruno-alves/AnimationsShowcase/Assets.xcassets/backCard.imageset/backCard.png b/solutions/devsprint-leonardo-santos-5/bruno-alves/AnimationsShowcase/Assets.xcassets/backCard.imageset/backCard.png new file mode 100644 index 0000000..196f861 Binary files /dev/null and b/solutions/devsprint-leonardo-santos-5/bruno-alves/AnimationsShowcase/Assets.xcassets/backCard.imageset/backCard.png differ diff --git a/solutions/devsprint-leonardo-santos-5/bruno-alves/AnimationsShowcase/Assets.xcassets/frontCard.imageset/Contents.json b/solutions/devsprint-leonardo-santos-5/bruno-alves/AnimationsShowcase/Assets.xcassets/frontCard.imageset/Contents.json new file mode 100644 index 0000000..07e030c --- /dev/null +++ b/solutions/devsprint-leonardo-santos-5/bruno-alves/AnimationsShowcase/Assets.xcassets/frontCard.imageset/Contents.json @@ -0,0 +1,15 @@ +{ + "images" : [ + { + "filename" : "frontCard.png", + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + }, + "properties" : { + "preserves-vector-representation" : true + } +} diff --git a/solutions/devsprint-leonardo-santos-5/bruno-alves/AnimationsShowcase/Assets.xcassets/frontCard.imageset/frontCard.png b/solutions/devsprint-leonardo-santos-5/bruno-alves/AnimationsShowcase/Assets.xcassets/frontCard.imageset/frontCard.png new file mode 100644 index 0000000..cd405a3 Binary files /dev/null and b/solutions/devsprint-leonardo-santos-5/bruno-alves/AnimationsShowcase/Assets.xcassets/frontCard.imageset/frontCard.png differ diff --git a/solutions/devsprint-leonardo-santos-5/bruno-alves/AnimationsShowcase/Showcases/FirstSection/Challenge/FirstSectionChallenge.swift b/solutions/devsprint-leonardo-santos-5/bruno-alves/AnimationsShowcase/Showcases/FirstSection/Challenge/FirstSectionChallenge.swift deleted file mode 100644 index 07ef96a..0000000 --- a/solutions/devsprint-leonardo-santos-5/bruno-alves/AnimationsShowcase/Showcases/FirstSection/Challenge/FirstSectionChallenge.swift +++ /dev/null @@ -1,21 +0,0 @@ -import UIKit - -final class FirstSectionChallengeViewController: UIViewController {} - -// MARK: - ShowcaseRow - -struct FirstSectionChallengeShowcase: ShowcaseRow { - var title: String { - "UIView.animate Challenge šŸ†" - } - - var description: String { - "Utilize sua criatividade e faƧa uma animação que pode ser usada em produção" - } - - var destination: UIViewController { - let vc = FirstSectionChallengeViewController() - vc.title = title - return vc - } -} diff --git a/solutions/devsprint-leonardo-santos-5/bruno-alves/AnimationsShowcase/Showcases/FirstSection/Challenge/Presenter/FirstSectionChallengePresenter.swift b/solutions/devsprint-leonardo-santos-5/bruno-alves/AnimationsShowcase/Showcases/FirstSection/Challenge/Presenter/FirstSectionChallengePresenter.swift new file mode 100644 index 0000000..6e4eaf8 --- /dev/null +++ b/solutions/devsprint-leonardo-santos-5/bruno-alves/AnimationsShowcase/Showcases/FirstSection/Challenge/Presenter/FirstSectionChallengePresenter.swift @@ -0,0 +1,12 @@ +// +// FirstSectionChallengePresenter.swift +// AnimationsShowcase +// +// Created by Bruno Silva on 27/11/22. +// + +import UIKit + +final class FirstSectionChallengePresenter { + +} diff --git a/solutions/devsprint-leonardo-santos-5/bruno-alves/AnimationsShowcase/Showcases/FirstSection/Challenge/View/FirstSectionChallenge.swift b/solutions/devsprint-leonardo-santos-5/bruno-alves/AnimationsShowcase/Showcases/FirstSection/Challenge/View/FirstSectionChallenge.swift new file mode 100644 index 0000000..c33be47 --- /dev/null +++ b/solutions/devsprint-leonardo-santos-5/bruno-alves/AnimationsShowcase/Showcases/FirstSection/Challenge/View/FirstSectionChallenge.swift @@ -0,0 +1,73 @@ +import UIKit + +final class FirstSectionChallengeViewController: UIViewController { + + // MARK: - Private Properties + + private let firstSectionView: FirstSectionChallengeView + private let presenter: FirstSectionChallengePresenter + private var isOpen = false + + // MARK: - Init + + init(firstSectionView: FirstSectionChallengeView, + presenter: FirstSectionChallengePresenter) { + self.firstSectionView = firstSectionView + self.presenter = presenter + super.init(nibName: nil, bundle: nil) + } + + @available(*, unavailable) + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + // MARK: - Life Cycle + + override func loadView() { + view = firstSectionView + firstSectionView.delegate = self + } +} + +// MARK: - Extension + +extension FirstSectionChallengeViewController: FirstSectionChallengeViewDelegate { + func didCallAnimation() { + if isOpen { + isOpen = false + let imageName = "backCard.png" + let image = UIImage(named: imageName) + firstSectionView.cardImageView.image = image + UIView.transition(with: firstSectionView.cardImageView, duration: 0.3, options: .transitionFlipFromLeft, animations: nil) + } else { + isOpen = true + let imageName = "frontCard.png" + let image = UIImage(named: imageName) + firstSectionView.cardImageView.image = image + + UIView.transition(with: firstSectionView.cardImageView, duration: 0.3, options: .transitionFlipFromRight, animations: nil) + } + } +} + +// MARK: - ShowcaseRow + +struct FirstSectionChallengeShowcase: ShowcaseRow { + var title: String { + "UIView.animate Challenge šŸ†" + } + + var description: String { + "Utilize sua criatividade e faƧa uma animação que pode ser usada em produção" + } + + var destination: UIViewController { + let firstSection = FirstSectionChallengeView() + let presenter = FirstSectionChallengePresenter() + let vc = FirstSectionChallengeViewController(firstSectionView: firstSection, + presenter: presenter) + vc.title = title + return vc + } +} diff --git a/solutions/devsprint-leonardo-santos-5/bruno-alves/AnimationsShowcase/Showcases/FirstSection/Challenge/View/FirstSectionChallengeView.swift b/solutions/devsprint-leonardo-santos-5/bruno-alves/AnimationsShowcase/Showcases/FirstSection/Challenge/View/FirstSectionChallengeView.swift new file mode 100644 index 0000000..df03dbb --- /dev/null +++ b/solutions/devsprint-leonardo-santos-5/bruno-alves/AnimationsShowcase/Showcases/FirstSection/Challenge/View/FirstSectionChallengeView.swift @@ -0,0 +1,89 @@ +// +// FirstSectionChallengeView.swift +// AnimationsShowcase +// +// Created by Bruno Silva on 27/11/22. +// + +import UIKit + +protocol FirstSectionChallengeViewDelegate: AnyObject { + func didCallAnimation() +} + +final class FirstSectionChallengeView: UIView { + + // MARK: - Properties + + weak var delegate: FirstSectionChallengeViewDelegate? + + // MARK: - Properties UI + + lazy var cardImageView: UIImageView = { + let imageName = "backCard.png" + let image = UIImage(named: imageName) + let imageView = UIImageView(image: image) + imageView.translatesAutoresizingMaskIntoConstraints = false + + return imageView + }() + + private lazy var changeSideButton: UIButton = { + var config = UIButton.Configuration.filled() + config.baseBackgroundColor = .devpass + let button = UIButton(configuration: config) + button.setTitle("Animar", for: .normal) + button.addTarget(self, action: #selector(animate), for: .touchUpInside) + button.translatesAutoresizingMaskIntoConstraints = false + + return button + }() + + // MARK: - Init + + init() { + super.init(frame: .zero) + setup() + } + + @available(*, unavailable) + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + // MARK: - Actions + + @objc + private func animate() { + delegate?.didCallAnimation() + } +} + +// MARK: - Extension + +extension FirstSectionChallengeView: ViewCodable { + func setupSubviews() { + addSubview(cardImageView) + addSubview(changeSideButton) + } + + func setupConstraints() { + NSLayoutConstraint.activate([ + cardImageView.centerXAnchor.constraint(equalTo: centerXAnchor), + cardImageView.centerYAnchor.constraint(equalTo: centerYAnchor), + cardImageView.heightAnchor.constraint(equalToConstant: 300), + cardImageView.widthAnchor.constraint(equalToConstant: 200) + ]) + + NSLayoutConstraint.activate([ + changeSideButton.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 16), + changeSideButton.bottomAnchor.constraint(equalTo: safeAreaLayoutGuide.bottomAnchor, constant: -50), + changeSideButton.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -16), + changeSideButton.heightAnchor.constraint(equalToConstant: 50) + ]) + } + + func setupExtraConfiguration() { + backgroundColor = .systemBackground + } +}