@@ -74,9 +74,12 @@ public class InlineTagController: UICollectionView {
7474 return CGSize ( width: self . bounds. width, height: max ( self . minimumHeight ( ) , size. height) )
7575 }
7676
77- private func customInit( ) {
78- sizingCell = InlineTagCell ( frame: CGRect ( x: 0 , y: 0 , width: 100 , height: CGFloat ( InlineTagControllerConfiguration . cellHeight) ) )
77+ public func setConfiguration( _ config: InlineTagConfigurable ) {
78+ Config . instance. set ( config: config)
79+ updateForConfig ( )
80+ }
7981
82+ private func customInit( ) {
8083 self . backgroundColor = UIColor . white
8184 var frame = self . bounds
8285 frame. size. height = minimumHeight ( )
@@ -85,28 +88,34 @@ public class InlineTagController: UICollectionView {
8588 let view = UIView ( frame: frame)
8689 view. addSubview ( self . placeholderLabel)
8790
88- self . placeholderLabel. font = InlineTagControllerConfiguration . placeholderFont
89- self . placeholderLabel. textColor = InlineTagControllerConfiguration . placeholderFontColor
90-
9191 self . backgroundView = view
9292 self . register ( InlineTagCell . self, forCellWithReuseIdentifier: InlineTagCell . identifier)
9393
9494 self . dataSource = self
9595 self . delegate = self
9696
97+ self . tapRecognizer = UITapGestureRecognizer ( target: self , action: #selector( didTapOnView ( _: ) ) )
98+ self . addGestureRecognizer ( self . tapRecognizer)
99+
100+ updateForConfig ( )
101+ }
102+
103+ private func updateForConfig( ) {
104+ sizingCell = InlineTagCell ( frame: CGRect ( x: 0 , y: 0 , width: 100 , height: CGFloat ( TagConfig . cellHeight) ) )
105+
97106 if let layout = self . collectionViewLayout as? InlineTagControllerFlowLayout {
98- layout. sectionInset = InlineTagControllerConfiguration . inset
99- layout. minimumInteritemSpacing = InlineTagControllerConfiguration . interitemSpacing
100- layout. minimumLineSpacing = InlineTagControllerConfiguration . lineSpacing
107+ layout. sectionInset = TagConfig . inset
108+ layout. minimumInteritemSpacing = TagConfig . interitemSpacing
109+ layout. minimumLineSpacing = TagConfig . lineSpacing
101110 }
102111
103- self . tapRecognizer = UITapGestureRecognizer ( target : self , action : #selector ( didTapOnView ( _ : ) ) )
104- self . addGestureRecognizer ( self . tapRecognizer )
112+ self . placeholderLabel . font = TagConfig . font . placeholder
113+ self . placeholderLabel . textColor = TagConfig . fontColor . placeholder
105114 }
106115
107116 private func minimumHeight( ) -> CGFloat {
108- let defaultHeight : CGFloat = CGFloat ( InlineTagControllerConfiguration . cellHeight)
109- let padding = InlineTagControllerConfiguration . inset. top + InlineTagControllerConfiguration . inset. bottom
117+ let defaultHeight : CGFloat = CGFloat ( TagConfig . cellHeight)
118+ let padding = TagConfig . inset. top + TagConfig . inset. bottom
110119
111120 return defaultHeight + padding
112121 }
@@ -158,7 +167,7 @@ public class InlineTagController: UICollectionView {
158167 }
159168
160169 private func isTextValid( text: String ) -> Bool {
161- if let validation = InlineTagControllerConfiguration . itemValidation {
170+ if let validation = TagConfig . itemValidation {
162171 return validation ( text)
163172 } else {
164173 return true
@@ -223,7 +232,7 @@ extension InlineTagController {
223232 }
224233
225234 private func replaceLastInvalidOrInsertItemText( text: String , switchToNext: Bool = true , completion: ( ( ) -> ( ) ) ? = nil ) {
226- if let validator = InlineTagControllerConfiguration . itemValidation, let tag = self . tags. last, !validator( tag. text) {
235+ if let validator = TagConfig . itemValidation, let tag = self . tags. last, !validator( tag. text) {
227236 let position = self . tags. index ( where: { ( i) -> Bool in
228237 i. text == tag. text
229238 } )
@@ -335,7 +344,7 @@ extension InlineTagController: UICollectionViewDelegate, UICollectionViewDataSou
335344 let layoutInset = ( self . collectionViewLayout as! UICollectionViewFlowLayout ) . sectionInset
336345 let maximumWidth = self . bounds. width - layoutInset. left - layoutInset. right
337346
338- return CGSize ( width: min ( size. width, maximumWidth) , height: CGFloat ( InlineTagControllerConfiguration . cellHeight) )
347+ return CGSize ( width: min ( size. width, maximumWidth) , height: CGFloat ( TagConfig . cellHeight) )
339348 }
340349
341350}
@@ -401,7 +410,7 @@ extension InlineTagController: InlineTagCellDelegate {
401410 }
402411
403412 internal func needPreciseNumberOfItems( ) -> Int ? {
404- switch InlineTagControllerConfiguration . numberOfTags {
413+ switch TagConfig . numberOfTags {
405414 case . unlimited:
406415 return nil
407416 case let . quantity( value) :
0 commit comments