Last active
October 15, 2020 04:44
-
-
Save colinrtwhite/2b5a1a7dc353c0cf6c5a9ebeba456458 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// To load an image into an ImageView, use the load extension function. | |
imageView.load("https://www.example.com/image.jpg") | |
// Coil supports urls, uris, resources, drawables, bitmaps, files, and more. | |
imageView.load(R.drawable.image) | |
imageView.load(File("/path/to/image.jpg")) | |
imageView.load("content://com.android.externalstorage/image.jpg") | |
// Requests can be configured with an optional trailing lambda. | |
imageView.load("https://www.example.com/image.jpg") { | |
crossfade(true) | |
placeholder(R.drawable.image) | |
transformations(CircleCropTransformation()) | |
} | |
// Internally, ImageView.load() is powered by the singleton ImageLoader. | |
val imageLoader = context.imageLoader | |
// Optionally, you can create and inject your own instance(s). | |
val imageLoader = ImageLoader(context) | |
// Enqueue an ImageRequest to load the image asynchronously into a custom target. | |
val request = ImageRequest.Builder(context) | |
.data("https://www.example.com/image.jpg") | |
.target { drawable -> | |
// Handle the successful result. | |
} | |
.build() | |
imageLoader.enqueue(request) | |
// Execute an ImageRequest to suspend and return the drawable. | |
val request = ImageRequest.Builder(context) | |
.data("https://www.example.com/image.jpg") | |
.build() | |
val drawable = imageLoader.execute(request).drawable |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment