Skip to content

Commit

Permalink
explicit api, version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
alexzhirkevich committed Jul 9, 2024
1 parent 30b485a commit 4ef0218
Show file tree
Hide file tree
Showing 71 changed files with 297 additions and 334 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ private var _useStableWasmMemoryManagement : Boolean = false
* It is disabled by default. Turn this on if you have problems with dotLottie decompression on wasm
* */
@ExperimentalCompottieApi
var Compottie.useStableWasmMemoryManagement by ::_useStableWasmMemoryManagement
public var Compottie.useStableWasmMemoryManagement by ::_useStableWasmMemoryManagement

/**
* [LottieComposition] from a dotLottie zip archive.
Expand All @@ -27,7 +27,7 @@ var Compottie.useStableWasmMemoryManagement by ::_useStableWasmMemoryManagement
* @param animationId animation id (if dotLottie contains multiple animations)
* */
@Stable
fun LottieCompositionSpec.Companion.DotLottie(
public fun LottieCompositionSpec.Companion.DotLottie(
archive: ByteArray,
animationId: String? = null
) : LottieCompositionSpec = DotLottieCompositionSpec(archive, animationId)
Expand Down Expand Up @@ -113,7 +113,7 @@ private class DotLottieCompositionSpec(
}

@InternalCompottieApi
suspend fun ByteArray.decodeToLottieComposition(
public suspend fun ByteArray.decodeToLottieComposition(
format: LottieAnimationFormat,
) : LottieComposition {
return when (format) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import kotlin.random.Random
import kotlin.random.nextULong

@InternalCompottieApi
class UnsupportedFileSystemException : CompottieException("File system is not unsupported")
public class UnsupportedFileSystemException : CompottieException("File system is not unsupported")

@InternalCompottieApi
expect fun defaultFileSystem() : FileSystem
public expect fun defaultFileSystem() : FileSystem

@InternalCompottieApi
fun Closeable.closeQuietly() {
public fun Closeable.closeQuietly() {
try {
close()
} catch (e: RuntimeException) {
Expand All @@ -24,7 +24,7 @@ fun Closeable.closeQuietly() {
}

@InternalCompottieApi
fun FileSystem.createFile(file: Path, mustCreate: Boolean = false) {
public fun FileSystem.createFile(file: Path, mustCreate: Boolean = false) {
if (mustCreate) {
sink(file, mustCreate = true).closeQuietly()
} else if (!exists(file)) {
Expand All @@ -33,7 +33,7 @@ fun FileSystem.createFile(file: Path, mustCreate: Boolean = false) {
}

@InternalCompottieApi
fun FileSystem.createTempFile(): Path {
public fun FileSystem.createTempFile(): Path {
var tempFile: Path
do {
tempFile = FileSystem.SYSTEM_TEMPORARY_DIRECTORY / "tmp_${Random.nextULong()}"
Expand All @@ -43,7 +43,7 @@ fun FileSystem.createTempFile(): Path {
}

@InternalCompottieApi
fun FileSystem.deleteContents(directory: Path) {
public fun FileSystem.deleteContents(directory: Path) {
var exception: IOException? = null
val files = try {
list(directory)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import okio.Path.Companion.toPath
import okio.SYSTEM

@InternalCompottieApi
actual fun defaultFileSystem() : FileSystem = FileSystem.SYSTEM
public actual fun defaultFileSystem() : FileSystem = FileSystem.SYSTEM
//
//actual typealias FilePath = String
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import okio.Sink
import okio.Source

@InternalCompottieApi
actual fun defaultFileSystem() : FileSystem = ThrowingFileSystem
internal actual fun defaultFileSystem() : FileSystem = ThrowingFileSystem

private object ThrowingFileSystem : FileSystem() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ internal val DefaultHttpClient by lazy {
*
* See [HttpClient.prepareRequest], [HttpClient.prepareGet],
* */
typealias NetworkRequest = suspend (HttpClient, Url) -> HttpStatement
public typealias NetworkRequest = suspend (HttpClient, Url) -> HttpStatement

internal val GetRequest : NetworkRequest = { c, u -> c.prepareGet(u) }
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ import kotlin.js.JsName
* An LRU cache of files.
*/
@Stable
interface DiskCache {
public interface DiskCache {

/** The current size of the cache in bytes. */
val size: Long
public val size: Long

/** The maximum size of the cache in bytes. */
val maxSize: Long
public val maxSize: Long

/** The directory that contains the cache's files. */
val directory: Path
public val directory: Path

/** The file system that contains the cache's files. */
val fileSystem: FileSystem
public val fileSystem: FileSystem

/**
* Read the entry associated with [key].
Expand All @@ -33,7 +33,7 @@ interface DiskCache {
* finished reading the snapshot. An open snapshot prevents opening a new [Editor] or deleting
* the entry on disk.
*/
fun openSnapshot(key: String): Snapshot?
public fun openSnapshot(key: String): Snapshot?

/**
* Write to the entry associated with [key].
Expand All @@ -42,44 +42,44 @@ interface DiskCache {
* [Editor.abort] to complete the edit. An open editor prevents opening a new [Snapshot],
* opening a new [Editor], or deleting the entry on disk.
*/
fun openEditor(key: String): Editor?
public fun openEditor(key: String): Editor?

/**
* Delete the entry referenced by [key].
*
* @return 'true' if [key] was removed successfully. Else, return 'false'.
*/
fun remove(key: String): Boolean
public fun remove(key: String): Boolean

/**
* Delete all entries in the disk cache.
*/
fun clear()
public fun clear()

/**
* Close any open snapshots, abort all in-progress edits, and close any open system resources.
*/
fun shutdown()
public fun shutdown()

/**
* A snapshot of the values for an entry.
*
* IMPORTANT: You must **only read** [metadata] or [data]. Mutating either file can corrupt the
* disk cache. To modify the contents of those files, use [openEditor].
*/
interface Snapshot : Closeable {
public interface Snapshot : Closeable {

/** Get the metadata file path for this entry. */
val metadata: Path
public val metadata: Path

/** Get the data file path for this entry. */
val data: Path
public val data: Path

/** Close the snapshot to allow editing. */
override fun close()

/** Close the snapshot and call [openEditor] for this entry atomically. */
fun closeAndOpenEditor(): Editor?
public fun closeAndOpenEditor(): Editor?
}

/**
Expand All @@ -91,22 +91,22 @@ interface DiskCache {
* IMPORTANT: You must **only read or modify the contents** of [metadata] or [data].
* Renaming, locking, or other mutating file operations can corrupt the disk cache.
*/
interface Editor {
public interface Editor {

/** Get the metadata file path for this entry. */
val metadata: Path
public val metadata: Path

/** Get the data file path for this entry. */
val data: Path
public val data: Path

/** Commit the edit so the changes are visible to readers. */
fun commit()
public fun commit()

/** Commit the write and call [openSnapshot] for this entry atomically. */
fun commitAndOpenSnapshot(): Snapshot?
public fun commitAndOpenSnapshot(): Snapshot?

/** Abort the edit. Any written data will be discarded. */
fun abort()
public fun abort()
}

}
Expand All @@ -118,7 +118,7 @@ internal val SharedDiskCache by lazy {
@OptIn(InternalCompottieApi::class)
@JsName("LottieDiskCache")
@Stable
fun DiskCache(
public fun DiskCache(
directory: Path = FileSystem.SYSTEM_TEMPORARY_DIRECTORY.resolve("compottie_disc_cache".toPath()),
fileSystem : FileSystem = defaultFileSystem(),
maxSizeBytes : Long = MB_250,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import okio.Path
import okio.use

@Stable
class DiskCacheStrategy(
public class DiskCacheStrategy(
private val diskCache: DiskCache = SharedDiskCache
) : LottieCacheStrategy {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,32 @@ import androidx.compose.runtime.Stable
import okio.Path

@Stable
interface LottieCacheStrategy {
public interface LottieCacheStrategy {

/**
* Returns path to the cached file that was downloaded from [url]
* */
fun path(url: String) : Path?
public fun path(url: String) : Path?

/**
* Saves [bytes] downloaded from [url] to cache.
* Returns path to the saved file
* */
suspend fun save(
public suspend fun save(
url: String,
bytes: ByteArray
): Path?

/**
* Loads bytes downloaded from [url] from cache
* */
suspend fun load(
public suspend fun load(
url: String
): ByteArray?

/**
* Clear all ache
* */
suspend fun clear()
public suspend fun clear()
}

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import io.ktor.client.HttpClient
* @param cacheStrategy caching strategy. Caching to system temp dir by default
* */
@Stable
fun NetworkAssetsManager(
public fun NetworkAssetsManager(
client: HttpClient = DefaultHttpClient,
request : NetworkRequest = GetRequest,
cacheStrategy: LottieCacheStrategy = DiskCacheStrategy.Instance,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import okio.Path
* @param cacheStrategy caching strategy. Caching to system temp dir by default
* */
@Stable
fun NetworkFontManager(
public fun NetworkFontManager(
client: HttpClient = DefaultHttpClient,
request : NetworkRequest = GetRequest,
cacheStrategy: LottieCacheStrategy = DiskCacheStrategy.Instance,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import kotlinx.coroutines.withContext
* URL assets will be automatically prepared with [NetworkAssetsManager]
* */
@Stable
fun LottieCompositionSpec.Companion.Url(
public fun LottieCompositionSpec.Companion.Url(
url : String,
format: LottieAnimationFormat = LottieAnimationFormat.Undefined,
client: HttpClient = DefaultHttpClient,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import org.jetbrains.compose.resources.MissingResourceException
* */
@Composable
@ExperimentalCompottieApi
fun rememberResourcesAssetsManager(
public fun rememberResourcesAssetsManager(
directory : String = "files",
readBytes : suspend (path : String) -> ByteArray,
) : LottieAssetsManager {
Expand All @@ -53,7 +53,7 @@ fun rememberResourcesAssetsManager(
* */
@ExperimentalCompottieApi
@Stable
fun ResourcesAssetsManager(
public fun ResourcesAssetsManager(
directory : String = "files",
readBytes : suspend (path : String) -> ByteArray,
) : LottieAssetsManager = ResourcesAssetsManagerImpl(directory, readBytes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import org.jetbrains.compose.resources.rememberResourceEnvironment
@OptIn(ExperimentalResourceApi::class)
@Composable
@ExperimentalCompottieApi
fun rememberResourcesFontManager(
public fun rememberResourcesFontManager(
font : (LottieFontSpec) -> FontResource?
) : LottieFontManager {
val factory by rememberUpdatedState(font)
Expand Down Expand Up @@ -50,7 +50,7 @@ fun rememberResourcesFontManager(
*
* Warning: this manager uses internal Compose API on Android and should be considered unstable
* */
fun ResourcesFontManager(
public fun ResourcesFontManager(
environment: ResourceEnvironment = getSystemResourceEnvironment(),
resource : (LottieFontSpec) -> FontResource?
) : LottieFontManager = ResourcesFontManagerImpl(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import android.content.Context
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext

actual typealias LottieContext = Context
public actual typealias LottieContext = Context

@Composable
actual fun currentLottieContext() : LottieContext {
public actual fun currentLottieContext() : LottieContext {
return LocalContext.current
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ package io.github.alexzhirkevich.compottie
import io.github.alexzhirkevich.compottie.internal.Animation
import io.github.alexzhirkevich.compottie.internal.LottieJson

object Compottie {
public object Compottie {

const val IterateForever = Int.MAX_VALUE
public const val IterateForever : Int = Int.MAX_VALUE

/**
* Logger used to inform about various events, errors, unsupported features, etc.
*
* Default instance uses stdout / stderr.
* You can set it to null for production
* */
var logger : LottieLogger? = LottieLogger.Default
public var logger : LottieLogger? = LottieLogger.Default

/**
* Limit gradient shaders cache size.
Expand All @@ -33,24 +33,24 @@ object Compottie {
* All running animations will shrink their shader cache size.
* */
@ExperimentalCompottieApi
var shaderCacheLimit : Int = 1000
public var shaderCacheLimit : Int = 1000

/**
* Limit the number of in-memory cached lottie compositions.
* */
@ExperimentalCompottieApi
var compositionCacheLimit : Int = 15
public var compositionCacheLimit : Int = 15

/**
* Warmup JSON parser. The first animation parsing will be much faster
* */
@ExperimentalCompottieApi
fun warmup() {
public fun warmup() {
LottieJson.decodeFromString<Animation>(warmupAnim)
}

@InternalCompottieApi
var context : LottieContext? = null
public var context : LottieContext? = null
internal set
}

Expand Down
Loading

0 comments on commit 4ef0218

Please sign in to comment.