| 
				
			 | 
			
			
				@@ -1,102 +1,83 @@ 
			 | 
		
	
		
			
			| 
				1
			 | 
			
				1
			 | 
			
			
				 package com.reactnativenavigation.layout.impl; 
			 | 
		
	
		
			
			| 
				2
			 | 
			
				2
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				3
			 | 
			
				
			 | 
			
			
				-import android.app.Activity; 
			 | 
		
	
		
			
			| 
				4
			 | 
			
				
			 | 
			
			
				-import android.graphics.Color; 
			 | 
		
	
		
			
			| 
				5
			 | 
			
				
			 | 
			
			
				-import android.support.annotation.NonNull; 
			 | 
		
	
		
			
			| 
				6
			 | 
			
				
			 | 
			
			
				-import android.support.design.widget.BottomNavigationView; 
			 | 
		
	
		
			
			| 
				7
			 | 
			
				
			 | 
			
			
				-import android.view.Menu; 
			 | 
		
	
		
			
			| 
				8
			 | 
			
				
			 | 
			
			
				-import android.view.MenuItem; 
			 | 
		
	
		
			
			| 
				9
			 | 
			
				
			 | 
			
			
				-import android.view.View; 
			 | 
		
	
		
			
			| 
				10
			 | 
			
				
			 | 
			
			
				-import android.widget.RelativeLayout; 
			 | 
		
	
		
			
			| 
				11
			 | 
			
				
			 | 
			
			
				-import android.widget.RelativeLayout.LayoutParams; 
			 | 
		
	
		
			
			| 
				12
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				13
			 | 
			
				
			 | 
			
			
				-import com.reactnativenavigation.layout.Layout; 
			 | 
		
	
		
			
			| 
				14
			 | 
			
				
			 | 
			
			
				-import com.reactnativenavigation.utils.CompatUtils; 
			 | 
		
	
		
			
			| 
				15
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				16
			 | 
			
				
			 | 
			
			
				-import java.util.ArrayList; 
			 | 
		
	
		
			
			| 
				17
			 | 
			
				
			 | 
			
			
				-import java.util.List; 
			 | 
		
	
		
			
			| 
				18
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				19
			 | 
			
				
			 | 
			
			
				-import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; 
			 | 
		
	
		
			
			| 
				20
			 | 
			
				
			 | 
			
			
				-import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT; 
			 | 
		
	
		
			
			| 
				21
			 | 
			
				
			 | 
			
			
				-import static android.widget.RelativeLayout.ABOVE; 
			 | 
		
	
		
			
			| 
				22
			 | 
			
				
			 | 
			
			
				-import static android.widget.RelativeLayout.ALIGN_PARENT_BOTTOM; 
			 | 
		
	
		
			
			| 
				23
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				24
			 | 
			
				
			 | 
			
			
				-public class BottomTabsLayout implements Layout, BottomNavigationView.OnNavigationItemSelectedListener { 
			 | 
		
	
		
			
			| 
				25
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				26
			 | 
			
				
			 | 
			
			
				-	private StackLayout stackLayout; 
			 | 
		
	
		
			
			| 
				27
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				28
			 | 
			
				
			 | 
			
			
				-	public static class TooManyTabs extends RuntimeException { 
			 | 
		
	
		
			
			| 
				29
			 | 
			
				
			 | 
			
			
				-		// 
			 | 
		
	
		
			
			| 
				30
			 | 
			
				
			 | 
			
			
				-	} 
			 | 
		
	
		
			
			| 
				31
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				32
			 | 
			
				
			 | 
			
			
				-	private final RelativeLayout view; 
			 | 
		
	
		
			
			| 
				33
			 | 
			
				
			 | 
			
			
				-	private final BottomNavigationView bottomNavigationView; 
			 | 
		
	
		
			
			| 
				34
			 | 
			
				
			 | 
			
			
				-	private final List<Layout> tabs = new ArrayList<>(); 
			 | 
		
	
		
			
			| 
				35
			 | 
			
				
			 | 
			
			
				-	private int currentTab; 
			 | 
		
	
		
			
			| 
				36
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				37
			 | 
			
				
			 | 
			
			
				-	public BottomTabsLayout(Activity activity) { 
			 | 
		
	
		
			
			| 
				38
			 | 
			
				
			 | 
			
			
				-		view = new RelativeLayout(activity); 
			 | 
		
	
		
			
			| 
				39
			 | 
			
				
			 | 
			
			
				-		view.setId(CompatUtils.generateViewId()); 
			 | 
		
	
		
			
			| 
				40
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				41
			 | 
			
				
			 | 
			
			
				-		bottomNavigationView = new BottomNavigationView(view.getContext()); 
			 | 
		
	
		
			
			| 
				42
			 | 
			
				
			 | 
			
			
				-		bottomNavigationView.setId(CompatUtils.generateViewId()); 
			 | 
		
	
		
			
			| 
				43
			 | 
			
				
			 | 
			
			
				-		bottomNavigationView.setBackgroundColor(Color.DKGRAY); 
			 | 
		
	
		
			
			| 
				44
			 | 
			
				
			 | 
			
			
				-		bottomNavigationView.setOnNavigationItemSelectedListener(this); 
			 | 
		
	
		
			
			| 
				45
			 | 
			
				
			 | 
			
			
				-		LayoutParams lp = new LayoutParams(MATCH_PARENT, WRAP_CONTENT); 
			 | 
		
	
		
			
			| 
				46
			 | 
			
				
			 | 
			
			
				-		lp.addRule(ALIGN_PARENT_BOTTOM); 
			 | 
		
	
		
			
			| 
				47
			 | 
			
				
			 | 
			
			
				-		bottomNavigationView.setLayoutParams(lp); 
			 | 
		
	
		
			
			| 
				48
			 | 
			
				
			 | 
			
			
				-		view.addView(bottomNavigationView, lp); 
			 | 
		
	
		
			
			| 
				49
			 | 
			
				
			 | 
			
			
				-	} 
			 | 
		
	
		
			
			| 
				50
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				51
			 | 
			
				
			 | 
			
			
				-	@Override 
			 | 
		
	
		
			
			| 
				52
			 | 
			
				
			 | 
			
			
				-	public View getView() { 
			 | 
		
	
		
			
			| 
				53
			 | 
			
				
			 | 
			
			
				-		return view; 
			 | 
		
	
		
			
			| 
				54
			 | 
			
				
			 | 
			
			
				-	} 
			 | 
		
	
		
			
			| 
				55
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				56
			 | 
			
				
			 | 
			
			
				-	@Override 
			 | 
		
	
		
			
			| 
				57
			 | 
			
				
			 | 
			
			
				-	public void destroy() { 
			 | 
		
	
		
			
			| 
				58
			 | 
			
				
			 | 
			
			
				-		// 
			 | 
		
	
		
			
			| 
				59
			 | 
			
				
			 | 
			
			
				-	} 
			 | 
		
	
		
			
			| 
				60
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				61
			 | 
			
				
			 | 
			
			
				-	@Override 
			 | 
		
	
		
			
			| 
				62
			 | 
			
				
			 | 
			
			
				-	public boolean onNavigationItemSelected(@NonNull final MenuItem item) { 
			 | 
		
	
		
			
			| 
				63
			 | 
			
				
			 | 
			
			
				-		hideTab(currentTab); 
			 | 
		
	
		
			
			| 
				64
			 | 
			
				
			 | 
			
			
				-		currentTab = item.getItemId(); 
			 | 
		
	
		
			
			| 
				65
			 | 
			
				
			 | 
			
			
				-		showTab(currentTab); 
			 | 
		
	
		
			
			| 
				66
			 | 
			
				
			 | 
			
			
				-		return true; 
			 | 
		
	
		
			
			| 
				67
			 | 
			
				
			 | 
			
			
				-	} 
			 | 
		
	
		
			
			| 
				68
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				69
			 | 
			
				
			 | 
			
			
				-	public void addTab(String label, Layout tabLayout) { 
			 | 
		
	
		
			
			| 
				70
			 | 
			
				
			 | 
			
			
				-		if (tabs.size() >= 5) { 
			 | 
		
	
		
			
			| 
				71
			 | 
			
				
			 | 
			
			
				-			throw new TooManyTabs(); 
			 | 
		
	
		
			
			| 
				72
			 | 
			
				
			 | 
			
			
				-		} 
			 | 
		
	
		
			
			| 
				73
			 | 
			
				
			 | 
			
			
				-		int tabId = bottomNavigationView.getMenu().size(); 
			 | 
		
	
		
			
			| 
				74
			 | 
			
				
			 | 
			
			
				-		bottomNavigationView.getMenu().add(0, tabId, Menu.NONE, label); 
			 | 
		
	
		
			
			| 
				75
			 | 
			
				
			 | 
			
			
				-		LayoutParams tabParams = new LayoutParams(MATCH_PARENT, MATCH_PARENT); 
			 | 
		
	
		
			
			| 
				76
			 | 
			
				
			 | 
			
			
				-		tabParams.addRule(ABOVE, bottomNavigationView.getId()); 
			 | 
		
	
		
			
			| 
				77
			 | 
			
				
			 | 
			
			
				-		view.addView(tabLayout.getView(), tabParams); 
			 | 
		
	
		
			
			| 
				78
			 | 
			
				
			 | 
			
			
				-		tabs.add(tabLayout); 
			 | 
		
	
		
			
			| 
				79
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				80
			 | 
			
				
			 | 
			
			
				-		if (tabs.size() > 1) { 
			 | 
		
	
		
			
			| 
				81
			 | 
			
				
			 | 
			
			
				-			tabLayout.getView().setVisibility(View.GONE); 
			 | 
		
	
		
			
			| 
				82
			 | 
			
				
			 | 
			
			
				-		} 
			 | 
		
	
		
			
			| 
				83
			 | 
			
				
			 | 
			
			
				-	} 
			 | 
		
	
		
			
			| 
				84
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				85
			 | 
			
				
			 | 
			
			
				-	private void showTab(int tabId) { 
			 | 
		
	
		
			
			| 
				86
			 | 
			
				
			 | 
			
			
				-		tabs.get(tabId).getView().setVisibility(View.VISIBLE); 
			 | 
		
	
		
			
			| 
				87
			 | 
			
				
			 | 
			
			
				-	} 
			 | 
		
	
		
			
			| 
				88
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				89
			 | 
			
				
			 | 
			
			
				-	private void hideTab(int tabId) { 
			 | 
		
	
		
			
			| 
				90
			 | 
			
				
			 | 
			
			
				-		tabs.get(tabId).getView().setVisibility(View.GONE); 
			 | 
		
	
		
			
			| 
				91
			 | 
			
				
			 | 
			
			
				-	} 
			 | 
		
	
		
			
			| 
				92
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				93
			 | 
			
				
			 | 
			
			
				-	@Override 
			 | 
		
	
		
			
			| 
				94
			 | 
			
				
			 | 
			
			
				-	public void setParentStackLayout(final StackLayout stackLayout) { 
			 | 
		
	
		
			
			| 
				95
			 | 
			
				
			 | 
			
			
				-		this.stackLayout = stackLayout; 
			 | 
		
	
		
			
			| 
				96
			 | 
			
				
			 | 
			
			
				-	} 
			 | 
		
	
		
			
			| 
				97
			 | 
			
				
			 | 
			
			
				- 
			 | 
		
	
		
			
			| 
				98
			 | 
			
				
			 | 
			
			
				-	@Override 
			 | 
		
	
		
			
			| 
				99
			 | 
			
				
			 | 
			
			
				-	public StackLayout getParentStackLayout() { 
			 | 
		
	
		
			
			| 
				100
			 | 
			
				
			 | 
			
			
				-		return stackLayout; 
			 | 
		
	
		
			
			| 
				101
			 | 
			
				
			 | 
			
			
				-	} 
			 | 
		
	
		
			
			| 
				
			 | 
			
				3
			 | 
			
			
				+public class BottomTabsLayout { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				4
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				5
			 | 
			
			
				+//public class BottomTabsLayout implements Layout, BottomNavigationView.OnNavigationItemSelectedListener { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				6
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				7
			 | 
			
			
				+//	private StackLayout stackLayout; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				8
			 | 
			
			
				+// 
			 | 
		
	
		
			
			| 
				
			 | 
			
				9
			 | 
			
			
				+//	public static class TooManyTabs extends RuntimeException { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				10
			 | 
			
			
				+//		// 
			 | 
		
	
		
			
			| 
				
			 | 
			
				11
			 | 
			
			
				+//	} 
			 | 
		
	
		
			
			| 
				
			 | 
			
				12
			 | 
			
			
				+// 
			 | 
		
	
		
			
			| 
				
			 | 
			
				13
			 | 
			
			
				+//	private final RelativeLayout view; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				14
			 | 
			
			
				+//	private final BottomNavigationView bottomNavigationView; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				15
			 | 
			
			
				+//	private final List<Layout> tabs = new ArrayList<>(); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				16
			 | 
			
			
				+//	private int currentTab; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				17
			 | 
			
			
				+// 
			 | 
		
	
		
			
			| 
				
			 | 
			
				18
			 | 
			
			
				+//	public BottomTabsLayout(Activity activity) { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				19
			 | 
			
			
				+//		view = new RelativeLayout(activity); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				20
			 | 
			
			
				+//		view.setId(CompatUtils.generateViewId()); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				21
			 | 
			
			
				+// 
			 | 
		
	
		
			
			| 
				
			 | 
			
				22
			 | 
			
			
				+//		bottomNavigationView = new BottomNavigationView(view.getContext()); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				23
			 | 
			
			
				+//		bottomNavigationView.setId(CompatUtils.generateViewId()); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				24
			 | 
			
			
				+//		bottomNavigationView.setBackgroundColor(Color.DKGRAY); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				25
			 | 
			
			
				+//		bottomNavigationView.setOnNavigationItemSelectedListener(this); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				26
			 | 
			
			
				+//		LayoutParams lp = new LayoutParams(MATCH_PARENT, WRAP_CONTENT); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				27
			 | 
			
			
				+//		lp.addRule(ALIGN_PARENT_BOTTOM); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				28
			 | 
			
			
				+//		bottomNavigationView.setLayoutParams(lp); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				29
			 | 
			
			
				+//		view.addView(bottomNavigationView, lp); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				30
			 | 
			
			
				+//	} 
			 | 
		
	
		
			
			| 
				
			 | 
			
				31
			 | 
			
			
				+// 
			 | 
		
	
		
			
			| 
				
			 | 
			
				32
			 | 
			
			
				+//	@Override 
			 | 
		
	
		
			
			| 
				
			 | 
			
				33
			 | 
			
			
				+//	public View getView() { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				34
			 | 
			
			
				+//		return view; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				35
			 | 
			
			
				+//	} 
			 | 
		
	
		
			
			| 
				
			 | 
			
				36
			 | 
			
			
				+// 
			 | 
		
	
		
			
			| 
				
			 | 
			
				37
			 | 
			
			
				+//	@Override 
			 | 
		
	
		
			
			| 
				
			 | 
			
				38
			 | 
			
			
				+//	public void destroy() { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				39
			 | 
			
			
				+//		// 
			 | 
		
	
		
			
			| 
				
			 | 
			
				40
			 | 
			
			
				+//	} 
			 | 
		
	
		
			
			| 
				
			 | 
			
				41
			 | 
			
			
				+// 
			 | 
		
	
		
			
			| 
				
			 | 
			
				42
			 | 
			
			
				+//	@Override 
			 | 
		
	
		
			
			| 
				
			 | 
			
				43
			 | 
			
			
				+//	public boolean onNavigationItemSelected(@NonNull final MenuItem item) { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				44
			 | 
			
			
				+//		hideTab(currentTab); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				45
			 | 
			
			
				+//		currentTab = item.getItemId(); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				46
			 | 
			
			
				+//		showTab(currentTab); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				47
			 | 
			
			
				+//		return true; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				48
			 | 
			
			
				+//	} 
			 | 
		
	
		
			
			| 
				
			 | 
			
				49
			 | 
			
			
				+// 
			 | 
		
	
		
			
			| 
				
			 | 
			
				50
			 | 
			
			
				+//	public void addTab(String label, Layout tabLayout) { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				51
			 | 
			
			
				+//		if (tabs.size() >= 5) { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				52
			 | 
			
			
				+//			throw new TooManyTabs(); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				53
			 | 
			
			
				+//		} 
			 | 
		
	
		
			
			| 
				
			 | 
			
				54
			 | 
			
			
				+//		int tabId = bottomNavigationView.getMenu().size(); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				55
			 | 
			
			
				+//		bottomNavigationView.getMenu().add(0, tabId, Menu.NONE, label); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				56
			 | 
			
			
				+//		LayoutParams tabParams = new LayoutParams(MATCH_PARENT, MATCH_PARENT); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				57
			 | 
			
			
				+//		tabParams.addRule(ABOVE, bottomNavigationView.getId()); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				58
			 | 
			
			
				+//		view.addView(tabLayout.getView(), tabParams); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				59
			 | 
			
			
				+//		tabs.add(tabLayout); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				60
			 | 
			
			
				+// 
			 | 
		
	
		
			
			| 
				
			 | 
			
				61
			 | 
			
			
				+//		if (tabs.size() > 1) { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				62
			 | 
			
			
				+//			tabLayout.getView().setVisibility(View.GONE); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				63
			 | 
			
			
				+//		} 
			 | 
		
	
		
			
			| 
				
			 | 
			
				64
			 | 
			
			
				+//	} 
			 | 
		
	
		
			
			| 
				
			 | 
			
				65
			 | 
			
			
				+// 
			 | 
		
	
		
			
			| 
				
			 | 
			
				66
			 | 
			
			
				+//	private void showTab(int tabId) { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				67
			 | 
			
			
				+//		tabs.get(tabId).getView().setVisibility(View.VISIBLE); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				68
			 | 
			
			
				+//	} 
			 | 
		
	
		
			
			| 
				
			 | 
			
				69
			 | 
			
			
				+// 
			 | 
		
	
		
			
			| 
				
			 | 
			
				70
			 | 
			
			
				+//	private void hideTab(int tabId) { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				71
			 | 
			
			
				+//		tabs.get(tabId).getView().setVisibility(View.GONE); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				72
			 | 
			
			
				+//	} 
			 | 
		
	
		
			
			| 
				
			 | 
			
				73
			 | 
			
			
				+// 
			 | 
		
	
		
			
			| 
				
			 | 
			
				74
			 | 
			
			
				+//	@Override 
			 | 
		
	
		
			
			| 
				
			 | 
			
				75
			 | 
			
			
				+//	public void setParentStackLayout(final StackLayout stackLayout) { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				76
			 | 
			
			
				+//		this.stackLayout = stackLayout; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				77
			 | 
			
			
				+//	} 
			 | 
		
	
		
			
			| 
				
			 | 
			
				78
			 | 
			
			
				+// 
			 | 
		
	
		
			
			| 
				
			 | 
			
				79
			 | 
			
			
				+//	@Override 
			 | 
		
	
		
			
			| 
				
			 | 
			
				80
			 | 
			
			
				+//	public StackLayout getParentStackLayout() { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				81
			 | 
			
			
				+//		return stackLayout; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				82
			 | 
			
			
				+//	} 
			 | 
		
	
		
			
			| 
				102
			 | 
			
				83
			 | 
			
			
				 } 
			 |