Skip to content

Repository files navigation

ExpandableText ✂️

A beautifully crafted SwiftUI package that enables smooth, animated text expansion with native-feeling truncation and blur transitions --- powered by modern iOS text rendering APIs.

Built for developers who want pixel-perfect control over text behavior without compromising performance or API simplicity.


✨ Why ExpandableText?

ExpandableText is not just a "Read More" solution --- it's a custom rendering system for text expansion.

  • ⚡ Zero boilerplate integration
  • 🎯 Precise line-based truncation
  • 🎬 Smooth animated expansion
  • 🌫 Native blur-based reveal effect
  • 🧠 Built using TextRenderer (iOS 18+)
  • 🧩 Clean modifier-based API
  • 🎨 Fully customizable trailing text ("...More")

📱 Demo

ScreenRecording2026-05-02at1 10 59PM-ezgif com-video-to-gif-converter

🚀 Installation

Swift Package Manager

To integrate ExpandableText using Swift Package Manager, add the following dependency to your Package.swift:

dependencies: [
    .package(url: "https://github.com/thakur-vijay/ExpandableText.git", from: "1.0.0")
]

Then add the package to your target:

.target(
    name: "YourTarget",
    dependencies: ["ExpandableText"]
)

Or add it directly in Xcode:

File → Add Package Dependencies…

Enter the repository URL:

https://github.com/thakur-vijay/ExpandableText.git

📦 Import

import ExpandableText

🛠 Requirements

  • iOS 18.0+
  • SwiftUI

💡 Usage

import SwiftUI
import ExpandableText

struct ContentView: View {
    @State private var isCollapsed = true

    var body: some View {
        Text("Long text goes here...")
            .expandable(
                length: 3,
                isEnabled: isCollapsed,
                moreText: "...More",
                blurRadius: 2,
                animation: .easeInOut
            )
            .onTapGesture {
                isCollapsed.toggle()
            }
    }
}

⚙️ Configuration Options

Parameter Description
length Number of visible lines
isEnabled Controls collapse state
moreText Trailing text
blurRadius Blur intensity
animation Transition animation

🧠 How It Works

  • Custom TextRenderer
  • Line-by-line drawing
  • Blur + opacity animation
  • Injected trailing text

🎯 Best Practices

  • Use 2--4 lines
  • Keep text short
  • Use subtle animations

📄 License

MIT License

⭐ Support

If you find this project useful:

  • ⭐ Star the repository
  • 🧃 Or… let users tip you through it 😄

About

A lightweight SwiftUI package that provides an easy-to-use 'Read More / Read Less' functionality for long text strings, automatically handling line limits and truncation.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages