Skip to content

Commit 0548654

Browse files
troZeePiotr Trocki
andauthored
feat: migrate lib to ViewPager2 (#139)
Co-authored-by: Piotr Trocki <[email protected]>
1 parent fa7199f commit 0548654

File tree

13 files changed

+302
-494
lines changed

13 files changed

+302
-494
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ This component allows the user to swipe left and right through pages of data. Un
1111

1212
## Versions
1313

14-
| 1.x | 2.x | 3.x
15-
| ---------------- | ------------- | ------------- |
16-
| | iOS support | iOS support |
17-
| Android support | Android support | AndroidX support |
14+
| 1.x | 2.x | 3.x | 4.x |
15+
| ---------------- | ------------- | ------------- | ------------- |
16+
| | iOS support | iOS support | iOS support |
17+
| Android support | Android support | AndroidX support | ViewPager2 support |
1818

1919
## Getting started
2020

android/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,6 @@ repositories {
3838
dependencies {
3939
//noinspection GradleDynamicVersion
4040
api 'com.facebook.react:react-native:+'
41+
implementation 'com.github.troZee:ViewPager2:v1.0.6'
42+
4143
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.reactnativecommunity.viewpager;
2+
3+
import android.view.View;
4+
5+
import androidx.annotation.NonNull;
6+
import androidx.fragment.app.Fragment;
7+
import androidx.fragment.app.FragmentActivity;
8+
9+
10+
import com.reactnative.community.viewpager2.adapter.FragmentStateAdapter;
11+
12+
import java.util.ArrayList;
13+
14+
public class FragmentAdapter extends FragmentStateAdapter {
15+
16+
public FragmentAdapter(@NonNull FragmentActivity fragmentActivity) {
17+
super(fragmentActivity);
18+
}
19+
20+
private ArrayList<ViewPagerFragment> children = new ArrayList<>();
21+
22+
@NonNull
23+
@Override
24+
public Fragment createFragment(int position) {
25+
return children.get(position);
26+
}
27+
28+
@Override
29+
public int getItemCount() {
30+
return children.size();
31+
}
32+
33+
public void addFragment(View child, int index) {
34+
children.add(ViewPagerFragment.newInstance(child.getId()));
35+
notifyDataSetChanged();
36+
}
37+
38+
39+
public void removeFragment(View child) {
40+
for (int i = 0; i < children.size(); i++) {
41+
Fragment fragment = children.get(i);
42+
if (fragment.getId() == child.getId()) {
43+
children.remove(i);
44+
notifyItemRemoved(i);
45+
return;
46+
}
47+
}
48+
}
49+
50+
public void removeFragmentAt(int index) {
51+
children.remove(index);
52+
notifyItemRemoved(index);
53+
}
54+
55+
public View getChildAt(int index) {
56+
return children.get(index).getView();
57+
}
58+
}

android/src/main/java/com/reactnativecommunity/viewpager/ReactViewPager.java

Lines changed: 0 additions & 254 deletions
This file was deleted.

0 commit comments

Comments
 (0)