Quellcode durchsuchen

add missing files

Guy Carmeli vor 8 Jahren
Ursprung
Commit
ebbd40aee1

+ 53
- 0
android/app/src/main/java/com/reactnativenavigation/utils/ResourceDrawableIdHelper.java Datei anzeigen

@@ -0,0 +1,53 @@
1
+package com.reactnativenavigation.utils;// Copyright 2004-present Facebook. All Rights Reserved.
2
+
3
+import android.content.Context;
4
+import android.graphics.drawable.Drawable;
5
+import android.net.Uri;
6
+
7
+import com.facebook.common.util.UriUtil;
8
+
9
+import java.util.HashMap;
10
+import java.util.Map;
11
+
12
+import javax.annotation.Nullable;
13
+
14
+/**
15
+ * Helper class for obtaining information about local images.
16
+ */
17
+public class ResourceDrawableIdHelper {
18
+
19
+  private Map<String, Integer> mResourceDrawableIdMap;
20
+
21
+  public ResourceDrawableIdHelper() {
22
+    mResourceDrawableIdMap = new HashMap<String, Integer>();
23
+  }
24
+
25
+  public int getResourceDrawableId(Context context, @Nullable String name) {
26
+    if (name == null || name.isEmpty()) {
27
+      return 0;
28
+    }
29
+    name = name.toLowerCase().replace("-", "_");
30
+    if (mResourceDrawableIdMap.containsKey(name)) {
31
+      return mResourceDrawableIdMap.get(name);
32
+    }
33
+    int id = context.getResources().getIdentifier(
34
+        name,
35
+        "drawable",
36
+        context.getPackageName());
37
+    mResourceDrawableIdMap.put(name, id);
38
+    return id;
39
+  }
40
+
41
+  public @Nullable Drawable getResourceDrawable(Context context, @Nullable String name) {
42
+    int resId = getResourceDrawableId(context, name);
43
+    return resId > 0 ? context.getResources().getDrawable(resId) : null;
44
+  }
45
+
46
+  public Uri getResourceDrawableUri(Context context, @Nullable String name) {
47
+    int resId = getResourceDrawableId(context, name);
48
+    return resId > 0 ? new Uri.Builder()
49
+        .scheme(UriUtil.LOCAL_RESOURCE_SCHEME)
50
+        .path(String.valueOf(resId))
51
+        .build() : Uri.EMPTY;
52
+  }
53
+}

+ 3
- 0
example-redux/android/app/build.gradle Datei anzeigen

@@ -123,4 +123,7 @@ dependencies {
123 123
     compile fileTree(dir: "libs", include: ["*.jar"])
124 124
     compile "com.android.support:appcompat-v7:23.0.1"
125 125
     compile "com.facebook.react:react-native:+"  // From node_modules
126
+    debugCompile project(path: ':react-native-navigation', configuration: 'libraryDebug')
127
+    releaseCompile project(path: ':react-native-navigation', configuration: 'libraryRelease')
128
+//    compile project(':react-native-navigation')
126 129
 }

+ 6
- 25
example-redux/android/app/src/main/java/com/exampleredux/MainActivity.java Datei anzeigen

@@ -1,13 +1,8 @@
1 1
 package com.exampleredux;
2 2
 
3
-import com.facebook.react.ReactActivity;
4
-import com.facebook.react.ReactPackage;
5
-import com.facebook.react.shell.MainReactPackage;
3
+import com.reactnativenavigation.activities.RctActivity;
6 4
 
7
-import java.util.Arrays;
8
-import java.util.List;
9
-
10
-public class MainActivity extends ReactActivity {
5
+public class MainActivity extends RctActivity {
11 6
 
12 7
     /**
13 8
      * Returns the name of the main component registered from JavaScript.
@@ -15,26 +10,12 @@ public class MainActivity extends ReactActivity {
15 10
      */
16 11
     @Override
17 12
     protected String getMainComponentName() {
18
-        return "exampleRedux";
19
-    }
20
-
21
-    /**
22
-     * Returns whether dev mode should be enabled.
23
-     * This enables e.g. the dev menu.
24
-     */
25
-    @Override
26
-    protected boolean getUseDeveloperSupport() {
27
-        return BuildConfig.DEBUG;
13
+        return "ExampleRedux";
28 14
     }
29 15
 
30
-    /**
31
-     * A list of packages used by the app. If the app uses additional views
32
-     * or modules besides the default ones, add more packages here.
33
-     */
34 16
     @Override
35
-    protected List<ReactPackage> getPackages() {
36
-        return Arrays.<ReactPackage>asList(
37
-            new MainReactPackage()
38
-        );
17
+    protected void onPause() {
18
+        super.onPause();
19
+        finish();
39 20
     }
40 21
 }

+ 3
- 0
example-redux/android/settings.gradle Datei anzeigen

@@ -1,3 +1,6 @@
1 1
 rootProject.name = 'exampleRedux'
2 2
 
3 3
 include ':app'
4
+include ':react-native-navigation'
5
+project(':react-native-navigation').projectDir = new File(
6
+        rootProject.projectDir, '../node_modules/react-native-navigation/android/app/')

+ 2
- 44
example-redux/index.android.js Datei anzeigen

@@ -1,45 +1,3 @@
1
-/**
2
- * Sample React Native App
3
- * https://github.com/facebook/react-native
4
- */
5
-'use strict';
6
-import React, {
7
-  AppRegistry,
8
-  Component,
9
-  StyleSheet,
10
-  Text,
11
-  View
12
-} from 'react-native';
1
+import App from './src/app';
13 2
 
14
-class exampleRedux extends Component {
15
-  render() {
16
-    return (
17
-      <View style={styles.container}>
18
-        <Text style={styles.welcome}>
19
-          Coming Soon
20
-        </Text>
21
-      </View>
22
-    );
23
-  }
24
-}
25
-
26
-const styles = StyleSheet.create({
27
-  container: {
28
-    flex: 1,
29
-    justifyContent: 'center',
30
-    alignItems: 'center',
31
-    backgroundColor: '#F5FCFF',
32
-  },
33
-  welcome: {
34
-    fontSize: 20,
35
-    textAlign: 'center',
36
-    margin: 10,
37
-  },
38
-  instructions: {
39
-    textAlign: 'center',
40
-    color: '#333333',
41
-    marginBottom: 5,
42
-  },
43
-});
44
-
45
-AppRegistry.registerComponent('exampleRedux', () => exampleRedux);
3
+const app = new App();

+ 18
- 2
example-redux/src/app.js Datei anzeigen

@@ -1,3 +1,8 @@
1
+import React, {
2
+  AppRegistry,
3
+  Component,
4
+  View
5
+} from 'react-native';
1 6
 import { createStore, applyMiddleware, combineReducers } from 'redux';
2 7
 import { Provider } from 'react-redux';
3 8
 import { Navigation } from 'react-native-navigation';
@@ -14,13 +19,23 @@ const store = createStoreWithMiddleware(reducer);
14 19
 import { registerScreens } from './screens';
15 20
 registerScreens(store, Provider);
16 21
 
22
+AppRegistry.registerComponent('ExampleRedux', () => App);
23
+
17 24
 // notice that this is just a simple class, it's not a React component
18
-export default class App {
19
-  constructor() {
25
+export default class App extends React.Component {
26
+  constructor(props) {
27
+    super(props);
20 28
     // since react-redux only works on components, we need to subscribe this class manually
21 29
     store.subscribe(this.onStoreUpdate.bind(this));
22 30
     store.dispatch(appActions.appInitialized());
23 31
   }
32
+
33
+  render() {
34
+    return (
35
+      <View />
36
+    );
37
+  }
38
+
24 39
   onStoreUpdate() {
25 40
     const { root } = store.getState().app;
26 41
     // handle a root change
@@ -30,6 +45,7 @@ export default class App {
30 45
       this.startApp(root);
31 46
     }
32 47
   }
48
+
33 49
   startApp(root) {
34 50
     switch (root) {
35 51
       case 'login':

+ 15
- 7
example-redux/src/screens/FirstTabScreen.js Datei anzeigen

@@ -5,7 +5,7 @@ import React, {
5 5
   ScrollView,
6 6
   TouchableOpacity,
7 7
   StyleSheet,
8
-  AlertIOS
8
+  Alert
9 9
 } from 'react-native';
10 10
 import { connect } from 'react-redux';
11 11
 import * as counterActions from '../reducers/counter/actions';
@@ -20,6 +20,7 @@ class FirstTabScreen extends Component {
20 20
       },
21 21
       {
22 22
         icon: require('../../img/navicon_add.png'),
23
+        title: 'Add',
23 24
         id: 'add'
24 25
       }
25 26
     ]
@@ -30,11 +31,18 @@ class FirstTabScreen extends Component {
30 31
     this.props.navigator.setOnNavigatorEvent(this.onNavigatorEvent.bind(this));
31 32
   }
32 33
   onNavigatorEvent(event) {
33
-    if (event.id == 'edit') {
34
-      AlertIOS.alert('NavBar', 'Edit button pressed');
35
-    }
36
-    if (event.id == 'add') {
37
-      AlertIOS.alert('NavBar', 'Add button pressed');
34
+    switch (event.id) {
35
+      case 'edit':
36
+        Alert.alert('NavBar', 'Edit button pressed');
37
+        break;
38
+
39
+      case 'add':
40
+        Alert.alert('NavBar', 'Add button pressed');
41
+        break;
42
+
43
+      default:
44
+        console.log('Unhandled event ' + event.id);
45
+        break;
38 46
     }
39 47
   }
40 48
   render() {
@@ -72,7 +80,7 @@ const styles = StyleSheet.create({
72 80
     textAlign: 'center',
73 81
     fontSize: 18,
74 82
     marginBottom: 10,
75
-    marginTop:10,
83
+    marginTop:10
76 84
   },
77 85
   button: {
78 86
     textAlign: 'center',

+ 1
- 2
example-redux/src/screens/LoginScreen.js Datei anzeigen

@@ -4,8 +4,7 @@ import React, {
4 4
   View,
5 5
   ScrollView,
6 6
   TouchableOpacity,
7
-  StyleSheet,
8
-  AlertIOS
7
+  StyleSheet
9 8
 } from 'react-native';
10 9
 import { connect } from 'react-redux';
11 10
 import * as counterActions from '../reducers/counter/actions';

+ 1
- 1
example-redux/src/screens/SecondTabScreen.js Datei anzeigen

@@ -6,7 +6,7 @@ import React, {
6 6
   ScrollView,
7 7
   TouchableOpacity,
8 8
   StyleSheet,
9
-  AlertIOS
9
+  Alert
10 10
 } from 'react-native';
11 11
 import { connect } from 'react-redux';
12 12
 import * as counterActions from '../reducers/counter/actions';

+ 1
- 45
example/index.android.js Datei anzeigen

@@ -1,45 +1 @@
1
-/**
2
- * Sample React Native App
3
- * https://github.com/facebook/react-native
4
- */
5
-'use strict';
6
-import React, {
7
-  AppRegistry,
8
-  Component,
9
-  StyleSheet,
10
-  Text,
11
-  View
12
-} from 'react-native';
13
-
14
-class example extends Component {
15
-  render() {
16
-    return (
17
-      <View style={styles.container}>
18
-        <Text style={styles.welcome}>
19
-          Coming Soon
20
-        </Text>
21
-      </View>
22
-    );
23
-  }
24
-}
25
-
26
-const styles = StyleSheet.create({
27
-  container: {
28
-    flex: 1,
29
-    justifyContent: 'center',
30
-    alignItems: 'center',
31
-    backgroundColor: '#F5FCFF',
32
-  },
33
-  welcome: {
34
-    fontSize: 20,
35
-    textAlign: 'center',
36
-    margin: 10,
37
-  },
38
-  instructions: {
39
-    textAlign: 'center',
40
-    color: '#333333',
41
-    marginBottom: 5,
42
-  },
43
-});
44
-
45
-AppRegistry.registerComponent('example', () => example);
1
+import App from './src/app';