Giter VIP home page Giter VIP logo

dpadrecyclerview's Introduction

DpadRecyclerView

A RecyclerView built for Android TV as a replacement for Leanback's BaseGridView.

See the project website for more information: https://rubensousa.github.io/DpadRecyclerView

Why should you use this library?

  1. Leanback hasn't received any significant update for years
  2. Compose support for TV is still in its early stages
  3. RecyclerView is stable and works well with Compose
  4. You need to maintain an existing TV app and wish to introduce Compose in an incremental way
  5. Contains useful Espresso testing helpers for your TV UI tests
  6. More feature complete:
Feature DpadRecyclerView Leanback Compose TV
Custom scrolling speeds
Edge alignment preference
Sub position selections
Fading edges
Alignment listener
Grids with uneven span sizes
Extra layout space
Prefetching upcoming items
Reverse layout
Testing library
Scrollbars
Drag and Drop
Infinite layout with loop
Smooth alignment changes
Child focus observer
Circular and continuous focus
Throttling scroll events
Scrolling without animation
Scrolling in secondary directory

Background story for this library is available in my blog in case you're interested.

Check the sample app for a complete example of integration of this library

sample

Getting started

Add the following dependency to your app's build.gradle:

implementation "com.rubensousa.dpadrecyclerview:dpadrecyclerview:$latestVersion"

// Recommended: To use Compose together with DpadRecyclerView
implementation "com.rubensousa.dpadrecyclerview:dpadrecyclerview-compose:$latestVersion"

// Optional: Espresso test helpers for your instrumented tests:
androidTestImplementation "com.rubensousa.dpadrecyclerview:dpadrecyclerview-testing:$latestVersion"

Check the official website for more information and recipes: https://rubensousa.github.io/DpadRecyclerView

Easier Compose Integration

Documentation: https://rubensousa.github.io/DpadRecyclerView/compose/

class ComposeItemAdapter(
    private val onItemClick: (Int) -> Unit
) : ListAdapter<Int, DpadComposeFocusViewHolder<Int>>(Item.DIFF_CALLBACK) {

    override fun onCreateViewHolder(
        parent: ViewGroup,
        viewType: Int
    ): DpadComposeFocusViewHolder<Int> {
        return DpadComposeFocusViewHolder(parent) { item ->
            ItemComposable(
                item = item,
                onClick = {
                    onItemClick(item)
                }
            )
        }
    }

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

Sample app

Nested lists:

nested_lists

focus_overlay.webm

Grid with different span sizes:

grid

License

Copyright 2024 Rúben Sousa

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

dpadrecyclerview's People

Contributors

rubensousa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

dpadrecyclerview's Issues

Add support for infinite items

Expected behavior:

  1. RecyclerView allows infinite scrolling in the end direction if MAX loop is configured
  2. RecyclerView allows infinite scrolling in both directions if MIN_MAP loop is configured

Looping is only supported if there's enough items in the viewport

Can support both remote control and touchscreen?

I have a device that supports both remote control and touchscreen

but onTouchEvent return false and can not be override

    final override fun onTouchEvent(e: MotionEvent?): Boolean {
        return false
    }

Add state saving/restoring helper

  • Useful to persist scrolling positions of nested lists
  • Gives parity to the already existing leanback API that this library does not have

Create custom LayoutManager that extends directly from RecyclerView.LayoutManager

Pros:

  • We don't inherit anything unnecessary from GridLayoutManager & LinearLayoutManager
  • Get rid of ugly workarounds to align edges correctly
  • Potential performance gain (needs to benchmarked to confirm it's actually better)

Cons:

  • Complex task: both time consuming and hard to validate
  • SpanSizeLookup change would be incompatible unless we wrap it

New APIs required:

  • setExtraLayoutSpace
  • findLastVisibleItemPosition
  • findFirstVisibleItemPosition

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.