got send working
This commit is contained in:
parent
61f36b073f
commit
cfe6b6c3ea
|
@ -1 +1,2 @@
|
||||||
node_modules
|
node_modules
|
||||||
|
.DS_Store
|
||||||
|
|
|
@ -23,5 +23,6 @@
|
||||||
- (void)goForward;
|
- (void)goForward;
|
||||||
- (void)goBack;
|
- (void)goBack;
|
||||||
- (void)reload;
|
- (void)reload;
|
||||||
|
- (void)send:(id)message;
|
||||||
|
|
||||||
@end
|
@end
|
|
@ -57,6 +57,11 @@
|
||||||
[_webView reload];
|
[_webView reload];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)send:(id)message
|
||||||
|
{
|
||||||
|
NSLog(@"Message got %@", message);
|
||||||
|
}
|
||||||
|
|
||||||
- (void)setURL:(NSURL *)URL
|
- (void)setURL:(NSURL *)URL
|
||||||
{
|
{
|
||||||
// Because of the way React works, as pages redirect, we actually end up
|
// Because of the way React works, as pages redirect, we actually end up
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
#import "RCTBridge.h"
|
#import "RCTBridge.h"
|
||||||
#import "RCTSparseArray.h"
|
#import "RCTSparseArray.h"
|
||||||
#import "RCTUIManager.h"
|
#import "RCTUIManager.h"
|
||||||
#import "RCTWebView.h"
|
#import "WebViewEx.h"
|
||||||
|
|
||||||
@implementation WebViewExManager
|
@implementation WebViewExManager
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ RCT_EXPORT_MODULE()
|
||||||
|
|
||||||
- (UIView *)view
|
- (UIView *)view
|
||||||
{
|
{
|
||||||
return [[RCTWebView alloc] initWithEventDispatcher:self.bridge.eventDispatcher];
|
return [[WebViewEx alloc] initWithEventDispatcher:self.bridge.eventDispatcher];
|
||||||
}
|
}
|
||||||
|
|
||||||
RCT_REMAP_VIEW_PROPERTY(url, URL, NSURL);
|
RCT_REMAP_VIEW_PROPERTY(url, URL, NSURL);
|
||||||
|
@ -48,8 +48,8 @@ RCT_EXPORT_VIEW_PROPERTY(shouldInjectAJAXHandler, BOOL);
|
||||||
RCT_EXPORT_METHOD(goBack:(NSNumber *)reactTag)
|
RCT_EXPORT_METHOD(goBack:(NSNumber *)reactTag)
|
||||||
{
|
{
|
||||||
[self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, RCTSparseArray *viewRegistry) {
|
[self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, RCTSparseArray *viewRegistry) {
|
||||||
RCTWebView *view = viewRegistry[reactTag];
|
WebViewEx *view = viewRegistry[reactTag];
|
||||||
if (![view isKindOfClass:[RCTWebView class]]) {
|
if (![view isKindOfClass:[WebViewEx class]]) {
|
||||||
RCTLogError(@"Invalid view returned from registry, expecting RKWebView, got: %@", view);
|
RCTLogError(@"Invalid view returned from registry, expecting RKWebView, got: %@", view);
|
||||||
}
|
}
|
||||||
[view goBack];
|
[view goBack];
|
||||||
|
@ -60,7 +60,7 @@ RCT_EXPORT_METHOD(goForward:(NSNumber *)reactTag)
|
||||||
{
|
{
|
||||||
[self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, RCTSparseArray *viewRegistry) {
|
[self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, RCTSparseArray *viewRegistry) {
|
||||||
id view = viewRegistry[reactTag];
|
id view = viewRegistry[reactTag];
|
||||||
if (![view isKindOfClass:[RCTWebView class]]) {
|
if (![view isKindOfClass:[WebViewEx class]]) {
|
||||||
RCTLogError(@"Invalid view returned from registry, expecting RKWebView, got: %@", view);
|
RCTLogError(@"Invalid view returned from registry, expecting RKWebView, got: %@", view);
|
||||||
}
|
}
|
||||||
[view goForward];
|
[view goForward];
|
||||||
|
@ -71,12 +71,29 @@ RCT_EXPORT_METHOD(goForward:(NSNumber *)reactTag)
|
||||||
RCT_EXPORT_METHOD(reload:(NSNumber *)reactTag)
|
RCT_EXPORT_METHOD(reload:(NSNumber *)reactTag)
|
||||||
{
|
{
|
||||||
[self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, RCTSparseArray *viewRegistry) {
|
[self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, RCTSparseArray *viewRegistry) {
|
||||||
RCTWebView *view = viewRegistry[reactTag];
|
WebViewEx *view = viewRegistry[reactTag];
|
||||||
if (![view isKindOfClass:[RCTWebView class]]) {
|
if (![view isKindOfClass:[WebViewEx class]]) {
|
||||||
RCTLogMustFix(@"Invalid view returned from registry, expecting RKWebView, got: %@", view);
|
RCTLogMustFix(@"Invalid view returned from registry, expecting RKWebView, got: %@", view);
|
||||||
}
|
}
|
||||||
[view reload];
|
[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
|
@end
|
|
@ -15,9 +15,16 @@ var {
|
||||||
} = React;
|
} = React;
|
||||||
|
|
||||||
var webview = React.createClass({
|
var webview = React.createClass({
|
||||||
|
componentDidMount: function () {
|
||||||
|
this.refs.myWebView.onMessage(function () {
|
||||||
|
console.log('called from objective c');
|
||||||
|
});
|
||||||
|
|
||||||
|
this.refs.myWebView.send("HELLO");
|
||||||
|
},
|
||||||
render: function() {
|
render: function() {
|
||||||
return (
|
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>
|
</View>
|
||||||
);
|
);
|
||||||
|
|
||||||
var WebViewEx = React.createClass({
|
var WebView = React.createClass({
|
||||||
statics: {
|
statics: {
|
||||||
NavigationType: NavigationType,
|
NavigationType: NavigationType,
|
||||||
},
|
},
|
||||||
|
@ -177,6 +177,14 @@ var WebViewEx = React.createClass({
|
||||||
WebViewExManager.reload(this.getWebWiewHandle());
|
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:
|
* We return an event with a bunch of fields including:
|
||||||
* url, title, loading, canGoBack, canGoForward
|
* 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({
|
var styles = StyleSheet.create({
|
||||||
container: {
|
container: {
|
||||||
|
@ -250,4 +258,4 @@ var styles = StyleSheet.create({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = WebViewEx;
|
module.exports = WebView;
|
||||||
|
|
Binary file not shown.
|
@ -2,4 +2,22 @@
|
||||||
<Bucket
|
<Bucket
|
||||||
type = "1"
|
type = "1"
|
||||||
version = "2.0">
|
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>
|
</Bucket>
|
||||||
|
|
Loading…
Reference in New Issue