-
-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #305 from MohamedRejeb/1.x
Add Image support to RichText
- Loading branch information
Showing
26 changed files
with
1,376 additions
and
720 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl | ||
|
||
plugins { | ||
alias(libs.plugins.kotlinMultiplatform) | ||
alias(libs.plugins.composeMultiplatform) | ||
alias(libs.plugins.androidLibrary) | ||
id("module.publication") | ||
} | ||
|
||
kotlin { | ||
applyDefaultHierarchyTemplate() | ||
androidTarget { | ||
publishLibraryVariants("release") | ||
compilations.all { | ||
kotlinOptions { | ||
jvmTarget = "1.8" | ||
} | ||
} | ||
} | ||
jvm("desktop") { | ||
jvmToolchain(11) | ||
} | ||
js(IR) { | ||
browser() | ||
} | ||
@OptIn(ExperimentalWasmDsl::class) | ||
wasmJs { | ||
browser { | ||
testTask { | ||
enabled = false | ||
} | ||
} | ||
} | ||
iosX64() | ||
iosArm64() | ||
iosSimulatorArm64() | ||
|
||
sourceSets.commonMain.dependencies { | ||
implementation(projects.richeditorCompose) | ||
|
||
implementation(compose.ui) | ||
implementation(compose.foundation) | ||
|
||
implementation(libs.coil.compose) | ||
} | ||
|
||
sourceSets.commonTest.dependencies { | ||
implementation(kotlin("test")) | ||
} | ||
} | ||
|
||
android { | ||
namespace = "com.mohamedrejeb.richeditor.compose.coil" | ||
compileSdk = libs.versions.android.compileSdk.get().toInt() | ||
|
||
defaultConfig { | ||
minSdk = libs.versions.android.minSdk.get().toInt() | ||
} | ||
|
||
compileOptions { | ||
sourceCompatibility = JavaVersion.VERSION_1_8 | ||
targetCompatibility = JavaVersion.VERSION_1_8 | ||
} | ||
kotlin { | ||
jvmToolchain(8) | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...compose-coil3/src/commonMain/kotlin/com/mohamedrejeb/richeditor/coil3/Coil3ImageLoader.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.mohamedrejeb.richeditor.coil3 | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import coil3.compose.AsyncImagePainter | ||
import coil3.compose.rememberAsyncImagePainter | ||
import com.mohamedrejeb.richeditor.annotation.ExperimentalRichTextApi | ||
import com.mohamedrejeb.richeditor.model.ImageData | ||
import com.mohamedrejeb.richeditor.model.ImageLoader | ||
|
||
@OptIn(ExperimentalRichTextApi::class) | ||
object Coil3ImageLoader: ImageLoader { | ||
|
||
@Composable | ||
override fun load(model: Any): ImageData { | ||
val painter = rememberAsyncImagePainter(model = model) | ||
|
||
return ImageData( | ||
painter = painter | ||
) | ||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
...tor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/model/DefaultImageLoader.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.mohamedrejeb.richeditor.model | ||
|
||
import androidx.compose.runtime.Composable | ||
import com.mohamedrejeb.richeditor.annotation.ExperimentalRichTextApi | ||
|
||
@ExperimentalRichTextApi | ||
object DefaultImageLoader: ImageLoader { | ||
|
||
@Composable | ||
override fun load(model: Any): ImageData? = null | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/model/ImageLoader.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
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.staticCompositionLocalOf | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.painter.Painter | ||
import androidx.compose.ui.unit.Density | ||
import com.mohamedrejeb.richeditor.annotation.ExperimentalRichTextApi | ||
|
||
@ExperimentalRichTextApi | ||
interface ImageLoader { | ||
|
||
@Composable | ||
fun load(model: Any): ImageData? | ||
|
||
} | ||
|
||
@ExperimentalRichTextApi | ||
val LocalImageLoader = staticCompositionLocalOf<ImageLoader> { | ||
DefaultImageLoader | ||
} | ||
|
||
@Immutable | ||
data class ImageData( | ||
val painter: Painter, | ||
val contentDescription: String? = "Image", | ||
val alignment: Alignment = Alignment.CenterStart, | ||
val modifier: Modifier = Modifier.fillMaxWidth() | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.