Browse Source

Minor ViewPagerScreen refactor

Guy Carmeli 8 years ago
parent
commit
e5093a727a

+ 12
- 3
android/app/src/main/java/com/reactnativenavigation/screens/ViewPagerScreen.java View File

@@ -6,7 +6,6 @@ import android.support.v4.view.ViewPager;
6 6
 import android.support.v7.app.AppCompatActivity;
7 7
 import android.view.View;
8 8
 import android.view.ViewGroup;
9
-import android.widget.RelativeLayout;
10 9
 
11 10
 import com.reactnativenavigation.params.ScreenParams;
12 11
 import com.reactnativenavigation.params.TopTabParams;
@@ -30,15 +29,23 @@ public class ViewPagerScreen extends Screen {
30 29
     @Override
31 30
     protected void createContent() {
32 31
         TabLayout tabLayout = topBar.initTabs();
33
-        contentViews = new ArrayList<>();
32
+        createViewPager();
33
+        addPages();
34
+        setupViewPager(tabLayout);
35
+    }
36
+
37
+    private void createViewPager() {
34 38
         viewPager = new ViewPager(getContext());
35 39
         viewPager.setOffscreenPageLimit(99);
36
-        RelativeLayout.LayoutParams lp = new LayoutParams(MATCH_PARENT, MATCH_PARENT);
40
+        LayoutParams lp = new LayoutParams(MATCH_PARENT, MATCH_PARENT);
37 41
         if (screenParams.styleParams.drawScreenBelowTopBar) {
38 42
             lp.addRule(BELOW, topBar.getId());
39 43
         }
40 44
         addView(viewPager, lp);
45
+    }
41 46
 
47
+    private void addPages() {
48
+        contentViews = new ArrayList<>();
42 49
         for (TopTabParams topTabParam : screenParams.topTabParams) {
43 50
             ContentView contentView = new ContentView(getContext(),
44 51
                     topTabParam.screenId,
@@ -47,7 +54,9 @@ public class ViewPagerScreen extends Screen {
47 54
             addContent(contentView);
48 55
             contentViews.add(contentView);
49 56
         }
57
+    }
50 58
 
59
+    private void setupViewPager(TabLayout tabLayout) {
51 60
         ContentViewPagerAdapter adapter =
52 61
                 new ContentViewPagerAdapter(viewPager, contentViews, screenParams.topTabParams);
53 62
         viewPager.setAdapter(adapter);

+ 2
- 1
android/app/src/main/java/com/reactnativenavigation/views/TopBar.java View File

@@ -22,7 +22,8 @@ public class TopBar extends AppBarLayout {
22 22
         setId(ViewUtils.generateViewId());
23 23
     }
24 24
 
25
-    public void addTitleBarAndSetButtons(List<TitleBarButtonParams> rightButtons, TitleBarLeftButtonParams leftButton,
25
+    public void addTitleBarAndSetButtons(List<TitleBarButtonParams> rightButtons,
26
+                                         TitleBarLeftButtonParams leftButton,
26 27
                                          TitleBarBackButtonListener titleBarBackButtonListener,
27 28
                                          String navigatorEventId) {
28 29
         titleBar = new TitleBar(getContext());