You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by bo...@apache.org on 2017/03/29 07:24:56 UTC
[1/2] incubator-weex git commit: * [doc] add notice and code example
to exporting sync method documentation
Repository: incubator-weex
Updated Branches:
refs/heads/dev 692e88b2b -> 0d441c06a
* [doc] add notice and code example to exporting sync method documentation
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/65bad078
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/65bad078
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/65bad078
Branch: refs/heads/dev
Commit: 65bad078d58cb34269f5d70c23f552c4ac360c35
Parents: 692e88b
Author: \u9690\u98ce <cx...@apache.org>
Authored: Wed Mar 29 12:03:09 2017 +0800
Committer: \u9690\u98ce <cx...@apache.org>
Committed: Wed Mar 29 12:03:09 2017 +0800
----------------------------------------------------------------------
doc/source/references/advanced/extend-to-ios.md | 64 ++++++++++++++------
1 file changed, 47 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/65bad078/doc/source/references/advanced/extend-to-ios.md
----------------------------------------------------------------------
diff --git a/doc/source/references/advanced/extend-to-ios.md b/doc/source/references/advanced/extend-to-ios.md
index a2ffa33..2bd6f7e 100644
--- a/doc/source/references/advanced/extend-to-ios.md
+++ b/doc/source/references/advanced/extend-to-ios.md
@@ -47,7 +47,37 @@ For example: If you want to implement an address jumping function, you can achie
@end
```
-In addition, `0.10.0` begins to support synchronous module API call, you can use macro `WX_EXPORT_METHOD_SYNC` to export module methods which could make JavaScript receive return values from native, it **can only be called on JS thread**.
+#### export synchronous methods <span class="api-version">v0.10+</span>
+
+If you want to export synchronous methods which could make Javascript receive return values from natvie, you can use `WX_EXPORT_METHOD_SYNC` macro.
+
+native code:
+
+```objective-c
+@implementation WXEventModule
+
+WX_EXPORT_METHOD_SYNC(@selector(getString))
+
+- (NSString *)getString
+{
+ return @"testString";
+}
+
+@end
+```
+
+js code:
+
+```javascript
+const eventModule = weex.requireModule('event')
+const returnString = syncTest.getString() // return "testString"
+```
+
+You can alse return number/array/dictionary except string.
+
+`notice:` the exported synchronous native method **can only be called on JS thread**.
+
+`notice:` Vue 2.0 has not supported this feature yet.
#### Register the module
@@ -194,19 +224,19 @@ A Native Component has a life cycle managed by Weex. Weex creates it, layout it,
Weex offers component life cycle hooks that give you visibility into these key moments and the ability to act when they occur.
-method| description
-:----:|------
-initWithRef:type:...| Initializes a new component using the specified properties.
-layoutDidFinish | Called when the component has just laid out.
-loadView | Creates the view that the component manages.
-viewWillLoad | Called before the load of component's view .
-viewDidLoad | Called after the component's view is loaded and set.
-viewWillUnload | Called just before releasing the component's view.
-viewDidUnload | Called when the component's view is released.
-updateStyles:| Called when component's style are updated.
-updateAttributes:| Called when component's attributes are updated.
-addEvent:| Called when adding an event to the component.
-removeEvent:| Called when removing an event frome the component.
+| method | description |
+| :------------------: | ---------------------------------------- |
+| initWithRef:type:... | Initializes a new component using the specified properties. |
+| layoutDidFinish | Called when the component has just laid out. |
+| loadView | Creates the view that the component manages. |
+| viewWillLoad | Called before the load of component's view . |
+| viewDidLoad | Called after the component's view is loaded and set. |
+| viewWillUnload | Called just before releasing the component's view. |
+| viewDidUnload | Called when the component's view is released. |
+| updateStyles: | Called when component's style are updated. |
+| updateAttributes: | Called when component's attributes are updated. |
+| addEvent: | Called when adding an event to the component. |
+| removeEvent: | Called when removing an event frome the component. |
As in the image component example, if we need to use our own image view, we can override the `loadView` method.
@@ -287,9 +317,9 @@ for example:
}
@end
```
-
+
after your registration for your own custom component, now you can call it in your js file.
-
+
```html
<template>
<mycomponent id='mycomponent'></mycomponent>
@@ -301,4 +331,4 @@ after your registration for your own custom component, now you can call it in yo
}
}
</script>
-```
\ No newline at end of file
+```
\ No newline at end of file
[2/2] incubator-weex git commit: * [doc] add notice and code example
to exporting sync method documentation for Chinese
Posted by bo...@apache.org.
* [doc] add notice and code example to exporting sync method documentation for Chinese
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/0d441c06
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/0d441c06
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/0d441c06
Branch: refs/heads/dev
Commit: 0d441c06aa1be2df6e59f52d6f2ca2eec87404a4
Parents: 65bad07
Author: \u9690\u98ce <cx...@apache.org>
Authored: Wed Mar 29 14:56:52 2017 +0800
Committer: \u9690\u98ce <cx...@apache.org>
Committed: Wed Mar 29 14:56:52 2017 +0800
----------------------------------------------------------------------
.../cn/references/advanced/extend-to-ios.md | 78 ++++++++++++++------
doc/source/references/advanced/extend-to-ios.md | 4 +-
2 files changed, 57 insertions(+), 25 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/0d441c06/doc/source/cn/references/advanced/extend-to-ios.md
----------------------------------------------------------------------
diff --git a/doc/source/cn/references/advanced/extend-to-ios.md b/doc/source/cn/references/advanced/extend-to-ios.md
index 25872bb..c949ed2 100644
--- a/doc/source/cn/references/advanced/extend-to-ios.md
+++ b/doc/source/cn/references/advanced/extend-to-ios.md
@@ -19,7 +19,7 @@ Weex SDK \u53ea\u63d0\u4f9b\u6e32\u67d3\uff0c\u800c\u4e0d\u662f\u5176\u4ed6\u7684\u80fd\u529b\uff0c\u5982\u679c\u4f60\u9700\u8981 \u50cf\u7f51\u7edc
4. Module \u65b9\u6cd5\u4f1a\u5728UI\u7ebf\u7a0b\u4e2d\u88ab\u8c03\u7528\uff0c\u6240\u4ee5\u4e0d\u8981\u505a\u592a\u591a\u8017\u65f6\u7684\u4efb\u52a1\u5728\u8fd9\u91cc\uff0c\u5982\u679c\u8981\u5728\u5176\u4ed6\u7ebf\u7a0b\u6267\u884c\u6574\u4e2amodule \u65b9\u6cd5\uff0c\u9700\u8981\u5b9e\u73b0`WXModuleProtocol`\u4e2d`- (NSThread *)targetExecuteThread`\u7684\u65b9\u6cd5\uff0c\u8fd9\u6837\uff0c\u5206\u53d1\u5230\u8fd9\u4e2amodule\u7684\u4efb\u52a1\u4f1a\u5728\u6307\u5b9a\u7684\u7ebf\u7a0b\u4e2d\u8fd0\u884c
5. Weex \u7684\u53c2\u6570\u53ef\u4ee5\u662f String \u6216\u8005Map
6. Module \u652f\u6301\u8fd4\u56de\u503c\u7ed9 JavaScript\u4e2d\u7684\u56de\u8c03\uff0c\u56de\u8c03\u7684\u7c7b\u578b\u662f`WXModuleCallback`,\u56de\u8c03\u7684\u53c2\u6570\u53ef\u4ee5\u662fString\u6216\u8005Map
-
+
```object-c
@implementation WXEventModule
@synthesize weexInstance;
@@ -32,18 +32,50 @@ Weex SDK \u53ea\u63d0\u4f9b\u6e32\u67d3\uff0c\u800c\u4e0d\u662f\u5176\u4ed6\u7684\u80fd\u529b\uff0c\u5982\u679c\u4f60\u9700\u8981 \u50cf\u7f51\u7edc
} else if (![url hasPrefix:@"http"]) {
newURL = [NSURL URLWithString:url relativeToURL:weexInstance.scriptURL].absoluteString;
}
-
+
UIViewController *controller = [[WXDemoViewController alloc] init];
((WXDemoViewController *)controller).url = [NSURL URLWithString:newURL];
-
+
[[weexInstance.viewController navigationController] pushViewController:controller animated:YES];
callback(@{@"result":@"success"});
}
-
+
@end
```
-\u53e6\u5916\uff0c`0.10.0` \u5f00\u59cb\u652f\u6301\u540c\u6b65\u6a21\u5757 API \u8c03\u7528\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u5b8f `WX_EXPORT_METHOD_SYNC` \u5bfc\u51fa\u6a21\u5757\u65b9\u6cd5\uff0c\u8fd9\u4e9b\u65b9\u6cd5\u53ef\u4ee5\u4f7f JavaScript \u63a5\u53d7\u4ece native \u8fd4\u56de\u7684\u503c\uff0c\u5b83\u53ea\u80fd\u5728 JS \u7ebf\u7a0b\u88ab\u8c03\u7528\u3002
+#### \u66b4\u9732\u540c\u6b65\u65b9\u6cd5<span class="api-version">v0.10+</span>
+
+\u5982\u679c\u4f60\u60f3\u8981\u66b4\u9732\u540c\u6b65\u7684native\u65b9\u6cd5\u7ed9JS\uff0c \u5373JS\u53ef\u4ee5\u76f4\u63a5\u62ff\u5230Native\u7684\u8fd4\u56de\u503c\u3002 \u4f60\u53ef\u4ee5\u4f7f\u7528`WX_EXPORT_METHOD_SYNC` \u5b8f\u3002
+
+native \u4ee3\u7801:
+
+```objective-c
+@implementation WXEventModule
+
+WX_EXPORT_METHOD_SYNC(@selector(getString))
+
+- (NSString *)getString
+{
+ return @"testString";
+}
+
+@end
+```
+
+js \u4ee3\u7801:
+
+```javascript
+const eventModule = weex.requireModule('event')
+const returnString = syncTest.getString() // return "testString"
+```
+
+\u9664\u4e86string, \u4f60\u4e5f\u53ef\u4ee5\u8fd4\u56de `number/array/dictionary` \u7c7b\u578b.
+
+`\u6ce8\u610f:` \u66b4\u9732\u7684\u540c\u6b65\u65b9\u6cd5\u53ea\u80fd\u5728 JS \u7ebf\u7a0b\u6267\u884c\uff0c\u8bf7\u4e0d\u8981\u505a\u592a\u591a\u540c\u6b65\u7684\u5de5\u4f5c\u5bfc\u81f4JS\u6267\u884c\u963b\u585e\u3002
+
+`\u6ce8\u610f:` Vue 2.0 \u8fd8\u672a\u652f\u6301\u8fd9\u4e2a\u7279\u6027\uff0c\u6700\u65e9\u4f1a\u5728 0.12 \u7248\u672c\u652f\u6301
+
+
### \u6ce8\u518c module
@@ -117,7 +149,7 @@ WXImageLoaderProtocol.h
```
### handler\u6ce8\u518c
-
+
\u4f60\u53ef\u4ee5\u901a\u8fc7WXSDKEngine \u4e2d\u7684 `registerHandler:withProtocol`\u6ce8\u518chandler
```object-c
@@ -177,19 +209,19 @@ attribute \u4e2d\u62ff\u5230\u7684\u503c\u7684\u7c7b\u578b\u90fd\u662f `id`\uff0c\u6211\u4eec\u53ef\u4ee5\u7528\u8f6c\u6362\u65b9\u6cd5\u628a
native \u7684 component \u662f\u7531 Weex \u7ba1\u7406\u7684\uff0cWeex \u521b\u5efa\uff0c\u5e03\u5c40\uff0c\u6e32\u67d3\uff0c\u9500\u6bc1\u3002Weex \u7684 component \u751f\u547d\u5468\u671f\u90fd\u662f\u53ef\u4ee5 hook \u7684\uff0c\u4f60\u53ef\u4ee5\u5728\u8fd9\u4e9b\u751f\u547d\u5468\u671f\u4e2d\u53bb\u505a\u81ea\u5df1\u7684\u4e8b\u60c5\u3002
-| \u65b9\u6cd5 | \u63cf\u8ff0 |
-| :-: | --- |
-| initWithRef:type:... | \u7528\u7ed9\u5b9a\u7684\u5c5e\u6027\u521d\u59cb\u5316\u4e00\u4e2acomponent. |
-| layoutDidFinish | \u5728component\u5b8c\u6210\u5e03\u5c40\u65f6\u5019\u4f1a\u8c03\u7528. |
-| loadView | \u521b\u5efacomponent\u7ba1\u7406\u7684view. |
-| viewWillLoad | \u5728component\u7684view\u52a0\u8f7d\u4e4b\u524d\u4f1a\u8c03\u7528. |
-| viewDidLoad | \u5728component\u7684view\u52a0\u8f7d\u5b8c\u4e4b\u540e\u8c03\u7528. |
-| viewWillUnload | \u5728component\u7684view\u88ab\u91ca\u653e\u4e4b\u524d\u8c03\u7528. |
-| viewDidUnload | \u5728component\u7684view\u88ab\u91ca\u653e\u4e4b\u540e\u8c03\u7528. |
-| updateStyles: | \u5728component\u7684style\u66f4\u65b0\u65f6\u5019\u8c03\u7528. |
-| updateAttributes: | \u5728component\u7684attribute\u66f4\u65b0\u65f6\u5019\u8c03\u7528. |
-| addEvent: | \u7ed9component\u6dfb\u52a0event\u7684\u65f6\u5019\u8c03\u7528. |
-| removeEvent: | \u5728event\u79fb\u9664\u7684\u65f6\u5019\u8c03\u7528. |
+| \u65b9\u6cd5 | \u63cf\u8ff0 |
+| :------------------: | --------------------------- |
+| initWithRef:type:... | \u7528\u7ed9\u5b9a\u7684\u5c5e\u6027\u521d\u59cb\u5316\u4e00\u4e2acomponent. |
+| layoutDidFinish | \u5728component\u5b8c\u6210\u5e03\u5c40\u65f6\u5019\u4f1a\u8c03\u7528. |
+| loadView | \u521b\u5efacomponent\u7ba1\u7406\u7684view. |
+| viewWillLoad | \u5728component\u7684view\u52a0\u8f7d\u4e4b\u524d\u4f1a\u8c03\u7528. |
+| viewDidLoad | \u5728component\u7684view\u52a0\u8f7d\u5b8c\u4e4b\u540e\u8c03\u7528. |
+| viewWillUnload | \u5728component\u7684view\u88ab\u91ca\u653e\u4e4b\u524d\u8c03\u7528. |
+| viewDidUnload | \u5728component\u7684view\u88ab\u91ca\u653e\u4e4b\u540e\u8c03\u7528. |
+| updateStyles: | \u5728component\u7684style\u66f4\u65b0\u65f6\u5019\u8c03\u7528. |
+| updateAttributes: | \u5728component\u7684attribute\u66f4\u65b0\u65f6\u5019\u8c03\u7528. |
+| addEvent: | \u7ed9component\u6dfb\u52a0event\u7684\u65f6\u5019\u8c03\u7528. |
+| removeEvent: | \u5728event\u79fb\u9664\u7684\u65f6\u5019\u8c03\u7528. |
\u5728 image component \u7684\u4f8b\u5b50\u91cc\u9762\uff0c\u5982\u679c\u6211\u4eec\u9700\u8981\u6211\u4eec\u81ea\u5df1\u7684 image view \u7684\u8bdd\uff0c\u53ef\u4ee5\u590d\u5199 `loadView`\u8fd9\u4e2a\u65b9\u6cd5.
@@ -244,9 +276,9 @@ return [[WXImageView alloc] init];
##### component \u65b9\u6cd5
WeexSDK 0.9.5 \u4e4b\u540e\u652f\u6301\u4e86\u5728 js \u4e2d\u76f4\u63a5\u8c03\u7528 component \u7684\u65b9\u6cd5\uff0c\u8fd9\u91cc\u63d0\u4f9b\u4e00\u4e2a\u4f8b\u5b50
-
+
- \u81ea\u5b9a\u4e49\u4e00\u4e2a WXMyCompoenent \u7684\u7ec4\u4ef6
-
+
```
@implementation WXMyComponent
WX_EXPORT_METHOD(@selector(focus)) // \u66b4\u9732\u8be5\u65b9\u6cd5\u7ed9js
@@ -266,7 +298,7 @@ WeexSDK 0.9.5 \u4e4b\u540e\u652f\u6301\u4e86\u5728 js \u4e2d\u76f4\u63a5\u8c03\u7528 component \u7684\u65b9\u6cd5\uff0c\u8fd9\u91cc
}
@end
```
-
+
- \u6ce8\u518c\u7ec4\u4ef6 `[WXSDKEngine registerComponent:@"mycomponent" withClass:[WXMyComponent class]]`
- \u5728 weex \u6587\u4ef6\u4e2d\u8c03\u7528
@@ -282,4 +314,4 @@ WeexSDK 0.9.5 \u4e4b\u540e\u652f\u6301\u4e86\u5728 js \u4e2d\u76f4\u63a5\u8c03\u7528 component \u7684\u65b9\u6cd5\uff0c\u8fd9\u91cc
}
}
</script>
- ```
+ ```
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/0d441c06/doc/source/references/advanced/extend-to-ios.md
----------------------------------------------------------------------
diff --git a/doc/source/references/advanced/extend-to-ios.md b/doc/source/references/advanced/extend-to-ios.md
index 2bd6f7e..2891a9f 100644
--- a/doc/source/references/advanced/extend-to-ios.md
+++ b/doc/source/references/advanced/extend-to-ios.md
@@ -75,9 +75,9 @@ const returnString = syncTest.getString() // return "testString"
You can alse return number/array/dictionary except string.
-`notice:` the exported synchronous native method **can only be called on JS thread**.
+`notice:` the exported synchronous native method **can only be called on JS thread**. **Do not** do heavy work which will block js execution.
-`notice:` Vue 2.0 has not supported this feature yet.
+`notice:` Vue 2.0 has not supported this feature yet. It will be supported in version 0.12 at the soonest.
#### Register the module