Daniel Zlotin 8 yıl önce
ebeveyn
işleme
35cff65b7c

+ 5
- 2
android/app/src/main/java/com/reactnativenavigation/NavigationApplication.java Dosyayı Görüntüle

23
         super.onCreate();
23
         super.onCreate();
24
         instance = this;
24
         instance = this;
25
         handler = new Handler(getMainLooper());
25
         handler = new Handler(getMainLooper());
26
-        navigationReactInstance = new NavigationReactInstance();
27
-        navigationReactInstance.startReactContextOnceInBackgroundAndExecuteJS();
28
     }
26
     }
29
 
27
 
30
     public void runOnMainThread(Runnable runnable) {
28
     public void runOnMainThread(Runnable runnable) {
76
     public void sendEvent(String eventId, String navigatorEventId) {
74
     public void sendEvent(String eventId, String navigatorEventId) {
77
         navigationReactInstance.getReactEventEmitter().sendEvent(eventId, navigatorEventId);
75
         navigationReactInstance.getReactEventEmitter().sendEvent(eventId, navigatorEventId);
78
     }
76
     }
77
+
78
+    public void startReactContext() {
79
+        navigationReactInstance = new NavigationReactInstance();
80
+        navigationReactInstance.startReactContextOnceInBackgroundAndExecuteJS();
81
+    }
79
 }
82
 }

+ 1
- 0
android/app/src/main/java/com/reactnativenavigation/bridge/NavigationReactModule.java Dosyayı Görüntüle

81
 
81
 
82
     @ReactMethod
82
     @ReactMethod
83
     public void popToRoot(final ReadableMap params) {
83
     public void popToRoot(final ReadableMap params) {
84
+        NavigationCommandsHandler.popToRoot(BundleConverter.toBundle(params));
84
     }
85
     }
85
 
86
 
86
     @ReactMethod
87
     @ReactMethod

+ 4
- 0
android/app/src/main/java/com/reactnativenavigation/controllers/NavigationActivity.java Dosyayı Görüntüle

113
     void pop(ScreenParams params) {
113
     void pop(ScreenParams params) {
114
         layout.pop(params);
114
         layout.pop(params);
115
     }
115
     }
116
+
117
+    void popToRoot(ScreenParams params) {
118
+        layout.popToRoot(params);
119
+    }
116
 }
120
 }

+ 15
- 0
android/app/src/main/java/com/reactnativenavigation/controllers/NavigationCommandsHandler.java Dosyayı Görüntüle

58
             }
58
             }
59
         });
59
         });
60
     }
60
     }
61
+
62
+    public static void popToRoot(Bundle screenParams) {
63
+        final NavigationActivity currentActivity = NavigationActivity.currentActivity;
64
+        if (currentActivity == null) {
65
+            return;
66
+        }
67
+
68
+        final ScreenParams params = ScreenParamsParser.parse(screenParams);
69
+        NavigationApplication.instance.runOnMainThread(new Runnable() {
70
+            @Override
71
+            public void run() {
72
+                currentActivity.popToRoot(params);
73
+            }
74
+        });
75
+    }
61
 }
76
 }

+ 6
- 0
android/app/src/main/java/com/reactnativenavigation/controllers/SplashActivity.java Dosyayı Görüntüle

1
 package com.reactnativenavigation.controllers;
1
 package com.reactnativenavigation.controllers;
2
 
2
 
3
+import android.graphics.Color;
3
 import android.os.Bundle;
4
 import android.os.Bundle;
4
 import android.support.annotation.Nullable;
5
 import android.support.annotation.Nullable;
5
 import android.support.v7.app.AppCompatActivity;
6
 import android.support.v7.app.AppCompatActivity;
7
+import android.view.View;
6
 import android.widget.Toast;
8
 import android.widget.Toast;
7
 
9
 
8
 import com.reactnativenavigation.NavigationApplication;
10
 import com.reactnativenavigation.NavigationApplication;
12
     @Override
14
     @Override
13
     protected void onCreate(@Nullable Bundle savedInstanceState) {
15
     protected void onCreate(@Nullable Bundle savedInstanceState) {
14
         super.onCreate(savedInstanceState);
16
         super.onCreate(savedInstanceState);
17
+        NavigationApplication.instance.startReactContext();
15
         //TODO show fancy splash
18
         //TODO show fancy splash
19
+        View view = new View(this);
20
+        view.setBackgroundColor(Color.RED);
21
+        setContentView(view);
16
         Toast.makeText(this, "Loading navigation...", Toast.LENGTH_LONG).show();
22
         Toast.makeText(this, "Loading navigation...", Toast.LENGTH_LONG).show();
17
     }
23
     }
18
 }
24
 }

+ 2
- 0
android/app/src/main/java/com/reactnativenavigation/layouts/Layout.java Dosyayı Görüntüle

12
     void push(ScreenParams params);
12
     void push(ScreenParams params);
13
 
13
 
14
     void pop(ScreenParams params);
14
     void pop(ScreenParams params);
15
+
16
+    void popToRoot(ScreenParams params);
15
 }
17
 }

+ 5
- 1
android/app/src/main/java/com/reactnativenavigation/layouts/ScreenStack.java Dosyayı Görüntüle

34
     }
34
     }
35
 
35
 
36
     public void popToRoot() {
36
     public void popToRoot() {
37
-        while (getStackSize() > 1) {
37
+        while (canPop()) {
38
             pop();
38
             pop();
39
         }
39
         }
40
     }
40
     }
59
         return stack.peek();
59
         return stack.peek();
60
     }
60
     }
61
 
61
 
62
+    public boolean canPop() {
63
+        return getStackSize() > 1;
64
+    }
65
+
62
 
66
 
63
 //    /**
67
 //    /**
64
 //     * Remove the ScreenStack from {@code parent} while preventing all child react views from getting unmounted
68
 //     * Remove the ScreenStack from {@code parent} while preventing all child react views from getting unmounted

+ 8
- 3
android/app/src/main/java/com/reactnativenavigation/layouts/SingleScreenLayout.java Dosyayı Görüntüle

28
 
28
 
29
     @Override
29
     @Override
30
     public boolean onBackPressed() {
30
     public boolean onBackPressed() {
31
-        if (stack.isEmpty()) {
32
-            return false;
33
-        } else {
31
+        if (stack.canPop()) {
34
             stack.pop();
32
             stack.pop();
35
             return true;
33
             return true;
34
+        } else {
35
+            return false;
36
         }
36
         }
37
     }
37
     }
38
 
38
 
55
     public void pop(ScreenParams params) {
55
     public void pop(ScreenParams params) {
56
         stack.pop();
56
         stack.pop();
57
     }
57
     }
58
+
59
+    @Override
60
+    public void popToRoot(ScreenParams params) {
61
+        stack.popToRoot();
62
+    }
58
 }
63
 }

+ 10
- 7
src/deprecated/platformSpecificDeprecated.android.js Dosyayı Görüntüle

54
   newPlatformSpecific.pop(adapted);
54
   newPlatformSpecific.pop(adapted);
55
 }
55
 }
56
 
56
 
57
+function navigatorPopToRoot(navigator, params) {
58
+  addNavigatorParams(params, navigator);
59
+
60
+  params.screenId = params.screen;
61
+  let adapted = adaptNavigationStyleToScreenStyle(params);
62
+  adapted = adaptNavigationParams(adapted);
63
+
64
+  newPlatformSpecific.popToRoot(adapted);
65
+}
66
+
57
 function adaptNavigationStyleToScreenStyle(screen) {
67
 function adaptNavigationStyleToScreenStyle(screen) {
58
   const navigatorStyle = screen.navigatorStyle;
68
   const navigatorStyle = screen.navigatorStyle;
59
   if (!navigatorStyle) {
69
   if (!navigatorStyle) {
128
   //RctActivity.setNavigatorButtons(params);
138
   //RctActivity.setNavigatorButtons(params);
129
 }
139
 }
130
 
140
 
131
-function navigatorPopToRoot(navigator, params) {
132
-  //RctActivity.navigatorPopToRoot({
133
-  //  navigatorID: navigator.navigatorID,
134
-  //  animated: !(params.animated === false)
135
-  //});
136
-}
137
-
138
 function navigatorResetTo(navigator, params) {
141
 function navigatorResetTo(navigator, params) {
139
   //addNavigatorParams(params, navigator);
142
   //addNavigatorParams(params, navigator);
140
   //addNavigatorButtons(params);
143
   //addNavigatorButtons(params);

+ 6
- 1
src/platformSpecific.android.js Dosyayı Görüntüle

24
   NativeModules.NavigationReactModule.pop(screenParams);
24
   NativeModules.NavigationReactModule.pop(screenParams);
25
 }
25
 }
26
 
26
 
27
+function popToRoot(screenParams) {
28
+  NativeModules.NavigationReactModule.pop(screenParams);
29
+}
30
+
27
 module.exports = {
31
 module.exports = {
28
   startApp,
32
   startApp,
29
   push,
33
   push,
30
-  pop
34
+  pop,
35
+  popToRoot
31
 };
36
 };