question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Migration to ViewPager2

See original GitHub issue

Feature Request

Why it is needed

Earlier this year, Google announced ViewPager2 in Google IO/19. ViewPager2 is the replacement of ViewPager and is much better. The biggest change in the ViewPager2 API is that it now uses the RecyclerView.

Possible implementation

class PagerAdapter : RecyclerView.Adapter<PageViewHolder>() {
    var list: List<ReactNativeView> = listOf()
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PageViewHolder {
        return PageViewHolder(parent)
    }
override fun onBindViewHolder(holder: PageViewHolder, position: Int) {
        holder.bind(list[position])
    }
fun setItem(list: List<ReactNativeView>) {
        this.list = list
        notifyDataSetChanged()
    }
override fun getItemCount(): Int = list.size
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:6
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
troZeecommented, Jan 20, 2020

You can checkout my progress here: https://github.com/react-native-community/react-native-viewpager/commits/%40troZee/viewpager2 . Currently, I am struggling with FragmentStateAdapter. Previously I implemented it using pure RecyclerViewAdapter, but IMO it is not a good solution. Feel free to share some code, if you would like to.

1reaction
ferrannpcommented, Dec 3, 2019

I recommend playing and having fun with https://github.com/android/views-widgets-samples/tree/master/ViewPager2. See examples:

ezgif-1-590bcacca31d tabs

😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

Migrate from ViewPager to ViewPager2
The primary reason to migrate is that ViewPager2 is receiving active development support and ViewPager is not. However, ViewPager2 also offers ...
Read more >
Migrating to ViewPager2. Hands-on guide
The migration. First step is to add a new dependency — yes, the new version has its own dependency. And yes, ViewPager2 is...
Read more >
Problem when migrate from ViewPager to ViewPager2
I want to migrate from viewpager to viewpager2. But there is a problem when I scroll viewpager2 left/right, the tables in the fragment ......
Read more >
Migration from ViewPager to ViewPager2 - Rahul Rathore
Changes Required for migration ViewPager -> ViewPager2. Adapter parant class. from: class MyAdapter : PagerAdapter().
Read more >
Migrate to ViewPager2 (#1544) · d2ca776b34 - Husky
Migrate to ViewPager2 (#1544. An error occurred. ) · 1. app/build. · 23. app/src/main/java/com/keylesspalace/tusky/AccountActivity. · 17. app/src/main/java/com/ ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found