Selaa lähdekoodia

example-redux works on iOS but dear god this code is ugly

Daniel Zlotin 8 vuotta sitten
vanhempi
commit
38f849af47

+ 8
- 2
example-redux/ios/exampleRedux.xcodeproj/project.pbxproj Näytä tiedosto

@@ -650,7 +650,10 @@
650 650
 				);
651 651
 				INFOPLIST_FILE = exampleRedux/Info.plist;
652 652
 				LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
653
-				OTHER_LDFLAGS = "-ObjC";
653
+				OTHER_LDFLAGS = (
654
+					"-ObjC",
655
+					"-lc++",
656
+				);
654 657
 				PRODUCT_NAME = exampleRedux;
655 658
 			};
656 659
 			name = Debug;
@@ -667,7 +670,10 @@
667 670
 				);
668 671
 				INFOPLIST_FILE = exampleRedux/Info.plist;
669 672
 				LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
670
-				OTHER_LDFLAGS = "-ObjC";
673
+				OTHER_LDFLAGS = (
674
+					"-ObjC",
675
+					"-lc++",
676
+				);
671 677
 				PRODUCT_NAME = exampleRedux;
672 678
 			};
673 679
 			name = Release;

+ 76
- 72
example-redux/src/app.js Näytä tiedosto

@@ -1,9 +1,11 @@
1
-import {createStore, applyMiddleware, combineReducers} from 'redux';
2
-import {Provider} from 'react-redux';
3
-import {Navigation} from 'react-native-navigation';
4
-import thunk from 'redux-thunk';
5
-import * as reducers from './reducers';
6
-import * as appActions from './reducers/app/actions';
1
+import {createStore, applyMiddleware, combineReducers} from "redux";
2
+import {Provider} from "react-redux";
3
+import {Navigation} from "react-native-navigation";
4
+import thunk from "redux-thunk";
5
+import * as reducers from "./reducers";
6
+import * as appActions from "./reducers/app/actions";
7
+import {registerScreens} from "./screens";
8
+import {Platform} from "react-native";
7 9
 
8 10
 // redux related book keeping
9 11
 const createStoreWithMiddleware = applyMiddleware(thunk)(createStore);
@@ -11,7 +13,6 @@ const reducer = combineReducers(reducers);
11 13
 const store = createStoreWithMiddleware(reducer);
12 14
 
13 15
 // screen related book keeping
14
-import {registerScreens} from './screens';
15 16
 registerScreens(store, Provider);
16 17
 
17 18
 // notice that this is just a simple class, it's not a React component
@@ -35,74 +36,77 @@ export default class App {
35 36
   startApp(root) {
36 37
     switch (root) {
37 38
       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
-        //    fn: function() {
65
-        //      return 'Hello from a function!';
66
-        //    }
67
-        //  }
68
-        // });
69
-        Navigation.startSingleScreenApp({
70
-          screen: {
71
-            title: 'Example',
72
-            screen: 'example.TopTabsScreen',
73
-            topTabs: [
74
-              {
75
-                screenId: 'example.FirstTabScreen',
76
-                title: 'Tab1',
77
-                passProps: {
78
-                  str: 'This is a prop passed to Tab1',
79
-                  fn: () => 'Hello from a function passed as passProps!'
80
-                }
81
-              },
82
-              {
83
-                screenId: 'example.PushedScreen',
84
-                title: 'Tab2',
85
-                passProps: {
86
-                  str: 'This is a prop passed to Tab2'
87
-                }
39
+        if (Platform.OS === 'ios') {
40
+          Navigation.startSingleScreenApp({
41
+            screen: {
42
+              screen: 'example.LoginScreen',
43
+              title: 'Login',
44
+              navigatorStyle: {}
45
+            },
46
+            passProps: {
47
+              str: 'This is a prop passed in \'startSingleScreenApp()\'!',
48
+              obj: {
49
+                str: 'This is a prop passed in an object!',
50
+                arr: [
51
+                  {
52
+                    str: 'This is a prop in an object in an array in an object!'
53
+                  }
54
+                ],
55
+                arr2: [
56
+                  [
57
+                    'array of strings',
58
+                    'with two strings'
59
+                  ],
60
+                  [
61
+                    1, 2, 3
62
+                  ]
63
+                ]
88 64
               },
89
-              {
90
-                screenId: 'example.ListScreen',
91
-                title: 'Tab3',
92
-                passProps: {
93
-                  str: 'This is a prop passed to Tab3'
94
-                }
65
+              num: 1234,
66
+              fn: function() {
67
+                return 'Hello from a function!';
95 68
               }
96
-            ],
97
-            navigatorStyle: {}
98
-          },
99
-          drawer: { // optional, add this if you want a side menu drawer in your app
100
-            left: { // optional, define if you want a drawer from the left
101
-              screen: 'example.SideMenu' // unique ID registered with Navigation.registerScreen
69
+            }
70
+          });
71
+        } else {
72
+          Navigation.startSingleScreenApp({
73
+            screen: {
74
+              title: 'Example',
75
+              screen: 'example.TopTabsScreen',
76
+              topTabs: [
77
+                {
78
+                  screenId: 'example.FirstTabScreen',
79
+                  title: 'Tab1',
80
+                  passProps: {
81
+                    str: 'This is a prop passed to Tab1',
82
+                    fn: () => 'Hello from a function passed as passProps!'
83
+                  }
84
+                },
85
+                {
86
+                  screenId: 'example.PushedScreen',
87
+                  title: 'Tab2',
88
+                  passProps: {
89
+                    str: 'This is a prop passed to Tab2'
90
+                  }
91
+                },
92
+                {
93
+                  screenId: 'example.ListScreen',
94
+                  title: 'Tab3',
95
+                  passProps: {
96
+                    str: 'This is a prop passed to Tab3'
97
+                  }
98
+                }
99
+              ],
100
+              navigatorStyle: {}
102 101
             },
103
-            disableOpenGesture: false // optional, can the drawer be opened with a swipe instead of button
104
-          }
105
-        });
102
+            drawer: { // optional, add this if you want a side menu drawer in your app
103
+              left: { // optional, define if you want a drawer from the left
104
+                screen: 'example.SideMenu' // unique ID registered with Navigation.registerScreen
105
+              },
106
+              disableOpenGesture: false // optional, can the drawer be opened with a swipe instead of button
107
+            }
108
+          });
109
+        }
106 110
         return;
107 111
       case 'after-login':
108 112
         Navigation.startTabBasedApp({

+ 6
- 2
example-redux/src/screens/TopTabsScreen.js Näytä tiedosto

@@ -1,3 +1,7 @@
1
-export default class TopTabsScreen {
1
+import React, {Component} from "react";
2 2
 
3
-}
3
+export default class TopTabsScreen extends Component {
4
+  render() {
5
+    return null;
6
+  }
7
+}