阿里云赞助

globalEvent

globalEvent

v0.8+

Summary

globalEvent are used to listen for persistent events, such as changes in positioning information, gyroscopes, and so on. A global event is a secondary API that requires additional APIs to work with.

You can register events via addEventListener, which can be removed by removeEventListener when you do not need to listen for globalEvent.

AUCTION

  • Only instance level is not application level .

How to make your Module support global events

API development is complete, when the event needs to be sent, the need through the following methods:

/**
*
* @param eventName eventName
* @param params event params
*/
instance.fireGlobalEventCallback(eventName,params);

How to dispatch a global event in a weex-html5 component or module ? Just dispatch the event on the document element:

var evt = new Event('some-type')
evt.data = { foo: 'bar' }
document.dispatchEvent(evt)

Example

Android

Map<String,Object> params=new HashMap<>();
params.put("key","value");
mWXSDKInstance.fireGlobalEventCallback("geolocation", params);

iOS

[weexInstance fireGlobalEvent:@"geolocation" params:@{@"key":@"value"}];

API

addEventListener(String eventName, String callback)

register global event.

Arguments

  • eventName(string): The name of the event you want to listen to.
  • callback(function): the callback function after executing this action.

Example

var globalEvent = weex.requireModule('globalEvent');
globalEvent.addEventListener("geolocation", function (e) {
2console.log("get geolocation")
});

removeEventListener(String eventName)

remove global event

Arguments

  • eventName(string): You no longer need to listen for event names.

Example

var globalEvent = weex.requireModule('globalEvent');
globalEvent.removeEventListener("geolocation");
Apache Incubator
Disclaimer: Apache Weex is an effort undergoing incubation at The Apache Software Foundation (ASF), sponsored by the Apache Incubator. Incubation is required of all newly accepted projects until a further review indicates that the infrastructure, communications, and decision making process have stabilized in a manner consistent with other successful ASF projects. While incubation status is not necessarily a reflection of the completeness or stability of the code, it does indicate that the project has yet to be fully endorsed by the ASF.


ApacheCopyright(c) 2017 The Apache Software Foundation. Licensed under the Apache License, Version 2.0