瀏覽代碼

work on screenLayout

Daniel Zlotin 8 年之前
父節點
當前提交
92a53593ef

+ 11
- 8
android/app/src/main/java/com/reactnativenavigation/controllers/NavigationActivity.java 查看文件

@@ -5,9 +5,11 @@ import android.content.Intent;
5 5
 import android.os.Bundle;
6 6
 import android.support.v7.app.AppCompatActivity;
7 7
 import android.view.KeyEvent;
8
+import android.view.View;
8 9
 
9 10
 import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
10 11
 import com.reactnativenavigation.NavigationApplication;
12
+import com.reactnativenavigation.layouts.Layout;
11 13
 import com.reactnativenavigation.layouts.SingleScreenLayout;
12 14
 import com.reactnativenavigation.params.ActivityParams;
13 15
 import com.reactnativenavigation.params.parsers.ActivityParamsParser;
@@ -28,7 +30,7 @@ public class NavigationActivity extends AppCompatActivity implements DefaultHard
28 30
     private static Activity currentActivity;
29 31
     private ActivityParams activityParams;
30 32
     private ModalController modalController;
31
-    private SingleScreenLayout singleScreenLayout;
33
+    private Layout layout;
32 34
 
33 35
     @Override
34 36
     protected void onCreate(Bundle savedInstanceState) {
@@ -43,8 +45,9 @@ public class NavigationActivity extends AppCompatActivity implements DefaultHard
43 45
     }
44 46
 
45 47
     private void createLayout() {
46
-        singleScreenLayout = new SingleScreenLayout(this, activityParams.screenParams);
47
-        setContentView(singleScreenLayout);
48
+        //TODO layout factory (tabsLayout etc)
49
+        layout = new SingleScreenLayout(this, activityParams.screenParams);
50
+        setContentView((View) layout);
48 51
     }
49 52
 
50 53
     @Override
@@ -64,7 +67,7 @@ public class NavigationActivity extends AppCompatActivity implements DefaultHard
64 67
     @Override
65 68
     protected void onDestroy() {
66 69
         modalController.onDestroy();
67
-//        layout.onDestroy();
70
+        layout.onDestroy();
68 71
         super.onDestroy();
69 72
         if (currentActivity == null || currentActivity.isFinishing()) {
70 73
             getNavigationReactInstance().onHostDestroy();
@@ -73,7 +76,7 @@ public class NavigationActivity extends AppCompatActivity implements DefaultHard
73 76
 
74 77
     @Override
75 78
     public void onJsDevReload() {
76
-        singleScreenLayout.removeAllReactViews();
79
+        layout.removeAllReactViews();
77 80
     }
78 81
 
79 82
     @Override
@@ -86,9 +89,9 @@ public class NavigationActivity extends AppCompatActivity implements DefaultHard
86 89
         if (modalController.onBackPressed()) {
87 90
             return;
88 91
         }
89
-//        if (layout.onBackPressed()) {
90
-//            return;
91
-//        }
92
+        if (layout.onBackPressed()) {
93
+            return;
94
+        }
92 95
         getNavigationReactInstance().onBackPressed();
93 96
     }
94 97
 

+ 0
- 57
android/app/src/main/java/com/reactnativenavigation/layouts/BaseLayout.java 查看文件

@@ -1,57 +0,0 @@
1
-package com.reactnativenavigation.layouts;
2
-
3
-public abstract class BaseLayout {
4
-
5
-//    private OnScreenPoppedListener onScreenPoppedListener;
6
-//
7
-//    private RnnToolBar toolBar;
8
-//    private ScreenStack screenStack;
9
-//
10
-//    public BaseLayout(Context context, _Screen initialScreen) {
11
-//        super(context);
12
-//        toolBar = (RnnToolBar) findViewById(R.id.toolbar);
13
-//        screenStack = (ScreenStack) findViewById(R.id.screenStack);
14
-//
15
-//        toolBar.update(initialScreen);
16
-//        addInitialScreen(initialScreen);
17
-//    }
18
-//
19
-//    private void addInitialScreen(_Screen screen) {
20
-//        screenStack.push(screen, new RctView.OnDisplayedListener() {
21
-//            @Override
22
-//            public void onDisplayed() {
23
-//                Animation animation = AnimationUtils.loadAnimation(getContext(), R.anim.slide_up);
24
-//                setAnimation(animation);
25
-//                animate();
26
-//            }
27
-//        });
28
-//    }
29
-//
30
-//    @Override
31
-//    public void push(_Screen screen) {
32
-//        screenStack.push(screen);
33
-//    }
34
-//
35
-//    @Override
36
-//    public _Screen pop() {
37
-//        _Screen popped = screenStack.pop();
38
-//        if (onScreenPoppedListener != null) {
39
-//            onScreenPoppedListener.onScreenPopped(popped);
40
-//        }
41
-//        return popped;
42
-//    }
43
-//
44
-//    @Override
45
-//    public int getScreenCount() {
46
-//        return screenStack.getStackSize();
47
-//    }
48
-//
49
-//    @Override
50
-//    public void removeAllReactViews() {
51
-//        screenStack.removeAllReactViews();
52
-//    }
53
-//
54
-//    public void setOnScreenPoppedListener(OnScreenPoppedListener onScreenPoppedListener) {
55
-//        this.onScreenPoppedListener = onScreenPoppedListener;
56
-//    }
57
-}

+ 0
- 6
android/app/src/main/java/com/reactnativenavigation/layouts/OnScreenPoppedListener.java 查看文件

@@ -1,6 +0,0 @@
1
-package com.reactnativenavigation.layouts;
2
-
3
-
4
-public interface OnScreenPoppedListener {
5
-
6
-}

+ 5
- 0
android/app/src/main/java/com/reactnativenavigation/layouts/Screen.java 查看文件

@@ -0,0 +1,5 @@
1
+package com.reactnativenavigation.layouts;
2
+
3
+public interface Screen {
4
+    void removeAllReactViews();
5
+}

android/app/src/main/java/com/reactnativenavigation/layouts/ScreenLayout.java → android/app/src/main/java/com/reactnativenavigation/layouts/ScreenImpl.java 查看文件

@@ -13,17 +13,18 @@ import com.reactnativenavigation.params.ScreenStyleParams;
13 13
 import com.reactnativenavigation.utils.SdkSupports;
14 14
 import com.reactnativenavigation.views.ContentView;
15 15
 import com.reactnativenavigation.views.ScrollDirectionListener;
16
+import com.reactnativenavigation.views.TopBar;
16 17
 
17 18
 import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
18 19
 import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
19 20
 
20
-public class ScreenLayout extends LinearLayout implements ScrollDirectionListener.OnScrollChanged, Layout {
21
+public class ScreenImpl extends LinearLayout implements Screen, ScrollDirectionListener.OnScrollChanged {
21 22
 
22 23
     private final ScreenParams screenParams;
23 24
     private ContentView contentView;
24 25
     private TopBar topBar;
25 26
 
26
-    public ScreenLayout(Context context, ScreenParams screenParams) {
27
+    public ScreenImpl(Context context, ScreenParams screenParams) {
27 28
         super(context);
28 29
         this.screenParams = screenParams;
29 30
         setOrientation(VERTICAL);
@@ -100,17 +101,7 @@ public class ScreenLayout extends LinearLayout implements ScrollDirectionListene
100 101
 
101 102
     @Override
102 103
     public void onScrollChanged(ScrollDirectionListener.Direction direction) {
103
-
104
-    }
105
-
106
-    @Override
107
-    public boolean onBackPressed() {
108
-        return false;
109
-    }
110
-
111
-    @Override
112
-    public void onDestroy() {
113
-
104
+        // TODO handle if needed
114 105
     }
115 106
 
116 107
     @Override

+ 78
- 0
android/app/src/main/java/com/reactnativenavigation/layouts/ScreenStack.java 查看文件

@@ -0,0 +1,78 @@
1
+package com.reactnativenavigation.layouts;
2
+
3
+import android.animation.LayoutTransition;
4
+import android.content.Context;
5
+import android.view.View;
6
+import android.widget.FrameLayout;
7
+
8
+import com.reactnativenavigation.params.ScreenParams;
9
+
10
+import java.util.Stack;
11
+
12
+import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
13
+
14
+public class ScreenStack extends FrameLayout {
15
+    private Stack<Screen> stack = new Stack<>();
16
+
17
+    public ScreenStack(Context context, ScreenParams initialScreenParams) {
18
+        super(context);
19
+        setLayoutTransition(new LayoutTransition());
20
+        push(initialScreenParams);
21
+    }
22
+
23
+    public void push(ScreenParams screenParams) {
24
+        Screen screen = new ScreenImpl(getContext(), screenParams);
25
+        addView((View) screen, new FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT));
26
+        stack.push(screen);
27
+    }
28
+
29
+    public Screen pop() {
30
+        return stack.pop();
31
+    }
32
+
33
+    public void popToRoot() {
34
+        while (getStackSize() > 1) {
35
+            pop();
36
+        }
37
+    }
38
+
39
+    public void destroy() {
40
+        while (!isEmpty()) {
41
+            Screen screen = pop();
42
+            screen.removeAllReactViews();
43
+        }
44
+        removeAllViews();
45
+    }
46
+
47
+    public boolean isEmpty() {
48
+        return stack.isEmpty();
49
+    }
50
+
51
+    public int getStackSize() {
52
+        return stack.size();
53
+    }
54
+
55
+    public Screen peek() {
56
+        return stack.peek();
57
+    }
58
+
59
+
60
+//    /**
61
+//     * Remove the ScreenStack from {@code parent} while preventing all child react views from getting unmounted
62
+//        -= USE WHEN SWITCHING TABS =-
63
+//     */
64
+//    public void removeFromScreen(ViewGroup parent) {
65
+//        mStack.peek().view.onTemporallyRemovedFromScreen();
66
+//
67
+//        parent.removeView(this);
68
+//    }
69
+//    /**
70
+//     * Add ScreenStack to {@code parent}
71
+//       -= USE WHEN SWITCHING TABS =-
72
+//     */
73
+//    public void addToScreen(ViewGroup parent) {
74
+//        mStack.peek().view.onReAddToScreen();
75
+//
76
+//        parent.addView(this, new CoordinatorLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT));
77
+//    }
78
+}

+ 16
- 8
android/app/src/main/java/com/reactnativenavigation/layouts/SingleScreenLayout.java 查看文件

@@ -10,31 +10,39 @@ import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
10 10
 public class SingleScreenLayout extends FrameLayout implements Layout {
11 11
 
12 12
     private final ScreenParams screenParams;
13
-    private ScreenLayout screenLayout;
13
+    private ScreenStack stack;
14 14
 
15 15
     public SingleScreenLayout(Context context, ScreenParams screenParams) {
16 16
         super(context);
17 17
         this.screenParams = screenParams;
18
-        createLayout();
18
+        createStack(context);
19 19
     }
20 20
 
21
-    private void createLayout() {
22
-        screenLayout = new ScreenLayout(getContext(), screenParams);
23
-        addView(screenLayout, new FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT));
21
+    private void createStack(Context context) {
22
+        if (stack != null) {
23
+            stack.destroy();
24
+        }
25
+        stack = new ScreenStack(context, screenParams);
26
+        addView(stack, new LayoutParams(MATCH_PARENT, MATCH_PARENT));
24 27
     }
25 28
 
26 29
     @Override
27 30
     public boolean onBackPressed() {
28
-        return false;
31
+        if (stack.isEmpty()) {
32
+            return false;
33
+        } else {
34
+            stack.pop();
35
+            return true;
36
+        }
29 37
     }
30 38
 
31 39
     @Override
32 40
     public void onDestroy() {
33
-
41
+        stack.destroy();
34 42
     }
35 43
 
36 44
     @Override
37 45
     public void removeAllReactViews() {
38
-        screenLayout.removeAllReactViews();
46
+        stack.destroy();
39 47
     }
40 48
 }

android/app/src/main/java/com/reactnativenavigation/layouts/TopBar.java → android/app/src/main/java/com/reactnativenavigation/views/TopBar.java 查看文件

@@ -1,10 +1,9 @@
1
-package com.reactnativenavigation.layouts;
1
+package com.reactnativenavigation.views;
2 2
 
3 3
 import android.content.Context;
4 4
 import android.support.design.widget.AppBarLayout;
5 5
 
6 6
 import com.reactnativenavigation.params.TitleBarButtonParams;
7
-import com.reactnativenavigation.views.TitleBar;
8 7
 
9 8
 import java.util.List;
10 9