|
@@ -1,11 +1,8 @@
|
1
|
1
|
package com.reactnativenavigation.screens;
|
2
|
2
|
|
3
|
3
|
import android.support.design.widget.TabLayout;
|
4
|
|
-import android.support.v4.view.PagerAdapter;
|
5
|
4
|
import android.support.v4.view.ViewPager;
|
6
|
5
|
import android.support.v7.app.AppCompatActivity;
|
7
|
|
-import android.view.View;
|
8
|
|
-import android.view.ViewGroup;
|
9
|
6
|
|
10
|
7
|
import com.reactnativenavigation.params.ScreenParams;
|
11
|
8
|
import com.reactnativenavigation.params.TopTabParams;
|
|
@@ -19,6 +16,7 @@ import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
|
19
|
16
|
|
20
|
17
|
public class ViewPagerScreen extends Screen {
|
21
|
18
|
|
|
19
|
+ private static final int OFFSCREEN_PAGE_LIMIT = 99;
|
22
|
20
|
private List<ContentView> contentViews;
|
23
|
21
|
private ViewPager viewPager;
|
24
|
22
|
|
|
@@ -36,7 +34,7 @@ public class ViewPagerScreen extends Screen {
|
36
|
34
|
|
37
|
35
|
private void createViewPager() {
|
38
|
36
|
viewPager = new ViewPager(getContext());
|
39
|
|
- viewPager.setOffscreenPageLimit(99);
|
|
37
|
+ viewPager.setOffscreenPageLimit(OFFSCREEN_PAGE_LIMIT);
|
40
|
38
|
LayoutParams lp = new LayoutParams(MATCH_PARENT, MATCH_PARENT);
|
41
|
39
|
if (screenParams.styleParams.drawScreenBelowTopBar) {
|
42
|
40
|
lp.addRule(BELOW, topBar.getId());
|
|
@@ -47,18 +45,14 @@ public class ViewPagerScreen extends Screen {
|
47
|
45
|
private void addPages() {
|
48
|
46
|
contentViews = new ArrayList<>();
|
49
|
47
|
for (TopTabParams topTabParam : screenParams.topTabParams) {
|
50
|
|
- ContentView contentView = new ContentView(getContext(),
|
51
|
|
- topTabParam.screenId,
|
52
|
|
- screenParams.passProps,
|
53
|
|
- screenParams.navigationParams);
|
|
48
|
+ ContentView contentView = new ContentView(getContext(), screenParams, topTabParam.screenId);
|
54
|
49
|
addContent(contentView);
|
55
|
50
|
contentViews.add(contentView);
|
56
|
51
|
}
|
57
|
52
|
}
|
58
|
53
|
|
59
|
54
|
private void setupViewPager(TabLayout tabLayout) {
|
60
|
|
- ContentViewPagerAdapter adapter =
|
61
|
|
- new ContentViewPagerAdapter(viewPager, contentViews, screenParams.topTabParams);
|
|
55
|
+ ContentViewPagerAdapter adapter = new ContentViewPagerAdapter(contentViews, screenParams.topTabParams);
|
62
|
56
|
viewPager.setAdapter(adapter);
|
63
|
57
|
tabLayout.setupWithViewPager(viewPager);
|
64
|
58
|
}
|
|
@@ -88,73 +82,4 @@ public class ViewPagerScreen extends Screen {
|
88
|
82
|
contentView.preventMountAfterReattachedToWindow();
|
89
|
83
|
}
|
90
|
84
|
}
|
91
|
|
-
|
92
|
|
- public class ContentViewPagerAdapter extends PagerAdapter implements TabLayout.OnTabSelectedListener, ViewPager.OnPageChangeListener {
|
93
|
|
-
|
94
|
|
- private ViewPager viewPager;
|
95
|
|
- private List<ContentView> contentViews;
|
96
|
|
- private List<TopTabParams> topTabParams;
|
97
|
|
-
|
98
|
|
- public ContentViewPagerAdapter(ViewPager viewPager, List<ContentView> contentViews, List<TopTabParams> topTabParams) {
|
99
|
|
- this.viewPager = viewPager;
|
100
|
|
- this.contentViews = contentViews;
|
101
|
|
- this.topTabParams = topTabParams;
|
102
|
|
- }
|
103
|
|
-
|
104
|
|
- @Override
|
105
|
|
- public Object instantiateItem(ViewGroup container, int position) {
|
106
|
|
- return contentViews.get(position);
|
107
|
|
- }
|
108
|
|
-
|
109
|
|
- @Override
|
110
|
|
- public void destroyItem(ViewGroup container, int position, Object view) {
|
111
|
|
-
|
112
|
|
- }
|
113
|
|
-
|
114
|
|
- @Override
|
115
|
|
- public int getCount() {
|
116
|
|
- return contentViews.size();
|
117
|
|
- }
|
118
|
|
-
|
119
|
|
- @Override
|
120
|
|
- public boolean isViewFromObject(View view, Object object) {
|
121
|
|
- return view == object;
|
122
|
|
- }
|
123
|
|
-
|
124
|
|
- @Override
|
125
|
|
- public CharSequence getPageTitle(int position) {
|
126
|
|
- return topTabParams.get(position).title;
|
127
|
|
- }
|
128
|
|
-
|
129
|
|
- @Override
|
130
|
|
- public void onTabSelected(TabLayout.Tab tab) {
|
131
|
|
- int position = tab.getPosition();
|
132
|
|
- viewPager.setCurrentItem(position);
|
133
|
|
- }
|
134
|
|
-
|
135
|
|
- @Override
|
136
|
|
- public void onTabUnselected(TabLayout.Tab tab) {
|
137
|
|
-
|
138
|
|
- }
|
139
|
|
-
|
140
|
|
- @Override
|
141
|
|
- public void onTabReselected(TabLayout.Tab tab) {
|
142
|
|
-
|
143
|
|
- }
|
144
|
|
-
|
145
|
|
- @Override
|
146
|
|
- public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
147
|
|
-
|
148
|
|
- }
|
149
|
|
-
|
150
|
|
- @Override
|
151
|
|
- public void onPageSelected(int position) {
|
152
|
|
-
|
153
|
|
- }
|
154
|
|
-
|
155
|
|
- @Override
|
156
|
|
- public void onPageScrollStateChanged(int state) {
|
157
|
|
-
|
158
|
|
- }
|
159
|
|
- }
|
160
|
85
|
}
|