From 61ab0fa26dcd3c5ce6fd8a56722b19b6fb1a5050 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BAben=20Sousa?= Date: Sat, 18 Feb 2023 16:40:43 +0100 Subject: [PATCH 1/3] Update docs for 1.0.0-alpha05 --- README.MD | 7 +++---- docs/alignment.md | 2 +- docs/changelog.md | 13 ++++++++++++- docs/compose.md | 2 +- docs/getting_started.md | 6 +++--- docs/index.md | 12 ++++++------ mkdocs.yml | 4 ++-- 7 files changed, 28 insertions(+), 18 deletions(-) diff --git a/README.MD b/README.MD index dbc764f4..9070e5a7 100644 --- a/README.MD +++ b/README.MD @@ -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" ``` @@ -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 diff --git a/docs/alignment.md b/docs/alignment.md index 0fcfab8f..896ab9fe 100644 --- a/docs/alignment.md +++ b/docs/alignment.md @@ -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`. diff --git a/docs/changelog.md b/docs/changelog.md index e939fd9b..f23d9593 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -6,11 +6,22 @@ 2023-02-?? +#### 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. + #### 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)) + #### 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 diff --git a/docs/compose.md b/docs/compose.md index 32859b1c..5afbdebc 100644 --- a/docs/compose.md +++ b/docs/compose.md @@ -1,4 +1,4 @@ -# Compose +# Compose interoperability TBD diff --git a/docs/getting_started.md b/docs/getting_started.md index de6cd3d9..ca2dfc79 100644 --- a/docs/getting_started.md +++ b/docs/getting_started.md @@ -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 }}" ``` diff --git a/docs/index.md b/docs/index.md index 06355660..c28bd2ee 100644 --- a/docs/index.md +++ b/docs/index.md @@ -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` diff --git a/mkdocs.yml b/mkdocs.yml index 1c341e16..ef175f5e 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -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' @@ -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': From 55415c8db3ccd7d6709d131cebfb1b5321213121 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BAben=20Sousa?= Date: Sat, 18 Feb 2023 16:56:30 +0100 Subject: [PATCH 2/3] Update compose interop sample --- docs/compose.md | 77 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-) diff --git a/docs/compose.md b/docs/compose.md index 5afbdebc..3895f1fa 100644 --- a/docs/compose.md +++ b/docs/compose.md @@ -1,4 +1,79 @@ # 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>(Item.DIFF_CALLBACK) { + + override fun onCreateViewHolder( + parent: ViewGroup, + viewType: Int + ): DpadComposeViewHolder { + 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, 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. \ No newline at end of file From 7eb055712048d8207c421ed570c6a8662d6e2994 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BAben=20Sousa?= Date: Tue, 21 Feb 2023 00:24:21 +0100 Subject: [PATCH 3/3] Update changelog for new version --- docs/changelog.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/changelog.md b/docs/changelog.md index f23d9593..67479879 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -4,13 +4,17 @@ ### 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)) @@ -18,6 +22,7 @@ - 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