Browse Source

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

Daniel Zlotin 8 years ago
parent
commit
dbe2b1587a

+ 0
- 3
android/app/src/main/java/com/reactnativenavigation/params/ScreenParams.java View File

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

+ 0
- 3
android/app/src/main/java/com/reactnativenavigation/params/TopTabParams.java View File

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

+ 0
- 2
android/app/src/main/java/com/reactnativenavigation/params/parsers/ScreenParamsParser.java View File

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

+ 0
- 2
android/app/src/main/java/com/reactnativenavigation/params/parsers/TopTabParamsParser.java View File

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

+ 3
- 4
android/app/src/main/java/com/reactnativenavigation/screens/FragmentScreen.java View File

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

+ 1
- 1
android/app/src/main/java/com/reactnativenavigation/screens/SingleScreen.java View File

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

+ 1
- 1
android/app/src/main/java/com/reactnativenavigation/screens/ViewPagerScreen.java View File

45
     private void addPages() {
45
     private void addPages() {
46
         contentViews = new ArrayList<>();
46
         contentViews = new ArrayList<>();
47
         for (TopTabParams tab : screenParams.topTabParams) {
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
             addContent(contentView);
49
             addContent(contentView);
50
             contentViews.add(contentView);
50
             contentViews.add(contentView);
51
         }
51
         }

+ 4
- 12
android/app/src/main/java/com/reactnativenavigation/views/ContentView.java View File

12
 
12
 
13
     private final String screenId;
13
     private final String screenId;
14
     private final String navigatorEventId;
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
         super(context);
18
         super(context);
19
         this.screenId = screenId;
19
         this.screenId = screenId;
20
         navigatorEventId = screenParams.navigatorEventId;
20
         navigatorEventId = screenParams.navigatorEventId;
21
-        this.passProps = mergePropsAndNavigationParams(screenParams, passProps);
21
+        navigationParams = screenParams.navigationParams;
22
         attachToJS();
22
         attachToJS();
23
     }
23
     }
24
 
24
 
39
     }
39
     }
40
 
40
 
41
     private void attachToJS() {
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 View File

35
   startApp(root) {
35
   startApp(root) {
36
     switch (root) {
36
     switch (root) {
37
       case 'login':
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
         Navigation.startSingleScreenApp({
38
         Navigation.startSingleScreenApp({
67
           screen: {
39
           screen: {
68
-            screen: 'example.FirstTabScreen',
40
+            screen: 'example.LoginScreen',
69
             title: 'Login',
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
             navigatorStyle: {}
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
         return;
107
         return;
105
       case 'after-login':
108
       case 'after-login':
106
         Navigation.startTabBasedApp({
109
         Navigation.startTabBasedApp({

+ 1
- 0
example-redux/src/screens/LoginScreen.js View File

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

+ 14
- 3
src/Navigation.js View File

3
 import platformSpecific from './deprecated/platformSpecificDeprecated';
3
 import platformSpecific from './deprecated/platformSpecificDeprecated';
4
 import Screen from './Screen';
4
 import Screen from './Screen';
5
 
5
 
6
+import PropRegistry from './PropRegistry';
7
+
6
 const registeredScreens = {};
8
 const registeredScreens = {};
7
 
9
 
8
 function registerScreen(screenID, generator) {
10
 function registerScreen(screenID, generator) {
25
       static navigatorStyle = InternalComponent.navigatorStyle || {};
27
       static navigatorStyle = InternalComponent.navigatorStyle || {};
26
       static navigatorButtons = InternalComponent.navigatorButtons || {};
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
       render() {
35
       render() {
29
         return (
36
         return (
30
-          <InternalComponent navigator={this.navigator} {...this.props} />
37
+          <InternalComponent navigator={this.navigator} {...this.allProps} />
31
         );
38
         );
32
       }
39
       }
33
     };
40
     };
43
       static navigatorStyle = InternalComponent.navigatorStyle || {};
50
       static navigatorStyle = InternalComponent.navigatorStyle || {};
44
       static navigatorButtons = InternalComponent.navigatorButtons || {};
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
       render() {
58
       render() {
47
         return (
59
         return (
48
           <Provider store={store}>
60
           <Provider store={store}>
49
-            <InternalComponent navigator={this.navigator} {...this.props} />
61
+            <InternalComponent navigator={this.navigator} {...this.allProps} />
50
           </Provider>
62
           </Provider>
51
         );
63
         );
52
       }
64
       }
102
 }
114
 }
103
 
115
 
104
 export default {
116
 export default {
105
-  registerScreen,
106
   getRegisteredScreen,
117
   getRegisteredScreen,
107
   registerComponent,
118
   registerComponent,
108
   showModal: showModal,
119
   showModal: showModal,

+ 15
- 0
src/PropRegistry.js View File

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 View File

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

+ 1
- 3
src/index.js View File

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