sud.previewImage
Preview a list of images and optionally specify which image to display first.
javascript
sud.previewImage(object)Parameters
Object object
| Property | Type | Required | Description |
|---|---|---|---|
| current | string | No | Address of the image to display first; it should be an entry in urls. Specify it explicitly when possible |
| urls | Array<string> | Yes | A nonempty list of image addresses to preview |
| success | function | No | Called when the preview request succeeds |
| fail | function | No | Called when the preview request fails |
| complete | function | No | Called when the request finishes, whether successful or failed |
Return value
This asynchronous API reports its result through callbacks.
Callback parameters
success
Called when the preview request is accepted. No business result fields are defined. This callback does not mean that all images have finished loading or that the user has closed the preview.
fail
| Property | Type | Description |
|---|---|---|
| errCode | number | Error code |
| errMsg | string | Error message |
complete
Called after success or fail, with no arguments. It does not indicate that the preview page has closed.
Usage notes
- Ensure that
urlsis nonempty and setcurrentto one of its entries. Avoid relying on how omitted or invalid values are handled. - Image addresses can be local file paths or network URLs supported by the current runtime. Supported address formats depend on the runtime. Local files must be readable and network images must be accessible.
- Image loading errors may be shown inside the preview without triggering this request's
failcallback. - This API does not provide a preview-close callback or return the last image viewed by the user.
Example
Pass an existing list of image addresses to previewImages, such as res.tempFilePaths returned by sud.chooseImage.
javascript
function previewImages(urls) {
if (!urls || urls.length === 0) {
return;
}
sud.previewImage({
current: urls[0],
urls,
success: () => {
console.log('Preview request accepted');
},
fail: (err) => {
console.error('Preview request failed', err.errCode, err.errMsg);
},
complete: () => {
console.log('Preview request completed');
},
});
}