@@ -122,16 +122,14 @@ struct RichTextContainer: UIViewRepresentable {
122122 func makeUIView( context: Context ) -> UIView {
123123 let container = UIView ( )
124124
125+ // MARK: Toolbar
125126 let toolbar = UIToolbar ( )
126127 toolbar. isTranslucent = true
127- toolbar. setBackgroundImage ( UIImage ( ) , forToolbarPosition: . any, barMetrics: . default)
128128
129- if #available( iOS 15 . 0 , * ) {
130- let appearance = UIToolbarAppearance ( )
131- appearance. configureWithTransparentBackground ( )
132- toolbar. standardAppearance = appearance
133- toolbar. scrollEdgeAppearance = appearance
134- }
129+ let appearance = UIToolbarAppearance ( )
130+ appearance. configureWithTransparentBackground ( )
131+ toolbar. standardAppearance = appearance
132+ toolbar. scrollEdgeAppearance = appearance
135133
136134 toolbar. items = [
137135 makeItem ( " bold " , context, #selector( Coordinator . bold) ) ,
@@ -142,10 +140,14 @@ struct RichTextContainer: UIViewRepresentable {
142140 makeItem ( " checklist " , context, #selector( Coordinator . checklist) )
143141 ]
144142
143+ // MARK: TextView
145144 let textView = UITextView ( )
146145 textView. font = . systemFont( ofSize: 16 )
147146 textView. delegate = context. coordinator
148- textView. text = text // ⭐ EN KRİTİK SATIR
147+ textView. text = text
148+ textView. backgroundColor = . clear
149+ textView. textContainerInset = UIEdgeInsets ( top: 12 , left: 8 , bottom: 12 , right: 8 )
150+
149151 context. coordinator. textView = textView
150152
151153 toolbar. translatesAutoresizingMaskIntoConstraints = false
@@ -177,27 +179,57 @@ struct RichTextContainer: UIViewRepresentable {
177179 Coordinator ( onTextChange: onTextChange)
178180 }
179181
182+ // MARK: - Toolbar Button Factory
180183 private func makeItem(
181184 _ system: String ,
182185 _ context: Context ,
183186 _ selector: Selector
184187 ) -> UIBarButtonItem {
185188
186- let image = UIImage ( systemName: system,
187- withConfiguration: UIImage . SymbolConfiguration ( pointSize: 13 ) )
189+ let image = UIImage (
190+ systemName: system,
191+ withConfiguration: UIImage . SymbolConfiguration (
192+ pointSize: 14 ,
193+ weight: . semibold
194+ )
195+ )
188196
189- var config = UIButton . Configuration. plain ( )
197+ var config = UIButton . Configuration. filled ( )
190198 config. image = image
191- config. contentInsets = . zero
199+ config. cornerStyle = . capsule
200+ config. baseForegroundColor = . tintColor
201+ config. baseBackgroundColor = UIColor . secondarySystemBackground
202+ config. contentInsets = NSDirectionalEdgeInsets (
203+ top: 6 ,
204+ leading: 10 ,
205+ bottom: 6 ,
206+ trailing: 10
207+ )
192208
193209 let button = UIButton ( configuration: config)
194- button. tintColor = . label
195- button. frame = CGRect ( x: 0 , y: 0 , width: 28 , height: 28 )
196- button. addTarget ( context. coordinator, action: selector, for: . touchUpInside)
210+
211+ button. addAction (
212+ UIAction { _ in
213+ // 🟡 Accent blink
214+ UIView . animate ( withDuration: 0.12 , animations: {
215+ button. backgroundColor = UIColor . tintColor. withAlphaComponent ( 0.25 )
216+ } ) { _ in
217+ UIView . animate ( withDuration: 0.18 ) {
218+ button. backgroundColor = UIColor . secondarySystemBackground
219+ }
220+ }
221+
222+ // 🎯 Gerçek aksiyon
223+ _ = context. coordinator. perform ( selector)
224+ } ,
225+ for: . touchUpInside
226+ )
197227
198228 return UIBarButtonItem ( customView: button)
199229 }
200230
231+
232+ // MARK: - Coordinator
201233 final class Coordinator : NSObject , UITextViewDelegate {
202234
203235 weak var textView : UITextView ?
@@ -211,8 +243,10 @@ struct RichTextContainer: UIViewRepresentable {
211243 onTextChange ( textView. text)
212244 }
213245
246+ // MARK: Actions
214247 @objc func bold( ) { toggle ( . traitBold) }
215248 @objc func italic( ) { toggle ( . traitItalic) }
249+
216250 @objc func underline( ) {
217251 guard let tv = textView else { return }
218252 let range = tv. selectedRange
@@ -223,22 +257,30 @@ struct RichTextContainer: UIViewRepresentable {
223257 )
224258 }
225259
226- @objc func bullet( ) { textView? . insertText ( " \n • " ) }
227- @objc func checklist( ) { textView? . insertText ( " \n ☐ " ) }
260+ @objc func bullet( ) {
261+ textView? . insertText ( " \n • " )
262+ }
263+
264+ @objc func checklist( ) {
265+ textView? . insertText ( " \n ☐ " )
266+ }
228267
229268 private func toggle( _ trait: UIFontDescriptor . SymbolicTraits ) {
230269 guard let tv = textView else { return }
231270 let font = tv. font ?? . systemFont( ofSize: 16 )
271+
232272 let traits = font. fontDescriptor. symbolicTraits. contains ( trait)
233273 ? font. fontDescriptor. symbolicTraits. subtracting ( trait)
234274 : font. fontDescriptor. symbolicTraits. union ( trait)
275+
235276 let desc = font. fontDescriptor. withSymbolicTraits ( traits) ?? font. fontDescriptor
236277 tv. font = UIFont ( descriptor: desc, size: font. pointSize)
237278 }
238279 }
239280}
240281
241282
283+
242284private extension UIFont {
243285 func toggle( _ trait: UIFontDescriptor . SymbolicTraits ) -> UIFont {
244286 let has = fontDescriptor. symbolicTraits. contains ( trait)
0 commit comments