61 lines
1.6 KiB
Swift
61 lines
1.6 KiB
Swift
//
|
|
// ComposeAttachmentView.swift
|
|
// Tusker
|
|
//
|
|
// Created by Shadowfacts on 1/10/19.
|
|
// Copyright © 2019 Shadowfacts. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
import Photos
|
|
|
|
protocol ComposeMediaViewDelegate {
|
|
func didRemoveMedia(_ mediaView: ComposeMediaView)
|
|
}
|
|
|
|
class ComposeMediaView: UIView {
|
|
|
|
var delegate: ComposeMediaViewDelegate?
|
|
|
|
@IBOutlet weak var imageView: UIImageView!
|
|
@IBOutlet weak var descriptionTextView: UITextView!
|
|
@IBOutlet weak var placeholderLabel: UILabel!
|
|
|
|
var assetIdentifier: String?
|
|
|
|
static func create() -> ComposeMediaView {
|
|
return UINib(nibName: "ComposeMediaView", bundle: nil).instantiate(withOwner: nil, options: nil).first as! ComposeMediaView
|
|
}
|
|
|
|
override func awakeFromNib() {
|
|
super.awakeFromNib()
|
|
|
|
imageView.layer.masksToBounds = true
|
|
imageView.layer.cornerRadius = 10 // 0.1 * imageView.frame.width
|
|
|
|
descriptionTextView.delegate = self
|
|
}
|
|
|
|
func update(asset: PHAsset) {
|
|
self.assetIdentifier = asset.localIdentifier
|
|
|
|
let size = CGSize(width: 80, height: 80)
|
|
PHImageManager.default().requestImage(for: asset, targetSize: size, contentMode: .aspectFill, options: nil) { (image, _) in
|
|
self.imageView.image = image
|
|
}
|
|
}
|
|
|
|
// MARK: - Interaction
|
|
|
|
@IBAction func removePressed(_ sender: Any) {
|
|
delegate?.didRemoveMedia(self)
|
|
}
|
|
|
|
}
|
|
|
|
extension ComposeMediaView: UITextViewDelegate {
|
|
func textViewDidChange(_ textView: UITextView) {
|
|
placeholderLabel.isHidden = !descriptionTextView.text.isEmpty
|
|
}
|
|
}
|