Quellcode durchsuchen

TabbedScreen basic functionality

Rotem M vor 8 Jahren
Ursprung
Commit
0a265329d7

+ 25
- 85
android/app/src/main/java/com/reactnativenavigation/screens/TabbedScreen.java Datei anzeigen

@@ -19,7 +19,7 @@ import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
19 19
 
20 20
 public class TabbedScreen extends Screen {
21 21
 
22
-    private List<ContentView> contentViews = new ArrayList<>();
22
+    private List<ContentView> contentViews;
23 23
     private ViewPager viewPager;
24 24
     private ViewPagerAdapter viewPagerAdapter;
25 25
 
@@ -30,20 +30,24 @@ public class TabbedScreen extends Screen {
30 30
     @Override
31 31
     protected void createContent() {
32 32
         TabLayout tabLayout = topBar.initTabs();
33
+        contentViews = new ArrayList<>();
33 34
         viewPager = new ViewPager(getContext());
34 35
         addView(viewPager);
35
-        viewPagerAdapter = new ViewPagerAdapter(getContext(), viewPager, contentViews);
36
-//        tabLayout.setupWithViewPager(viewPager);
37 36
 
38 37
         for (TopTabParams topTabParam : screenParams.topTabParams) {
39
-            ContentView contentView = new ContentView(getContext(), topTabParam.screenId, screenParams.passProps, screenParams.navigationParams, this);
38
+            ContentView contentView = new ContentView(getContext(),
39
+                    topTabParam.screenId,
40
+                    screenParams.passProps,
41
+                    screenParams.navigationParams,
42
+                    this);
40 43
             viewPager.addView(contentView, addBelowTopBar());
41 44
             contentView.init();
42
-
43
-            tabLayout.addTab(tabLayout.newTab().setText(topTabParam.title));
44
-//            viewPagerAdapter.addTabPage(topTabParam.title);
45
+            contentViews.add(contentView);
45 46
         }
46 47
 
48
+        viewPagerAdapter = new ViewPagerAdapter(viewPager, contentViews, screenParams.topTabParams);
49
+        viewPager.setAdapter(viewPagerAdapter);
50
+        tabLayout.setupWithViewPager(viewPager);
47 51
     }
48 52
 
49 53
     @NonNull
@@ -72,56 +76,20 @@ public class TabbedScreen extends Screen {
72 76
 
73 77
     public class ViewPagerAdapter extends PagerAdapter implements TabLayout.OnTabSelectedListener, ViewPager.OnPageChangeListener {
74 78
 
75
-        private static final String EVENT_ON_TAB_SELECTED = "OnTabSelected";
76
-
77
-        private ViewPager mViewPager;
78
-        //        private final ArrayList<ScreenStack> mScreenStacks;
79
-        private final ArrayList<String> mNavigatorIds;
79
+        private ViewPager viewPager;
80 80
         private List<ContentView> contentViews;
81
-        //        private final Map<String, ScreenStack> mStackByNavigatorId;
82
-        private int mCurrentPage = 0;
81
+        private List<TopTabParams> topTabParams;
83 82
 
84
-        public ViewPagerAdapter(Context context, ViewPager viewPager, List<ContentView> contentViews) {
85
-            this.mViewPager = viewPager;
83
+        public ViewPagerAdapter(ViewPager viewPager, List<ContentView> contentViews, List<TopTabParams> topTabParams) {
84
+            this.viewPager = viewPager;
86 85
             this.contentViews = contentViews;
87
-//            mScreenStacks = new ArrayList<>();
88
-            this.mNavigatorIds = new ArrayList<>();
89
-//            mStackByNavigatorId = new HashMap<> ();
90
-//            for (ContentView contentView : contentViews) {
91
-//                ScreenStack stack = new ScreenStack(context);
92
-//                stack.push(screen);
93
-//                mScreenStacks.add(stack);
94
-//                mNavigatorIds.add(screen.navigatorId);
95
-//                mStackByNavigatorId.put(screen.navigatorId, stack);
96
-//            }
97
-        }
98
-
99
-//        public void push(Screen screen) {
100
-//            ScreenStack stack = mStackByNavigatorId.get(screen.navigatorId);
101
-//            Screen prevScreen = mScreenStacks.get(mCurrentPage).peek();
102
-//            mToolbar.setupToolbarButtonsAsync(prevScreen, screen);
103
-//            stack.push(screen);
104
-//        }
105
-//
106
-//        public Screen pop(String navigatorId) {
107
-//            ScreenStack stack = mStackByNavigatorId.get(navigatorId);
108
-//            Screen oldScreen =  stack != null ? stack.pop() : null;
109
-//            Screen newScreen = stack.peek();
110
-//            mToolbar.setupToolbarButtonsAsync(oldScreen, newScreen);
111
-//            return oldScreen;
112
-//        }
113
-//
114
-//        public Screen peek(String navigatorId) {
115
-//            ScreenStack stack = mStackByNavigatorId.get(navigatorId);
116
-//            return stack != null ? stack.peek() : null;
117
-//        }
118
-
119
-//        @Override
120
-//        public Object instantiateItem(ViewGroup container, int position) {
121
-//            ScreenStack view = mScreenStacks.get(position);
122
-//            container.addView(view);
123
-//            return view;
124
-//        }
86
+            this.topTabParams = topTabParams;
87
+        }
88
+
89
+        @Override
90
+        public Object instantiateItem(ViewGroup container, int position) {
91
+            return contentViews.get(position);
92
+        }
125 93
 
126 94
         @Override
127 95
         public void destroyItem(ViewGroup container, int position, Object view) {
@@ -140,31 +108,13 @@ public class TabbedScreen extends Screen {
140 108
 
141 109
         @Override
142 110
         public CharSequence getPageTitle(int position) {
143
-//            return contentViews.get(position).peek().label;
144
-            return "";
111
+            return topTabParams.get(position).title;
145 112
         }
146 113
 
147 114
         @Override
148 115
         public void onTabSelected(TabLayout.Tab tab) {
149
-            // Set the viewPager's current item
150 116
             int position = tab.getPosition();
151
-            mViewPager.setCurrentItem(position);
152
-
153
-//            // Set screen buttons
154
-//            Screen prevScreen = mScreenStacks.get(mCurrentPage).peek();
155
-//            Screen newScreen = mScreenStacks.get(position).peek();
156
-//            mToolbar.setupToolbarButtonsAsync(prevScreen, newScreen);
157
-//
158
-//            // Set title
159
-//            mToolbar.setTitle(newScreen.title == null ? "" : newScreen.title);
160
-//
161
-//            // Set navigation color
162
-//            StyleHelper.updateStyles(mToolbar, newScreen);
163
-//
164
-//            // Send tab selected event
165
-//            WritableMap params = Arguments.createMap();
166
-//            Screen screen = mScreenStacks.get(position).peek();
167
-//            RctManager.getInstance().sendEvent(EVENT_ON_TAB_SELECTED, screen, params);
117
+            viewPager.setCurrentItem(position);
168 118
         }
169 119
 
170 120
         @Override
@@ -177,16 +127,6 @@ public class TabbedScreen extends Screen {
177 127
 
178 128
         }
179 129
 
180
-        public String getNavigatorId(int position) {
181
-            return mNavigatorIds.get(position);
182
-        }
183
-
184
-        public int getStackSizeForNavigatorId(String activeNavigatorID) {
185
-//            return mStackByNavigatorId.get(activeNavigatorID).getStackSize();
186
-            return 0;
187
-        }
188
-
189
-
190 130
         @Override
191 131
         public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
192 132
 
@@ -194,7 +134,7 @@ public class TabbedScreen extends Screen {
194 134
 
195 135
         @Override
196 136
         public void onPageSelected(int position) {
197
-            mCurrentPage = position;
137
+
198 138
         }
199 139
 
200 140
         @Override