{"id":31978979,"url":"https://github.com/dkvekariya/richtexteditordemo","last_synced_at":"2026-06-10T16:31:58.227Z","repository":{"id":318128294,"uuid":"1070049054","full_name":"DKVekariya/RichTextEditorDemo","owner":"DKVekariya","description":"This repository is for demonstration of  latest iOS 26 TextKit ApI's","archived":false,"fork":false,"pushed_at":"2025-10-06T06:47:53.000Z","size":166,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-14T22:46:49.573Z","etag":null,"topics":["ios","swift","swiftui","text-editor","texteditor","textformatter","textkit","textkit2"],"latest_commit_sha":null,"homepage":"https://medium.com/@dkvekariya/how-to-build-rich-text-editor-in-swiftui-f09a39d2dce9","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DKVekariya.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-10-05T06:40:55.000Z","updated_at":"2025-10-10T12:04:01.000Z","dependencies_parsed_at":"2025-10-05T10:26:39.408Z","dependency_job_id":"37f9bca3-c464-4a82-82b7-124d105f3b45","html_url":"https://github.com/DKVekariya/RichTextEditorDemo","commit_stats":null,"previous_names":["dkvekariya/richtexteditordemo"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/DKVekariya/RichTextEditorDemo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DKVekariya%2FRichTextEditorDemo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DKVekariya%2FRichTextEditorDemo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DKVekariya%2FRichTextEditorDemo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DKVekariya%2FRichTextEditorDemo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DKVekariya","download_url":"https://codeload.github.com/DKVekariya/RichTextEditorDemo/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DKVekariya%2FRichTextEditorDemo/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34161283,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-10T02:00:07.152Z","response_time":89,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ios","swift","swiftui","text-editor","texteditor","textformatter","textkit","textkit2"],"created_at":"2025-10-14T22:46:47.015Z","updated_at":"2026-06-10T16:31:58.202Z","avatar_url":"https://github.com/DKVekariya.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"![iOS](https://img.shields.io/badge/iOS-26.0+-blue.svg)\n![Swift](https://img.shields.io/badge/Swift-5.9+-orange.svg)\n![SwiftUI](https://img.shields.io/badge/SwiftUI-5.0-green.svg)\n\n# 📝 SwiftUI Rich Text Editor\n\nA modern, native rich text editor built with SwiftUI and iOS 26+ APIs. This demo showcases the power of `AttributedString`, `AttributedTextSelection`, and `TextEditor` to create a fully-featured text formatting experience without UIKit.\n\n## ✨ Features\n\n### 🎨 Text Formatting\n- **Bold** - Make your text stand out\n- **Italic** - Add emphasis with style\n- **Underline** - Highlight important content\n- **Strikethrough** - Mark completed items or revisions\n\n### 🌈 Color Controls\n- **Text Color** - Full color picker for foreground text\n- **Background Color** - Highlight text with custom backgrounds\n- **Clear Background** - Remove highlighting with one tap\n\n### 📐 Font Customization\n- **Font Size Control** - Adjust from 8pt to 72pt\n- **Increment/Decrement** - Precise 2pt adjustments\n- **Visual Feedback** - Live size indicator\n\n### 🎯 Smart Features\n- **Active State Indicators** - Visual feedback for applied formatting\n- **Clear Formatting** - Remove all formatting with one tap\n- **Select All** - Quick text selection\n- **Sample Text Insertion** - Demo formatted text\n- **Character Counter** - Track document length in real-time\n\n### 🎨 Modern UI/UX\n- **Horizontal Scrolling Toolbar** - Fits all controls elegantly\n- **Color Picker Integration** - Native iOS color selection\n- **Status Bar** - Live document statistics\n- **Responsive Design** - Works on all iOS devices\n\n### Article\nI have also written detaild article on this which explains it well, You can have a look here: https://medium.com/@dkvekariya/how-to-build-rich-text-editor-in-swiftui-f09a39d2dce9\n\n## 📱 Screenshots\n\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003cth  width=\"100%\" \u003emac Editor dark\u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr align=\"center\"\u003e\n    \u003ctd\u003e \u003cimg src=\"/RichTextEditorDemo/Documents/rich_editor_demo.png\"  width=\"70%\" /\u003e \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n## 🚀 Getting Started\n\n### Prerequisites\n\n- **Xcode 16.0+** or later\n- **iOS 26.0+** deployment target\n- **macOS Sonoma** or later (for development)\n\n### Installation\n\n1. **Clone the repository**\n   ```bash\n   git clone https://github.com/yourusername/swiftui-rich-text-editor.git\n   cd swiftui-rich-text-editor\n   ```\n\n2. **Open in Xcode**\n   ```bash\n   open RichTextEditorDemo.xcodeproj\n   ```\n\n3. **Build and Run**\n   - Select your target device or simulator\n   - Press `⌘ + R` to build and run\n\n## 💻 Code Structure\n\n```\nRichTextEditorDemo/\n├── ContentView.swift          # Main editor view\n├── ToolbarButton.swift        # Reusable toolbar button component\n├── RichTextEditorApp.swift    # App entry point\n└── Assets.xcassets/           # App assets\n```\n\n## 🎓 Key Concepts\n\n### Using FontResolutionContext\n\nThe app leverages `fontResolutionContext` to accurately detect font traits:\n\n```swift\n@Environment(\\.fontResolutionContext) var fontResolutionContext\n\nprivate var isBold: Bool {\n    let attributes = selection.typingAttributes(in: attributedText)\n    if let font = attributes.font {\n        let resolved = font.resolve(in: fontResolutionContext)\n        return resolved.isBold\n    }\n    return false\n}\n```\n\n### Transform Attributes Pattern\n\nAll formatting uses the modern `transformAttributes(in:)` API:\n\n```swift\nfunc toggleBold() {\n    attributedText.transformAttributes(in: \u0026selection) { container in\n        let currentFont = container.font ?? .body\n        let resolved = currentFont.resolve(in: fontResolutionContext)\n        container.font = currentFont.bold(!resolved.isBold)\n    }\n}\n```\n\n### Typing Attributes\n\nCheck current formatting state without accessing internal ranges:\n\n```swift\nlet attributes = selection.typingAttributes(in: attributedText)\nif let font = attributes.font {\n    // Work with font attributes\n}\n```\n\n## 🏗️ Architecture Highlights\n\n### State Management\n- Uses `@State` for local view state\n- Leverages SwiftUI's automatic UI updates\n- Minimal state for optimal performance\n\n### Environment Integration\n- Proper use of `@Environment` for system values\n- Respects iOS design patterns\n\n### Reusable Components\n- `ToolbarButton` - Custom button with active states\n- Modular design for easy extension\n\n## 🎯 iOS 26+ API Features\n\nThis demo exclusively uses iOS 26+ APIs:\n\n✅ **AttributedTextSelection** - Modern selection handling  \n✅ **FontResolutionContext** - Accurate trait detection  \n✅ **transformAttributes(in:)** - Safe attribute modification  \n✅ **typingAttributes(in:)** - State inspection  \n✅ **AttributedString** - Rich text representation  \n\n## 📚 Learning Resources\n\n### Key Concepts Demonstrated\n\n1. **Working with AttributedTextSelection**\n   - No direct range access\n   - Using `typingAttributes(in:)` and `transformAttributes(in:)`\n\n2. **Font Trait Resolution**\n   - Using `fontResolutionContext` for accurate detection\n   - Proper bold/italic toggling\n\n3. **Color Management**\n   - ColorPicker integration\n   - Foreground and background colors\n\n4. **Attribute Containers**\n   - Modifying multiple attributes efficiently\n   - Clearing all formatting\n\n## 🔧 Customization\n\n### Adding New Formatting Options\n\n```swift\n// Example: Add superscript\nfunc toggleSuperscript() {\n    attributedText.transformAttributes(in: \u0026selection) { container in\n        let currentOffset = container.baselineOffset ?? 0\n        container.baselineOffset = currentOffset == 0 ? 5 : 0\n    }\n}\n```\n\n### Changing Color Scheme\n\nModify the toolbar background:\n\n```swift\n.background(Color(.systemGray6))  // Change to your preferred color\n```\n\n## 🐛 Known Limitations\n\n- **iOS 26+ Only** - Requires latest iOS version\n- **No Undo/Redo** - Not implemented in this demo\n- **Single Font Family** - Uses system font only\n- **No Persistence** - Text is not saved between sessions\n\n## 👨‍💻 Author\n\n**Your Name**\n- GitHub: [@DKVekariya](https://github.com/DKVekariya)\n- Twitter: [@D_K_Vekariya](https://x.com/D_K_Vekariya)\n- LinkedIn: [Divyesh Vekariya](https://www.linkedin.com/in/dkvekariya)\n\n## 🙏 Acknowledgments\n\n- Inspired by Apple's WWDC 2024 sessions on SwiftUI\n- Built following iOS 26+ design patterns\n- Special thanks to the SwiftUI community\n\n## ⭐ Show Your Support\n\nIf this project helped you, please give it a ⭐️!\n\n---\n\n**Built with ❤️ using SwiftUI**\n\n*Last Updated: October 2025*\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdkvekariya%2Frichtexteditordemo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdkvekariya%2Frichtexteditordemo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdkvekariya%2Frichtexteditordemo/lists"}