Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
公共资源
ios-eros-plugin
Commits
86a31864
Commit
86a31864
authored
4 years ago
by
谢俊毅
Browse files
Options
Download
Email Patches
Plain Diff
有关 webview 遗漏的功能
parent
89c029dc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ios/sdk/WeexSDK/Sources/Component/WXWebComponent.m
+36
-38
ios/sdk/WeexSDK/Sources/Component/WXWebComponent.m
with
36 additions
and
38 deletions
+36
-38
ios/sdk/WeexSDK/Sources/Component/WXWebComponent.m
+
36
-
38
View file @
86a31864
...
...
@@ -43,8 +43,6 @@
@interface
WXWebComponent
()
@property
(
nonatomic
,
strong
)
JSContext
*
jsContext
;
@property
(
nonatomic
,
strong
)
WXWebView
*
webview
;
@property
(
nonatomic
,
strong
)
NSString
*
url
;
...
...
@@ -98,7 +96,7 @@ WX_EXPORT_METHOD(@selector(goForward))
-
(
UIView
*
)
loadView
{
return
[[
WXWebView
alloc
]
initWithFrame
:
self
.
view
.
frame
configuration
:[
self
baseConfiguration
]];
return
[[
WXWebView
alloc
]
initWithFrame
:
CGRectZero
configuration
:[
self
baseConfiguration
]];
}
-
(
void
)
viewDidLoad
...
...
@@ -107,39 +105,39 @@ WX_EXPORT_METHOD(@selector(goForward))
_webview
.
navigationDelegate
=
self
;
[
_webview
setBackgroundColor
:[
UIColor
clearColor
]];
_webview
.
opaque
=
NO
;
_jsContext
=
[
_webview
valueForKeyPath
:
@"documentView.webView.mainFrame.javaScriptContext"
];
__weak
typeof
(
self
)
weakSelf
=
self
;
// This method will be abandoned slowly.
_jsContext
[
@"$notifyWeex"
]
=
^
(
JSValue
*
data
)
{
if
(
weakSelf
.
notifyEvent
)
{
[
weakSelf
fireEvent
:
@"notify"
params
:[
data
toDictionary
]];
}
};
//Weex catch postMessage event from web
_jsContext
[
@"postMessage"
]
=
^
()
{
NSArray
*
args
=
[
JSContext
currentArguments
];
if
(
args
&&
args
.
count
<
2
)
{
return
;
}
NSDictionary
*
data
=
[
args
[
0
]
toDictionary
];
NSString
*
origin
=
[
args
[
1
]
toString
];
if
(
data
==
nil
)
{
return
;
}
NSDictionary
*
initDic
=
@{
@"type"
:
@"message"
,
@"data"
:
data
,
@"origin"
:
origin
};
[
weakSelf
fireEvent
:
@"message"
params
:
initDic
];
};
//
_jsContext = [_webview valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
//
__weak typeof(self) weakSelf = self;
//
//
// This method will be abandoned slowly.
//
_jsContext[@"$notifyWeex"] = ^(JSValue *data) {
//
if (weakSelf.notifyEvent) {
//
[weakSelf fireEvent:@"notify" params:[data toDictionary]];
//
}
//
};
//
//
//Weex catch postMessage event from web
//
_jsContext[@"postMessage"] = ^() {
//
//
NSArray *args = [JSContext currentArguments];
//
//
if (args && args.count < 2) {
//
return;
//
}
//
//
NSDictionary *data = [args[0] toDictionary];
//
NSString *origin = [args[1] toString];
//
//
if (data == nil) {
//
return;
//
}
//
//
NSDictionary *initDic = @{ @"type" : @"message",
//
@"data" : data,
//
@"origin" : origin
//
};
//
//
[weakSelf fireEvent:@"message" params:initDic];
//
};
self
.
source
=
_inInitsource
;
if
(
_url
)
{
...
...
@@ -235,7 +233,7 @@ WX_EXPORT_METHOD(@selector(goForward))
{
NSString
*
json
=
[
WXUtility
JSONString
:
data
];
NSString
*
code
=
[
NSString
stringWithFormat
:
@"(function(){var evt=null;var data=%@;if(typeof CustomEvent==='function'){evt=new CustomEvent('notify',{detail:data})}else{evt=document.createEvent('CustomEvent');evt.initCustomEvent('notify',true,true,data)}document.dispatchEvent(evt)}())"
,
json
];
[
_
jsContext
evaluateScript
:
code
];
[
_
webview
evaluate
Java
Script
:
code
completionHandler
:
nil
];
}
// Weex postMessage to web
...
...
@@ -259,7 +257,7 @@ WX_EXPORT_METHOD(@selector(goForward))
NSString
*
json
=
[
WXUtility
JSONString
:
initDic
];
NSString
*
code
=
[
NSString
stringWithFormat
:
@"(function (){window.dispatchEvent(new MessageEvent('message', %@));}())"
,
json
];
[
_
jsContext
evaluateScript
:
code
];
[
_
webview
evaluate
Java
Script
:
code
completionHandler
:
nil
];
}
#pragma mark Webview Delegate
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help