GriverPromptExtension

IAPMiniProgram SDK provides the ability to customize the prompt dialog, so that the Super App can customize the style of prompt dialog with the same style as mini program UI. Follow this topic to realize this ability by implementing the specific interface of IAPMiniProgram SDK.

Procedures

To customize the prompt dialog, follow these steps:

Step 1. Implement the GriverPromptExtension interface

Implement the GriverPromptExtension interface and write code in the required methods according to your business logic.

Code sample as follows:

copy
class CustomPromptExtensionImpl : GriverPromptExtension {
    
    override fun createDialog(activity: Activity, createParam: GriverCreatePromptParam?): Dialog? {
        return null
    }

    override fun applyShow(dialog: Dialog?, createDialogParam: GriverCreatePromptParam?) {
    }
}

Step 2: Register the CustomPromptExtensionImpl class

Refer to the following sample code and call the registerExtension interface to register the CustomPromptExtensionImpl class after initializing the SDK.

Then you can view the following screenshots for user experience.

copy
IAPConnect.init(application, initConfig, object : InitCallback() {
    fun onSuccess() {
        //···
        Griver.registerExtension(
            GriverExtensionManifest(
                GriverPromptExtension::class.java,
                CustomPromptExtensionImpl()
            )
        )
    }
})

Interface

GriverPromptExtension interface

The definition of the GriverPromptExtension interface is shown in the following codes:

copy
interface GriverPromptExtension : GriverExtension {
    fun createDialog(activity: Activity, createParam: GriverCreatePromptParam?): Dialog?

    fun applyShow(dialog: Dialog?, createDialogParam: GriverCreatePromptParam?)
}

Methods

Based on the definition above, this interface provides the following methods:

Method

Description

createDialog

Return a customized prompt dialog instance. When the my.prompt JSAPI is called, the customized dialog is displayed.

applyShow

Called after the the dialog shows to make further customization because some elements only can be obtained after the dialog is created.

createDialog method

Parameter

Data type

Required

Description

activity

Activity

No

The Activity where the mini program is located.

createParam

GriverCreatePromptParam class

No

The parameters that the dialog uses.

GriverCreatePromptParam class

Parameter

Data type

Required

Description

title

String

No

The title of the prompt dialog to be displayed.

message

String

No

The message of the prompt dialog to be displayed.

align

String

No

The alignment of the message of the prompt dialog to be displayed.

Valid values:

  • Gravity.LEFT: indicates the message alignment is left.
  • Gravity.RIGHT: indicates the message alignment is right
  • Gravity.CENTER: indicates the message alignment is center. If this parameter is not set, this is the default alignment.

placeHolder

String

No

The text to be displayed when the input is empty.

positiveString

String

No

The postive button text of the prompt dialog to be displayed.

negativeString

String

No

The negative button text of the prompt dialog to be displayed.

positiveTextColor

String

No

The positive button color of the prompt dialog to be displayed.

Supported color formats:

  • #RRGGBB
  • #AARRGGBB

negativeTextColor

String

No

The negative button color of the prompt dialog to be displayed.

Supported color formats:

  • #RRGGBB
  • #AARRGGBB

positiveListener

CreatePromptParam.PositiveListener

No

Sets the listener for positive button click.

When you click the positive button, you need to call the onClick method and pass in the dialog object and the content in the input box.

negativeListener

DialogInterface.OnClickListener

No

Sets the listener for negative button click.

When you click the nigative button, you need to call the onClick method and pass in the dialog object and the button that was clicked (ex. BUTTON_NEGATIVE) or the position of the item clicked.

cancelListener

DialogInterface.OnClickListener

No

Sets the listener when the prompt dialog is canceled.

The onCancel method needs to be called and pass in the dialog object when the Dialog is cancelled.

cancelable

Boolean

No

Indicates whether this prompt dialog is cancelable with the KeyEvent#KEYCODE_BACK BACK key.

applyShow method

Parameter

Data type

Required

Description

dialog

Dialog

No

The dialog instance.

createDialogParam

GriverCreatePromptParam

No

The dialog parameters.

PositiveListener interface

The definition of the PositiveListener interface is shown in the following codes:

copy
interface PositiveListener {
    fun onClick(dialog: DialogInterface?, inputText: String?)
}

onclick method

Parameter

Data type

Required

Description

dialog

DialogInterface

No

The dialog instance.

inputText

String

No

The content text of the EditText in the prompt dialog.

Appendices

User experience

prompt alignment

Screenshot

Align left

image.png

Align center

image.png

Align right

image.png