1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- package com.reactnativenavigation.views;
-
- import android.animation.LayoutTransition;
- import android.view.View;
- import android.widget.FrameLayout;
-
- import com.facebook.react.ReactInstanceManager;
- import com.reactnativenavigation.activities.BaseReactActivity;
- import com.reactnativenavigation.core.RctManager;
- import com.reactnativenavigation.core.objects.Screen;
-
- import java.util.Stack;
-
- import static android.view.ViewGroup.LayoutParams.*;
-
- public class ScreenStack extends FrameLayout {
-
- private class ScreenView{
- Screen screen;
- RctView view;
-
- public ScreenView(Screen screen, RctView view) {
- this.screen = screen;
- this.view = view;
- }
- }
-
- private final Stack<ScreenView> stack = new Stack<>();
- private final ReactInstanceManager mReactInstanceManager = RctManager.getInstance().getReactInstanceManager();
- private final BaseReactActivity reactActivity;
-
- public ScreenStack(BaseReactActivity context){
- super(context);
- reactActivity = context;
- setLayoutTransition(new LayoutTransition());
- }
-
- public void push(Screen screen){
- View oldView = null;
- if(!stack.isEmpty()) {
- oldView = stack.peek().view;
- }
- RctView view = new RctView(reactActivity, mReactInstanceManager, screen);
- addView(view, MATCH_PARENT, MATCH_PARENT);
- if(oldView!=null) {
- oldView.setVisibility(GONE);
- }
- stack.push(new ScreenView(screen, view));
- }
-
- public Screen pop(){
- if(stack.isEmpty()) {
- return null;
- }
- ScreenView popped = stack.pop();
- if(!stack.isEmpty()) {
- View view = stack.peek().view;
- if(view.getParent() == null)
- addView(stack.peek().view, 0);
- else {
- view.setVisibility(VISIBLE);
- }
- }
- removeView(popped.view);
- return popped.screen;
- }
-
- public boolean isEmpty(){
- return stack.isEmpty();
- }
-
- public int getStackSize(){
- return stack.size();
- }
-
- public Screen peek(){
- return stack.peek().screen;
- }
- }
|