GRVPromptDelegate
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 prompt dialog, follow these steps:
Step 1. Implement the GRVPromptDelegate
delegate
Implement the GRVPromptDelegate delegate and write code in the required methods according to your business logic.
Code sample as follows:
class DemoPromptDelegateImpl: NSObject, GRVPromptDelegate {
func showPrompt(
with param: GRVPromptParam,
currentViewController: UIViewController,
positiveAction: GRVAlertActionBlock,
negativeAction: GRVAlertActionBlock,
cancelAction: GRVAlertActionBlock
) {
// customize prompt
}
}
Step 2. Configure the GRVPromptDelegate
delegate
Refer to the following sample code. Configure the GRVExtensionDelegate interface to register the GRVPromptDelegate delegate after initializing the SDK.
Then you can view the following screenshots for user experience.
let extensionDelegate = GRVExtensionDelegate()
extensionDelegate.uiProvider.promptDelegate = DemoPromptDelegateImpl()
Delegates
GRVPromptDelegate
delegate
The definition of this delegate is shown in the following codes:
@protocol GRVPromptDelegate <NSObject>
@required
/** Show prompt view
Prompt view contains an input view or other custom view in it
@param param GRVPromptParam
@param currentViewController current view controller for presenting the prompt view controller.
@param positiveAction when user click the ok button, you should call the positiveAction for calling back.
@param negativeAction when user click the cancel button, you should call the negativeAction for calling back.
@param cancelAction when user click the prompt background view, you should cancel showing the prompt view and call the cancelAction for calling back.
*/
- (void)showPromptWithParam:(GRVPromptParam *)param
currentViewController:(UIViewController*)currentViewController
positiveAction:(GRVAlertActionBlock)positiveAction
negativeAction:(GRVAlertActionBlock)negativeAction
cancelAction:(GRVAlertActionBlock)cancelAction;
@end
Methods
Based on the definition above, this interface provides the following method:
Method | Description |
showPromptWithParam:currentViewController:positiveAction:negativeAction:cancelAction: | Return a customized prompt dialog instance. |
showPromptWithParam:currentViewController:positiveAction:negativeAction:cancelAction:
method
Method definition as follows:
Parameter | Data type | Required | Description |
param | GRVPromptParam class | Yes | The prompt information. |
currentViewController | UIViewController | Yes | The current view controller. |
positiveAction | Function | Yes | The callback function when clicking the positive button. |
negativeAction | Function | Yes | The callback function when clicking the negative button. |
cancelAction | Function | Yes | The callback function when clicking the background to trigger the "exit" prompt. |
GRVPromptParam class
@interface GRVPromptParam : GRVAlertParam
/**
placeHolder for prompt
*/
@property(nonatomic, copy)NSString *placeHolder;
@end
This class inherits the parent GRVAlertParam class, and has its extended parameters as follows:
Parameter | Data type | Required | Description |
placeHolder | NSString | No | The prompt text for the entry box. |
GRVAlertParam class
typedef void (^GRVAlertActionBlock)(NSString *_Nullable);
NS_ASSUME_NONNULL_BEGIN
@interface GRVAlertParam : NSObject
/**
title
*/
@property(nonatomic, copy)NSString *title;
/**
message
*/
@property(nonatomic, copy)NSString *message;
/**
message align, support left, center and right
*/
@property(nonatomic, copy)NSString *align;
/**
title for 'ok' button
*/
@property(nonatomic, copy)NSString *positiveString;
/**
title for 'no' button
*/
@property(nonatomic, copy)NSString *negativeString;
/**
positive text color, support hex string like "#ffffff"
*/
@property(nonatomic, copy)NSString *positiveTextColor;
/**
negative text color, support hex string like "#ffffff"
*/
@property(nonatomic, copy)NSString *negativeTextColor;
/**
cancelable decide whether the alert can be canceled.default value is true for alert and false for prompt.
*/
@property(nonatomic, assign)BOOL cancelable;
@end
Field | Data type | Required | Description |
title | String | No | The title of the prompt dialog to be displayed. |
message | String | Yes | 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:
|
positiveString | String | No | The postive button text of the dialog to be displayed. |
negativeString | String | No | The negative button text of the dialog to be displayed. |
positiveTextColor | String | No | The postive button color of the Dialog to be displayed. Supported color formats:
|
negativeTextColor | String | No | The negative button color of the Dialog to be displayed. Supported color formats:
|
cancelable | Boolean | No | Indicates whether this prompt dialog is cancelable. |
Appendices
User experience
Prompt alignment | Screenshot |
Align left | |
Align center | |
Align right |