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(
        input: SpacePullInfo,
        containerView: ViewGroup,
        actionDelegate: WidgetActionDelegate,
        completion: WidgetRenderCallback?=null
    )

Request parameters

Name

Type

Description

input

SpacePullInfo

SpacePullInfo object containing information about the requested space, including its code, pagination info, and any conditions or extended info.

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.

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

1200

A network error has occurred.

1201

A backend error has occurred.

1202

The user ID is empty.

1203

A response payload is unavailable.

1400

Parameters are invalid

1500

  • SpaceContent is invalid.
  • SpaceCode is invalid.
  • ContentItems is invalid.
  • TemplateCode is invalid.
  • TemplateVersion is invalid.

Sample

Kotlin

copy
ComponentManager.ASAP.getBusinessComponent()
    .renderWidget(spacePullInfo, flRender, object :
                                WidgetActionDelegate {
                                 
                                    override fun performAction(type: String?, data: Map<String, Any>?) {
                                      //View click event callback
                                    }

                                }, object : WidgetRenderCallback {
                                    override fun onSuccess() {
                                     
                                    }

                                    override fun onFailure(code: Int, msg: String, throwable: Throwable?) {
                                     
                                    }
                                })