Skip to content

Commit

Permalink
Merge pull request #113 from rubensousa/docs
Browse files Browse the repository at this point in the history
Update docs
  • Loading branch information
rubensousa authored Feb 20, 2023
2 parents f44f0d2 + 7eb0557 commit 777fe82
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 20 deletions.
7 changes: 3 additions & 4 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ Add the following dependency to your app's `build.gradle`:

```groovy
implementation "com.rubensousa.dpadrecyclerview:dpadrecyclerview:$latestVersion"
```
You can also import the Espresso test helpers for your instrumented tests:
// Optional: If you want to use Compose together with DpadRecyclerView
implementation "com.rubensousa.dpadrecyclerview:dpadrecyclerview-compose:$latestVersion"
```groovy
// Optional: Espresso test helpers for your instrumented tests:
androidTestImplementation "com.rubensousa.dpadrecyclerview:dpadrecyclerview-testing:$latestVersion"
```

Expand All @@ -42,7 +42,6 @@ Check the official website for more information and recipes: https://rubensousa.
- Scrolling in secondary direction
- Disabling recycling of children
- Saving and restoring children states: clients can save and restore children on the appropriate RecyclerView.Adapter callbacks
- Touch event scrolling: on purpose, since `DpadRecyclerView` is only meant to react to focus changes
- `setChildrenVisibility`: clients can do this by iterating over the children

## Sample app
Expand Down
2 changes: 1 addition & 1 deletion docs/alignment.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ The `ChildAlignment` class will take care of calculating the anchor position for

Consider the following example for a **horizontal** `DpadRecyclerView`:

![Start alignment](../img/start_alignment.png)
![Start alignment](img/start_alignment.png)

The blue circle shows the keyline position defined by `ParentAlignment` and the green circles shows the anchor position of each child
defined by `ChildAlignment`.
Expand Down
20 changes: 18 additions & 2 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,29 @@

### 1.0.0-alpha05

2023-02-??
2023-02-21

#### New Features

- New `dpadrecyclerview-compose` module that contains `DpadComposeViewHolder` for Compose interoperability. Check [Compose interoperability](compose.md) for more information.
- Allow setting 0 max pending moves with `setSmoothScrollMaxPendingMoves(0)` to fully prevent unwanted scroll events.

#### API changes

- `offsetRatio` in `ParentAlignment`, `ChildAlignment` and `SubPositionAlignment` was renamed to `fraction`.

#### Bug fixes

- Fixed alignment issue when the first item has decoration ([#91](https://github.com/rubensousa/DpadRecyclerView/issues/91))
- Fixed alignment issue when `Edge.MIN` is used and there's a small number of adapter items ([#93](https://github.com/rubensousa/DpadRecyclerView/issues/93))
- Fixed focus changing to the incorrect span in a grid ([#96](https://github.com/rubensousa/DpadRecyclerView/issues/96))
- Fixed focus being lost when scrolling a grid and triggering layout passes at the same time ([#102](https://github.com/rubensousa/DpadRecyclerView/issues/102))
- Fixed `DpadRecyclerView` scrolling automatically to the current selected position when there's a touch event ([#104](https://github.com/rubensousa/DpadRecyclerView/issues/104))
- Fixed pending alignments in opposite direction not being ignored ([#106](https://github.com/rubensousa/DpadRecyclerView/issues/106))

#### Testing

- New `KeyEvents.click` to easily dispatch DPAD_CENTER events
- New `KeyEvents.click()` to easily dispatch click events in UI tests

### 1.0.0-alpha04

Expand Down
79 changes: 77 additions & 2 deletions docs/compose.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,79 @@
# Compose
# Compose interoperability

TBD
The `dpadrecyclerview-module` contains a `DpadComposeViewHolder`
that you can extend to easily render composables in your `RecyclerView`.

Example: `ItemComposable` that should render a text and different colors based on the focus state

```kotlin linenums="1"
@Composable
fun ItemComposable(
item: Int,
isFocused: Boolean,
modifier: Modifier = Modifier,
) {
val backgroundColor = if (isFocused) {
Color.White
} else {
Color.Black
}
val textColor = if (isFocused) {
Color.Black
} else {
Color.White
}
Box(
modifier = modifier.background(backgroundColor),
contentAlignment = Alignment.Center,
) {
Text(
text = item.toString(),
color = textColor,
fontSize = 35.sp
)
}
}
```

To render `ItemComposable` in a `RecyclerView.Adapter`, just use `DpadComposeViewHolder`:


```kotlin linenums="1"
class ComposeItemAdapter(
private val onItemClick: (Int) -> Unit
) : ListAdapter<Int, DpadComposeViewHolder<Int>>(Item.DIFF_CALLBACK) {

override fun onCreateViewHolder(
parent: ViewGroup,
viewType: Int
): DpadComposeViewHolder<Int> {
return DpadComposeViewHolder(
parent,
composable = { item, isFocused, _ ->
ItemComposable(
modifier = Modifier
.width(120.dp)
.aspectRatio(9 / 16f),
item = item,
isFocused = isFocused
)
},
onClick = onItemClick
)
}

override fun onBindViewHolder(holder: DpadComposeViewHolder<Int>, position: Int) {
holder.setItemState(getItem(position))
}

}

```

New compositions will be triggered whenever the following happens:

- New item is bound in `onBindViewHolder`
- Focus state changes
- Selection state changes

Check the sample on [Github](https://github.com/rubensousa/DpadRecyclerView/) for more examples that include simple animations.
6 changes: 3 additions & 3 deletions docs/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ Add the following dependency to your app's `build.gradle`:

```groovy
implementation "com.rubensousa.dpadrecyclerview:dpadrecyclerview:{{ dpadrecyclerview.version }}"
```
You can also import the Espresso test helpers for your instrumented tests:
// Optional: If you want to use Compose together with DpadRecyclerView
implementation "com.rubensousa.dpadrecyclerview:dpadrecyclerview-compose:{{ dpadrecyclerview.version }}"
```groovy
// Optional: Espresso test helpers for your instrumented tests:
androidTestImplementation "com.rubensousa.dpadrecyclerview:dpadrecyclerview-testing:{{ dpadrecyclerview.version }}"
```

Expand Down
12 changes: 6 additions & 6 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ Motivation for this library is available in my [blog](https://rubensousa.com/202

### Layout

- Supports grids with different span sizes
- Supports reverse layout
- Grids with different span sizes
- Reverse layout
- XML attributes for easier configuration

### Scrolling and focus

- Supports changing the alignment configuration smoothly
- Supports limiting the number of pending alignments
- Supports non smooth scroll changes
- Supports continuous and circular grid focus
- Changing the alignment configuration smoothly
- Limiting the number of pending alignments
- Non smooth scroll changes
- Continuous and circular grid focus

## Features missing from Leanback's `BaseGridView`

Expand Down
4 changes: 2 additions & 2 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ theme:

extra:
dpadrecyclerview:
version: '1.0.0-alpha04'
version: '1.0.0-alpha05'
social:
- icon: 'fontawesome/brands/github'
link: 'https://github.com/rubensousa/DpadRecyclerView'
Expand Down Expand Up @@ -56,7 +56,7 @@ nav:
- 'Migrating from Leanback': migrating_leanback.md
- 'Focus and selection': selection.md
- 'Alignment': alignment.md
#- 'Compose interoperability': compose.md
- 'Compose interoperability': compose.md
- 'Testing': testing.md
- 'XML attributes': xml.md
- 'Recipes':
Expand Down

0 comments on commit 777fe82

Please sign in to comment.