v0.8+
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
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)
Map<String,Object> params=new HashMap<>(); params.put("key","value"); mWXSDKInstance.fireGlobalEventCallback("geolocation", params);
[weexInstance fireGlobalEvent:@"geolocation" params:@{@"key":@"value"}];
register global event.
eventName
(string): The name of the event you want to listen to.callback
(function): the callback function after executing this action.var globalEvent = weex.requireModule('globalEvent'); globalEvent.addEventListener("geolocation", function (e) { console.log("get geolocation") });
remove global event
eventName
(string): You no longer need to listen for event names.var globalEvent = weex.requireModule('globalEvent'); globalEvent.removeEventListener("geolocation");
0.14
You can specify the event name as WXApplicationDidBecomeActiveEvent
or WXApplicationWillResignActiveEvent
to obtain application becoming foreground or background, so that you can pause your video or music at this time.For example
var globalEvent = weex.requireModule('globalEvent'); globalEvent.addEventListener("WXApplicationDidBecomeActiveEvent", function (e) { console.log("WXApplicationDidBecomeActiveEvent"); });
WXApplicationDidBecomeActiveEvent
fired while application did become foregroundWXApplicationWillResignActiveEvent
fired while application will become backgroundthis feature only works on iOS and Android platforms, it doesn't work on Web. Obtain your weex platform on weex page