Alipay+ Super App PlatformAlipay+ Super App Platform

renderWidget

Use the renderWidget API to create and render view compontents based on templates.

Method signature

The following code shows the method signature of the renderWidget API:

copy
 fun renderWidget(
        containerView: ViewGroup,
        model: WidgetDataModel,
        actionDelegate: WidgetActionDelegate,
        completion: WidgetRenderCallback?=null
    )

Request parameters

Name

Type

Description

containerView

ViewGroup

A pre-allocated ViewGroup placed in a designated area on the page to reserve space. Once the widget is created, the ASAPWidget component will render it onto the containerView as soon as possible.

model

WidgetDataModel

Data model of the widget.

actionDelegate

WidgetActionDelegate

actionDelegate for handling user click events.

completion

WidgetRenderCallback

A callback function. On success, onSuccess is triggered. On failure, onFailure is triggered.

Response parameters

N/A

Exception

Error Code

Error message

1400

A widget render error has occurred

Sample

Kotlin

copy
ComponentManager.ASAP.getWidgetComponent()
    .renderWidget(flRender, model, object : WidgetActionDelegate {
        
        override fun performAction(type: String?, data: Map<String, Any>?) {
            Toast.makeText(
                flRender.context,
                "performAction $type",
                Toast.LENGTH_SHORT
            ).show()
        }
        
    }, object : WidgetRenderCallback {
        
        override fun onSuccess() {
            Toast.makeText(flRender.context, "render success", Toast.LENGTH_SHORT)
                .show()
        }
        
        override fun onFailure(code: Int, msg: String, throwable: Throwable?) {
            Toast.makeText(
                flRender.context,
                "render failed ${code},$msg",
                Toast.LENGTH_SHORT
            ).show()
        }
    })