Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"images" : [
{
"filename" : "backCard.png",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"preserves-vector-representation" : true
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"images" : [
{
"filename" : "frontCard.png",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"preserves-vector-representation" : true
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// FirstSectionChallengePresenter.swift
// AnimationsShowcase
//
// Created by Bruno Silva on 27/11/22.
//

import UIKit

final class FirstSectionChallengePresenter {

}
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
@@ -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
}
}