Compose-html - An Android library which provides HTML support for Jetpack Compose texts

Overview

Android Arsenal

HtmlCompose

An Android library which provides HTML support for Jetpack Compose texts.

Setup

Add to top level gradle.build file

allprojects {
    repositories {
        maven { url "https://jitpack.io" }
    }
}

Add to app module gradle.build file.

dependencies {
    implementation 'com.github.ireward.compose-html:1.0.1'
}

Usage

For the time being, the composable Text layout doesn't provide any HTML support. This library fills that gap by exposing the composable HtmlText layout, which is built on top of the Text layout and the Span/Spannable Android classes. Its API goes as follows:

HtmlText(
    text = htmlString,
    linkClicked = { link ->
        Log.d("linkClicked", link)
    }
)

And these are all the available parameters that allows you to change the default behaviour:

fun HtmlText(
    text: String,
    modifier: Modifier = Modifier,
    style: TextStyle = TextStyle.Default,
    softWrap: Boolean = true,
    overflow: TextOverflow = TextOverflow.Clip,
    maxLines: Int = Int.MAX_VALUE,
    onTextLayout: (TextLayoutResult) -> Unit = {},
    linkClicked: (String) -> Unit = {},
    fontSize: TextUnit = 14.sp,
    flags: Int = HtmlCompat.FROM_HTML_MODE_COMPACT,
    URLSpanStyle: SpanStyle = SpanStyle(
        color = linkTextColor(),
        textDecoration = TextDecoration.Underline
    )
)

HtmlText supports almost as many HTML tags as android.widget.TextView does, with the exception of <img> tag and <ul>, being the latter partially supported, as HtmlText renders properly the elements of the list but it does not add the bullet (β€’)

What follows are screenshots taken from the companion showcase app hosted in this same repo, where all the HTML tags are rendered side by side to compare HtmlText with android.widget.TextView:

Alt text Alt text Alt text Alt text Alt text Alt text Alt text

You might also like...
Instagraph is an Instagram Clone which I am practicing on a new concepts and other advanced Jetpack compose specific concepts.

Instagraph Instagraph is an Instagram Clone which I am practicing on a new concepts and other advanced Jetpack compose specific concepts. The clone on

Learn Jetpack Compose for Android by Examples. Learn how to use Jetpack Compose for Android App Development. Android’s modern toolkit for building native UI.
Learn Jetpack Compose for Android by Examples. Learn how to use Jetpack Compose for Android App Development. Android’s modern toolkit for building native UI.

Learn Jetpack Compose for Android by Examples. Learn how to use Jetpack Compose for Android App Development. Android’s modern toolkit for building native UI.

Provides a callback for when a @Composible is shown to the user

Compose-Shown Provides a callback for when a @Composible is shown to the user. This can be useful for 'pageview' analytics. It will re-fire when the a

Jetpack Compose Boids | Flocking Insect 🐜. bird or Fish simulation using Jetpack Compose Desktop πŸš€, using Canvas API 🎨
Jetpack Compose Boids | Flocking Insect 🐜. bird or Fish simulation using Jetpack Compose Desktop πŸš€, using Canvas API 🎨

🐜 🐜 🐜 Compose flocking Ants(boids) 🐜 🐜 🐜 Jetpack compose Boids | Flocking Insect. bird or Fish simulation using Jetpack Compose Desktop πŸš€ , usi

A collection of animations, compositions, UIs using Jetpack Compose. You can say Jetpack Compose cookbook or play-ground if you want!
A collection of animations, compositions, UIs using Jetpack Compose. You can say Jetpack Compose cookbook or play-ground if you want!

Why Not Compose! A collection of animations, compositions, UIs using Jetpack Compose. You can say Jetpack Compose cookbook or play-ground if you want!

This is a sample app(For beginners - App #2) built using Jetpack Compose. It demonstrates the concept of State Hoisting in Jetpack Compose.
This is a sample app(For beginners - App #2) built using Jetpack Compose. It demonstrates the concept of State Hoisting in Jetpack Compose.

JetBMICalculator This is a sample app(For beginners - App #2) built using Jetpack Compose. It demonstrates the concept of State Hoisting in Jetpack Co

Jetpack-Compose-Demo - Instagram Profile UI using Jetpack Compose
Jetpack-Compose-Demo - Instagram Profile UI using Jetpack Compose

Jetpack-Compose-Demo Instagram Profile UI using Jetpack Compose

Jetpack-compose-animations-examples - Cool animations implemented with Jetpack compose
Jetpack-compose-animations-examples - Cool animations implemented with Jetpack compose

Jetpack-compose-animations-examples This repository consists of 4 animations: St

Compose-navigation - Set of utils to help with integrating Jetpack Compose and Jetpack's Navigation

Jetpack Compose Navigation Set of utils to help with integrating Jetpack Compose

Owner
iRewardHealth
Promoting healthy behavior change
iRewardHealth
SSJetpackComposeSwipeableView is a small library which provides support for the swipeable views

SSJetpackComposeSwipeableView is a small library which provides support for the swipeable views. You can use this in your lazyColumns or can add a simple view which contains swipe to edit/delete functionality.

Simform Solutions 60 Nov 18, 2022
Jetpack Compose Text composable to show html text from resources

HtmlText Current Compose Version: 1.0.3 Compose HtmlText Text composable to show html text from resources Add to your project Add actual HtmlText libr

Alexander Karkossa 57 Dec 23, 2022
A CLI utility to convert Jetpack Compose compiler metrics and reports to beautified 😍 HTML page

Compose Compiler Reports to HTML Generator A CLI utility to convert Jetpack Compose compiler metrics and reports to beautified ?? HTML page. Made with

Shreyas Patil 145 Jan 3, 2023
A specific release of the Jacoco library provide coverage support for Jetpack Compose

This project depends on a specific release of the Jacoco library, which has been updated to provide coverage support for Jetpack Compose. This release is available on GitHub, and requires the use of the GitHub Apache Maven Package Repository

Pawnies - AR Chess 12 Aug 7, 2022
Copy of https://github.com/joreilly/MortyComposeKMM to support Android & JVM with Jetpack Compose Multiplatform

Rick&Morty with Compose Multiplatform (Android/Desktop) A copycat of https://github.com/joreilly/MortyComposeKMM to support Android & JVM with Jetpack

GrΓ©gory Lureau 19 Sep 19, 2022
Easy zoom in with drag support for Jetpack Compose

ComposeZoomableImage Jetpack Compose Zoomable Image Android Library Easy zoom in with drag support for Jetpack Compose Demo Setup Add Jitpack maven {

Umut Soysal 61 Nov 23, 2022
πŸ‚ Jetpack Compose image loading library which can fetch and display network images using Glide, Coil, and Fresco.

Landscapist ?? Jetpack Compose image loading library which can fetch and display network images using Glide, Coil, Fresco Usecase You can see the use

Jaewoong Eum 1.4k Jan 1, 2023
Simple Jetpack Compose demo app which is developed with CoinGecko API and modern android technologies.

CoinBox CoinBox is a multi module small currency tracker app which is developed with Jetpack Compose. This demo app used coingecko.com API to fetch da

Enes Zor 13 Apr 8, 2022
Jetpack Compose app which generates random names

Compose-Your-Name? A Jetpack Compose App Meme App for knowing you nick name Inspiration You recently might have seen this meme on Instagram, I also di

Chetan Gupta 14 Jan 26, 2022
A Collection of major Jetpack compose UI components which are commonly used.πŸŽ‰πŸ”πŸ‘Œ

SSComposeCookBook A Collection of major Jetpack compose UI components which are commonly used. Introduction Jetpack Compose is a modern toolkit for bu

Simform Solutions 370 Dec 28, 2022