-
-
Notifications
You must be signed in to change notification settings - Fork 45
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 #196 from MohamedRejeb/0.6.x
Update Coil to 3.0.1
- Loading branch information
Showing
7 changed files
with
114 additions
and
50 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
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
50 changes: 50 additions & 0 deletions
50
sample/common/src/commonMain/kotlin/com.mohamedrejeb.calf.sample/coil/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,50 @@ | ||
package com.mohamedrejeb.calf.sample.coil | ||
|
||
import androidx.compose.runtime.Composable | ||
import coil3.ImageLoader | ||
import coil3.PlatformContext | ||
import coil3.annotation.ExperimentalCoilApi | ||
import coil3.memory.MemoryCache | ||
import coil3.network.ktor3.KtorNetworkFetcherFactory | ||
import coil3.request.crossfade | ||
import coil3.util.DebugLogger | ||
import com.mohamedrejeb.calf.picker.coil.KmpFileFetcher | ||
|
||
@OptIn(ExperimentalCoilApi::class) | ||
@Composable | ||
fun setSingletonImageLoaderFactory() { | ||
coil3.compose.setSingletonImageLoaderFactory { | ||
newImageLoader( | ||
context = it, | ||
debug = false, | ||
) | ||
} | ||
} | ||
|
||
private fun newImageLoader( | ||
context: PlatformContext, | ||
debug: Boolean = false, | ||
): ImageLoader { | ||
return ImageLoader.Builder(context) | ||
.components { | ||
add(KtorNetworkFetcherFactory()) | ||
|
||
// Add a custom fetcher for loading KmpFile objects. | ||
add(KmpFileFetcher.Factory()) | ||
} | ||
.memoryCache { | ||
MemoryCache.Builder() | ||
// Set the max size to 25% of the app's available memory. | ||
.maxSizePercent(context, percent = 0.25) | ||
.build() | ||
} | ||
// Show a short crossfade when loading images asynchronously. | ||
.crossfade(true) | ||
// Enable logging if this is a debug build. | ||
.apply { | ||
if (debug) { | ||
logger(DebugLogger()) | ||
} | ||
} | ||
.build() | ||
} |
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
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
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
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