Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it easier to override the default UriHandler #187

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.compose.ui.input.pointer.pointerHoverIcon
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.platform.UriHandler
import androidx.compose.ui.text.TextLayoutResult
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.style.TextOverflow
Expand All @@ -28,10 +29,10 @@ fun BasicRichText(
softWrap: Boolean = true,
maxLines: Int = Int.MAX_VALUE,
minLines: Int = 1,
uriHandler: UriHandler = LocalUriHandler.current,
inlineContent: Map<String, InlineTextContent> = mapOf()
) {
val density = LocalDensity.current
val uriHandler = LocalUriHandler.current
val pointerIcon = remember {
mutableStateOf(PointerIcon.Default)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
package com.mohamedrejeb.richeditor.ui.material

import androidx.compose.foundation.text.InlineTextContent
import androidx.compose.material.*
import androidx.compose.material.LocalContentAlpha
import androidx.compose.material.LocalContentColor
import androidx.compose.material.LocalTextStyle
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.takeOrElse
import androidx.compose.ui.text.*
import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.platform.UriHandler
import androidx.compose.ui.text.Paragraph
import androidx.compose.ui.text.TextLayoutResult
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontWeight
Expand Down Expand Up @@ -74,7 +81,8 @@ fun RichText(
minLines: Int = 1,
inlineContent: Map<String, InlineTextContent> = mapOf(),
onTextLayout: (TextLayoutResult) -> Unit = {},
style: TextStyle = LocalTextStyle.current
style: TextStyle = LocalTextStyle.current,
uriHandler: UriHandler = LocalUriHandler.current,
) {
val textColor = color.takeOrElse {
style.color.takeOrElse {
Expand Down Expand Up @@ -105,6 +113,7 @@ fun RichText(
softWrap = softWrap,
maxLines = maxLines,
minLines = minLines,
inlineContent = inlineContent
inlineContent = inlineContent,
uriHandler = uriHandler,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.LocalTextStyle
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.takeOrElse
import androidx.compose.ui.input.pointer.PointerIcon
import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.platform.UriHandler
import androidx.compose.ui.text.Paragraph
import androidx.compose.ui.text.TextLayoutResult
import androidx.compose.ui.text.TextStyle
Expand Down Expand Up @@ -79,7 +77,8 @@ fun RichText(
maxLines: Int = Int.MAX_VALUE,
inlineContent: Map<String, InlineTextContent> = mapOf(),
onTextLayout: (TextLayoutResult) -> Unit = {},
style: TextStyle = LocalTextStyle.current
style: TextStyle = LocalTextStyle.current,
uriHandler: UriHandler = LocalUriHandler.current,
) {
val textColor = color.takeOrElse {
style.color.takeOrElse {
Expand Down Expand Up @@ -109,6 +108,7 @@ fun RichText(
overflow = overflow,
softWrap = softWrap,
maxLines = maxLines,
inlineContent = inlineContent
inlineContent = inlineContent,
uriHandler = uriHandler,
)
}
Loading