Skip to content

Commit

Permalink
Merge pull request #14 from mono0926/fix
Browse files Browse the repository at this point in the history
Rename  imageView property
  • Loading branch information
mono0926 authored May 30, 2017
2 parents 4b7fcca + 2bbc445 commit c190c99
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions NativePopup/NativePopup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class NativePopup: UIView {
private let keyWindow = UIApplication.shared.keyWindow!
fileprivate weak static var currentView: NativePopup?
private let effectView: UIVisualEffectView
private let imageView: UIView
private let imageContentView: UIView

public static func show(image: ImageConvertible,
title: String,
Expand All @@ -39,20 +39,20 @@ public class NativePopup: UIView {
imageValue.validate()
switch imageValue {
case .image(let image):
imageView = UIImageView(image: image)
imageView.contentMode = .scaleAspectFit
imageView.layer.cornerRadius = 6
imageView.clipsToBounds = true
imageContentView = UIImageView(image: image)
imageContentView.contentMode = .scaleAspectFit
imageContentView.layer.cornerRadius = 6
imageContentView.clipsToBounds = true
case .view(let view):
imageView = view
imageContentView = view
case .emoji(let character):
let label = UILabel()
label.text = String(character)
label.font = UIFont.systemFont(ofSize: 120)
label.textAlignment = .center
imageView = UIView()
imageView.np.addSubviewCenter(label)
imageView.clipsToBounds = false
imageContentView = UIView()
imageContentView.np.addSubviewCenter(label)
imageContentView.clipsToBounds = false
}

super.init(frame: CGRect.zero)
Expand All @@ -64,7 +64,7 @@ public class NativePopup: UIView {
isUserInteractionEnabled = false

tintColor = #colorLiteral(red: 0.3529411765, green: 0.3529411765, blue: 0.3529411765, alpha: 1)
imageView.tintColor = tintColor
imageContentView.tintColor = tintColor

let titleLabel = UILabel()
titleLabel.text = title
Expand All @@ -84,14 +84,14 @@ public class NativePopup: UIView {
$0.attributedText = NSAttributedString(string: $0.text ?? "", attributes: [NSParagraphStyleAttributeName: style])
}

effectView.addSubview(imageView)
effectView.addSubview(imageContentView)
effectView.addSubview(titleLabel)

imageView.heightAnchor.constraint(equalTo: imageView.widthAnchor, multiplier: 1).isActive = true
imageView.heightAnchor.constraint(equalToConstant: 112).isActive = true
imageView.topAnchor.constraint(equalTo: topAnchor, constant: 32 + image.additionalMarginTop).isActive = true
imageView.centerXAnchor.constraint(equalTo: centerXAnchor).isActive = true
imageView.bottomAnchor.constraint(equalTo: titleLabel.topAnchor, constant: -(17 + image.additionalMarginBottom)).isActive = true
imageContentView.heightAnchor.constraint(equalTo: imageContentView.widthAnchor, multiplier: 1).isActive = true
imageContentView.heightAnchor.constraint(equalToConstant: 112).isActive = true
imageContentView.topAnchor.constraint(equalTo: topAnchor, constant: 32 + image.additionalMarginTop).isActive = true
imageContentView.centerXAnchor.constraint(equalTo: centerXAnchor).isActive = true
imageContentView.bottomAnchor.constraint(equalTo: titleLabel.topAnchor, constant: -(17 + image.additionalMarginBottom)).isActive = true

let sideSpace: CGFloat = 8
titleLabel.leftAnchor.constraint(equalTo: leftAnchor, constant: sideSpace).isActive = true
Expand All @@ -108,10 +108,10 @@ public class NativePopup: UIView {
messageLabel.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -bottomSpace).isActive = true
}

[self, effectView, imageView, titleLabel, messageLabel].forEach { $0.translatesAutoresizingMaskIntoConstraints = false }
[self, effectView, imageContentView, titleLabel, messageLabel].forEach { $0.translatesAutoresizingMaskIntoConstraints = false }

if let animatable = imageView as? HasAnimatablePath {
imageView.layoutIfNeeded()
if let animatable = imageContentView as? HasAnimatablePath {
imageContentView.layoutIfNeeded()
animatable.configureAnimatableLayer()
animatable.layer.addSublayer(animatable.animatableLayer)
}
Expand Down Expand Up @@ -173,7 +173,7 @@ public class NativePopup: UIView {
}

private func dismissAfter(duration: TimeInterval) {
if let animatable = imageView as? Animatable {
if let animatable = imageContentView as? Animatable {
animatable.animate()
}
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + duration) {
Expand Down

0 comments on commit c190c99

Please sign in to comment.