Browse Source

fixed code styling and removed unused files

Guy Carmeli 8 years ago
parent
commit
625c3420a2

+ 15
- 11
android/app/src/main/java/com/reactnativenavigation/activities/BaseReactActivity.java View File

40
     private static final String REDBOX_PERMISSION_MESSAGE =
40
     private static final String REDBOX_PERMISSION_MESSAGE =
41
             "Overlay permissions needs to be granted in order for react native apps to run in dev mode";
41
             "Overlay permissions needs to be granted in order for react native apps to run in dev mode";
42
 
42
 
43
-    protected  @Nullable ReactInstanceManager mReactInstanceManager;
43
+    @Nullable
44
+    protected ReactInstanceManager mReactInstanceManager;
44
     private LifecycleState mLifecycleState = LifecycleState.BEFORE_RESUME;
45
     private LifecycleState mLifecycleState = LifecycleState.BEFORE_RESUME;
45
     private boolean mDoRefresh = false;
46
     private boolean mDoRefresh = false;
46
     private Menu mMenu;
47
     private Menu mMenu;
51
      * always try to load the JS bundle from the packager server.
52
      * always try to load the JS bundle from the packager server.
52
      * e.g. "index.android.bundle"
53
      * e.g. "index.android.bundle"
53
      */
54
      */
54
-    protected @Nullable String getBundleAssetName() {
55
+    @Nullable
56
+    protected String getBundleAssetName() {
55
         return "index.android.bundle";
57
         return "index.android.bundle";
56
-    };
58
+    }
57
 
59
 
58
     /**
60
     /**
59
      * Returns a custom path of the bundle file. This is used in cases the bundle should be loaded
61
      * Returns a custom path of the bundle file. This is used in cases the bundle should be loaded
61
      * by {getBundleAssetName}.
63
      * by {getBundleAssetName}.
62
      * e.g. "file://sdcard/myapp_cache/index.android.bundle"
64
      * e.g. "file://sdcard/myapp_cache/index.android.bundle"
63
      */
65
      */
64
-    protected @Nullable String getJSBundleFile() {
66
+    @Nullable
67
+    protected String getJSBundleFile() {
65
         return null;
68
         return null;
66
     }
69
     }
67
 
70
 
82
      * If your React Native application requires props set outside of JS, override
85
      * If your React Native application requires props set outside of JS, override
83
      * this method to return the Android.os.Bundle of your desired initial props.
86
      * this method to return the Android.os.Bundle of your desired initial props.
84
      */
87
      */
85
-    protected @Nullable Bundle getLaunchOptions() {
88
+    @Nullable
89
+    protected Bundle getLaunchOptions() {
86
         return null;
90
         return null;
87
     }
91
     }
88
 
92
 
191
 
195
 
192
         // Destroy react instance manager only if there are no resumed react activities
196
         // Destroy react instance manager only if there are no resumed react activities
193
         BaseReactActivity activity = ContextProvider.getActivityContext();
197
         BaseReactActivity activity = ContextProvider.getActivityContext();
194
-        if (mReactInstanceManager != null && activity!=null && activity.isFinishing()) {
198
+        if (mReactInstanceManager != null && activity != null && activity.isFinishing()) {
195
             Log.i(TAG, "Destroying ReactInstanceManager");
199
             Log.i(TAG, "Destroying ReactInstanceManager");
196
             mReactInstanceManager.onDestroy();
200
             mReactInstanceManager.onDestroy();
197
         } else {
201
         } else {
255
 
259
 
256
     @Override
260
     @Override
257
     public void onBackPressed() {
261
     public void onBackPressed() {
258
-        if(getScreenStackSize() > 1){
262
+        if (getScreenStackSize() > 1) {
259
             pop(getActiveNavigatorID());
263
             pop(getActiveNavigatorID());
260
-        }
261
-        else{
262
-            if (mReactInstanceManager != null)
264
+        } else {
265
+            if (mReactInstanceManager != null) {
263
                 mReactInstanceManager.onBackPressed();
266
                 mReactInstanceManager.onBackPressed();
264
-            else
267
+            } else {
265
                 super.onBackPressed();
268
                 super.onBackPressed();
269
+            }
266
         }
270
         }
267
     }
271
     }
268
 
272
 

+ 6
- 11
android/app/src/main/java/com/reactnativenavigation/adapters/ViewPagerAdapter.java View File

3
 import android.support.design.widget.TabLayout;
3
 import android.support.design.widget.TabLayout;
4
 import android.support.v4.view.PagerAdapter;
4
 import android.support.v4.view.PagerAdapter;
5
 import android.support.v4.view.ViewPager;
5
 import android.support.v4.view.ViewPager;
6
-import android.support.v7.widget.Toolbar;
7
 import android.view.View;
6
 import android.view.View;
8
 import android.view.ViewGroup;
7
 import android.view.ViewGroup;
9
 
8
 
10
-import com.facebook.react.ReactInstanceManager;
11
 import com.facebook.react.bridge.Arguments;
9
 import com.facebook.react.bridge.Arguments;
12
 import com.facebook.react.bridge.WritableMap;
10
 import com.facebook.react.bridge.WritableMap;
13
 import com.reactnativenavigation.activities.BaseReactActivity;
11
 import com.reactnativenavigation.activities.BaseReactActivity;
27
 
25
 
28
     private static final String EVENT_ON_TAB_SELECTED = "OnTabSelected";
26
     private static final String EVENT_ON_TAB_SELECTED = "OnTabSelected";
29
 
27
 
30
-    private BaseReactActivity mContext;
31
     private ViewPager mViewPager;
28
     private ViewPager mViewPager;
32
     private RnnToolBar mToolbar;
29
     private RnnToolBar mToolbar;
33
-    private final ReactInstanceManager mReactInstanceManager;
34
     private final ArrayList<ScreenStack> screenStacks;
30
     private final ArrayList<ScreenStack> screenStacks;
35
     private final ArrayList<String> navIDs;
31
     private final ArrayList<String> navIDs;
36
     private final Map<String, ScreenStack> stacksByNavId;
32
     private final Map<String, ScreenStack> stacksByNavId;
38
 
34
 
39
     public ViewPagerAdapter(BaseReactActivity context, ViewPager viewPager, RnnToolBar toolbar,
35
     public ViewPagerAdapter(BaseReactActivity context, ViewPager viewPager, RnnToolBar toolbar,
40
                             ArrayList<Screen> screens) {
36
                             ArrayList<Screen> screens) {
41
-        mContext = context;
42
         mViewPager = viewPager;
37
         mViewPager = viewPager;
43
         mToolbar = toolbar;
38
         mToolbar = toolbar;
44
         screenStacks = new ArrayList<>();
39
         screenStacks = new ArrayList<>();
45
         navIDs = new ArrayList<>();
40
         navIDs = new ArrayList<>();
46
-        stacksByNavId  = new HashMap<>();
47
-        for(Screen screen: screens){
41
+        stacksByNavId = new HashMap<>();
42
+        for (Screen screen : screens) {
48
             ScreenStack stack = new ScreenStack(context);
43
             ScreenStack stack = new ScreenStack(context);
49
             stack.push(screen);
44
             stack.push(screen);
50
             screenStacks.add(stack);
45
             screenStacks.add(stack);
51
             navIDs.add(screen.navigatorId);
46
             navIDs.add(screen.navigatorId);
52
             stacksByNavId.put(screen.navigatorId, stack);
47
             stacksByNavId.put(screen.navigatorId, stack);
53
         }
48
         }
54
-        mReactInstanceManager = RctManager.getInstance().getReactInstanceManager();
55
     }
49
     }
56
 
50
 
57
-    public void pushScreen(Screen screen){
51
+    public void pushScreen(Screen screen) {
58
         ScreenStack stack = stacksByNavId.get(screen.navigatorId);
52
         ScreenStack stack = stacksByNavId.get(screen.navigatorId);
59
         stack.push(screen);
53
         stack.push(screen);
60
     }
54
     }
61
 
55
 
62
-    public Screen pop(String navID){
56
+    public Screen pop(String navID) {
63
         ScreenStack stack = stacksByNavId.get(navID);
57
         ScreenStack stack = stacksByNavId.get(navID);
64
-        if(stack != null)
58
+        if (stack != null) {
65
             return stack.pop();
59
             return stack.pop();
60
+        }
66
         return null;
61
         return null;
67
     }
62
     }
68
 
63
 

+ 0
- 71
android/app/src/main/java/com/reactnativenavigation/layouts/ReactTabLayout.java View File

1
-package com.reactnativenavigation.layouts;
2
-
3
-import android.content.Context;
4
-import android.support.design.widget.TabLayout;
5
-
6
-import java.util.ArrayList;
7
-import java.util.List;
8
-import java.util.UUID;
9
-
10
-/**
11
- *
12
- * Created by guyc on 06/03/16.
13
- */
14
-@Deprecated
15
-public class ReactTabLayout extends TabLayout {
16
-
17
-    public enum InitialState {
18
-        TAB_POSITION_UNSET,
19
-        TAB_POSITION_SET,
20
-        TAB_SELECTED
21
-    }
22
-
23
-    private List<Tab> mTabs = new ArrayList<>();
24
-    private List<Integer> mIds = new ArrayList<>();
25
-    private InitialState mInitialState = InitialState.TAB_POSITION_UNSET;
26
-    private int mInitialTabPosition;
27
-
28
-    public ReactTabLayout(Context context) {
29
-        super(context);
30
-    }
31
-
32
-
33
-    @Override
34
-    public void addTab(Tab tab) {
35
-        super.addTab(tab);
36
-        mTabs.add(tab);
37
-        mIds.add(UUID.randomUUID().hashCode());
38
-    }
39
-
40
-    public int getId(int index) {
41
-        return mIds.get(index);
42
-    }
43
-
44
-    public int indexOf(Tab tab) {
45
-        return mTabs.indexOf(tab);
46
-    }
47
-
48
-    @Override
49
-    public void removeAllTabs() {
50
-        mTabs.clear();
51
-        mIds.clear();
52
-        super.removeAllTabs();
53
-    }
54
-
55
-    public InitialState getInitialState() {
56
-        return mInitialState;
57
-    }
58
-
59
-    public int getInitialTabPosition() {
60
-        return mInitialTabPosition;
61
-    }
62
-
63
-    public void setInitialState(InitialState initialState) {
64
-        mInitialState = initialState;
65
-    }
66
-
67
-    public void setInitialTabPosition(int initialTabPosition) {
68
-        mInitialTabPosition = initialTabPosition;
69
-    }
70
-}
71
-

+ 0
- 110
android/app/src/main/java/com/reactnativenavigation/managers/AppBarLayoutManager.java View File

1
-package com.reactnativenavigation.managers;
2
-
3
-import android.support.design.widget.AppBarLayout;
4
-import android.view.View;
5
-
6
-import com.facebook.infer.annotation.Assertions;
7
-import com.facebook.react.bridge.JSApplicationIllegalArgumentException;
8
-import com.facebook.react.bridge.ReadableArray;
9
-import com.facebook.react.bridge.ReadableMap;
10
-import com.facebook.react.common.MapBuilder;
11
-import com.facebook.react.uimanager.ThemedReactContext;
12
-import com.facebook.react.uimanager.ViewGroupManager;
13
-import com.facebook.react.uimanager.annotations.ReactProp;
14
-
15
-import java.util.Map;
16
-
17
-/**
18
- * Created by guyc on 08/03/16.
19
- */
20
-@Deprecated
21
-public class AppBarLayoutManager extends ViewGroupManager<AppBarLayout> {
22
-    private static final String REACT_CLASS = "AppbarLayout";
23
-    private static final int COMMAND_SET_CHILDREN_SCROLL_FLAGS = 1;
24
-
25
-    @Override
26
-    public String getName() {
27
-        return REACT_CLASS;
28
-    }
29
-
30
-    @Override
31
-    protected AppBarLayout createViewInstance(ThemedReactContext reactContext) {
32
-        AppBarLayout appBarLayout = new AppBarLayout(reactContext);
33
-        appBarLayout.setFitsSystemWindows(true);
34
-        return appBarLayout;
35
-    }
36
-
37
-    @Override
38
-    public boolean needsCustomLayoutForChildren() {
39
-        return true;
40
-    }
41
-
42
-    @Override
43
-    public Map<String,Integer> getCommandsMap() {
44
-        return MapBuilder.of(
45
-                "setChildrenScrollFlags", COMMAND_SET_CHILDREN_SCROLL_FLAGS);
46
-    }
47
-
48
-    @Override
49
-    public void receiveCommand(AppBarLayout view, int commandType, ReadableArray args) {
50
-        Assertions.assertNotNull(view);
51
-        Assertions.assertNotNull(args);
52
-
53
-        switch (commandType) {
54
-            case COMMAND_SET_CHILDREN_SCROLL_FLAGS: {
55
-                ReadableArray options = args.getArray(0);
56
-                setChildrenScrollFlags(view, options);
57
-                return;
58
-            }
59
-
60
-            default:
61
-                throw new JSApplicationIllegalArgumentException(String.format(
62
-                        "Unsupported command %d received by %s.",
63
-                        commandType,
64
-                        getClass().getSimpleName()));
65
-        }
66
-    }
67
-
68
-    @ReactProp(name = "childrenScrollFlags")
69
-    public void setScrollFlags(AppBarLayout view, ReadableArray options) {
70
-        setChildrenScrollFlags(view, options);
71
-    }
72
-
73
-    private void setChildrenScrollFlags(AppBarLayout view, ReadableArray options) {
74
-        try {
75
-            int optionSize = options.size();
76
-            for (int i=0; i<optionSize; i++) {
77
-
78
-                ReadableMap optionMap = options.getMap(i);
79
-                ReadableArray scrollFlags = optionMap.getArray("scrollFlags");
80
-
81
-                int scrollFlagsSize = scrollFlags.size();
82
-                int scrollFlagsInteger = 0;
83
-
84
-                for (int j=0; j<scrollFlagsSize; j++) {
85
-                    String scrollFlagString = scrollFlags.getString(j);
86
-
87
-                    if ("enterAlways".equals(scrollFlagString)) {
88
-                        scrollFlagsInteger = scrollFlagsInteger | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS;
89
-                    } else if ("enterAlwaysCollapsed".equals(scrollFlagString)) {
90
-                        scrollFlagsInteger = scrollFlagsInteger | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS_COLLAPSED;
91
-                    } else if ("exitUntilCollapsed".equals(scrollFlagString)) {
92
-                        scrollFlagsInteger = scrollFlagsInteger | AppBarLayout.LayoutParams.SCROLL_FLAG_EXIT_UNTIL_COLLAPSED;
93
-                    } else if ("scroll".equals(scrollFlagString)) {
94
-                        scrollFlagsInteger = scrollFlagsInteger | AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL;
95
-                    } else if ("snap".equals(scrollFlagString)) {
96
-                        scrollFlagsInteger = scrollFlagsInteger | AppBarLayout.LayoutParams.SCROLL_FLAG_SNAP;
97
-                    }
98
-                }
99
-
100
-                View childView = view.getChildAt(optionMap.getInt("index"));
101
-                AppBarLayout.LayoutParams param = (AppBarLayout.LayoutParams) childView.getLayoutParams();
102
-
103
-                //noinspection ResourceType
104
-                param.setScrollFlags(scrollFlagsInteger);
105
-            }
106
-        } catch (Exception e) {
107
-            // TODO: Handle Exception
108
-        }
109
-    }
110
-}

+ 0
- 49
android/app/src/main/java/com/reactnativenavigation/managers/CoordinatorLayoutManager.java View File

1
-package com.reactnativenavigation.managers;
2
-
3
-import android.support.design.widget.CoordinatorLayout;
4
-import android.view.View;
5
-
6
-import com.facebook.react.common.MapBuilder;
7
-import com.facebook.react.uimanager.ThemedReactContext;
8
-import com.facebook.react.uimanager.ViewGroupManager;
9
-
10
-import java.util.Map;
11
-
12
-/**
13
- * Created by guyc on 19/03/16.
14
- */
15
-@Deprecated
16
-public class CoordinatorLayoutManager extends ViewGroupManager<CoordinatorLayout> {
17
-    private static final String REACT_CLASS = "CoordinatorLayout";
18
-    private static final String COMMAND_CHILD_FLAGS = "setChildFlags";
19
-    private static final int COMMAND_SET_CHILD_FLAGS_TYPE = 1;
20
-
21
-    @Override
22
-    public String getName() {
23
-        return REACT_CLASS;
24
-    }
25
-
26
-    @Override
27
-    public boolean needsCustomLayoutForChildren() {
28
-        return true;
29
-    }
30
-
31
-    @Override
32
-    protected CoordinatorLayout createViewInstance(ThemedReactContext reactContext) {
33
-        CoordinatorLayout coordinatorLayout = new CoordinatorLayout(reactContext);
34
-        coordinatorLayout.setFitsSystemWindows(true);
35
-        return coordinatorLayout;
36
-    }
37
-
38
-
39
-    @Override
40
-    public void addView(CoordinatorLayout parent, View child, int index) {
41
-        child.setFitsSystemWindows(true);
42
-        super.addView(parent, child, index);
43
-    }
44
-
45
-    @Override
46
-    public Map<String, Integer> getCommandsMap() {
47
-        return MapBuilder.of(COMMAND_CHILD_FLAGS, COMMAND_SET_CHILD_FLAGS_TYPE);
48
-    }
49
-}

+ 0
- 293
android/app/src/main/java/com/reactnativenavigation/managers/TabLayoutManager.java View File

1
-package com.reactnativenavigation.managers;
2
-
3
-import android.content.Context;
4
-import android.graphics.drawable.Drawable;
5
-import android.support.design.widget.TabLayout;
6
-import android.support.v4.view.ViewPager;
7
-import android.util.Log;
8
-import android.view.View;
9
-import android.view.ViewGroup;
10
-
11
-import com.facebook.infer.annotation.Assertions;
12
-import com.facebook.react.bridge.JSApplicationIllegalArgumentException;
13
-import com.facebook.react.bridge.ReadableArray;
14
-import com.facebook.react.bridge.ReadableMap;
15
-import com.facebook.react.common.MapBuilder;
16
-import com.facebook.react.uimanager.ThemedReactContext;
17
-import com.facebook.react.uimanager.UIManagerModule;
18
-import com.facebook.react.uimanager.ViewGroupManager;
19
-import com.facebook.react.uimanager.annotations.ReactProp;
20
-import com.facebook.react.uimanager.events.EventDispatcher;
21
-import com.reactnativenavigation.layouts.ReactTabLayout;
22
-import com.reactnativenavigation.layouts.ReactTabLayout.InitialState;
23
-import com.reactnativenavigation.utils.ResourceUtils;
24
-
25
-import java.util.Map;
26
-
27
-import static android.support.design.widget.TabLayout.Tab;
28
-
29
-/**
30
- *
31
- * Created by guyc on 06/03/16.
32
- */
33
-@Deprecated
34
-public class TabLayoutManager extends ViewGroupManager<ReactTabLayout> {
35
-    private static final String REACT_CLASS = "TabLayout";
36
-    public static final int COMMAND_SET_VIEW_PAGER_TYPE = 1;
37
-    public static final String PARAM_ICON = "icon";
38
-    public static final String PARAM_TEXT = "text";
39
-    public static final String REGISTRATION_NAME = "registrationName";
40
-    public static final String EVENT_ON_TAB_SELECTED = "onTabSelected";
41
-    public static final String COMMAND_SET_VIEW_PAGER = "setViewPager";
42
-    private static final String TAG = TabLayoutManager.class.getSimpleName();
43
-
44
-    private enum TabMode {
45
-        SCROLLABLE(TabLayout.MODE_SCROLLABLE),
46
-        FIXED(TabLayout.MODE_FIXED);
47
-
48
-        int mode;
49
-
50
-        TabMode(int mode) {
51
-            this.mode = mode;
52
-        }
53
-
54
-        public static TabMode fromString(String text) {
55
-            return text != null ? Enum.valueOf(TabMode.class, text.trim().toUpperCase()) : null;
56
-        }
57
-    }
58
-
59
-    private enum TabGravity {
60
-        FILL(TabLayout.GRAVITY_FILL),
61
-        CENTER(TabLayout.GRAVITY_CENTER);
62
-
63
-        int gravity;
64
-
65
-        TabGravity(int gravity) {
66
-            this.gravity = gravity;
67
-        }
68
-
69
-        public static TabGravity fromString(String text) {
70
-            return text != null ? Enum.valueOf(TabGravity.class, text.trim().toUpperCase()) : null;
71
-        }
72
-    }
73
-
74
-    private EventDispatcher mDispatcher;
75
-
76
-    @Override
77
-    public String getName() {
78
-        return REACT_CLASS;
79
-    }
80
-
81
-    @Override
82
-    protected ReactTabLayout createViewInstance(ThemedReactContext reactContext) {
83
-        ReactTabLayout tabLayout = new ReactTabLayout(reactContext);
84
-//        setupWithViewPager(tabLayout);
85
-        return tabLayout;
86
-    }
87
-
88
-    private void setupWithViewPager(final ReactTabLayout tabLayout, final ReadableArray tabs) {
89
-        tabLayout.post(new Runnable() {
90
-            @Override
91
-            public void run() {
92
-                if (tabLayout.getParent() == null) {
93
-                    Log.e(TAG, "Tried to setupViewPager but parent is null");
94
-                    return;
95
-                }
96
-                
97
-                ViewGroup parent = (ViewGroup) tabLayout.getParent().getParent();
98
-                if (parent == null) {
99
-                    return;
100
-                }
101
-
102
-                for (int i = 0; i < parent.getChildCount(); i++) {
103
-                    View child = parent.getChildAt(i);
104
-                    if (child instanceof ViewPager) {
105
-                        // Setup TabLayout with ViewPager
106
-                        ViewPager viewPager = (ViewPager) child;
107
-                        tabLayout.setupWithViewPager(viewPager);
108
-
109
-                        // Add tabs
110
-                        if (tabs != null) {
111
-                            tabLayout.removeAllTabs();
112
-                            populateTabLayoutWithTabs(tabLayout, tabs);
113
-                            tabLayout.setOnTabSelectedListener(new OnTabSelectedListener(viewPager, tabLayout, TabLayoutManager.this));
114
-                        }
115
-                    }
116
-                }
117
-
118
-                Log.i("GUY", "childCount" + parent.getChildCount());
119
-                for (int i = 0; i < parent.getChildCount(); i++) {
120
-                    Log.d("GUY", "[" + 1 + "] " + parent.getChildAt(i).getClass().getSimpleName());
121
-                }
122
-            }
123
-        });
124
-
125
-    }
126
-
127
-    @Override
128
-    public void addView(ReactTabLayout tabLayout, View child, int index) {
129
-        Tab tab = tabLayout.newTab();
130
-        tabLayout.addTab(tab);
131
-
132
-        // when initial position was stored, update tab selection
133
-        if (tabLayout.getInitialState() == InitialState.TAB_POSITION_SET &&
134
-            tabLayout.getInitialTabPosition() == index) {
135
-            tabLayout.setInitialState(InitialState.TAB_SELECTED);
136
-            tab.select();
137
-        }
138
-    }
139
-
140
-    @ReactProp(name = "tabs")
141
-    public void setTabs(ReactTabLayout tabLayout, ReadableArray tabs) {
142
-        setupWithViewPager(tabLayout, tabs);
143
-    }
144
-
145
-
146
-    @ReactProp(name = "selectedTab", defaultInt = 0)
147
-    public void setSelectedTab(ReactTabLayout view, int selectedTab) {
148
-        selectTab(view, selectedTab);
149
-    }
150
-
151
-    private void selectTab(ReactTabLayout tabLayout, int position) {
152
-        if (position < 0 || position >= tabLayout.getTabCount()) {
153
-            Log.w(REACT_CLASS, "Tried to select tab " + position + " but index is out of bounds");
154
-            return;
155
-        }
156
-
157
-        Tab tab = tabLayout.getTabAt(position);
158
-        if (tab != null) {
159
-            tab.select();
160
-        }
161
-    }
162
-
163
-    @ReactProp(name = "selectedTabIndicatorColor")
164
-    public void setSelectedTabIndicatorColor(ReactTabLayout view, int indicatorColor) {
165
-        view.setSelectedTabIndicatorColor(indicatorColor);
166
-    }
167
-
168
-    @ReactProp(name = "tabMode")
169
-    public void setTabMode(ReactTabLayout view, String mode) {
170
-        TabMode tabMode = TabMode.fromString(mode);
171
-        if (tabMode == null) {
172
-            Log.w(REACT_CLASS, "Invalid tabMode [" + tabMode + "]");
173
-        } else {
174
-            view.setTabMode(tabMode.mode);
175
-        }
176
-    }
177
-
178
-    @ReactProp(name = "tabGravity")
179
-    public void setTabGravity(ReactTabLayout view, String gravity) {
180
-        TabGravity tabGravity = TabGravity.fromString(gravity);
181
-        if (tabGravity == null) {
182
-            Log.w(REACT_CLASS, "Invalid tabGravity [" + gravity + "]");
183
-        } else {
184
-            view.setTabGravity(tabGravity.gravity);
185
-        }
186
-    }
187
-
188
-    @Override
189
-    public boolean needsCustomLayoutForChildren() {
190
-        return true;
191
-    }
192
-
193
-    @Override
194
-    protected void addEventEmitters(ThemedReactContext reactContext, ReactTabLayout view) {
195
-        mDispatcher = reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
196
-    }
197
-
198
-//    @Override
199
-//    public Map<String, Object> getExportedCustomDirectEventTypeConstants() {
200
-//        return MapBuilder.of(
201
-//                TabSelectedEvent.EVENT_NAME, (Object) MapBuilder.of(REGISTRATION_NAME, EVENT_ON_TAB_SELECTED)
202
-//        );
203
-//    }
204
-
205
-    /*
206
-    * This method allows us to expose an interface which we can use from react.
207
-    * If we obtain a reference to this native view, we can call `setViewPager` method and handle
208
-    * the call in `receiveCommand`
209
-    * */
210
-    @Override
211
-    public Map<String, Integer> getCommandsMap() {
212
-        return MapBuilder.of(COMMAND_SET_VIEW_PAGER, COMMAND_SET_VIEW_PAGER_TYPE);
213
-    }
214
-
215
-    @Override
216
-    public void receiveCommand(ReactTabLayout tabLayout, int commandType, ReadableArray args) {
217
-        Assertions.assertNotNull(tabLayout);
218
-        Assertions.assertNotNull(args);
219
-
220
-        switch (commandType) {
221
-            case COMMAND_SET_VIEW_PAGER_TYPE: {
222
-                // Setup TabLayout with ViewPager
223
-                int viewPagerId = args.getInt(0);
224
-                ViewPager viewPager = (ViewPager) tabLayout.getRootView().findViewById(viewPagerId);
225
-                tabLayout.setupWithViewPager(viewPager);
226
-
227
-                // Add tabs
228
-                ReadableArray tabs = args.getArray(1);
229
-                if (tabs != null) {
230
-                    tabLayout.removeAllTabs();
231
-                    this.populateTabLayoutWithTabs(tabLayout, tabs);
232
-//                    tabLayout.setOnTabSelectedListener(new OnTabSelectedListener(viewPager, tabLayout, this));
233
-                }
234
-
235
-                return;
236
-            }
237
-
238
-            default:
239
-                throw new JSApplicationIllegalArgumentException(String.format(
240
-                        "Unsupported command %d received by %s.", commandType, REACT_CLASS));
241
-        }
242
-    }
243
-
244
-    private void populateTabLayoutWithTabs(ReactTabLayout tabLayout, ReadableArray tabs) {
245
-        for (int i = 0; i < tabs.size(); i++) {
246
-            ReadableMap tabMap = tabs.getMap(i);
247
-            TabLayout.Tab tab = tabLayout.newTab();
248
-
249
-            // Set tab text
250
-            if (tabMap.hasKey(PARAM_TEXT)) {
251
-                tab.setText(tabMap.getString(PARAM_TEXT));
252
-            }
253
-
254
-            // Set tab icon
255
-            if (tabMap.hasKey(PARAM_ICON)) {
256
-                Context ctx = tabLayout.getContext();
257
-                Drawable icon = ResourceUtils.getDrawable(ctx, tabMap.getString(PARAM_ICON));
258
-                if (icon != null) {
259
-                    tab.setIcon(icon);
260
-                }
261
-            }
262
-
263
-            tabLayout.addTab(tab);
264
-        }
265
-    }
266
-
267
-    private static class OnTabSelectedListener extends TabLayout.ViewPagerOnTabSelectedListener {
268
-        private final ReactTabLayout mTabLayout;
269
-        private TabLayoutManager mTabLayoutManager;
270
-
271
-        public OnTabSelectedListener(ViewPager viewPager, ReactTabLayout tabLayout, TabLayoutManager manager) {
272
-            super(viewPager);
273
-            mTabLayout = tabLayout;
274
-            mTabLayoutManager = manager;
275
-        }
276
-
277
-        @Override
278
-        public void onTabSelected(Tab tab) {
279
-            super.onTabSelected(tab);
280
-            int position = mTabLayout.indexOf(tab);
281
-//            mTabLayoutManager.mDispatcher.dispatchEvent(new TabSelectedEvent(mTabLayout.getId(position), position));
282
-//            mTabLayoutManager.mDispatcher.dispatchEvent(new TabSelectedEvent(mTabLayout.getId(), position));
283
-        }
284
-
285
-        @Override
286
-        public void onTabUnselected(Tab tab) {
287
-        }
288
-
289
-        @Override
290
-        public void onTabReselected(Tab tab) {
291
-        }
292
-    }
293
-}

+ 0
- 41
android/app/src/main/java/com/reactnativenavigation/managers/ToolbarManager.java View File

1
-package com.reactnativenavigation.managers;
2
-
3
-import android.content.Context;
4
-import android.support.v7.widget.Toolbar;
5
-import android.view.LayoutInflater;
6
-
7
-import com.facebook.react.uimanager.ThemedReactContext;
8
-import com.facebook.react.uimanager.ViewGroupManager;
9
-import com.facebook.react.uimanager.annotations.ReactProp;
10
-import com.reactnativenavigation.R;
11
-
12
-/**
13
- *
14
- * Created by guyc on 19/03/16.
15
- */
16
-@Deprecated
17
-public class ToolbarManager extends ViewGroupManager<Toolbar> {
18
-    private static final String REACT_CLASS = "Toolbar";
19
-
20
-    @Override
21
-    public String getName() {
22
-        return REACT_CLASS;
23
-    }
24
-
25
-    @Override
26
-    public boolean needsCustomLayoutForChildren() {
27
-        return true;
28
-    }
29
-
30
-    @Override
31
-    protected Toolbar createViewInstance(ThemedReactContext reactContext) {
32
-        return (Toolbar)
33
-                ((LayoutInflater) reactContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE))
34
-                .inflate(R.layout.toolbar, null, false);
35
-    }
36
-
37
-    @ReactProp(name = "title")
38
-    public void setTitle(Toolbar view, String title) {
39
-        view.setTitle(title);
40
-    }
41
-}

+ 2
- 2
android/app/src/main/java/com/reactnativenavigation/utils/ContextProvider.java View File

7
 import java.lang.ref.WeakReference;
7
 import java.lang.ref.WeakReference;
8
 
8
 
9
 /**
9
 /**
10
- *
11
  * Created by guyc on 10/03/16.
10
  * Created by guyc on 10/03/16.
12
  */
11
  */
13
 public class ContextProvider {
12
 public class ContextProvider {
19
         }
18
         }
20
     }
19
     }
21
 
20
 
22
-    public static @Nullable BaseReactActivity getActivityContext() {
21
+    @Nullable
22
+    public static BaseReactActivity getActivityContext() {
23
         return sActivityWR != null ? sActivityWR.get() : null;
23
         return sActivityWR != null ? sActivityWR.get() : null;
24
     }
24
     }
25
 
25
 

+ 31
- 30
android/app/src/main/java/com/reactnativenavigation/utils/ResourceDrawableIdHelper.java View File

16
  */
16
  */
17
 public class ResourceDrawableIdHelper {
17
 public class ResourceDrawableIdHelper {
18
 
18
 
19
-  private Map<String, Integer> mResourceDrawableIdMap;
19
+    private Map<String, Integer> mResourceDrawableIdMap;
20
 
20
 
21
-  public ResourceDrawableIdHelper() {
22
-    mResourceDrawableIdMap = new HashMap<String, Integer>();
23
-  }
21
+    public ResourceDrawableIdHelper() {
22
+        mResourceDrawableIdMap = new HashMap<>();
23
+    }
24
+
25
+    public int getResourceDrawableId(Context context, @Nullable String name) {
26
+        if (name == null || name.isEmpty()) {
27
+            return 0;
28
+        }
29
+        name = name.toLowerCase().replace("-", "_");
30
+        if (mResourceDrawableIdMap.containsKey(name)) {
31
+            return mResourceDrawableIdMap.get(name);
32
+        }
33
+        int id = context.getResources().getIdentifier(
34
+                name,
35
+                "drawable",
36
+                context.getPackageName());
37
+        mResourceDrawableIdMap.put(name, id);
38
+        return id;
39
+    }
24
 
40
 
25
-  public int getResourceDrawableId(Context context, @Nullable String name) {
26
-    if (name == null || name.isEmpty()) {
27
-      return 0;
41
+    @Nullable
42
+    public Drawable getResourceDrawable(Context context, @Nullable String name) {
43
+        int resId = getResourceDrawableId(context, name);
44
+        return resId > 0 ? context.getResources().getDrawable(resId) : null;
28
     }
45
     }
29
-    name = name.toLowerCase().replace("-", "_");
30
-    if (mResourceDrawableIdMap.containsKey(name)) {
31
-      return mResourceDrawableIdMap.get(name);
46
+
47
+    public Uri getResourceDrawableUri(Context context, @Nullable String name) {
48
+        int resId = getResourceDrawableId(context, name);
49
+        return resId > 0 ? new Uri.Builder()
50
+                .scheme(UriUtil.LOCAL_RESOURCE_SCHEME)
51
+                .path(String.valueOf(resId))
52
+                .build() : Uri.EMPTY;
32
     }
53
     }
33
-    int id = context.getResources().getIdentifier(
34
-        name,
35
-        "drawable",
36
-        context.getPackageName());
37
-    mResourceDrawableIdMap.put(name, id);
38
-    return id;
39
-  }
40
-
41
-  public @Nullable Drawable getResourceDrawable(Context context, @Nullable String name) {
42
-    int resId = getResourceDrawableId(context, name);
43
-    return resId > 0 ? context.getResources().getDrawable(resId) : null;
44
-  }
45
-
46
-  public Uri getResourceDrawableUri(Context context, @Nullable String name) {
47
-    int resId = getResourceDrawableId(context, name);
48
-    return resId > 0 ? new Uri.Builder()
49
-        .scheme(UriUtil.LOCAL_RESOURCE_SCHEME)
50
-        .path(String.valueOf(resId))
51
-        .build() : Uri.EMPTY;
52
-  }
53
 }
54
 }

+ 0
- 21
android/app/src/main/java/com/reactnativenavigation/utils/ResourceUtils.java View File

1
-package com.reactnativenavigation.utils;
2
-
3
-import android.content.Context;
4
-import android.content.res.Resources;
5
-import android.graphics.drawable.Drawable;
6
-import android.support.v4.content.res.ResourcesCompat;
7
-
8
-/**
9
- * Created by guyc on 17/03/16.
10
- */
11
-public class ResourceUtils {
12
-
13
-    public static final String TYPE_DRAWABLE = "drawable";
14
-
15
-    public static Drawable getDrawable(Context context, String resourceName) {
16
-        Resources resources = context.getResources();
17
-        int id =  resources.getIdentifier(resourceName, TYPE_DRAWABLE, context.getPackageName());
18
-        return id > 0 ? ResourcesCompat.getDrawable(resources, id, context.getTheme()) : null;
19
-    }
20
-
21
-}

+ 15
- 15
android/app/src/main/java/com/reactnativenavigation/views/ScreenStack.java View File

1
 package com.reactnativenavigation.views;
1
 package com.reactnativenavigation.views;
2
 
2
 
3
 import android.animation.LayoutTransition;
3
 import android.animation.LayoutTransition;
4
-import android.view.View;
5
 import android.widget.FrameLayout;
4
 import android.widget.FrameLayout;
6
 
5
 
7
 import com.facebook.react.ReactInstanceManager;
6
 import com.facebook.react.ReactInstanceManager;
17
 
16
 
18
 public class ScreenStack extends FrameLayout {
17
 public class ScreenStack extends FrameLayout {
19
 
18
 
20
-    private class ScreenView{
19
+    private class ScreenView {
21
         Screen screen;
20
         Screen screen;
22
         RctView view;
21
         RctView view;
23
 
22
 
28
     }
27
     }
29
 
28
 
30
     private final Stack<ScreenView> stack = new Stack<>();
29
     private final Stack<ScreenView> stack = new Stack<>();
31
-    private final ReactInstanceManager mReactInstanceManager = RctManager.getInstance().getReactInstanceManager();
30
+    private final ReactInstanceManager mReactInstanceManager =
31
+            RctManager.getInstance().getReactInstanceManager();
32
     private final BaseReactActivity reactActivity;
32
     private final BaseReactActivity reactActivity;
33
 
33
 
34
-    public ScreenStack(BaseReactActivity context){
34
+    public ScreenStack(BaseReactActivity context) {
35
         super(context);
35
         super(context);
36
         reactActivity = context;
36
         reactActivity = context;
37
         setLayoutTransition(new LayoutTransition());
37
         setLayoutTransition(new LayoutTransition());
38
     }
38
     }
39
 
39
 
40
-    public void push(Screen screen){
41
-        View oldView = null;
42
-        if(!stack.isEmpty()) {
40
+    public void push(Screen screen) {
41
+        RctView oldView = null;
42
+        if (!stack.isEmpty()) {
43
             oldView = stack.peek().view;
43
             oldView = stack.peek().view;
44
         }
44
         }
45
         RctView view = new RctView(reactActivity, mReactInstanceManager, screen);
45
         RctView view = new RctView(reactActivity, mReactInstanceManager, screen);
46
         addView(view, MATCH_PARENT, MATCH_PARENT);
46
         addView(view, MATCH_PARENT, MATCH_PARENT);
47
-        if(oldView != null) {
48
-            ReactRootView reactRootView = ((RctView) oldView).getReactRootView();
47
+        if (oldView != null) {
48
+            ReactRootView reactRootView = oldView.getReactRootView();
49
             ReflectionUtils.setBooleanField(reactRootView, "mAttachScheduled", true);
49
             ReflectionUtils.setBooleanField(reactRootView, "mAttachScheduled", true);
50
             removeView(oldView);
50
             removeView(oldView);
51
         }
51
         }
52
         stack.push(new ScreenView(screen, view));
52
         stack.push(new ScreenView(screen, view));
53
     }
53
     }
54
 
54
 
55
-    public Screen pop(){
56
-        if(stack.isEmpty()) {
55
+    public Screen pop() {
56
+        if (stack.isEmpty()) {
57
             return null;
57
             return null;
58
         }
58
         }
59
         ScreenView popped = stack.pop();
59
         ScreenView popped = stack.pop();
60
-        if(!stack.isEmpty()) {
60
+        if (!stack.isEmpty()) {
61
             addView(stack.peek().view, 0);
61
             addView(stack.peek().view, 0);
62
         }
62
         }
63
 
63
 
66
         return popped.screen;
66
         return popped.screen;
67
     }
67
     }
68
 
68
 
69
-    public boolean isEmpty(){
69
+    public boolean isEmpty() {
70
         return stack.isEmpty();
70
         return stack.isEmpty();
71
     }
71
     }
72
 
72
 
73
-    public int getStackSize(){
73
+    public int getStackSize() {
74
         return stack.size();
74
         return stack.size();
75
     }
75
     }
76
 
76
 
77
-    public Screen peek(){
77
+    public Screen peek() {
78
         return stack.peek().screen;
78
         return stack.peek().screen;
79
     }
79
     }
80
 }
80
 }