got send working
This commit is contained in:
parent
61f36b073f
commit
cfe6b6c3ea
|
@ -1 +1,2 @@
|
|||
node_modules
|
||||
.DS_Store
|
||||
|
|
|
@ -23,5 +23,6 @@
|
|||
- (void)goForward;
|
||||
- (void)goBack;
|
||||
- (void)reload;
|
||||
- (void)send:(id)message;
|
||||
|
||||
@end
|
|
@ -57,6 +57,11 @@
|
|||
[_webView reload];
|
||||
}
|
||||
|
||||
- (void)send:(id)message
|
||||
{
|
||||
NSLog(@"Message got %@", message);
|
||||
}
|
||||
|
||||
- (void)setURL:(NSURL *)URL
|
||||
{
|
||||
// Because of the way React works, as pages redirect, we actually end up
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
#import "RCTBridge.h"
|
||||
#import "RCTSparseArray.h"
|
||||
#import "RCTUIManager.h"
|
||||
#import "RCTWebView.h"
|
||||
#import "WebViewEx.h"
|
||||
|
||||
@implementation WebViewExManager
|
||||
|
||||
|
@ -20,7 +20,7 @@ RCT_EXPORT_MODULE()
|
|||
|
||||
- (UIView *)view
|
||||
{
|
||||
return [[RCTWebView alloc] initWithEventDispatcher:self.bridge.eventDispatcher];
|
||||
return [[WebViewEx alloc] initWithEventDispatcher:self.bridge.eventDispatcher];
|
||||
}
|
||||
|
||||
RCT_REMAP_VIEW_PROPERTY(url, URL, NSURL);
|
||||
|
@ -48,8 +48,8 @@ RCT_EXPORT_VIEW_PROPERTY(shouldInjectAJAXHandler, BOOL);
|
|||
RCT_EXPORT_METHOD(goBack:(NSNumber *)reactTag)
|
||||
{
|
||||
[self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, RCTSparseArray *viewRegistry) {
|
||||
RCTWebView *view = viewRegistry[reactTag];
|
||||
if (![view isKindOfClass:[RCTWebView class]]) {
|
||||
WebViewEx *view = viewRegistry[reactTag];
|
||||
if (![view isKindOfClass:[WebViewEx class]]) {
|
||||
RCTLogError(@"Invalid view returned from registry, expecting RKWebView, got: %@", view);
|
||||
}
|
||||
[view goBack];
|
||||
|
@ -60,7 +60,7 @@ RCT_EXPORT_METHOD(goForward:(NSNumber *)reactTag)
|
|||
{
|
||||
[self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, RCTSparseArray *viewRegistry) {
|
||||
id view = viewRegistry[reactTag];
|
||||
if (![view isKindOfClass:[RCTWebView class]]) {
|
||||
if (![view isKindOfClass:[WebViewEx class]]) {
|
||||
RCTLogError(@"Invalid view returned from registry, expecting RKWebView, got: %@", view);
|
||||
}
|
||||
[view goForward];
|
||||
|
@ -71,12 +71,29 @@ RCT_EXPORT_METHOD(goForward:(NSNumber *)reactTag)
|
|||
RCT_EXPORT_METHOD(reload:(NSNumber *)reactTag)
|
||||
{
|
||||
[self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, RCTSparseArray *viewRegistry) {
|
||||
RCTWebView *view = viewRegistry[reactTag];
|
||||
if (![view isKindOfClass:[RCTWebView class]]) {
|
||||
WebViewEx *view = viewRegistry[reactTag];
|
||||
if (![view isKindOfClass:[WebViewEx class]]) {
|
||||
RCTLogMustFix(@"Invalid view returned from registry, expecting RKWebView, got: %@", view);
|
||||
}
|
||||
[view reload];
|
||||
}];
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(onMessage:(RCTResponseSenderBlock) callback)
|
||||
{
|
||||
NSLog(@"Called");
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(send:(NSNumber *)reactTag :(id)message)
|
||||
{
|
||||
[self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, RCTSparseArray *viewRegistry) {
|
||||
WebViewEx *view = viewRegistry[reactTag];
|
||||
if (![view isKindOfClass:[WebViewEx class]]) {
|
||||
RCTLogMustFix(@"Invalid view returned from registry, expecting RKWebView, got: %@", view);
|
||||
}
|
||||
[view send:message];
|
||||
}];
|
||||
}
|
||||
|
||||
|
||||
@end
|
|
@ -15,9 +15,16 @@ var {
|
|||
} = React;
|
||||
|
||||
var webview = React.createClass({
|
||||
componentDidMount: function () {
|
||||
this.refs.myWebView.onMessage(function () {
|
||||
console.log('called from objective c');
|
||||
});
|
||||
|
||||
this.refs.myWebView.send("HELLO");
|
||||
},
|
||||
render: function() {
|
||||
return (
|
||||
<WebViewEx style={{flex: 1}} url="http://google.com"/>
|
||||
<WebViewEx ref="myWebView" style={{flex: 1}} url="http://google.com"/>
|
||||
);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -73,7 +73,7 @@ var defaultRenderError = (errorDomain, errorCode, errorDesc) => (
|
|||
</View>
|
||||
);
|
||||
|
||||
var WebViewEx = React.createClass({
|
||||
var WebView = React.createClass({
|
||||
statics: {
|
||||
NavigationType: NavigationType,
|
||||
},
|
||||
|
@ -177,6 +177,14 @@ var WebViewEx = React.createClass({
|
|||
WebViewExManager.reload(this.getWebWiewHandle());
|
||||
},
|
||||
|
||||
onMessage: function (cb) {
|
||||
WebViewExManager.onMessage(cb);
|
||||
},
|
||||
|
||||
send: function (message) {
|
||||
WebViewExManager.send(this.getWebWiewHandle(), message);
|
||||
},
|
||||
|
||||
/**
|
||||
* We return an event with a bunch of fields including:
|
||||
* url, title, loading, canGoBack, canGoForward
|
||||
|
@ -213,7 +221,7 @@ var WebViewEx = React.createClass({
|
|||
},
|
||||
});
|
||||
|
||||
var WebViewEx = requireNativeComponent('WebViewEx', WebViewEx);
|
||||
var WebViewEx = requireNativeComponent('WebViewEx', WebView);
|
||||
|
||||
var styles = StyleSheet.create({
|
||||
container: {
|
||||
|
@ -250,4 +258,4 @@ var styles = StyleSheet.create({
|
|||
}
|
||||
});
|
||||
|
||||
module.exports = WebViewEx;
|
||||
module.exports = WebView;
|
||||
|
|
Binary file not shown.
|
@ -2,4 +2,22 @@
|
|||
<Bucket
|
||||
type = "1"
|
||||
version = "2.0">
|
||||
<Breakpoints>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
shouldBeEnabled = "No"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "WebViewJavascriptBridge/WebViewEx.m"
|
||||
timestampString = "455486993.854932"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "33"
|
||||
endingLineNumber = "33"
|
||||
landmarkName = "-initWithEventDispatcher:"
|
||||
landmarkType = "5">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
</Breakpoints>
|
||||
</Bucket>
|
||||
|
|
Loading…
Reference in New Issue