@@ -52,6 +52,10 @@ protocol IssueTextActionsViewDelegate: class {
5252 func didSelect( actionsView: IssueTextActionsView , operation: IssueTextActionOperation )
5353}
5454
55+ protocol IssueTextActionsViewSendDelegate : class {
56+ func didSend( for actionsView: IssueTextActionsView )
57+ }
58+
5559struct IssueTextActionOperation {
5660
5761 enum Operation {
@@ -71,6 +75,7 @@ struct IssueTextActionOperation {
7175final class IssueTextActionsView : UIView , UICollectionViewDataSource , UICollectionViewDelegateFlowLayout {
7276
7377 weak var delegate : IssueTextActionsViewDelegate ?
78+ weak var sendDelegate : IssueTextActionsViewSendDelegate ?
7479
7580 private let operations : [ IssueTextActionOperation ]
7681 private let identifier = " cell "
@@ -86,18 +91,43 @@ final class IssueTextActionsView: UIView, UICollectionViewDataSource, UICollecti
8691 c. showsHorizontalScrollIndicator = false
8792 return c
8893 } ( )
94+ private let gradientWidth = Styles . Sizes. gutter
95+ private let sendButtonGradientLayer = CAGradientLayer ( )
96+ private let sendButton = UIButton ( )
97+
98+ public var sendButtonEnabled : Bool {
99+ get { return sendButton. isEnabled }
100+ set { sendButton. isEnabled = newValue }
101+ }
89102
90- init ( operations: [ IssueTextActionOperation ] ) {
103+ init ( operations: [ IssueTextActionOperation ] , showSendButton : Bool ) {
91104 self . operations = operations
92105
93106 super. init ( frame: . zero)
94107
95108 translatesAutoresizingMaskIntoConstraints = false
96109
110+ collectionView. clipsToBounds = true
97111 collectionView. register ( IssueTextActionsCell . self, forCellWithReuseIdentifier: identifier)
98112 collectionView. dataSource = self
99113 collectionView. delegate = self
100114 addSubview ( collectionView)
115+
116+ if showSendButton {
117+ collectionView. contentInset = UIEdgeInsets ( top: 0 , left: 0 , bottom: 0 , right: gradientWidth)
118+
119+ sendButtonGradientLayer. startPoint = CGPoint ( x: 0 , y: 0.5 )
120+ sendButtonGradientLayer. endPoint = CGPoint ( x: 1 , y: 0.5 )
121+ sendButtonGradientLayer. colors = [ UIColor ( white: 1 , alpha: 0 ) . cgColor, UIColor . white. cgColor]
122+ layer. addSublayer ( sendButtonGradientLayer)
123+
124+ let blue = Styles . Colors. Blue. medium. color
125+ sendButton. tintColor = blue
126+ sendButton. imageView? . tintColor = blue
127+ sendButton. setImage ( UIImage ( named: " send " ) ? . withRenderingMode ( . alwaysTemplate) , for: . normal)
128+ sendButton. addTarget ( self , action: #selector( onSend) , for: . touchUpInside)
129+ addSubview ( sendButton)
130+ }
101131 }
102132
103133 required init ? ( coder aDecoder: NSCoder ) {
@@ -106,7 +136,31 @@ final class IssueTextActionsView: UIView, UICollectionViewDataSource, UICollecti
106136
107137 override func layoutSubviews( ) {
108138 super. layoutSubviews ( )
109- collectionView. frame = bounds
139+ if sendButton. superview != nil {
140+ let height = bounds. height
141+ let imageWidth = sendButton. image ( for: . normal) ? . size. width ?? 0
142+ let buttonWidth = imageWidth + 2 * Styles. Sizes. gutter
143+ sendButton. frame = CGRect (
144+ x: bounds. width - buttonWidth,
145+ y: 0 ,
146+ width: buttonWidth,
147+ height: height
148+ )
149+ sendButtonGradientLayer. frame = CGRect (
150+ x: sendButton. frame. minX - gradientWidth,
151+ y: 0 ,
152+ width: gradientWidth,
153+ height: height
154+ )
155+ // put collection view beneath the gradient layer
156+ collectionView. frame = CGRect ( x: 0 , y: 0 , width: sendButton. frame. minX, height: height)
157+ } else {
158+ collectionView. frame = bounds
159+ }
160+ }
161+
162+ @objc private func onSend( ) {
163+ sendDelegate? . didSend ( for: self )
110164 }
111165
112166 // MARK: UICollectionViewDataSource
0 commit comments