Repository: incubator-weex Updated Branches: refs/heads/0.13-dev 2615aa529 -> 62d1d3f83
* [ios] add fireEvent js method Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/e7e93c09 Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/e7e93c09 Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/e7e93c09 Branch: refs/heads/0.13-dev Commit: e7e93c09632a13ef0abdb106e82c404343a6e59b Parents: 507cd7c Author: acton393 <zhangxing610...@gmail.com> Authored: Wed Apr 26 19:03:46 2017 +0800 Committer: acton393 <zhangxing610...@gmail.com> Committed: Wed Apr 26 19:03:46 2017 +0800 ---------------------------------------------------------------------- .../alibaba/weex/extend/module/WXEventModule.java | 18 ++++++++++++++++++ .../WeexDemo/extend/module/WXEventModule.m | 16 ++++++++++++++++ 2 files changed, 34 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/e7e93c09/android/playground/app/src/main/java/com/alibaba/weex/extend/module/WXEventModule.java ---------------------------------------------------------------------- diff --git a/android/playground/app/src/main/java/com/alibaba/weex/extend/module/WXEventModule.java b/android/playground/app/src/main/java/com/alibaba/weex/extend/module/WXEventModule.java index 098681d..06c5326 100644 --- a/android/playground/app/src/main/java/com/alibaba/weex/extend/module/WXEventModule.java +++ b/android/playground/app/src/main/java/com/alibaba/weex/extend/module/WXEventModule.java @@ -23,9 +23,11 @@ import android.net.Uri; import android.text.TextUtils; import com.taobao.weex.annotation.JSMethod; +import com.taobao.weex.bridge.JSCallback; import com.taobao.weex.common.WXModule; import java.util.HashMap; +import java.util.Map; public class WXEventModule extends WXModule { @@ -61,4 +63,20 @@ public class WXEventModule extends WXModule { mWXSDKInstance.fireModuleEvent("event", this, params); } } + /* + * a test method for macaca case, you can fire globalEvent when download finishãdevice shaked and so on. + * @param event event name + * */ + @JSMethod(uiThread = true) + public void fireNativeGlobalEvent(String event, JSCallback callback) { + Map<String,Object> params=new HashMap<String,Object>(); + params.put("eventParam","value"); + + mWXSDKInstance.fireGlobalEventCallback(event, params); + if (null != callback) { + Map<String, Boolean> result = new HashMap<String, Boolean>(); + result.put("ok",true); + callback.invoke(result); + } + } } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/e7e93c09/ios/playground/WeexDemo/extend/module/WXEventModule.m ---------------------------------------------------------------------- diff --git a/ios/playground/WeexDemo/extend/module/WXEventModule.m b/ios/playground/WeexDemo/extend/module/WXEventModule.m index b3b1cfb..9f58090 100644 --- a/ios/playground/WeexDemo/extend/module/WXEventModule.m +++ b/ios/playground/WeexDemo/extend/module/WXEventModule.m @@ -27,6 +27,8 @@ WX_EXPORT_METHOD(@selector(openURL:)) +WX_EXPORT_METHOD(@selector(fireNativeGlobalEvent:callback:)) + - (void)openURL:(NSString *)url { NSString *newURL = url; @@ -43,5 +45,19 @@ WX_EXPORT_METHOD(@selector(openURL:)) [[weexInstance.viewController navigationController] pushViewController:controller animated:YES]; } + +/** + a test method for macaca case, you can fire globalEvent when download finishãdevice shaked and so on. + @param event event name + */ +- (void)fireNativeGlobalEvent:(NSString *)event callback:(WXModuleCallback)callback +{ + [weexInstance fireGlobalEvent:event params:@{@"eventParam":@"eventValue"}]; + if (callback) { + NSDictionary * result = @{@"ok": @true}; + callback(result); + } +} + @end