The function of sending custom event to mini program through Android custom View is only supported in mPaaS 10.1.68.29 and later. When the current baseline version is lower than 10.1.68.29, refer to mPaaS Upgrade Guide to upgrade the version to 10.1.68.29.
Add custom event callback in the tag of mini program
Add custom event callback in xxx.axml
.
<mpaas-component
id="mpaas-map"
type="custom_map"
style="{{ width: 200, height: 200 }}"
color="#FFFF00FF"
onAnimationStart="onAnimationStart"
/>
onAnimationStart
is a custom callback event, and the name of the custom event should start with on
.
Handle custom events in JavaScript
onAnimationStart(data) {
my.showToast({
type: 'success',
content: `onAnimationStart: ${JSON.stringify(data)}`,
});
},
Trigger client custom View event
JSONObject data = new JSONObject();
data.put("sth", "start");
mMPBaseEmbedView.sendEventToTiny("onAnimationStart", data);
mMPBaseEmbedView
is an instance of the class. The first parameter in the sendEventToTiny
is the name of event callback, which needs to be consistent with the mini program; the second parameter is the event parameter.