Skip to content

Commit

Permalink
fix duplicate jvm class name, hide io dispatcher
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhirkevich Alexander Y authored and Zhirkevich Alexander Y committed Aug 28, 2024
1 parent 4fd8042 commit d9dc8ff
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private class DotLottieCompositionSpec(

@OptIn(InternalCompottieApi::class)
override suspend fun load(): LottieComposition {
return withContext(ioDispatcher()) {
return withContext(Compottie.ioDispatcher()) {
val fileSystem = FakeFileSystem()
val path = "lottie".toPath()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public fun DiskCache(
directory: Path = FileSystem.SYSTEM_TEMPORARY_DIRECTORY.resolve("compottie_disc_cache".toPath()),
fileSystem : FileSystem = defaultFileSystem(),
maxSizeBytes : Long = MB_250,
cleanupDispatcher : CoroutineDispatcher = ioDispatcher()
cleanupDispatcher : CoroutineDispatcher = Compottie.ioDispatcher()
) : DiskCache = RealDiskCache(
maxSize = maxSizeBytes,
directory = directory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ internal suspend fun networkLoad(
cacheStrategy: LottieCacheStrategy,
url: String
): Pair<Path?, ByteArray?> {
return withContext(ioDispatcher()) {
return withContext(Compottie.ioDispatcher()) {
NetworkLock.withLock(url) {
try {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
@file:JvmName("CoreNetworkAssetsManager")


package io.github.alexzhirkevich.compottie

import androidx.compose.runtime.Stable
import io.github.alexzhirkevich.compottie.assets.ImageRepresentable
import io.github.alexzhirkevich.compottie.assets.LottieAssetsManager
import io.github.alexzhirkevich.compottie.assets.LottieImageSpec
import kotlin.jvm.JvmName

/**
* Asset manager that load images from web using [request] .
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
@file:JvmName("CoreNetworkFontManager")


package io.github.alexzhirkevich.compottie

import androidx.compose.runtime.Stable
import androidx.compose.ui.text.font.Font
import io.github.alexzhirkevich.compottie.assets.LottieFontManager
import io.github.alexzhirkevich.compottie.assets.LottieFontSpec
import okio.Path
import kotlin.jvm.JvmName

/**
* Font manager that loads fonts from the web using [request].
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
@file:JvmName("CoreUrlCompositionSpec")

package io.github.alexzhirkevich.compottie

import androidx.compose.runtime.Stable
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import kotlin.jvm.JvmName

/**
* [LottieComposition] from network [url]
Expand Down Expand Up @@ -50,7 +53,7 @@ private class NetworkCompositionSpec(

@OptIn(InternalCompottieApi::class)
override suspend fun load(): LottieComposition {
return withContext(ioDispatcher()) {
return withContext(Compottie.ioDispatcher()) {

val (_, bytes) = networkLoad(request, cacheStrategy, url)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.github.alexzhirkevich.compottie

import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers

@InternalCompottieApi
public expect fun ioDispatcher() : CoroutineDispatcher
public expect fun Compottie.ioDispatcher() : CoroutineDispatcher
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public fun rememberLottieComposition(

LaunchedEffect(result) {
try {
val composition = withContext(ioDispatcher()) {
val composition = withContext(Compottie.ioDispatcher()) {
val specInstance = updatedSpec()
val k = when (key) {
UnspecifiedCompositionKey -> specInstance.key
Expand Down Expand Up @@ -105,7 +105,7 @@ public fun rememberLottieComposition(

LaunchedEffect(result) {
try {
val composition = withContext(ioDispatcher()) {
val composition = withContext(Compottie.ioDispatcher()) {
spec.load()
}
result.complete(composition)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private value class JsonStringImpl(

@OptIn(InternalCompottieApi::class)
override suspend fun load(): LottieComposition {
return withContext(ioDispatcher()) {
return withContext(Compottie.ioDispatcher()) {
LottieComposition.parse(jsonString)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ public fun rememberLottiePainter(
dp != null
) {
if (composition != null) {
val assets = async(ioDispatcher()) {
val assets = async(Compottie.ioDispatcher()) {
composition.loadAssets(assetsManager ?: EmptyAssetsManager, true)
}
val fonts = async(ioDispatcher()) {
val fonts = async(Compottie.ioDispatcher()) {
composition.loadFonts(fontManager ?: EmptyFontManager)
}

Expand Down Expand Up @@ -222,12 +222,12 @@ public suspend fun LottiePainter(
enableMergePaths: Boolean = false,
enableExpressions: Boolean = true,
) : Painter = coroutineScope {
val assets = async(ioDispatcher()) {
val assets = async(Compottie.ioDispatcher()) {
assetsManager?.let {
composition.loadAssets(it, true)
}
}
val fonts = async(ioDispatcher()) {
val fonts = async(Compottie.ioDispatcher()) {
fontManager?.let {
composition.loadFonts(it)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.IO

public actual fun ioDispatcher() : CoroutineDispatcher = Dispatchers.IO
public actual fun Compottie.ioDispatcher() : CoroutineDispatcher = Dispatchers.IO

Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ package io.github.alexzhirkevich.compottie
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers

public actual fun ioDispatcher() : CoroutineDispatcher = Dispatchers.Default
public actual fun Compottie.ioDispatcher() : CoroutineDispatcher = Dispatchers.Default

0 comments on commit d9dc8ff

Please sign in to comment.