@ProxyService(proxy = ExternalElementProxy.class)public class MyExternalElementProxy extends ExternalElementProxy{}
/** * Creates a component. This API is called when the mini program creates a custom native component. * * @param widgetId The unique ID of the component created by the mini program. * @param widgetContext The context of the mini program component, which is used to pass content back to the mini program. * @param type The type name of the component created by the mini program. * @param parent The parent container that carries the native component. * @param params The parameters passed when the mini program creates a component */ public abstract void handleInsertElement(long widgetId, ExternalWidgetContext widgetContext, String type, ViewGroup parent, JSONObject params);
/** * Updates component style. This API is called when the mini program updates the style of a custom native component. * * @param widgetId The ID of the mini program component. * @param widgetContext The mini program component context, which is used to pass content back to the mini program. * @param params The parameters passed when the mini program updates a component. */ public abstract void handleUpdateElement(long widgetId, ExternalWidgetContext widgetContext, JSONObject params);
/** * Operates a component. This API is called when the mini program needs to send instructions to the component or call a specific method. * * @param widgetId The ID of the mini program component. * @param widgetContext The mini program component context, which is used to pass content back to the mini program. * @param params The parameters passed when the mini program updates the component. */ public abstract void handleOperateElement(long widgetId, ExternalWidgetContext widgetContext, JSONObject params);
/** * Deletes a component. * * @param widgetId The ID of the mini program component. * @param widgetContext The mini program component context, which is used to pass content back to the mini program. */ public abstract void handleRemoveElement(long widgetId, ExternalWidgetContext widgetContext);
/** * Sends an onExternalElementEvent event to the mini program.* * @param jsonObject JSON data carried by the event. */ public final void onExternalElementEvent(JSONObject jsonObject); /** * Calls the success callback. * * @param jsonObject JSON data carried by the callback, which can be null. */ public final void callbackSuccess(JSONObject jsonObject); /** * Calls the fail callback. * * @param jsonObject jsonObject JSON data carried by the callback, which can be null. * @param message Error message description. */ public final void callbackFail(JSONObject jsonObject, String message);
<external-elementid="comp1"type="maTestView"_insert2WebLayer="true"style="width: 200px;height: 100px;"bindexternalelementevent="handleEvent"></external-element>
_insert2WebLayer indicates whether the component is a same-layer component or a non-same-layer component (true for same-layer, which requires the client to implement a same-layer component proxy; false for non-same-layer, which requires the client to implement a non-same-layer proxy). The bindexternalelementevent can capture events passed from the native side, such as onExternalElementEvent or onXWebExternalElementEvent. The callback parameters include:{target,currentTarget,timeStamp,touches,detail, // Parameters passed by native}
this.ctx = wx.createExternalElementContext('comp1');
this.ctx.call({params1: {name: 'name1',age: 11},params2: {name: 'name2',age: 22},success: (e) => {console.log('====operate success=====', e)},fail: (e) => {console.log('====operate fail=====', e)},complete: (e) => {console.log('====operate complete=====', e)}})
Feedback