Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update0.33 #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 17 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,32 +60,21 @@ dependencies {
}
```

* Register Module (in MainActivity.java)
* Register Module (in MainApplication.java)

```java
import cn.tuofeng.rnwebview.RNWebViewPackage; // <--- import

public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler {
public class MainApplication extends Application implements ReactApplication {
......

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mReactRootView = new ReactRootView(this);

mReactInstanceManager = ReactInstanceManager.builder()
.setApplication(getApplication())
.setBundleAssetName("index.android.bundle")
.setJSMainModuleName("index.android")
.addPackage(new MainReactPackage())
.addPackage(new RNWebViewPackage(this)) // <------ add this line to yout MainActivity class
.setUseDeveloperSupport(BuildConfig.DEBUG)
.setInitialLifecycleState(LifecycleState.RESUMED)
.build();

mReactRootView.startReactApplication(mReactInstanceManager, "AndroidRNSample", null);

setContentView(mReactRootView);
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
.....
new RNWebViewPackage()// <------ add this line
);
}

......
Expand All @@ -95,8 +84,13 @@ public class MainActivity extends Activity implements DefaultHardwareBackBtnHand

## Example
```javascript
var React = require('react-native');
var { StyleSheet } = React;
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View
} from 'react-native';

var WebViewAndroid = require('react-native-crosswalk-android');

Expand Down Expand Up @@ -153,6 +147,7 @@ var styles = StyleSheet.create({
flex: 1,
}
});
AppRegistry.registerComponent('your component', () => WebViewAndroidExample);
```

## Tips for Video (HTML5) inside WebView
Expand All @@ -162,4 +157,4 @@ To work with some html5 video player inside your Webview, I recommend you to set
More info here: http://stackoverflow.com/questions/17259636/enabling-html5-video-playback-in-android-webview

## License
MIT
MIT
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
defaultConfig {
minSdkVersion 16
targetSdkVersion 22
versionCode 5
versionName "1.5"
versionCode 6
versionName "1.6"
}
}

Expand All @@ -23,6 +23,6 @@ repositories {

dependencies {
provided 'com.android.support:appcompat-v7:23.0.1'
provided 'com.facebook.react:react-native:0.13.+'
provided 'com.facebook.react:react-native:+'
compile(name:'xwalk_core_library-17.46.448.10', ext:'aar')
}
60 changes: 43 additions & 17 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,68 @@
/**
* @providesModule WebViewAndroid
*/
'use strict';
'use strict';
Copy link
Author

@jykun jykun Sep 10, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'use strict';

try {
var React = require('react');
} catch(ex) {
var React = require('react-native');
}

var React = require('react-native');
var { requireNativeComponent, PropTypes } = React;
var RCTUIManager = React.NativeModules.UIManager;
var RN = require("react-native");

var { requireNativeComponent, NativeModules } = require('react-native');
var RCTUIManager = NativeModules.UIManager;

var WEBVIEW_REF = 'androidWebView';

var WebViewAndroid = React.createClass({
propTypes: {
url: PropTypes.string,
baseUrl: PropTypes.string,
html: PropTypes.string,
htmlCharset: PropTypes.string,
userAgent: PropTypes.string,
injectedJavaScript: PropTypes.string,
disablePlugins: PropTypes.bool,
disableCookies: PropTypes.bool,
javaScriptEnabled: PropTypes.bool,
geolocationEnabled: PropTypes.bool,
builtInZoomControls: PropTypes.bool,
onNavigationStateChange: PropTypes.func
url: React.PropTypes.string,
source: React.PropTypes.object,
baseUrl: React.PropTypes.string,
html: React.PropTypes.string,
htmlCharset: React.PropTypes.string,
userAgent: React.PropTypes.string,
injectedJavaScript: React.PropTypes.string,
disablePlugins: React.PropTypes.bool,
disableCookies: React.PropTypes.bool,
javaScriptEnabled: React.PropTypes.bool,
geolocationEnabled: React.PropTypes.bool,
allowUrlRedirect: React.PropTypes.bool,
builtInZoomControls: React.PropTypes.bool,
onNavigationStateChange: React.PropTypes.func
},
_onNavigationStateChange: function(event) {
if (this.props.onNavigationStateChange) {
this.props.onNavigationStateChange(event.nativeEvent);
}
},
goBack: function() {
RCTUIManager.dispatchViewManagerCommand(
this._getWebViewHandle(),
RCTUIManager.RNWebViewAndroid.Commands.goBack,
null
);
},
goForward: function() {
RCTUIManager.dispatchViewManagerCommand(
this._getWebViewHandle(),
RCTUIManager.RNWebViewAndroid.Commands.goForward,
null
);
},
reload: function() {
RCTUIManager.dispatchViewManagerCommand(
this._getWebViewHandle(),
RCTUIManager.RNWebViewAndroid.Commands.reload,
null
);
},
render: function() {
return <RNWebViewAndroid ref={WEBVIEW_REF} {...this.props} onNavigationStateChange={this._onNavigationStateChange} />;
},
_getWebViewHandle: function() {
return React.findNodeHandle(this.refs[WEBVIEW_REF]);
return RN.findNodeHandle(this.refs[WEBVIEW_REF]);
},
});

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-crosswalk-android",
"version": "0.0.5",
"version": "0.0.6",
"description": "Simple React Native Android module to use Crosswalk's WebView inside your app",
"main": "index.js",
"scripts": {
Expand Down
15 changes: 6 additions & 9 deletions src/main/java/cn/tuofeng/rnwebview/RNWebViewManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@

import android.app.Activity;
import javax.annotation.Nullable;
import android.util.AttributeSet;

import org.xwalk.core.XWalkView;

import com.facebook.react.uimanager.annotations.ReactProp;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.SimpleViewManager;
import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.uimanager.ReactProp;
import com.facebook.react.common.annotations.VisibleForTesting;

public class RNWebViewManager extends SimpleViewManager<RNWebView> {
Expand All @@ -19,11 +16,10 @@ public class RNWebViewManager extends SimpleViewManager<RNWebView> {
public static final int GO_FORWARD = 2;
public static final int RELOAD = 3;

Activity mActivity;
ReactApplicationContext rContext;

public RNWebViewManager(Activity activity) {
super();
mActivity = activity;
public RNWebViewManager(ReactApplicationContext reactApplicationContext) {
rContext = reactApplicationContext;
}

@VisibleForTesting
Expand All @@ -36,6 +32,7 @@ public String getName() {

@Override
public RNWebView createViewInstance(ThemedReactContext context) {
Activity mActivity = rContext.getCurrentActivity();
return new RNWebView(context, mActivity);
//xWalkWebView.setX(0);
//xWalkWebView.setY(0);
Expand Down
10 changes: 1 addition & 9 deletions src/main/java/cn/tuofeng/rnwebview/RNWebViewPackage.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package cn.tuofeng.rnwebview;

import android.app.Activity;

import com.facebook.react.ReactPackage;
import com.facebook.react.bridge.JavaScriptModule;
import com.facebook.react.bridge.NativeModule;
Expand All @@ -12,12 +10,6 @@


public class RNWebViewPackage implements ReactPackage {
Activity mActivity;

public RNWebViewPackage(Activity activity) {
mActivity = activity;
}

@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
return Collections.emptyList();
Expand All @@ -30,6 +22,6 @@ public List<Class<? extends JavaScriptModule>> createJSModules() {

@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
return Arrays.<ViewManager>asList(new RNWebViewManager(mActivity));
return Arrays.<ViewManager>asList(new RNWebViewManager(reactContext));
}
}