Browse Source

Refactor towards StackLayout (#2506)

* Deleted getContentView method
* Delete Custom dialog code
* Delete topTab code
* sendOnNavigationButtonPressed was pulled to a dedicated interface
Guy Carmeli 7 years ago
parent
commit
3a9e8d5368
No account linked to committer's email address

+ 0
- 5
lib/android/app/src/main/java/com/reactnativenavigation/anim/NavigationAnimator.java View File

4
 import android.animation.AnimatorListenerAdapter;
4
 import android.animation.AnimatorListenerAdapter;
5
 import android.animation.AnimatorSet;
5
 import android.animation.AnimatorSet;
6
 import android.animation.ObjectAnimator;
6
 import android.animation.ObjectAnimator;
7
-import android.animation.TimeInterpolator;
8
 import android.content.Context;
7
 import android.content.Context;
9
 import android.support.annotation.Nullable;
8
 import android.support.annotation.Nullable;
10
-import android.util.DisplayMetrics;
11
 import android.view.View;
9
 import android.view.View;
12
-import android.view.ViewGroup;
13
-import android.view.WindowManager;
14
 import android.view.animation.AccelerateInterpolator;
10
 import android.view.animation.AccelerateInterpolator;
15
 import android.view.animation.DecelerateInterpolator;
11
 import android.view.animation.DecelerateInterpolator;
16
 
12
 
17
 import com.reactnativenavigation.utils.UiUtils;
13
 import com.reactnativenavigation.utils.UiUtils;
18
-import com.reactnativenavigation.views.TopBar;
19
 
14
 
20
 @SuppressWarnings("ResourceType")
15
 @SuppressWarnings("ResourceType")
21
 public class NavigationAnimator {
16
 public class NavigationAnimator {

+ 0
- 25
lib/android/app/src/main/java/com/reactnativenavigation/parse/LayoutFactory.java View File

3
 import android.app.Activity;
3
 import android.app.Activity;
4
 
4
 
5
 import com.facebook.react.ReactInstanceManager;
5
 import com.facebook.react.ReactInstanceManager;
6
-import com.reactnativenavigation.react.ReactComponentViewCreator;
7
 import com.reactnativenavigation.utils.TypefaceLoader;
6
 import com.reactnativenavigation.utils.TypefaceLoader;
8
 import com.reactnativenavigation.viewcontrollers.BottomTabsController;
7
 import com.reactnativenavigation.viewcontrollers.BottomTabsController;
9
 import com.reactnativenavigation.viewcontrollers.ComponentViewController;
8
 import com.reactnativenavigation.viewcontrollers.ComponentViewController;
10
 import com.reactnativenavigation.viewcontrollers.SideMenuController;
9
 import com.reactnativenavigation.viewcontrollers.SideMenuController;
11
 import com.reactnativenavigation.viewcontrollers.StackController;
10
 import com.reactnativenavigation.viewcontrollers.StackController;
12
 import com.reactnativenavigation.viewcontrollers.ViewController;
11
 import com.reactnativenavigation.viewcontrollers.ViewController;
13
-import com.reactnativenavigation.viewcontrollers.overlay.DialogViewController;
14
 import com.reactnativenavigation.viewcontrollers.toptabs.TopTabController;
12
 import com.reactnativenavigation.viewcontrollers.toptabs.TopTabController;
15
 import com.reactnativenavigation.viewcontrollers.toptabs.TopTabsController;
13
 import com.reactnativenavigation.viewcontrollers.toptabs.TopTabsController;
16
 import com.reactnativenavigation.views.ComponentViewCreator;
14
 import com.reactnativenavigation.views.ComponentViewCreator;
49
 				return createSideMenuLeft(node);
47
 				return createSideMenuLeft(node);
50
 			case SideMenuRight:
48
 			case SideMenuRight:
51
 				return createSideMenuRight(node);
49
 				return createSideMenuRight(node);
52
-//			case CustomDialog:
53
-//				return createDialogComponent(node);
54
             case TopTabs:
50
             case TopTabs:
55
                 return createTopTabs(node);
51
                 return createTopTabs(node);
56
-//            case TopTab:
57
-//                return createTopTab(node);
58
 			default:
52
 			default:
59
 				throw new IllegalArgumentException("Invalid node type: " + node.type);
53
 				throw new IllegalArgumentException("Invalid node type: " + node.type);
60
 		}
54
 		}
123
 		return tabsComponent;
117
 		return tabsComponent;
124
 	}
118
 	}
125
 
119
 
126
-	private ViewController createDialogComponent(LayoutNode node) {
127
-		String id = node.id;
128
-		String name = node.data.optString("name");
129
-		ReactComponentViewCreator creator = new ReactComponentViewCreator(reactInstanceManager);
130
-		return new DialogViewController(activity, id, name, creator);
131
-	}
132
-
133
     private ViewController createTopTabs(LayoutNode node) {
120
     private ViewController createTopTabs(LayoutNode node) {
134
         final List<TopTabController> tabs = new ArrayList<>();
121
         final List<TopTabController> tabs = new ArrayList<>();
135
         for (int i = 0; i < node.children.size(); i++) {
122
         for (int i = 0; i < node.children.size(); i++) {
140
         Options options = Options.parse(typefaceManager, node.getNavigationOptions(), defaultOptions);
127
         Options options = Options.parse(typefaceManager, node.getNavigationOptions(), defaultOptions);
141
         return new TopTabsController(activity, node.id, tabs, new TopTabsLayoutCreator(activity, tabs), options);
128
         return new TopTabsController(activity, node.id, tabs, new TopTabsLayoutCreator(activity, tabs), options);
142
     }
129
     }
143
-
144
-    private ViewController createTopTab(LayoutNode node) {
145
-        String id = node.id;
146
-        String name = node.data.optString("name");
147
-        Options options = Options.parse(typefaceManager, node.getNavigationOptions(), defaultOptions);
148
-        return new TopTabController(activity,
149
-                id,
150
-                name,
151
-                new ReactComponentViewCreator(reactInstanceManager),
152
-                options
153
-        );
154
-    }
155
 }
130
 }

+ 2
- 13
lib/android/app/src/main/java/com/reactnativenavigation/react/NavigationModule.java View File

19
 import com.reactnativenavigation.utils.UiThread;
19
 import com.reactnativenavigation.utils.UiThread;
20
 import com.reactnativenavigation.viewcontrollers.Navigator;
20
 import com.reactnativenavigation.viewcontrollers.Navigator;
21
 import com.reactnativenavigation.viewcontrollers.ViewController;
21
 import com.reactnativenavigation.viewcontrollers.ViewController;
22
-import com.reactnativenavigation.viewcontrollers.overlay.OverlayFactory;
23
 
22
 
24
 public class NavigationModule extends ReactContextBaseJavaModule {
23
 public class NavigationModule extends ReactContextBaseJavaModule {
25
 	private static final String NAME = "RNNBridgeModule";
24
 	private static final String NAME = "RNNBridgeModule";
102
 
101
 
103
 	@ReactMethod
102
 	@ReactMethod
104
 	public void showOverlay(final String type, final ReadableMap data, final Promise promise) {
103
 	public void showOverlay(final String type, final ReadableMap data, final Promise promise) {
105
-		if (OverlayFactory.Overlay.create(type) == OverlayFactory.Overlay.CustomDialog) {
106
-			final LayoutNode layoutTree = LayoutNodeParser.parse(JSONParser.parse(data));
107
-			handle(() -> {
108
-                ViewController viewController = newLayoutFactory().create(layoutTree);
109
-                navigator().showOverlay(type, OverlayOptions.create(viewController), promise);
110
-            });
111
-		} else {
112
-			final OverlayOptions overlayOptions = OverlayOptions.parse(JSONParser.parse(data));
113
-			handle(() -> navigator().showOverlay(type, overlayOptions, promise));
114
-		}
115
-
116
-
104
+        final OverlayOptions overlayOptions = OverlayOptions.parse(JSONParser.parse(data));
105
+        handle(() -> navigator().showOverlay(type, overlayOptions, promise));
117
 	}
106
 	}
118
 
107
 
119
 	@ReactMethod
108
 	@ReactMethod

+ 7
- 16
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/StackController.java View File

38
 		View enteringView = child.getView();
38
 		View enteringView = child.getView();
39
 		getView().addView(enteringView);
39
 		getView().addView(enteringView);
40
 
40
 
41
-		//TODO animatePush only when needed
42
 		if (previousTop != null) {
41
 		if (previousTop != null) {
43
-			animator.animatePush(enteringView, new NavigationAnimator.NavigationAnimationListener() {
44
-				@Override
45
-				public void onAnimationEnd() {
46
-					getView().removeView(previousTop.getView());
47
-					if (promise != null) {
48
-						promise.resolve(child.getId());
49
-					}
50
-				}
51
-			});
42
+			animator.animatePush(enteringView, () -> {
43
+                getView().removeView(previousTop.getView());
44
+                if (promise != null) {
45
+                    promise.resolve(child.getId());
46
+                }
47
+            });
52
 		} else if (promise != null) {
48
 		} else if (promise != null) {
53
 			promise.resolve(child.getId());
49
 			promise.resolve(child.getId());
54
 		}
50
 		}
80
 		getView().addView(enteringView, getView().getChildCount() - 1);
76
 		getView().addView(enteringView, getView().getChildCount() - 1);
81
 
77
 
82
 		if (animate) {
78
 		if (animate) {
83
-			animator.animatePop(exitingView, new NavigationAnimator.NavigationAnimationListener() {
84
-				@Override
85
-				public void onAnimationEnd() {
86
-					finishPopping(exitingView, poppedTop, promise);
87
-				}
88
-			});
79
+			animator.animatePop(exitingView, () -> finishPopping(exitingView, poppedTop, promise));
89
 		} else {
80
 		} else {
90
 			finishPopping(exitingView, poppedTop, promise);
81
 			finishPopping(exitingView, poppedTop, promise);
91
 		}
82
 		}

+ 0
- 36
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/overlay/CustomOverlay.java View File

1
-package com.reactnativenavigation.viewcontrollers.overlay;
2
-
3
-
4
-import android.content.Context;
5
-
6
-import com.reactnativenavigation.parse.OverlayOptions;
7
-import com.reactnativenavigation.viewcontrollers.ComponentViewController;
8
-import com.reactnativenavigation.viewcontrollers.ViewController;
9
-import com.reactnativenavigation.views.CustomDialog;
10
-
11
-public class CustomOverlay implements OverlayInterface {
12
-
13
-	private CustomDialog dialog;
14
-
15
-	@Override
16
-	public CustomOverlay create(ViewController root, OverlayOptions options) {
17
-		//TODO; implement
18
-
19
-		ViewController viewController = options.getCustomView();
20
-		dialog = new CustomDialog(root.getActivity(), viewController.getView());
21
-
22
-		return this;
23
-	}
24
-
25
-	@Override
26
-	public void show() {
27
-		dialog.show();
28
-	}
29
-
30
-	@Override
31
-	public void dismiss() {
32
-		if (dialog != null) {
33
-			dialog.dismiss();
34
-		}
35
-	}
36
-}

+ 1
- 4
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/overlay/OverlayFactory.java View File

1
 package com.reactnativenavigation.viewcontrollers.overlay;
1
 package com.reactnativenavigation.viewcontrollers.overlay;
2
 
2
 
3
 
3
 
4
-import android.content.Context;
5
-
6
 import com.reactnativenavigation.parse.OverlayOptions;
4
 import com.reactnativenavigation.parse.OverlayOptions;
7
 import com.reactnativenavigation.viewcontrollers.ViewController;
5
 import com.reactnativenavigation.viewcontrollers.ViewController;
8
 
6
 
10
 
8
 
11
 	public enum Overlay {
9
 	public enum Overlay {
12
 		AlertDialog("alert", new AlertOverlay()),
10
 		AlertDialog("alert", new AlertOverlay()),
13
-		Snackbar("snackbar", new SnackbarOverlay()),
14
-		CustomDialog("custom", new CustomOverlay());
11
+		Snackbar("snackbar", new SnackbarOverlay());
15
 
12
 
16
 		private String name;
13
 		private String name;
17
 		private OverlayInterface overlayInstance;
14
 		private OverlayInterface overlayInstance;

+ 0
- 6
lib/android/app/src/main/java/com/reactnativenavigation/views/Component.java View File

1
 package com.reactnativenavigation.views;
1
 package com.reactnativenavigation.views;
2
 
2
 
3
-import android.view.View;
4
-
5
 import com.reactnativenavigation.parse.Options;
3
 import com.reactnativenavigation.parse.Options;
6
 
4
 
7
 public interface Component {
5
 public interface Component {
8
     void applyOptions(Options options);
6
     void applyOptions(Options options);
9
 
7
 
10
-    void sendOnNavigationButtonPressed(String id);
11
-
12
     TopBar getTopBar();
8
     TopBar getTopBar();
13
 
9
 
14
-    View getContentView();
15
-
16
     void drawBehindTopBar();
10
     void drawBehindTopBar();
17
 
11
 
18
     void drawBelowTopBar();
12
     void drawBelowTopBar();

+ 7
- 7
lib/android/app/src/main/java/com/reactnativenavigation/views/ComponentLayout.java View File

13
 import static android.view.ViewGroup.LayoutParams.*;
13
 import static android.view.ViewGroup.LayoutParams.*;
14
 
14
 
15
 @SuppressLint("ViewConstructor")
15
 @SuppressLint("ViewConstructor")
16
-public class ComponentLayout extends RelativeLayout implements ReactComponent {
16
+public class ComponentLayout extends RelativeLayout implements ReactComponent, TitleBarButton.OnClickListener {
17
 
17
 
18
     private TopBar topBar;
18
     private TopBar topBar;
19
     private IReactView reactView;
19
     private IReactView reactView;
22
 	public ComponentLayout(Context context, IReactView reactView, EventDispatcher eventDispatcher) {
22
 	public ComponentLayout(Context context, IReactView reactView, EventDispatcher eventDispatcher) {
23
 		super(context);
23
 		super(context);
24
 		this.reactView = reactView;
24
 		this.reactView = reactView;
25
-		this.topBar = new TopBar(context, this, eventDispatcher);
25
+		this.topBar = new TopBar(context, reactView.asView(), this, eventDispatcher);
26
         optionsPresenter = new OptionsPresenter(this);
26
         optionsPresenter = new OptionsPresenter(this);
27
         initViews();
27
         initViews();
28
     }
28
     }
74
         return topBar;
74
         return topBar;
75
     }
75
     }
76
 
76
 
77
-    @Override
78
-    public View getContentView() {
79
-        return reactView.asView();
80
-    }
81
-
82
     @Override
77
     @Override
83
     public void drawBehindTopBar() {
78
     public void drawBehindTopBar() {
84
         RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) reactView.asView().getLayoutParams();
79
         RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) reactView.asView().getLayoutParams();
92
         layoutParams.addRule(BELOW, topBar.getId());
87
         layoutParams.addRule(BELOW, topBar.getId());
93
         reactView.asView().setLayoutParams(layoutParams);
88
         reactView.asView().setLayoutParams(layoutParams);
94
     }
89
     }
90
+
91
+    @Override
92
+    public void onPress(String buttonId) {
93
+        reactView.sendOnNavigationButtonPressed(buttonId);
94
+    }
95
 }
95
 }

+ 0
- 29
lib/android/app/src/main/java/com/reactnativenavigation/views/CustomDialog.java View File

1
-package com.reactnativenavigation.views;
2
-
3
-import android.app.Dialog;
4
-import android.content.Context;
5
-import android.support.annotation.NonNull;
6
-import android.util.Log;
7
-import android.view.View;
8
-import android.view.ViewGroup;
9
-import android.view.ViewTreeObserver;
10
-import android.view.WindowManager;
11
-
12
-import com.facebook.react.ReactRootView;
13
-
14
-
15
-public class CustomDialog extends Dialog {
16
-
17
-	private View component;
18
-
19
-	public CustomDialog(@NonNull Context context, @NonNull View component) {
20
-		super(context);
21
-
22
-		this.component = component;
23
-		init();
24
-	}
25
-
26
-	private void init() {
27
-		addContentView(component, new WindowManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
28
-	}
29
-}

+ 9
- 5
lib/android/app/src/main/java/com/reactnativenavigation/views/TitleBarButton.java View File

22
 import java.util.ArrayList;
22
 import java.util.ArrayList;
23
 
23
 
24
 public class TitleBarButton implements MenuItem.OnMenuItemClickListener {
24
 public class TitleBarButton implements MenuItem.OnMenuItemClickListener {
25
+    public interface OnClickListener {
26
+        void onPress(String buttonId);
27
+    }
28
+
25
 	private Toolbar toolbar;
29
 	private Toolbar toolbar;
26
 	private final Button button;
30
 	private final Button button;
27
-	private Component component;
28
 	private Drawable icon;
31
 	private Drawable icon;
32
+    private OnClickListener onPressListener;
29
 
33
 
30
-	TitleBarButton(Component component, Toolbar toolbar, Button button) {
31
-		this.component = component;
34
+    TitleBarButton(Toolbar toolbar, Button button, OnClickListener onPressListener) {
35
+        this.onPressListener = onPressListener;
32
 		this.toolbar = toolbar;
36
 		this.toolbar = toolbar;
33
 		this.button = button;
37
 		this.button = button;
34
 	}
38
 	}
118
 	}
122
 	}
119
 
123
 
120
 	private void setNavigationClickListener() {
124
 	private void setNavigationClickListener() {
121
-		toolbar.setNavigationOnClickListener(view -> component.sendOnNavigationButtonPressed(button.id));
125
+		toolbar.setNavigationOnClickListener(view -> onPressListener.onPress(button.id));
122
 	}
126
 	}
123
 
127
 
124
 	@Override
128
 	@Override
125
 	public boolean onMenuItemClick(MenuItem menuItem) {
129
 	public boolean onMenuItemClick(MenuItem menuItem) {
126
-		this.component.sendOnNavigationButtonPressed(button.id);
130
+		onPressListener.onPress(button.id);
127
 		return true;
131
 		return true;
128
 	}
132
 	}
129
 
133
 

+ 24
- 20
lib/android/app/src/main/java/com/reactnativenavigation/views/TopBar.java View File

1
 package com.reactnativenavigation.views;
1
 package com.reactnativenavigation.views;
2
 
2
 
3
-import android.annotation.*;
4
-import android.content.*;
5
-import android.graphics.*;
6
-import android.support.annotation.*;
7
-import android.support.design.widget.*;
3
+import android.annotation.SuppressLint;
4
+import android.content.Context;
5
+import android.graphics.Typeface;
6
+import android.support.annotation.ColorInt;
7
+import android.support.annotation.Nullable;
8
+import android.support.design.widget.AppBarLayout;
8
 import android.support.v7.widget.Toolbar;
9
 import android.support.v7.widget.Toolbar;
9
-import android.util.*;
10
-import android.view.*;
11
-import android.widget.*;
12
-
13
-import com.facebook.react.uimanager.events.*;
14
-import com.reactnativenavigation.anim.*;
10
+import android.util.Log;
11
+import android.view.Menu;
12
+import android.view.View;
13
+import android.view.ViewGroup;
14
+import android.widget.TextView;
15
+
16
+import com.facebook.react.uimanager.events.EventDispatcher;
17
+import com.reactnativenavigation.anim.TopBarAnimator;
18
+import com.reactnativenavigation.anim.TopBarCollapseBehavior;
15
 import com.reactnativenavigation.parse.Button;
19
 import com.reactnativenavigation.parse.Button;
16
 import com.reactnativenavigation.parse.Color;
20
 import com.reactnativenavigation.parse.Color;
17
-import com.reactnativenavigation.parse.*;
18
 import com.reactnativenavigation.parse.Number;
21
 import com.reactnativenavigation.parse.Number;
19
-import com.reactnativenavigation.viewcontrollers.toptabs.*;
22
+import com.reactnativenavigation.parse.Options;
23
+import com.reactnativenavigation.viewcontrollers.toptabs.TopTabsViewPager;
20
 
24
 
21
-import java.util.*;
25
+import java.util.ArrayList;
22
 
26
 
23
 @SuppressLint("ViewConstructor")
27
 @SuppressLint("ViewConstructor")
24
 public class TopBar extends AppBarLayout {
28
 public class TopBar extends AppBarLayout {
25
     private final Toolbar titleBar;
29
     private final Toolbar titleBar;
30
+    private TitleBarButton.OnClickListener onClickListener;
26
     private final TopBarCollapseBehavior collapsingBehavior;
31
     private final TopBarCollapseBehavior collapsingBehavior;
27
     private final TopBarAnimator animator;
32
     private final TopBarAnimator animator;
28
-    private Component component;
29
     private TopTabs topTabs;
33
     private TopTabs topTabs;
30
 
34
 
31
-    public TopBar(final Context context, Component component, EventDispatcher eventDispatcher) {
35
+    public TopBar(final Context context, View contentView, TitleBarButton.OnClickListener onClickListener, EventDispatcher eventDispatcher) {
32
         super(context);
36
         super(context);
37
+        this.onClickListener = onClickListener;
33
         collapsingBehavior = new TopBarCollapseBehavior(eventDispatcher, this);
38
         collapsingBehavior = new TopBarCollapseBehavior(eventDispatcher, this);
34
-        this.component = component;
35
         titleBar = new Toolbar(context);
39
         titleBar = new Toolbar(context);
36
         topTabs = new TopTabs(getContext());
40
         topTabs = new TopTabs(getContext());
37
-        this.animator = new TopBarAnimator(this, component != null ? component.getContentView() : null);
41
+        this.animator = new TopBarAnimator(this, contentView);
38
         addView(titleBar);
42
         addView(titleBar);
39
     }
43
     }
40
 
44
 
119
     }
123
     }
120
 
124
 
121
     private void setLeftButton(final Button button) {
125
     private void setLeftButton(final Button button) {
122
-        TitleBarButton leftBarButton = new TitleBarButton(component, this.titleBar, button);
126
+        TitleBarButton leftBarButton = new TitleBarButton(this.titleBar, button, onClickListener);
123
         leftBarButton.applyNavigationIcon(getContext());
127
         leftBarButton.applyNavigationIcon(getContext());
124
     }
128
     }
125
 
129
 
133
 
137
 
134
         for (int i = 0; i < rightButtons.size(); i++) {
138
         for (int i = 0; i < rightButtons.size(); i++) {
135
             Button button = rightButtons.get(i);
139
             Button button = rightButtons.get(i);
136
-            TitleBarButton titleBarButton = new TitleBarButton(component, this.titleBar, button);
140
+            TitleBarButton titleBarButton = new TitleBarButton(this.titleBar, button, onClickListener);
137
             titleBarButton.addToMenu(getContext(), menu);
141
             titleBarButton.addToMenu(getContext(), menu);
138
         }
142
         }
139
     }
143
     }

+ 8
- 13
lib/android/app/src/main/java/com/reactnativenavigation/views/TopTabsLayout.java View File

15
 import java.util.*;
15
 import java.util.*;
16
 
16
 
17
 @SuppressLint("ViewConstructor")
17
 @SuppressLint("ViewConstructor")
18
-public class TopTabsLayout extends RelativeLayout implements Component {
18
+public class TopTabsLayout extends RelativeLayout implements Component, TitleBarButton.OnClickListener {
19
 
19
 
20
     private TopBar topBar;
20
     private TopBar topBar;
21
     private List<TopTabController> tabs;
21
     private List<TopTabController> tabs;
25
     public TopTabsLayout(Context context, List<TopTabController> tabs, TopTabsAdapter adapter) {
25
     public TopTabsLayout(Context context, List<TopTabController> tabs, TopTabsAdapter adapter) {
26
         super(context);
26
         super(context);
27
         this.tabs = tabs;
27
         this.tabs = tabs;
28
-        topBar = new TopBar(context, this, null);
29
-        topBar.setId(View.generateViewId());
30
         viewPager = new TopTabsViewPager(context, tabs, adapter);
28
         viewPager = new TopTabsViewPager(context, tabs, adapter);
29
+        topBar = new TopBar(context, viewPager, this, null);
30
+        topBar.setId(View.generateViewId());
31
         optionsPresenter = new OptionsPresenter(this);
31
         optionsPresenter = new OptionsPresenter(this);
32
         initViews();
32
         initViews();
33
     }
33
     }
45
         optionsPresenter.applyOptions(options);
45
         optionsPresenter.applyOptions(options);
46
     }
46
     }
47
 
47
 
48
-    @Override
49
-    public void sendOnNavigationButtonPressed(String id) {
50
-        viewPager.sendOnNavigationButtonPressed(id);
51
-    }
52
-
53
     @Override
48
     @Override
54
     public TopBar getTopBar() {
49
     public TopBar getTopBar() {
55
         return topBar;
50
         return topBar;
56
     }
51
     }
57
 
52
 
58
-    @Override
59
-    public View getContentView() {
60
-        return viewPager;
61
-    }
62
-
63
     @Override
53
     @Override
64
     public void drawBehindTopBar() {
54
     public void drawBehindTopBar() {
65
 
55
 
87
     public int getCurrentItem() {
77
     public int getCurrentItem() {
88
         return viewPager.getCurrentItem();
78
         return viewPager.getCurrentItem();
89
     }
79
     }
80
+
81
+    @Override
82
+    public void onPress(String buttonId) {
83
+        viewPager.sendOnNavigationButtonPressed(buttonId);
84
+    }
90
 }
85
 }

+ 7
- 7
lib/android/app/src/test/java/com/reactnativenavigation/mocks/TestComponentLayout.java View File

8
 import com.reactnativenavigation.presentation.*;
8
 import com.reactnativenavigation.presentation.*;
9
 import com.reactnativenavigation.views.*;
9
 import com.reactnativenavigation.views.*;
10
 
10
 
11
-public class TestComponentLayout extends RelativeLayout implements ReactComponent {
11
+public class TestComponentLayout extends RelativeLayout implements ReactComponent, TitleBarButton.OnClickListener {
12
 
12
 
13
     private final TopBar topBar;
13
     private final TopBar topBar;
14
     private final View contentView;
14
     private final View contentView;
16
 
16
 
17
     public TestComponentLayout(final Context context) {
17
     public TestComponentLayout(final Context context) {
18
         super(context);
18
         super(context);
19
-        topBar = new TopBar(context, this, null);
20
         contentView = new View(context);
19
         contentView = new View(context);
20
+        topBar = new TopBar(context, contentView, this, null);
21
         addView(topBar);
21
         addView(topBar);
22
         addView(contentView);
22
         addView(contentView);
23
         optionsPresenter = new OptionsPresenter(this);
23
         optionsPresenter = new OptionsPresenter(this);
27
         return topBar;
27
         return topBar;
28
     }
28
     }
29
 
29
 
30
-    @Override
31
-    public View getContentView() {
32
-        return contentView;
33
-    }
34
-
35
     @Override
30
     @Override
36
     public void drawBehindTopBar() {
31
     public void drawBehindTopBar() {
37
         RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
32
         RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
77
     public void sendOnNavigationButtonPressed(String id) {
72
     public void sendOnNavigationButtonPressed(String id) {
78
 
73
 
79
     }
74
     }
75
+
76
+    @Override
77
+    public void onPress(String buttonId) {
78
+
79
+    }
80
 }
80
 }

+ 6
- 6
lib/android/app/src/test/java/com/reactnativenavigation/mocks/TestComponentView.java View File

6
 import com.reactnativenavigation.parse.*;
6
 import com.reactnativenavigation.parse.*;
7
 import com.reactnativenavigation.views.*;
7
 import com.reactnativenavigation.views.*;
8
 
8
 
9
-public class TestComponentView extends View implements ReactComponent {
9
+public class TestComponentView extends View implements ReactComponent, TitleBarButton.OnClickListener {
10
 
10
 
11
     private TopBar topBar;
11
     private TopBar topBar;
12
 
12
 
13
     public TestComponentView(final Context context) {
13
     public TestComponentView(final Context context) {
14
         super(context);
14
         super(context);
15
-        topBar = new TopBar(context, this, null);
15
+        topBar = new TopBar(context, this, this, null);
16
 
16
 
17
     }
17
     }
18
 
18
 
54
     }
54
     }
55
 
55
 
56
     @Override
56
     @Override
57
-    public View getContentView() {
58
-        return null;
57
+    public void drawBehindTopBar() {
58
+
59
     }
59
     }
60
 
60
 
61
     @Override
61
     @Override
62
-    public void drawBehindTopBar() {
62
+    public void drawBelowTopBar() {
63
 
63
 
64
     }
64
     }
65
 
65
 
66
     @Override
66
     @Override
67
-    public void drawBelowTopBar() {
67
+    public void onPress(String buttonId) {
68
 
68
 
69
     }
69
     }
70
 }
70
 }

+ 1
- 1
lib/android/app/src/test/java/com/reactnativenavigation/views/TopBarTest.java View File

9
 public class TopBarTest extends BaseTest {
9
 public class TopBarTest extends BaseTest {
10
     @Test
10
     @Test
11
     public void title() throws Exception {
11
     public void title() throws Exception {
12
-        TopBar topBar = new TopBar(newActivity(), null, null);
12
+        TopBar topBar = new TopBar(newActivity(), null, buttonId -> {}, null);
13
         assertThat(topBar.getTitle()).isEmpty();
13
         assertThat(topBar.getTitle()).isEmpty();
14
 
14
 
15
         topBar.setTitle("new title");
15
         topBar.setTitle("new title");