@ -108,8 +108,6 @@ public class AttachmentApprovalViewController: UIPageViewController, UIPageViewC
public weak var approvalDelegate : AttachmentApprovalViewControllerDelegate ?
private ( set ) var captioningToolbar : CaptioningToolbar !
// MARK: - I n i t i a l i z e r s
@ available ( * , unavailable , message : " use attachment: constructor instead. " )
@ -148,45 +146,35 @@ public class AttachmentApprovalViewController: UIPageViewController, UIPageViewC
return navController
}
// MARK: - Vi e w L i f e c y c l e
// MARK: - Su b v i e w s
let galleryRailView = GalleryRailView ( )
let railContainerView = UIView ( )
var galleryRailView : GalleryRailView {
return bottomToolView . galleryRailView
}
override public func viewDidLoad ( ) {
super . viewDidLoad ( )
var captioningToolbar : CaptioningToolbar {
return bottomToolView . captioningToolbar
}
self . view . backgroundColor = . black
lazy var bottomToolView : BottomToolView = {
let isAddMoreVisible = mode = = . sharedNavigation
let bottomToolView = BottomToolView ( isAddMoreVisible : isAddMoreVisible )
disablePagingIfNecessary ( )
return bottomToolView
} ( )
railContainerView . backgroundColor = UIColor . black . withAlphaComponent ( 0.6 )
view . addSubview ( railContainerView )
railContainerView . preservesSuperviewLayoutMargins = true
railContainerView . layoutMargins . bottom = 50
railContainerView . autoPinEdgesToSuperviewEdges ( with : . zero , excludingEdge : . top )
// MARK: - V i e w L i f e c y c l e
let footerGradientView = GradientView ( from : . clear , to : . black )
railContainerView . addSubview ( footerGradientView )
footerGradientView . autoPinEdgesToSuperviewEdges ( with : . zero , excludingEdge : . top )
footerGradientView . autoSetDimension ( . height , toSize : ScaleFromIPhone5 ( 100 ) )
override public func viewDidLoad ( ) {
super . viewDidLoad ( )
railContainerView . addSubview ( galleryRailView )
galleryRailView . delegate = self
galleryRailView . scrollFocusMode = . keepWithinBounds
self . view . backgroundColor = . black
galleryRailView . autoPinEdge ( toSuperviewEdge : . leading )
galleryRailView . autoPinEdge ( toSuperviewEdge : . trailing )
galleryRailView . autoPinEdge ( toSuperviewMargin : . top )
galleryRailView . autoPinEdge ( toSuperviewMargin : . bottom )
galleryRailView . autoSetDimension ( . height , toSize : 72 )
disablePagingIfNecessary ( )
// B o t t o m T o o l b a r
let isAddMoreVisible = mode = = . sharedNavigation
let captioningToolbar = CaptioningToolbar ( isAddMoreVisible : isAddMoreVisible )
galleryRailView . delegate = self
captioningToolbar . captioningToolbarDelegate = self
self . captioningToolbar = captioningToolbar
// N a v i g a t i o n
@ -232,8 +220,8 @@ public class AttachmentApprovalViewController: UIPageViewController, UIPageViewC
}
override public var inputAccessoryView : UIView ? {
self . captioningToolbar . layoutIfNeeded ( )
return self . captioningToolbar
bottomToolView . layoutIfNeeded ( )
return bottomToolView
}
override public var canBecomeFirstResponder : Bool {
@ -447,8 +435,7 @@ public class AttachmentApprovalViewController: UIPageViewController, UIPageViewC
galleryRailView . configureCellViews ( itemProvider : attachmentItemCollection , focusedItem : currentItem )
addDeleteIcon ( cellViews : galleryRailView . cellViews )
railContainerView . isHidden = attachmentItemCollection . attachmentItems . count < 2
captioningToolbar . alwaysShowGradient = railContainerView . isHidden
galleryRailView . isHidden = attachmentItemCollection . attachmentItems . count < 2
}
let attachmentItemCollection : AttachmentItemCollection
@ -944,6 +931,54 @@ extension AttachmentPrepViewController: UIScrollViewDelegate {
}
}
class BottomToolView : UIView {
let captioningToolbar : CaptioningToolbar
let galleryRailView : GalleryRailView
let kGalleryRailViewHeight : CGFloat = 72
required init ( isAddMoreVisible : Bool ) {
captioningToolbar = CaptioningToolbar ( isAddMoreVisible : isAddMoreVisible )
galleryRailView = GalleryRailView ( )
galleryRailView . scrollFocusMode = . keepWithinBounds
galleryRailView . autoSetDimension ( . height , toSize : kGalleryRailViewHeight )
super . init ( frame : . zero )
// S p e c i f y i n g a u t o r s i z i n g m a s k a n d a n i n t r i n s i c c o n t e n t s i z e a l l o w s p r o p e r
// s i z i n g w h e n u s e d a s a n i n p u t a c c e s s o r y v i e w .
self . autoresizingMask = . flexibleHeight
self . translatesAutoresizingMaskIntoConstraints = false
backgroundColor = UIColor . black . withAlphaComponent ( 0.6 )
preservesSuperviewLayoutMargins = true
let stackView = UIStackView ( arrangedSubviews : [ self . galleryRailView , self . captioningToolbar ] )
stackView . axis = . vertical
addSubview ( stackView )
stackView . autoPinEdge ( toSuperviewEdge : . leading )
stackView . autoPinEdge ( toSuperviewEdge : . trailing )
stackView . autoPinEdge ( toSuperviewEdge : . top )
stackView . autoPinEdge ( toSuperviewMargin : . bottom )
}
required init ? ( coder aDecoder : NSCoder ) {
fatalError ( " init(coder:) has not been implemented " )
}
// MARK:
override var intrinsicContentSize : CGSize {
get {
// S i n c e w e h a v e ` s e l f . a u t o r e s i z i n g M a s k = U I V i e w A u t o r e s i z i n g F l e x i b l e H e i g h t ` , w e m u s t s p e c i f y
// a n i n t r i n s i c C o n t e n t S i z e . S p e c i f y i n g C G S i z e . z e r o c a u s e s t h e h e i g h t t o b e d e t e r m i n e d b y a u t o l a y o u t .
return CGSize . zero
}
}
}
protocol CaptioningToolbarDelegate : class {
func captioningToolbarDidTapSend ( _ captioningToolbar : CaptioningToolbar )
func captioningToolbarDidBeginEditing ( _ captioningToolbar : CaptioningToolbar )
@ -964,7 +999,6 @@ class CaptioningToolbar: UIView, UITextViewDelegate {
set { self . textView . text = newValue }
}
private let bottomGradient : GradientView = GradientView ( from : . clear , to : . black )
private let lengthLimitLabel : UILabel = UILabel ( )
// L a y o u t C o n s t a n t s
@ -1051,7 +1085,6 @@ class CaptioningToolbar: UIView, UITextViewDelegate {
self . lengthLimitLabel . isHidden = true
let contentView = UIView ( )
contentView . addSubview ( bottomGradient )
contentView . addSubview ( sendButton )
contentView . addSubview ( textView )
contentView . addSubview ( lengthLimitLabel )
@ -1103,11 +1136,6 @@ class CaptioningToolbar: UIView, UITextViewDelegate {
lengthLimitLabel . autoPinEdge ( . bottom , to : . top , of : textView , withOffset : - 6 )
lengthLimitLabel . setContentHuggingHigh ( )
lengthLimitLabel . setCompressionResistanceHigh ( )
bottomGradient . isHidden = true
let bottomGradientHeight = ScaleFromIPhone5 ( 100 )
bottomGradient . autoSetDimension ( . height , toSize : bottomGradientHeight )
bottomGradient . autoPinEdgesToSuperviewEdges ( with : . zero , excludingEdge : . top )
}
required init ? ( coder aDecoder : NSCoder ) {
@ -1166,30 +1194,12 @@ class CaptioningToolbar: UIView, UITextViewDelegate {
}
}
var alwaysShowGradient : Bool = false {
didSet {
if alwaysShowGradient {
bottomGradient . isHidden = false
}
}
}
public func textViewDidBeginEditing ( _ textView : UITextView ) {
self . captioningToolbarDelegate ? . captioningToolbarDidBeginEditing ( self )
if ! alwaysShowGradient {
UIView . animate ( withDuration : 0.2 ) {
self . bottomGradient . isHidden = false
}
}
}
public func textViewDidEndEditing ( _ textView : UITextView ) {
self . captioningToolbarDelegate ? . captioningToolbarDidEndEditing ( self )
if ! alwaysShowGradient {
UIView . animate ( withDuration : 0.2 ) {
self . bottomGradient . isHidden = true
}
}
}
// MARK: - H e l p e r s