浏览代码

connected Modal

Daniel Zlotin 8 年前
父节点
当前提交
9a85260af9

+ 7
- 1
android/app/src/main/java/com/reactnativenavigation/controllers/Modal.java 查看文件

@@ -14,6 +14,7 @@ import com.reactnativenavigation.params.ScreenParams;
14 14
 
15 15
 public class Modal extends Dialog implements DialogInterface.OnDismissListener, ScreenStackContainer {
16 16
 
17
+    private final Activity activity;
17 18
     private final OnModalDismissedListener onModalDismissedListener;
18 19
 
19 20
     public interface OnModalDismissedListener {
@@ -25,16 +26,21 @@ public class Modal extends Dialog implements DialogInterface.OnDismissListener,
25 26
 
26 27
     public Modal(Activity activity, OnModalDismissedListener onModalDismissedListener, ScreenParams screenParams) {
27 28
         super(activity, R.style.Modal);
29
+        this.activity = activity;
28 30
         this.onModalDismissedListener = onModalDismissedListener;
29 31
         this.screenParams = screenParams;
30 32
         createContent();
31 33
     }
32 34
 
35
+    public Activity getActivity() {
36
+        return activity;
37
+    }
38
+
33 39
     private void createContent() {
34 40
         setCancelable(true);
35 41
         setOnDismissListener(this);
36 42
         requestWindowFeature(Window.FEATURE_NO_TITLE);
37
-        layout = new SingleScreenLayout(getContext(), screenParams);
43
+        layout = new SingleScreenLayout(getActivity(), screenParams);
38 44
         setContentView(layout.asView());
39 45
     }
40 46
 

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

@@ -70,7 +70,7 @@ public class NavigationActivity extends AppCompatActivity implements DefaultHard
70 70
 
71 71
     @Override
72 72
     protected void onDestroy() {
73
-        modalController.onDestroy();
73
+        modalController.destroy();
74 74
         layout.destroy();
75 75
         super.onDestroy();
76 76
         if (currentActivity == null || currentActivity.isFinishing()) {

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

@@ -1,6 +1,6 @@
1 1
 package com.reactnativenavigation.layouts;
2 2
 
3
-import android.content.Context;
3
+import android.app.Activity;
4 4
 import android.view.View;
5 5
 import android.widget.FrameLayout;
6 6
 
@@ -17,18 +17,18 @@ public class SingleScreenLayout extends FrameLayout implements Layout {
17 17
     private final ScreenParams screenParams;
18 18
     private ScreenStack stack;
19 19
 
20
-    public SingleScreenLayout(Context context, ScreenParams screenParams) {
21
-        super(context);
20
+    public SingleScreenLayout(Activity activity, ScreenParams screenParams) {
21
+        super(activity);
22 22
         this.screenParams = screenParams;
23
-        createStack(context);
23
+        createStack();
24 24
     }
25 25
 
26
-    private void createStack(Context context) {
26
+    private void createStack() {
27 27
         if (stack != null) {
28 28
             stack.destroy();
29 29
             removeView(stack);
30 30
         }
31
-        stack = new ScreenStack(context, screenParams);
31
+        stack = new ScreenStack(getContext(), screenParams);
32 32
         addView(stack, new LayoutParams(MATCH_PARENT, MATCH_PARENT));
33 33
     }
34 34
 
@@ -64,7 +64,7 @@ public class SingleScreenLayout extends FrameLayout implements Layout {
64 64
 
65 65
     @Override
66 66
     public void newStack(ScreenParams params) {
67
-        createStack(getContext());
67
+        createStack();
68 68
     }
69 69
 
70 70
     @Override

+ 8
- 8
android/app/src/main/java/com/reactnativenavigation/screens/TabbedScreen.java 查看文件

@@ -21,9 +21,9 @@ public class TabbedScreen extends Screen {
21 21
 
22 22
     private List<ContentView> contentViews;
23 23
     private ViewPager viewPager;
24
-    private ViewPagerAdapter viewPagerAdapter;
24
+    private ContentViewPagerAdapter adapter;
25 25
 
26
-    public  TabbedScreen(Context context, ScreenParams screenParams) {
26
+    public TabbedScreen(Context context, ScreenParams screenParams) {
27 27
         super(context, screenParams);
28 28
     }
29 29
 
@@ -45,8 +45,8 @@ public class TabbedScreen extends Screen {
45 45
             contentViews.add(contentView);
46 46
         }
47 47
 
48
-        viewPagerAdapter = new ViewPagerAdapter(viewPager, contentViews, screenParams.topTabParams);
49
-        viewPager.setAdapter(viewPagerAdapter);
48
+        adapter = new ContentViewPagerAdapter(viewPager, contentViews, screenParams.topTabParams);
49
+        viewPager.setAdapter(adapter);
50 50
         tabLayout.setupWithViewPager(viewPager);
51 51
     }
52 52
 
@@ -61,26 +61,26 @@ public class TabbedScreen extends Screen {
61 61
 
62 62
     @Override
63 63
     public void ensureUnmountOnDetachedFromWindow() {
64
-        for (ContentView contentView: contentViews) {
64
+        for (ContentView contentView : contentViews) {
65 65
             contentView.ensureUnmountOnDetachedFromWindow();
66 66
         }
67 67
     }
68 68
 
69 69
     @Override
70 70
     public void preventUnmountOnDetachedFromWindow() {
71
-        for (ContentView contentView: contentViews) {
71
+        for (ContentView contentView : contentViews) {
72 72
             contentView.preventUnmountOnDetachedFromWindow();
73 73
         }
74 74
     }
75 75
 
76 76
 
77
-    public class ViewPagerAdapter extends PagerAdapter implements TabLayout.OnTabSelectedListener, ViewPager.OnPageChangeListener {
77
+    public class ContentViewPagerAdapter extends PagerAdapter implements TabLayout.OnTabSelectedListener, ViewPager.OnPageChangeListener {
78 78
 
79 79
         private ViewPager viewPager;
80 80
         private List<ContentView> contentViews;
81 81
         private List<TopTabParams> topTabParams;
82 82
 
83
-        public ViewPagerAdapter(ViewPager viewPager, List<ContentView> contentViews, List<TopTabParams> topTabParams) {
83
+        public ContentViewPagerAdapter(ViewPager viewPager, List<ContentView> contentViews, List<TopTabParams> topTabParams) {
84 84
             this.viewPager = viewPager;
85 85
             this.contentViews = contentViews;
86 86
             this.topTabParams = topTabParams;

+ 21
- 14
src/deprecated/platformSpecificDeprecated.android.js 查看文件

@@ -21,11 +21,10 @@ function startSingleScreenApp(params) {
21 21
   screen.passProps = params.passProps;
22 22
   //const drawer = setupDrawer(params.drawer);
23 23
 
24
-  screen.screenId = screen.screen;
25
-
26 24
   /*
27 25
    * adapt to new API
28 26
    */
27
+  screen.screenId = screen.screen;
29 28
   params.screen = adaptNavigationStyleToScreenStyle(screen);
30 29
   params.screen = adaptNavigationParams(screen);
31 30
 
@@ -139,14 +138,14 @@ function addTabIcon(tab) {
139 138
 
140 139
 function navigatorSetButtons(navigator, navigatorEventID, params) {
141 140
   if (params.rightButtons) {
142
-   params.rightButtons.forEach(function(button) {
143
-     if (button.icon) {
144
-       const icon = resolveAssetSource(button.icon);
145
-       if (icon) {
146
-         button.icon = icon.uri;
147
-       }
148
-     }
149
-   });
141
+    params.rightButtons.forEach(function(button) {
142
+      if (button.icon) {
143
+        const icon = resolveAssetSource(button.icon);
144
+        if (icon) {
145
+          button.icon = icon.uri;
146
+        }
147
+      }
148
+    });
150 149
   }
151 150
   newPlatformSpecific.setScreenTitleBarButtons(navigator.screenInstanceID, navigatorEventID, params.rightButtons);
152 151
 }
@@ -197,10 +196,18 @@ function navigatorToggleTabs(navigator, params) {
197 196
 }
198 197
 
199 198
 function showModal(params) {
200
-  //addNavigatorParams(params);
201
-  //addNavigatorButtons(params);
202
-  //addNavigationStyleParams(params);
203
-  //RctActivity.showModal(params);
199
+  addNavigatorParams(params);
200
+  addNavigatorButtons(params);
201
+  addNavigationStyleParams(params);
202
+
203
+  /*
204
+   * adapt to new API
205
+   */
206
+  params.screenId = params.screen;
207
+  let adapted = adaptNavigationStyleToScreenStyle(params);
208
+  adapted = adaptNavigationParams(adapted);
209
+
210
+  newPlatformSpecific.showModal(adapted);
204 211
 }
205 212
 
206 213
 function dismissModal() {

+ 16
- 9
src/platformSpecific.android.js 查看文件

@@ -4,6 +4,8 @@ import _ from 'lodash';
4 4
 
5 5
 import Navigation from './Navigation';
6 6
 
7
+NativeBridge = NativeModules.NavigationReactModule;
8
+
7 9
 const resolveAssetSource = require('react-native/Libraries/Image/resolveAssetSource');
8 10
 
9 11
 function startApp(activityParams) {
@@ -13,35 +15,39 @@ function startApp(activityParams) {
13 15
     return;
14 16
   }
15 17
 
16
-  NativeModules.NavigationReactModule.startApp(activityParams);
18
+  NativeBridge.startApp(activityParams);
17 19
 }
18 20
 
19 21
 function push(screenParams) {
20
-  NativeModules.NavigationReactModule.push(screenParams);
22
+  NativeBridge.push(screenParams);
21 23
 }
22 24
 
23 25
 function pop(screenParams) {
24
-  NativeModules.NavigationReactModule.pop(screenParams);
26
+  NativeBridge.pop(screenParams);
25 27
 }
26 28
 
27 29
 function popToRoot(screenParams) {
28
-  NativeModules.NavigationReactModule.popToRoot(screenParams);
30
+  NativeBridge.popToRoot(screenParams);
29 31
 }
30 32
 
31 33
 function newStack(screenParams) {
32
-  NativeModules.NavigationReactModule.newStack(screenParams);
34
+  NativeBridge.newStack(screenParams);
33 35
 }
34 36
 
35 37
 function toggleTopBarVisible(screenInstanceID, visible, animated) {
36
-  NativeModules.NavigationReactModule.setTopBarVisible(screenInstanceID, visible, animated);
38
+  NativeBridge.setTopBarVisible(screenInstanceID, visible, animated);
37 39
 }
38 40
 
39 41
 function setScreenTitleBarTitle(screenInstanceID, title) {
40
-  NativeModules.NavigationReactModule.setScreenTitleBarTitle(screenInstanceID, title);
42
+  NativeBridge.setScreenTitleBarTitle(screenInstanceID, title);
41 43
 }
42 44
 
43 45
 function setScreenTitleBarButtons(screenInstanceID, navigatorEventID, buttons) {
44
-  NativeModules.NavigationReactModule.setScreenTitleBarButtons(screenInstanceID, navigatorEventID, buttons);
46
+  NativeBridge.setScreenTitleBarButtons(screenInstanceID, navigatorEventID, buttons);
47
+}
48
+
49
+function showModal(screenParams) {
50
+  NativeBridge.showModal(screenParams);
45 51
 }
46 52
 
47 53
 module.exports = {
@@ -52,5 +58,6 @@ module.exports = {
52 58
   newStack,
53 59
   toggleTopBarVisible,
54 60
   setScreenTitleBarTitle,
55
-  setScreenTitleBarButtons
61
+  setScreenTitleBarButtons,
62
+  showModal
56 63
 };