Skip to content

Commit

Permalink
Merge branch 'main' into snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbanes committed Sep 30, 2020
2 parents 030b475 + befb514 commit c7cac61
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 41 deletions.
8 changes: 1 addition & 7 deletions .gitignore
Expand Up @@ -34,13 +34,7 @@ org.eclipse.buildship.core.prefs

# Temporary API docs
docs/api
# These are generated from files in the root folder
docs/index.md
docs/contributing.md
docs/coil.md
docs/coil/
docs/picasso.md
docs/picasso/
# Mkdocs temporary serving folder
docs-gen
site
*.bak
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -2,8 +2,8 @@

Accompanist is a group of libraries that contains some utilities which I've found myself copying around projects which use [Jetpack Compose][compose]. Currently, it contains:

🖼️ [Coil image loading composables](./coil/README.md)
🖼️ [Picasso image loading composables](./picasso/README.md)
- 🖼️ [Coil image loading composables](./coil/README.md)
- 🖼️ [Picasso image loading composables](./picasso/README.md)

[Jetpack Compose][compose] is a fast-moving project and I'll be updating these libraries to match the
latest tagged release as quickly as possible. Each [release listing](https://github.com/chrisbanes/accompanist/releases) will outline what version of Compose libraries it depends on.
Expand Down
18 changes: 10 additions & 8 deletions coil/README.md
Expand Up @@ -4,6 +4,7 @@

This library brings easy-to-use composable which can fetch and display images from external sources, such as network, using the [Coil][coil] image loading library.

<img src="https://coil-kt.github.io/coil/logo.svg" width="480" alt="Coil logo">

## `CoilImage()`

Expand All @@ -13,28 +14,28 @@ The simplest usage is like so:

```kotlin
CoilImage(
data = "https://loremflickr.com/300/300"
data = "https://picsum.photos/300/300"
)
```

This loads the `data` passed in with [Coil][coil], and then displays the resulting image using the standard `Image` composable.

There is also a version of this function which accepts a Coil [`ImageRequest`](https://coil-kt.github.io/coil/image_requests/), allowing full customization of the request. This allows usage of things like (but not limited to) transformations:
You can also customize the Coil [`ImageRequest`](https://coil-kt.github.io/coil/image_requests/) through the `requestBuilder` parameter. This allows usage of things like (but not limited to) transformations:

```kotlin
CoilImage(
request = ImageRequest.Builder(ContextAmbient.current)
.data("https://loremflickr.com/300/300")
.transformations(CircleCropTransformation())
.build()
data = "https://picsum.photos/300/300",
requestBuilder = {
transformations(CircleCropTransformation())
},
)
```

It also provides optional content 'slots', allowing you to provide custom content to be displayed when the request is loading, and/or if the image request failed:

``` kotlin
CoilImage(
data = "https://loremflickr.com/300/300",
data = "https://picsum.photos/300/300",
loading = {
Box(Modifier.matchParentSize()) {
CircularProgressIndicator(Modifier.align(Alignment.Center))
Expand Down Expand Up @@ -71,7 +72,7 @@ If you need more control over the animation, or you want to provide custom layou

``` kotlin
CoilImage(
data = "https://random.image",
data = "https://picsum.photos/300/300",
) { imageState ->
when (imageState) {
is ImageLoadState.Success -> {
Expand All @@ -86,6 +87,7 @@ CoilImage(
ImageLoadState.Empty -> /* TODO */
}
}
```

## GIFs

Expand Down
44 changes: 26 additions & 18 deletions generate_docs.sh
@@ -1,5 +1,9 @@
#!/bin/sh

DOCS_ROOT=docs-gen

mkdir $DOCS_ROOT

# Work around Dokka failing to link against external links generated from 'gfm' sources.
wget -O package-list-coil-base https://coil-kt.github.io/coil/api/coil-base/package-list
sed -i.bak 's/$dokka.linkExtension:md/$dokka.linkExtension:html/g' package-list-coil-base
Expand All @@ -9,36 +13,40 @@ rm -r docs/api
# Build the docs with dokka
./gradlew clean dokkaGfm

# Clean up the temp Coil package list
rm package-list-coil-base

cp README.md docs/index.md
cp CONTRIBUTING.md docs/contributing.md
cp images/social.png docs/header.png
# Copy over any static + API docs to our $DOCS_ROOT
cp -r docs/ $DOCS_ROOT/

cp README.md $DOCS_ROOT/index.md
cp CONTRIBUTING.md $DOCS_ROOT/contributing.md
cp images/social.png $DOCS_ROOT/header.png

sed -i.bak 's/CONTRIBUTING.md/contributing/' docs/index.md
sed -i.bak 's/coil\/README.md/coil/' docs/index.md
sed -i.bak 's/images\/social.png/header.png/' docs/index.md
sed -i.bak 's/CONTRIBUTING.md/contributing/' $DOCS_ROOT/index.md
sed -i.bak 's/coil\/README.md/coil/' $DOCS_ROOT/index.md
sed -i.bak 's/images\/social.png/header.png/' $DOCS_ROOT/index.md

cp coil/README.md docs/coil.md
mkdir -p docs/coil
cp coil/images/crossfade.gif docs/coil/crossfade.gif
sed -i.bak 's/images\/crossfade.gif/crossfade.gif/' docs/coil.md
cp coil/README.md $DOCS_ROOT/coil.md
mkdir -p $DOCS_ROOT/coil
cp coil/images/crossfade.gif $DOCS_ROOT/coil/crossfade.gif
sed -i.bak 's/images\/crossfade.gif/crossfade.gif/' $DOCS_ROOT/coil.md

cp picasso/README.md docs/picasso.md
mkdir -p docs/picasso
cp picasso/images/crossfade.gif docs/picasso/crossfade.gif
sed -i.bak 's/images\/crossfade.gif/crossfade.gif/' docs/picasso.md
cp picasso/README.md $DOCS_ROOT/picasso.md
mkdir -p $DOCS_ROOT/picasso
cp picasso/images/crossfade.gif $DOCS_ROOT/picasso/crossfade.gif
sed -i.bak 's/images\/crossfade.gif/crossfade.gif/' $DOCS_ROOT/picasso.md

# Convert docs/xxx.md links to just xxx/
sed -i.bak 's/docs\/\([a-zA-Z-]*\).md/\1/' docs/index.md
sed -i.bak 's/docs\/\([a-zA-Z-]*\).md/\1/' $DOCS_ROOT/index.md

#########################
# Tidy up Dokka output
#########################

# Remove all of the line breaks in the docs
find docs/api/ -name '*.md' -exec sed -i.bak 's/<br><br>//g' {} \;
find $DOCS_ROOT/api/ -name '*.md' -exec sed -i.bak 's/<br><br>//g' {} \;
# Remove the random androidJvm headers
find docs/api/ -name '*.md' -exec sed -i.bak 's/\[*androidJvm\]*//g' {} \;
find $DOCS_ROOT/api/ -name '*.md' -exec sed -i.bak 's/\[*androidJvm\]*//g' {} \;
# Remove the 'Brief description' headers
find docs/api/ -name '*.md' -exec sed -i.bak 's/Brief description//g' {} \;
find $DOCS_ROOT/api/ -name '*.md' -exec sed -i.bak 's/Brief description//g' {} \;
2 changes: 2 additions & 0 deletions mkdocs.yml
Expand Up @@ -5,6 +5,8 @@ site_author: 'Chris Banes'
site_url: 'https://chrisbanes.github.io/accompanist/'
remote_branch: gh-pages

docs_dir: docs-gen

# Repository
repo_name: 'Accompanist'
repo_url: 'https://github.com/chrisbanes/accompanist'
Expand Down
14 changes: 8 additions & 6 deletions picasso/README.md
Expand Up @@ -4,25 +4,27 @@

This library brings easy-to-use composable which can fetch and display images from external sources, such as network, using the [Picasso][picasso] image loading library.

<img src="https://raw.githubusercontent.com/square/picasso/master/website/static/sample.png" width="400" alt="Picasso sample screenshot">

## `PicassoImage()`

The primary API is via the `PicassoImage()` functions. There are a 2 function versions available.
The primary API is via the `PicassoImage()` functions. There are multiple function versions available.

The simplest usage is like so:

```kotlin
PicassoImage(
data = "https://loremflickr.com/300/300"
data = "https://picsum.photos/300/300"
)
```

This loads the `data` passed in with [Picasso][Picasso], and then displays the resulting image using the standard `Image` composable.

There is also a version of this function which accepts a Picasso [`ImageRequest`](https://Picasso-kt.github.io/Picasso/image_requests/), allowing full customization of the request. This allows usage of things like (but not limited to) transformations:
You can also customize the Coil Picasso [`RequestCreator`](https://square.github.io/picasso/2.x/picasso/com/squareup/picasso/RequestCreator.html) through the `requestBuilder` parameter. This allows usage of things like (but not limited to) transformations:

```kotlin
PicassoImage(
data = "https://loremflickr.com/300/300",
data = "https://picsum.photos/300/300",
requestBuilder = {
rotate(90f)
}
Expand All @@ -33,7 +35,7 @@ It also provides optional content 'slots', allowing you to provide custom conten

``` kotlin
PicassoImage(
data = "https://loremflickr.com/300/300",
data = "https://picsum.photos/300/300",
loading = {
Box(Modifier.matchParentSize()) {
CircularProgressIndicator(Modifier.align(Alignment.Center))
Expand Down Expand Up @@ -70,7 +72,7 @@ If you need more control over the animation, or you want to provide custom layou

``` kotlin
PicassoImage(
data = "https://random.image",
data = "https://picsum.photos/300/300",
) { imageState ->
when (imageState) {
is ImageLoadState.Success -> {
Expand Down
Expand Up @@ -40,6 +40,7 @@ import androidx.ui.test.onNodeWithTag
import androidx.ui.test.onNodeWithText
import com.google.common.truth.Truth.assertThat
import com.squareup.picasso.MemoryPolicy
import com.squareup.picasso.NetworkPolicy
import dev.chrisbanes.accompanist.imageloading.ImageLoadState
import dev.chrisbanes.accompanist.picasso.test.R
import kotlinx.coroutines.ExperimentalCoroutinesApi
Expand Down Expand Up @@ -279,6 +280,7 @@ class PicassoTest {
// Disable any caches. If the item is in the cache, the fetch is
// synchronous which means the Loading state is skipped
requestBuilder = {
networkPolicy(NetworkPolicy.NO_CACHE)
memoryPolicy(MemoryPolicy.NO_CACHE)
},
onRequestCompleted = { latch.countDown() }
Expand Down Expand Up @@ -310,6 +312,7 @@ class PicassoTest {
// Disable any caches. If the item is in the cache, the fetch is
// synchronous which means the Loading state is skipped
requestBuilder = {
networkPolicy(NetworkPolicy.NO_CACHE)
memoryPolicy(MemoryPolicy.NO_CACHE)
},
onRequestCompleted = { latch.countDown() }
Expand Down Expand Up @@ -371,6 +374,7 @@ class PicassoTest {
// Disable any caches. If the item is in the cache, the fetch is
// synchronous which means the Loading state is skipped
requestBuilder = {
networkPolicy(NetworkPolicy.NO_CACHE)
memoryPolicy(MemoryPolicy.NO_CACHE)
},
loading = { Text(text = "Loading") },
Expand Down

0 comments on commit c7cac61

Please sign in to comment.