Migration to ViewPager2
See original GitHub issueFeature 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:
- Created 4 years ago
- Reactions:6
- Comments:7 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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 pureRecyclerViewAdapter
, but IMO it is not a good solution. Feel free to share some code, if you would like to.I recommend playing and having fun with https://github.com/android/views-widgets-samples/tree/master/ViewPager2. See examples:
😄