GRVNavigationBarExtension
IAPMiniProgram SDK provides the ability to customize whether to intercept the H5 pages when the Back button on the navigation bar is clicked for H5 type of mini programs. Follow this topic to realize this ability by implementing the specific interface of IAPMiniProgram SDK.
Procedures
To realize the customization, follow these steps:
Step 1. Implement the GRVNavigationBarExtension interface
Implement the GRVNavigationBarExtension interface and write code in the required methods according to your business logic. See the following example for how to implement this interface.
When the user clicks the Back button in the navigation bar, a dialog appears asking whether to close the current H5 page:
- If the user clicks the OK button in the dialog, the
completion.closeWindow()
method is called to close the H5 page - If the user clicks the Cancel button, only the dialog is closed without closing the H5 page.
class CustomNavigationBarExtensionImpl : GRVNavigationBarExtension {
override fun h5NavigationBarBackItemDidClicked(
context: Context,
url: String,
completion: CompletionCallback
) {
AlertDialog.Builder(context)
.setTitle("close h5?")
.setPositiveButton("OK") { dialog, which ->
completion.closeWindow() //close H5 page
}
.setNegativeButton("Cancel") { dialog, which ->
dialog.dismiss()//close dialog only, not close the H5 page
}
.create().show()
}
}
Step 2. Register the CustomNavigationBarExtensionImpl class
Refer to the following sample code and call the registerExtension interface to register the CustomNavigationBarExtensionImpl class after initializing the SDK.
IAPConnect.init(application, initConfig, object : InitCallback {
override fun onSuccess() {
//ยทยทยท
Griver.registerExtension(
GriverExtensionManifest(
GRVNavigationBarExtension::class.java,
CustomNavigationBarExtensionImpl()
)
)
}
})
Interface
GRVNavigationBarExtension interface
The definition of this interface is shown in the following codes:
interface GRVNavigationBarExtension : GriverExtension {
fun h5NavigationBarBackItemDidClicked(
context: Context?, url: String?, completion: CompletionCallback?
)
}
Based on the definition, this interface provides the following methods:
Method | Description |
h5NavigationBarBackItemDidClicked | This method is triggered when the Back button in the navigation bar is clicked or when the system physical back event occurs. |
Methods
h5NavigationBarBackItemDidClicked method
Parameter | Data type | Required | Description |
context | Context | Yes | Indicates the |
url | String | Yes | Indicates the URL of H5 mini programs. |
completion | Yes | A callback function that is used to return the interception result. |
Structure
CompletionCallback interface
The definition of the CompletionCallback interface is shown in the following codes:
interface CompletionCallback {
fun completion(isInterceptor: Boolean)
fun closeWindow()
}
Based on the definition, this interface provides the following methods:
Method | Description |
Call this method to notify the SDK of the back event handling result.
| |
closeWindow | Call this method to directly close the current H5 page. |
Methods
completion method
Parameter | Data type | Required | Description |
isInterceptor | Boolean | Yes | Indicates whether to intercept this back event. |