Skip to content

Commit

Permalink
Merge pull request #312 from Goooler/explicit-api-mode
Browse files Browse the repository at this point in the history
Enable Explicit API mode
  • Loading branch information
MohamedRejeb authored Jul 28, 2024
2 parents c7150e2 + 56fa5b3 commit 80545e1
Show file tree
Hide file tree
Showing 24 changed files with 134 additions and 131 deletions.
1 change: 1 addition & 0 deletions richeditor-compose-coil3/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ plugins {
}

kotlin {
explicitApi()
applyDefaultHierarchyTemplate()
androidTarget {
publishLibraryVariants("release")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import com.mohamedrejeb.richeditor.model.ImageData
import com.mohamedrejeb.richeditor.model.ImageLoader

@OptIn(ExperimentalRichTextApi::class)
object Coil3ImageLoader: ImageLoader {
public object Coil3ImageLoader: ImageLoader {

@Composable
override fun load(model: Any): ImageData {
Expand Down
1 change: 1 addition & 0 deletions richeditor-compose/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ plugins {
}

kotlin {
explicitApi()
applyDefaultHierarchyTemplate()
androidTarget {
publishLibraryVariants("release")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ package com.mohamedrejeb.richeditor.annotation
AnnotationTarget.PROPERTY
)
@Retention(AnnotationRetention.BINARY)
annotation class ExperimentalRichTextApi
public annotation class ExperimentalRichTextApi
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ package com.mohamedrejeb.richeditor.annotation
AnnotationTarget.PROPERTY
)
@Retention(AnnotationRetention.BINARY)
annotation class InternalRichTextApi
public annotation class InternalRichTextApi
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import androidx.compose.runtime.Composable
import com.mohamedrejeb.richeditor.annotation.ExperimentalRichTextApi

@ExperimentalRichTextApi
object DefaultImageLoader: ImageLoader {
public object DefaultImageLoader: ImageLoader {

@Composable
override fun load(model: Any): ImageData? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.mohamedrejeb.richeditor.model
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Immutable
import androidx.compose.runtime.ProvidableCompositionLocal
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
Expand All @@ -11,20 +12,20 @@ import androidx.compose.ui.unit.Density
import com.mohamedrejeb.richeditor.annotation.ExperimentalRichTextApi

@ExperimentalRichTextApi
interface ImageLoader {
public interface ImageLoader {

@Composable
fun load(model: Any): ImageData?
public fun load(model: Any): ImageData?

}

@ExperimentalRichTextApi
val LocalImageLoader = staticCompositionLocalOf<ImageLoader> {
public val LocalImageLoader: ProvidableCompositionLocal<ImageLoader> = staticCompositionLocalOf {
DefaultImageLoader
}

@Immutable
data class ImageData(
public data class ImageData(
val painter: Painter,
val contentDescription: String? = "Image",
val alignment: Alignment = Alignment.CenterStart,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,31 @@ import com.mohamedrejeb.richeditor.utils.fastForEachIndexed
import com.mohamedrejeb.richeditor.utils.getBoundingBoxes

@ExperimentalRichTextApi
interface RichSpanStyle {
val spanStyle: (RichTextConfig) -> SpanStyle
public interface RichSpanStyle {
public val spanStyle: (RichTextConfig) -> SpanStyle

/**
* If true, the user can add new text in the edges of the span,
* For example, if the span is "Hello" and the user adds "World" in the end, the span will be "Hello World"
* If false, the user can't add new text in the edges of the span,
* For example, if the span is a "Hello" link and the user adds "World" in the end, the "World" will be added in a separate a span,
*/
val acceptNewTextInTheEdges: Boolean
public val acceptNewTextInTheEdges: Boolean

fun DrawScope.drawCustomStyle(
public fun DrawScope.drawCustomStyle(
layoutResult: TextLayoutResult,
textRange: TextRange,
richTextConfig: RichTextConfig,
topPadding: Float = 0f,
startPadding: Float = 0f,
)

fun AnnotatedString.Builder.appendCustomContent(
public fun AnnotatedString.Builder.appendCustomContent(
richTextState: RichTextState
) = this
): AnnotatedString.Builder = this

class Link(
val url: String,
public class Link(
public val url: String,
) : RichSpanStyle {
override val spanStyle: (RichTextConfig) -> SpanStyle = {
SpanStyle(
Expand All @@ -62,7 +62,7 @@ interface RichSpanStyle {
richTextConfig: RichTextConfig,
topPadding: Float,
startPadding: Float,
) = Unit
): Unit = Unit

override val acceptNewTextInTheEdges: Boolean =
false
Expand All @@ -81,7 +81,7 @@ interface RichSpanStyle {
}
}

class Code(
public class Code(
private val cornerRadius: TextUnit = 8.sp,
private val strokeWidth: TextUnit = 1.sp,
private val padding: TextPaddingValues = TextPaddingValues(horizontal = 2.sp, vertical = 2.sp)
Expand Down Expand Up @@ -161,10 +161,10 @@ interface RichSpanStyle {
}
}

class Image(
val model: Any,
val width: TextUnit,
val height: TextUnit,
public class Image(
public val model: Any,
public val width: TextUnit,
public val height: TextUnit,
) : RichSpanStyle {
private val id = "$model-$width-$height"

Expand All @@ -177,7 +177,7 @@ interface RichSpanStyle {
richTextConfig: RichTextConfig,
topPadding: Float,
startPadding: Float,
) = Unit
): Unit = Unit

override fun AnnotatedString.Builder.appendCustomContent(
richTextState: RichTextState
Expand Down Expand Up @@ -236,7 +236,7 @@ interface RichSpanStyle {
}
}

data object Default : RichSpanStyle {
public data object Default : RichSpanStyle {
override val spanStyle: (RichTextConfig) -> SpanStyle =
{ SpanStyle() }

Expand All @@ -246,13 +246,13 @@ interface RichSpanStyle {
richTextConfig: RichTextConfig,
topPadding: Float,
startPadding: Float,
) = Unit
): Unit = Unit

override val acceptNewTextInTheEdges: Boolean =
true
}

companion object {
public companion object {
internal val DefaultSpanStyle = SpanStyle()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,40 @@ package com.mohamedrejeb.richeditor.model
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.style.TextDecoration

class RichTextConfig internal constructor(
public class RichTextConfig internal constructor(
private val updateText: () -> Unit,
) {
var linkColor: Color = Color.Blue
public var linkColor: Color = Color.Blue
set(value) {
field = value
updateText()
}

var linkTextDecoration: TextDecoration = TextDecoration.Underline
public var linkTextDecoration: TextDecoration = TextDecoration.Underline
set(value) {
field = value
updateText()
}

var codeSpanColor: Color = Color.Unspecified
public var codeSpanColor: Color = Color.Unspecified
set(value) {
field = value
updateText()
}

var codeSpanBackgroundColor: Color = Color.Transparent
public var codeSpanBackgroundColor: Color = Color.Transparent
set(value) {
field = value
updateText()
}

var codeSpanStrokeColor: Color = Color.LightGray
public var codeSpanStrokeColor: Color = Color.LightGray
set(value) {
field = value
updateText()
}

var listIndent: Int = DefaultListIndent
public var listIndent: Int = DefaultListIndent
set(value) {
field = value
updateText()
Expand All @@ -49,7 +49,7 @@ class RichTextConfig internal constructor(
*
* Default is `true`.
*/
var preserveStyleOnEmptyLine: Boolean = true
public var preserveStyleOnEmptyLine: Boolean = true
}

internal const val DefaultListIndent = 38
Loading

0 comments on commit 80545e1

Please sign in to comment.