Customize the more menu
To support different business requirements within the super app, IAPMiniProgram SDK supports customizing the menu panel. This topic introduces how to customize the menu panel in the mini program with the SDK.
Default user experience
The following picture shows a default menu panel where only the Setting and About menus are displayed:
Procedures
To customize the menu panel, complete the following steps:
Step 1: Implement GRVMPMoreMenuDelegate and getMenuList
By default, IAPMiniProgram SDK shows the default menu list including the Setting and About menus in the menu panel. If you want to add or remove the default menus, you need to implement the GRVMPMoreMenuDelegate
protocol and the getMenuList
method. For more information about the protocol and method, see GRVMPMoreMenuDelegate and getMenuList. Refer to the following sample for the implementation:
class DemoMoreMenuDelegate: NSObject, GRVMPMoreMenuDelegate {
func getMenuList(_ appId: String) -> [GRVMPMoreMenuItem] {
let item = GRVMPMoreMenuItem()
item.row = 2
item.title = "Attention"
item.icon = icon
item.clickMenuItemAction = { context in
}
return [item]
}
}
If you want to add the feedback item, see Use feedback capacity for more detailed requirements.
Step 2: Configure moreMenuDelegate
Refer to the following sample code to configure moreMenuDelegate
to IAPMiniProgram SDK:
// let extensionDelegate = GRVExtensionDelegate()
extensionDelegate.uiProvider.moreMenuDelegate = MPMoreMenuDelegateImpl()
Protocol
GRVMPMoreMenuDelegate
@protocol GRVMPMoreMenuDelegate <NSObject>
@required
- (NSArray <GRVMPMoreMenuItem *>*)getMenuList:(NSString *)appId;
@end
getMenuList:
The getMenuList:
method is used by the SDK to obtain the menu item list for a certain mini program. The following sections provide the details of the request parameters and response parameters of this method.
Request parameters
Name | Type | Length | Description | Required |
appId | String | N/A | The ID of the mini program. | M |
Response parameters
Refer to the following sample code to return the response parameters:
// A block that represents the action to be taken when a menu item is clicked
typedef void (^GRVMPMoreMenuActionBlock)(GRVMoreMenuContext *context);
@interface GRVMPMoreMenuItem : NSObject
/**
The title of the menu item. This should be kept concise.
*/
@property (nonatomic, copy) NSString *title;
/**
The icon of the menu item. If nil, a default icon will be used. The size of the image should be 25x25 (2x).
*/
@property (nonatomic, strong) UIImage * _Nullable icon;
/**
The identifier of the menu item. This can be any string that identifies the menu item, such as "About", "Share", or "Feedback".
*/
@property (nonatomic, copy) NSString *identifier;
/**
The row of the menu item. This property supports either 1 or 2. A row of 1 will place the menu item in the first row, and a row of 2 will place it in the second row. If this property is not set, the menu item will not be displayed.
*/
@property (nonatomic, assign) NSInteger row;
/**
The block of code that represents the action to be taken when the menu item is clicked.
*/
@property(nonatomic, copy)GRVMPMoreMenuActionBlock clickMenuItemAction;
/**
This method initializes a new menu item with an identifier, row, and clickMenuItemAction block.
@param identifier A string that identifies the menu item, such as "About", "Share", or "Feedback".
@param row An integer indicating the row of the menu item. 1 for the first row and 2 for the second row.
@param clickMenuItemAction A block of code that represents the action to be taken when the menu item is clicked.
*/
- (instancetype)initWithIdentifier:(NSString *)identifier row:(NSInteger)row clickMenuItemAction:(GRVMPMoreMenuActionBlock)clickMenuItemAction NS_DESIGNATED_INITIALIZER;
/**
This method initializes a new menu item with a title, icon, identifier, row, and clickMenuItemAction block.
@param title The title of the menu item. This should be kept concise.
@param icon The icon of the menu item. If nil, a default icon will be used. The size of the image should be 25x25 (2x).
@param identifier A string that identifies the menu item, such as "About", "Share", or "Feedback".
@param row An integer indicating the row of the menu item. 1 for the first row and 2 for the second row.
@param clickMenuItemAction A block of code that represents the action to be taken when the menu item is clicked.
*/
- (instancetype)initWithTitle:(NSString *)title icon:(UIImage *)icon identifier:(NSString *)identifier row:(NSInteger)row clickMenuItemAction:(GRVMPMoreMenuActionBlock)clickMenuItemAction;
/**
This method determines whether or not the menu item should be displayed in the mini program app.
By default, this method returns YES.
@param appId The identifier of the mini program app for which the more menu items are being displayed.
@return YES if the menu item should be displayed, NO otherwise.
*/
- (BOOL)canShowForMPAppId:(NSString *)appId;
@end
Name | Type | Length | Description | Required |
N/A | GRVMPMoreMenuItem | N/A | The menu items that you need to display in the menu panel. For more information, see properties and method for GRVMPMoreMenuItem. | M |
GRVMPMoreMenuItem
Property | Type | Description | Required |
identifier | String | The unique identifier of the menu. | M |
title | String | The title of the menu, which is displayed in the panel. | M |
icon | Image | The icon of the menu item, which is displayed in the panel. | O |
row | Integer | The row of the menu. The value values are:
Note: If you do not set the row, the menu is not displayed. | M |
clickMenuItemAction | GRVMPMoreMenuActionBlock | The block of code that represents the action to be taken when the menu item is clicked. | M |
canShowForMPAppId
The GRVMPMoreMenuItem
uses the canShowForMPAppId
method to decide whether to display the menu item in the menu panel. Refer to the following sample to implement the canShowForMPAppId
method:
/**
Decide whether the menu item can be showed in the mini program app.
Default value is YES.
@param appId NSString represent the mini program app, which shows the more menu items.
@return BOOL, YES for showing the menu item, No for not showing the menu item.
*/
- (BOOL)canShowForMPAppId:(NSString *)appId;
Appendices
Use feedback capacity
The function of the Feedback menu is to open another mini program to collect users' feedback. Since IAPMiniProgram SDK cannot know the appId of the Feedback menu, you are required to tell the SDK what the appId is. Otherwise, the Feedback menu cannot be displayed in the panel. To pass the appId to the SDK, complete the following steps:
Step 1: Complete GRVMPFeedbackDelegate
Refer to the following sample code to complete the GRVMPFeedbackDelegate
delegate to pass the appId of the Feedback menu to IAPMiniProgram SDK.
@protocol GRVMPFeedbackDelegate <NSObject>
@required
- (NSString *)getFeedbackMiniProgramId:(NSString *)appId;
@end
Step 2: Implement the extension and configure it to IAPMiniProgram SDK
Refer to the following sample to implement the extension and configure it to IAPMiniProgram SDK. After that, you can use the feedback capacity and improve your mini program continuously based on users' feedback.
// let extensionDelegate = GRVExtensionDelegate()
extensionDelegate.uiProvider.feedbackDelegate = DemoGRVMPFeedbackDelegateImpl()