Quellcode durchsuchen

Android example project, fix for missing ;

Yedidya Kennard vor 8 Jahren
Ursprung
Commit
9a2a0a274f

+ 1
- 1
example/android/app/build.gradle Datei anzeigen

@@ -129,7 +129,7 @@ dependencies {
129 129
     compile fileTree(dir: "libs", include: ["*.jar"])
130 130
     compile "com.android.support:appcompat-v7:23.0.1"
131 131
     compile "com.facebook.react:react-native:+"  // From node_modules
132
-    compile project(":react-native-navigation")
132
+    compile project(':react-native-webview-bridge')
133 133
 }
134 134
 
135 135
 // Run this once to be able to run the application with BUCK

+ 10
- 3
example/android/app/proguard-rules.pro Datei anzeigen

@@ -12,9 +12,9 @@
12 12
 # If your project uses WebView with JS, uncomment the following
13 13
 # and specify the fully qualified class name to the JavaScript interface
14 14
 # class:
15
-#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16
-#   public *;
17
-#}
15
+-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16
+   public *;
17
+}
18 18
 
19 19
 # Disabling obfuscation is useful if you collect stack traces from production crashes
20 20
 # (unless you are using a system that supports de-obfuscate the stack traces).
@@ -64,3 +64,10 @@
64 64
 -dontwarn java.nio.file.*
65 65
 -dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
66 66
 -dontwarn okio.**
67
+
68
+# react-native-webview-bridge
69
+-keepattributes JavascriptInterface
70
+-keep class com.github.alinz.reactnativewebviewbridge.**
71
+-keepclassmembers class ** {
72
+    @android.webkit.JavascriptInterface <methods>;
73
+}

+ 2
- 2
example/android/app/src/main/AndroidManifest.xml Datei anzeigen

@@ -1,5 +1,5 @@
1 1
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
-    package="com.react_native_navigation_bootstrap"
2
+    package="com.example"
3 3
     android:versionCode="1"
4 4
     android:versionName="1.0">
5 5
 
@@ -11,7 +11,7 @@
11 11
         android:targetSdkVersion="22" />
12 12
 
13 13
     <application
14
-      android:name=".MainApplication"
14
+    android:name=".MainApplication"
15 15
       android:allowBackup="true"
16 16
       android:label="@string/app_name"
17 17
       android:icon="@mipmap/ic_launcher"

+ 15
- 0
example/android/app/src/main/java/com/example/MainActivity.java Datei anzeigen

@@ -0,0 +1,15 @@
1
+package com.example;
2
+
3
+import com.facebook.react.ReactActivity;
4
+
5
+public class MainActivity extends ReactActivity {
6
+
7
+    /**
8
+     * Returns the name of the main component registered from JavaScript.
9
+     * This is used to schedule rendering of the component.
10
+     */
11
+    @Override
12
+    protected String getMainComponentName() {
13
+        return "example";
14
+    }
15
+}

+ 35
- 0
example/android/app/src/main/java/com/example/MainApplication.java Datei anzeigen

@@ -0,0 +1,35 @@
1
+package com.example;
2
+
3
+import android.app.Application;
4
+
5
+import com.facebook.react.ReactApplication;
6
+import com.facebook.react.ReactNativeHost;
7
+import com.facebook.react.ReactPackage;
8
+import com.facebook.react.shell.MainReactPackage;
9
+import com.github.alinz.reactnativewebviewbridge.WebViewBridgePackage;
10
+
11
+import java.util.Arrays;
12
+import java.util.List;
13
+
14
+public class MainApplication extends Application implements ReactApplication {
15
+
16
+    private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
17
+        @Override
18
+        protected boolean getUseDeveloperSupport() {
19
+            return BuildConfig.DEBUG;
20
+        }
21
+
22
+        @Override
23
+        protected List<ReactPackage> getPackages() {
24
+            return Arrays.<ReactPackage>asList(
25
+                    new MainReactPackage(),
26
+                    new WebViewBridgePackage()
27
+            );
28
+        }
29
+    };
30
+
31
+    @Override
32
+    public ReactNativeHost getReactNativeHost() {
33
+        return mReactNativeHost;
34
+    }
35
+}

+ 0
- 7
example/android/app/src/main/java/com/react_native_navigation_bootstrap/MainActivity.java Datei anzeigen

@@ -1,7 +0,0 @@
1
-package com.react_native_navigation_bootstrap;
2
-
3
-import com.reactnativenavigation.controllers.SplashActivity;
4
-
5
-public class MainActivity extends SplashActivity {
6
-
7
-}

+ 0
- 25
example/android/app/src/main/java/com/react_native_navigation_bootstrap/MainApplication.java Datei anzeigen

@@ -1,25 +0,0 @@
1
-package com.react_native_navigation_bootstrap;
2
-
3
-import android.support.annotation.NonNull;
4
-
5
-import com.facebook.react.ReactPackage;
6
-import com.reactnativenavigation.NavigationApplication;
7
-
8
-import java.util.List;
9
-
10
-public class MainApplication extends NavigationApplication {
11
-
12
-  @Override
13
-  public boolean isDebug() {
14
-    return BuildConfig.DEBUG;
15
-  }
16
-
17
-  @NonNull
18
-  @Override
19
-  public List<ReactPackage> createAdditionalReactPackages() {
20
-    // Add the packages you require here.
21
-    // No need to add RnnPackage and MainReactPackage
22
-    return null;
23
-  }
24
-
25
-}

+ 1
- 1
example/android/app/src/main/res/values/strings.xml Datei anzeigen

@@ -1,3 +1,3 @@
1 1
 <resources>
2
-    <string name="app_name">react_native_navigation_bootstrap</string>
2
+    <string name="app_name">example</string>
3 3
 </resources>

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

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

+ 32
- 36
example/index.android.js Datei anzeigen

@@ -1,9 +1,3 @@
1
-/**
2
- * Sample React Native App
3
- * https://github.com/facebook/react-native
4
- * @flow
5
- */
6
-
7 1
 import React, { Component } from 'react';
8 2
 import {
9 3
     AppRegistry,
@@ -11,50 +5,52 @@ import {
11 5
     Text,
12 6
     View
13 7
 } from 'react-native';
14
-import {Navigation} from 'react-native-navigation';
8
+import RichTextEditor from 'react-native-ZSSRichTextEditor'
9
+
10
+class RichTextExample extends Component {
11
+
12
+  constructor(props) {
13
+    super(props);
14
+    this.getHTML = this.getHTML.bind(this);
15
+  }
15 16
 
16
-class react_native_navigation_bootstrap extends Component {
17 17
   render() {
18 18
     return (
19 19
         <View style={styles.container}>
20
-          <Text style={styles.welcome}>
21
-            Welcome to React Native!
22
-          </Text>
23
-          <Text style={styles.instructions}>
24
-            To get started, edit index.ios.js
25
-          </Text>
26
-          <Text style={styles.instructions}>
27
-            Press Cmd+R to reload,{'\n'}
28
-            Cmd+D or shake for dev menu
29
-          </Text>
20
+          <RichTextEditor
21
+              ref={(r)=>this.richtext = r}
22
+              style={styles.richText}
23
+              initialHTML={'Hello <b>World</b> <p>this is a new paragraph</p>'}
24
+          />
30 25
         </View>
31 26
     );
32 27
   }
28
+
29
+  async getHTML() {
30
+    const html = await this.richtext.getHtml();
31
+    alert(html);
32
+  }
33
+
34
+  componentDidMount() {
35
+
36
+    setTimeout(()=>{
37
+      this.getHTML();
38
+    }, 3000);
39
+  }
33 40
 }
34 41
 
35 42
 const styles = StyleSheet.create({
36 43
   container: {
37 44
     flex: 1,
38
-    justifyContent: 'center',
39
-    alignItems: 'center',
45
+    flexDirection: 'column',
40 46
     backgroundColor: '#F5FCFF',
47
+    paddingTop: 40
41 48
   },
42
-  welcome: {
43
-    fontSize: 20,
44
-    textAlign: 'center',
45
-    margin: 10,
46
-  },
47
-  instructions: {
48
-    textAlign: 'center',
49
-    color: '#333333',
50
-    marginBottom: 5,
49
+  richText: {
50
+    alignItems:'center',
51
+    justifyContent: 'center',
52
+    backgroundColor: 'transparent',
51 53
   },
52 54
 });
53 55
 
54
-Navigation.registerComponent('react-native-navigation-bootstrap', () => react_native_navigation_bootstrap);
55
-Navigation.startSingleScreenApp({
56
-  screen: {
57
-    screen: 'react-native-navigation-bootstrap',
58
-    title: 'Navigation Bootstrap'
59
-  }
60
-});
56
+AppRegistry.registerComponent('example', () => RichTextExample);

+ 1
- 8
src/RichTextEditor.js Datei anzeigen

@@ -27,7 +27,6 @@ export default class RichTextEditor extends Component {
27 27
   }
28 28
 
29 29
   onBridgeMessage(message){
30
-    // handle other callbacks
31 30
     const json = JSON.parse(message);
32 31
     if (json && json.type && json.type === consts.HTML_RESPONSE) {
33 32
       if (this.resolve) {
@@ -42,11 +41,6 @@ export default class RichTextEditor extends Component {
42 41
     }
43 42
   }
44 43
 
45
-  onShouldStartLoadRequest(event) {
46
-    console.log('RichTextEditor', 'should start load request event: ', event);
47
-    return (event.url.indexOf("editor.html") != -1);
48
-  }
49
-
50 44
   render() {
51 45
     return (
52 46
       <WebViewBridge
@@ -54,9 +48,8 @@ export default class RichTextEditor extends Component {
54 48
         hideKeyboardAccessoryView={true}
55 49
         ref={(r) => {this.webviewBridge = r}}
56 50
         onBridgeMessage={(message) => this.onBridgeMessage(message)}
57
-        onShouldStartLoadWithRequest={(event) => this.onShouldStartLoadRequest(event)}
58
-        source={require('./editor.html')}
59 51
         injectedJavaScript={injectScript}
52
+        source={require('./editor.html')}
60 53
       />
61 54
     );
62 55
   }

+ 1
- 1
src/WebviewMessageHandler.js Datei anzeigen

@@ -40,7 +40,7 @@ export const InjectedMessageHandler = `
40 40
           zss_editor.setHeading('h6');
41 41
           break;
42 42
         case '${actions.setParagraph}':
43
-          zss_editor.setParagraph()
43
+          zss_editor.setParagraph();
44 44
           break;
45 45
         case '${actions.removeFormat}':
46 46
           zss_editor.removeFormating();