ソースを参照

passProps stays in JS using PropRegistry, not exporting Screen anymore, FragmentScreen broken

Daniel Zlotin 8 年 前
コミット
dbe2b1587a

+ 0
- 3
android/app/src/main/java/com/reactnativenavigation/params/ScreenParams.java ファイルの表示

@@ -7,7 +7,6 @@ import java.util.List;
7 7
 
8 8
 public class ScreenParams {
9 9
     public String screenId;
10
-    public Bundle passProps;
11 10
     public List<TitleBarButtonParams> rightButtons;
12 11
     public TitleBarLeftButtonParams leftButton;
13 12
     public String title;
@@ -16,8 +15,6 @@ public class ScreenParams {
16 15
     public String fragmentCreatorClassName;
17 16
     public boolean animateScreenTransitions;
18 17
 
19
-    //    public String tabLabel; TODO when tabs are supported move to TabParams
20
-    //    public Drawable tabIcon;
21 18
     public String tabLabel;
22 19
     public Drawable tabIcon;
23 20
 

+ 0
- 3
android/app/src/main/java/com/reactnativenavigation/params/TopTabParams.java ファイルの表示

@@ -1,9 +1,6 @@
1 1
 package com.reactnativenavigation.params;
2 2
 
3
-import android.os.Bundle;
4
-
5 3
 public class TopTabParams {
6 4
     public String screenId;
7 5
     public String title;
8
-    public Bundle passProps;
9 6
 }

+ 0
- 2
android/app/src/main/java/com/reactnativenavigation/params/parsers/ScreenParamsParser.java ファイルの表示

@@ -13,7 +13,6 @@ public class ScreenParamsParser extends Parser {
13 13
     private static final String KEY_SCREEN_ID = "screenId";
14 14
     private static final String KEY_SCREEN_INSTANCE_ID = "screenInstanceID";
15 15
     private static final String KEY_NAVIGATOR_EVENT_ID = "navigatorEventID";
16
-    private static final String KEY_PROPS = "passProps";
17 16
     private static final String KEY_NAVIGATION_PARAMS = "navigationParams";
18 17
     private static final String KEY_RIGHT_BUTTONS = "rightButtons";
19 18
     private static final String KEY_LEFT_BUTTON = "leftButton";
@@ -26,7 +25,6 @@ public class ScreenParamsParser extends Parser {
26 25
         ScreenParams result = new ScreenParams();
27 26
         result.screenId = params.getString(KEY_SCREEN_ID);
28 27
         result.screenInstanceId = params.getString(KEY_SCREEN_INSTANCE_ID);
29
-        result.passProps = params.getBundle(KEY_PROPS);
30 28
         assertKeyExists(params, KEY_NAVIGATION_PARAMS);
31 29
         result.navigationParams = params.getBundle(KEY_NAVIGATION_PARAMS);
32 30
         result.navigatorEventId = result.navigationParams.getString(KEY_NAVIGATOR_EVENT_ID);

+ 0
- 2
android/app/src/main/java/com/reactnativenavigation/params/parsers/TopTabParamsParser.java ファイルの表示

@@ -11,7 +11,6 @@ import java.util.List;
11 11
 public class TopTabParamsParser extends Parser {
12 12
     private static final String KEY_SCREEN_ID = "screenId";
13 13
     private static final String KEY_TITLE = "title";
14
-    private static final String KEY_PROPS = "passProps";
15 14
 
16 15
     @SuppressWarnings("ConstantConditions")
17 16
     public static List<TopTabParams> parse(Bundle params) {
@@ -27,7 +26,6 @@ public class TopTabParamsParser extends Parser {
27 26
         TopTabParams result = new TopTabParams();
28 27
         result.screenId = params.getString(KEY_SCREEN_ID);
29 28
         result.title = params.getString(KEY_TITLE);
30
-        result.passProps = params.getBundle(KEY_PROPS);
31 29
         return result;
32 30
     }
33 31
 }

+ 3
- 4
android/app/src/main/java/com/reactnativenavigation/screens/FragmentScreen.java ファイルの表示

@@ -42,8 +42,7 @@ public class FragmentScreen extends Screen {
42 42
     private void addContent() {
43 43
         ContentView contentView = new ContentView(getContext(),
44 44
                 screenParams,
45
-                screenParams.screenId,
46
-                screenParams.passProps);
45
+                screenParams.screenId);
47 46
         addView(contentView, 0, 0);
48 47
         LayoutParams params = new LayoutParams(MATCH_PARENT, MATCH_PARENT);
49 48
         if (screenParams.styleParams.drawScreenBelowTopBar) {
@@ -92,7 +91,7 @@ public class FragmentScreen extends Screen {
92 91
             String className = screenParams.fragmentCreatorClassName;
93 92
             Class<?> fragmentCreatorClass = Class.forName(className);
94 93
             Method method = fragmentCreatorClass.getMethod(CONTRACT_GET_FRAGMENT, Bundle.class);
95
-            return (android.app.Fragment) method.invoke(null, screenParams.passProps);
94
+            return (android.app.Fragment) method.invoke(null, "TODO");
96 95
         } catch (NoSuchMethodException noSuchMethod) {
97 96
             return null;
98 97
         }
@@ -104,7 +103,7 @@ public class FragmentScreen extends Screen {
104 103
             String className = screenParams.fragmentCreatorClassName;
105 104
             Class<?> fragmentCreatorClass = Class.forName(className);
106 105
             Method method = fragmentCreatorClass.getMethod(CONTRACT_GET_SUPPORT_FRAGMENT, Bundle.class);
107
-            return (android.support.v4.app.Fragment) method.invoke(null, screenParams.passProps);
106
+            return (android.support.v4.app.Fragment) method.invoke(null, "TODO");
108 107
         } catch (NoSuchMethodException noSuchMethod) {
109 108
             return null;
110 109
         }

+ 1
- 1
android/app/src/main/java/com/reactnativenavigation/screens/SingleScreen.java ファイルの表示

@@ -19,7 +19,7 @@ public class SingleScreen extends Screen {
19 19
 
20 20
     @Override
21 21
     protected void createContent() {
22
-        contentView = new ContentView(getContext(), screenParams, screenParams.screenId, screenParams.passProps);
22
+        contentView = new ContentView(getContext(), screenParams, screenParams.screenId);
23 23
         LayoutParams params = new LayoutParams(MATCH_PARENT, MATCH_PARENT);
24 24
         if (screenParams.styleParams.drawScreenBelowTopBar) {
25 25
             params.addRule(BELOW, topBar.getId());

+ 1
- 1
android/app/src/main/java/com/reactnativenavigation/screens/ViewPagerScreen.java ファイルの表示

@@ -45,7 +45,7 @@ public class ViewPagerScreen extends Screen {
45 45
     private void addPages() {
46 46
         contentViews = new ArrayList<>();
47 47
         for (TopTabParams tab : screenParams.topTabParams) {
48
-            ContentView contentView = new ContentView(getContext(), screenParams, tab.screenId, tab.passProps);
48
+            ContentView contentView = new ContentView(getContext(), screenParams, tab.screenId);
49 49
             addContent(contentView);
50 50
             contentViews.add(contentView);
51 51
         }

+ 4
- 12
android/app/src/main/java/com/reactnativenavigation/views/ContentView.java ファイルの表示

@@ -12,13 +12,13 @@ public class ContentView extends ReactRootView {
12 12
 
13 13
     private final String screenId;
14 14
     private final String navigatorEventId;
15
-    private final Bundle passProps;
15
+    private final Bundle navigationParams;
16 16
 
17
-    public ContentView(Context context, ScreenParams screenParams, String screenId, Bundle passProps) {
17
+    public ContentView(Context context, ScreenParams screenParams, String screenId) {
18 18
         super(context);
19 19
         this.screenId = screenId;
20 20
         navigatorEventId = screenParams.navigatorEventId;
21
-        this.passProps = mergePropsAndNavigationParams(screenParams, passProps);
21
+        navigationParams = screenParams.navigationParams;
22 22
         attachToJS();
23 23
     }
24 24
 
@@ -39,14 +39,6 @@ public class ContentView extends ReactRootView {
39 39
     }
40 40
 
41 41
     private void attachToJS() {
42
-        startReactApplication(NavigationApplication.instance.getReactGateway().getReactInstanceManager(), screenId, passProps);
43
-    }
44
-
45
-    private Bundle mergePropsAndNavigationParams(ScreenParams screenParams, Bundle passProps) {
46
-        Bundle navigationParams = (Bundle) screenParams.navigationParams.clone();
47
-        if (passProps != null) {
48
-            navigationParams.putAll(passProps);
49
-        }
50
-        return navigationParams;
42
+        startReactApplication(NavigationApplication.instance.getReactGateway().getReactInstanceManager(), screenId, navigationParams);
51 43
     }
52 44
 }

+ 63
- 60
example-redux/src/app.js ファイルの表示

@@ -35,72 +35,75 @@ export default class App {
35 35
   startApp(root) {
36 36
     switch (root) {
37 37
       case 'login':
38
-        //Navigation.startSingleScreenApp({
39
-        //  screen: {
40
-        //    screen: 'example.LoginScreen',
41
-        //    title: 'Login',
42
-        //    navigatorStyle: {}
43
-        //  },
44
-        //  passProps: {
45
-        //    str: 'This is a prop passed in \'startSingleScreenApp()\'!',
46
-        //    obj: {
47
-        //      str: 'This is a prop passed in an object!',
48
-        //      arr: [
49
-        //        {
50
-        //          str: 'This is a prop in an object in an array in an object!'
51
-        //        }
52
-        //      ],
53
-        //      arr2: [
54
-        //        [
55
-        //          'array of strings',
56
-        //          'with two strings'
57
-        //        ],
58
-        //        [
59
-        //          1, 2, 3
60
-        //        ]
61
-        //      ]
62
-        //    },
63
-        //    num: 1234
64
-        //  }
65
-        //});
66 38
         Navigation.startSingleScreenApp({
67 39
           screen: {
68
-            screen: 'example.FirstTabScreen',
40
+            screen: 'example.LoginScreen',
69 41
             title: 'Login',
70
-            topTabs: [
71
-              {
72
-                screenId: 'example.ListScreen',
73
-                title: 'Tab1',
74
-                 passProps: {
75
-                   str: 'This is a prop passed to Tab1'
76
-                 }
77
-              },
78
-              {
79
-                screenId: 'example.PushedScreen',
80
-                title: 'Tab2',
81
-                passProps: {
82
-                  str: 'This is a prop passed to Tab2'
83
-                }
84
-
85
-              },
86
-              {
87
-                screenId: 'example.PushedScreen',
88
-                title: 'Tab3',
89
-                passProps: {
90
-                  str: 'This is a prop passed to Tab3'
91
-                }
92
-              },
93
-              {
94
-                screenId: 'example.FirstTabScreen',
95
-                title: 'Tab4',
96
-                passProps: {
97
-                  str: 'This is a prop passed to Tab4'
98
-                }
99
-              }
100
-            ],
101 42
             navigatorStyle: {}
43
+          },
44
+          passProps: {
45
+            str: 'This is a prop passed in \'startSingleScreenApp()\'!',
46
+            obj: {
47
+              str: 'This is a prop passed in an object!',
48
+              arr: [
49
+                {
50
+                  str: 'This is a prop in an object in an array in an object!'
51
+                }
52
+              ],
53
+              arr2: [
54
+                [
55
+                  'array of strings',
56
+                  'with two strings'
57
+                ],
58
+                [
59
+                  1, 2, 3
60
+                ]
61
+              ]
62
+            },
63
+            num: 1234,
64
+            fn: function() {
65
+              return 'Hello from a function!';
66
+            }
102 67
           }
103 68
         });
69
+        //Navigation.startSingleScreenApp({
70
+        //  screen: {
71
+        //    screen: 'example.FirstTabScreen',
72
+        //    title: 'Login',
73
+        //    topTabs: [
74
+        //      {
75
+        //        screenId: 'example.ListScreen',
76
+        //        title: 'Tab1',
77
+        //         passProps: {
78
+        //           str: 'This is a prop passed to Tab1'
79
+        //         }
80
+        //      },
81
+        //      {
82
+        //        screenId: 'example.PushedScreen',
83
+        //        title: 'Tab2',
84
+        //        passProps: {
85
+        //          str: 'This is a prop passed to Tab2'
86
+        //        }
87
+        //
88
+        //      },
89
+        //      {
90
+        //        screenId: 'example.PushedScreen',
91
+        //        title: 'Tab3',
92
+        //        passProps: {
93
+        //          str: 'This is a prop passed to Tab3'
94
+        //        }
95
+        //      },
96
+        //      {
97
+        //        screenId: 'example.FirstTabScreen',
98
+        //        title: 'Tab4',
99
+        //        passProps: {
100
+        //          str: 'This is a prop passed to Tab4'
101
+        //        }
102
+        //      }
103
+        //    ],
104
+        //    navigatorStyle: {}
105
+        //  }
106
+        //});
104 107
         return;
105 108
       case 'after-login':
106 109
         Navigation.startTabBasedApp({

+ 1
- 0
example-redux/src/screens/LoginScreen.js ファイルの表示

@@ -47,6 +47,7 @@ class LoginScreen extends Component {
47 47
           <Text style={styles.button}>Show another login as modal</Text>
48 48
         </TouchableOpacity>
49 49
 
50
+        <Text style={{fontWeight: '500'}}>Function prop: {this.props.fn()}</Text>
50 51
         <Text style={{fontWeight: '500'}}>String prop: {this.props.str}</Text>
51 52
         <Text style={{fontWeight: '500'}}>Number prop: {this.props.num}</Text>
52 53
         <Text style={{fontWeight: '500'}}>Object prop: {this.props.obj.str}</Text>

+ 14
- 3
src/Navigation.js ファイルの表示

@@ -3,6 +3,8 @@ import {AppRegistry} from 'react-native';
3 3
 import platformSpecific from './deprecated/platformSpecificDeprecated';
4 4
 import Screen from './Screen';
5 5
 
6
+import PropRegistry from './PropRegistry';
7
+
6 8
 const registeredScreens = {};
7 9
 
8 10
 function registerScreen(screenID, generator) {
@@ -25,9 +27,14 @@ function _registerComponentNoRedux(screenID, generator) {
25 27
       static navigatorStyle = InternalComponent.navigatorStyle || {};
26 28
       static navigatorButtons = InternalComponent.navigatorButtons || {};
27 29
 
30
+      constructor(props) {
31
+        super(props);
32
+        this.allProps = {...props, ...PropRegistry.load(this.navigator.screenInstanceID)};
33
+      }
34
+
28 35
       render() {
29 36
         return (
30
-          <InternalComponent navigator={this.navigator} {...this.props} />
37
+          <InternalComponent navigator={this.navigator} {...this.allProps} />
31 38
         );
32 39
       }
33 40
     };
@@ -43,10 +50,15 @@ function _registerComponentRedux(screenID, generator, store, Provider) {
43 50
       static navigatorStyle = InternalComponent.navigatorStyle || {};
44 51
       static navigatorButtons = InternalComponent.navigatorButtons || {};
45 52
 
53
+      constructor(props) {
54
+        super(props);
55
+        this.allProps = {...props, ...PropRegistry.load(this.navigator.screenInstanceID)};
56
+      }
57
+
46 58
       render() {
47 59
         return (
48 60
           <Provider store={store}>
49
-            <InternalComponent navigator={this.navigator} {...this.props} />
61
+            <InternalComponent navigator={this.navigator} {...this.allProps} />
50 62
           </Provider>
51 63
         );
52 64
       }
@@ -102,7 +114,6 @@ function startSingleScreenApp(params) {
102 114
 }
103 115
 
104 116
 export default {
105
-  registerScreen,
106 117
   getRegisteredScreen,
107 118
   registerComponent,
108 119
   showModal: showModal,

+ 15
- 0
src/PropRegistry.js ファイルの表示

@@ -0,0 +1,15 @@
1
+class PropRegistry {
2
+  constructor() {
3
+    this.registry = {};
4
+  }
5
+
6
+  save(screenInstanceId, passProps) {
7
+    this.registry[screenInstanceId] = passProps;
8
+  }
9
+
10
+  load(screenInstanceId = '') {
11
+    return this.registry[screenInstanceId] || {};
12
+  }
13
+}
14
+
15
+module.exports = new PropRegistry();

+ 3
- 1
src/deprecated/platformSpecificDeprecated.android.js ファイルの表示

@@ -4,6 +4,8 @@ import _ from 'lodash';
4 4
 
5 5
 import Navigation from './../Navigation';
6 6
 
7
+import PropRegistry from '../PropRegistry';
8
+
7 9
 const resolveAssetSource = require('react-native/Libraries/Image/resolveAssetSource');
8 10
 
9 11
 import * as newPlatformSpecific from './../platformSpecific';
@@ -18,6 +20,7 @@ function startSingleScreenApp(params) {
18 20
   addNavigatorButtons(screen);
19 21
   addNavigationStyleParams(screen);
20 22
   screen.passProps = params.passProps;
23
+  PropRegistry.save(screen.screenInstanceID, screen.passProps);
21 24
   //const drawer = setupDrawer(params.drawer);
22 25
 
23 26
   /*
@@ -137,7 +140,6 @@ function startTabBasedApp(params) {
137 140
   }
138 141
 
139 142
   params.tabs.forEach(function(tab, idx) {
140
-    debugger;
141 143
     addNavigatorParams(tab, null, idx);
142 144
     addNavigatorButtons(tab);
143 145
     addNavigationStyleParams(tab);

+ 1
- 3
src/index.js ファイルの表示

@@ -1,9 +1,7 @@
1 1
 import Navigation from './Navigation';
2
-import Screen from './Screen';
3 2
 import {NavigationToolBarIOS} from 'react-native-controllers';
4 3
 
5 4
 module.exports = {
6 5
   Navigation,
7
-  NavigationToolBarIOS,
8
-  Screen
6
+  NavigationToolBarIOS
9 7
 };