|
| 1 | +--- |
| 2 | +id: preview |
| 3 | +title: Open Preview |
| 4 | +sidebar_label: Open Preview |
| 5 | +slug: /preview |
| 6 | +--- |
| 7 | + |
| 8 | +import ReactPlayer from 'react-player' |
| 9 | + |
| 10 | +## Overview |
| 11 | + |
| 12 | +Preview is a simple image viewer that supports both local and remote media. It allows you to preview images and videos seamlessly. |
| 13 | + |
| 14 | +<ReactPlayer |
| 15 | + playing |
| 16 | + controls |
| 17 | + width="100%" |
| 18 | + height="100%" |
| 19 | + url="https://github.com/user-attachments/assets/92a1c319-ad99-4d24-892c-7cd878787acd" |
| 20 | +/> |
| 21 | + |
| 22 | +## Usage |
| 23 | + |
| 24 | +```typescript |
| 25 | +import { openPreview } from '@baronha/react-native-multiple-image-picker' |
| 26 | + |
| 27 | +const cropConfig: CropConfig = { |
| 28 | + language: 'system', |
| 29 | +} |
| 30 | + |
| 31 | +const media: MediaPreview[] = [ |
| 32 | + // remote image |
| 33 | + { |
| 34 | + path: 'https://images.unsplash.com/photo-1733235015085-fc29c17c4a16?w=500', |
| 35 | + type: 'image', |
| 36 | + }, |
| 37 | + // local video |
| 38 | + { |
| 39 | + path: 'file://Documents/video-sample/mp4', |
| 40 | + thumbnail: |
| 41 | + 'https://images.unsplash.com/photo-1733889886752-f4599c954608?q=80&w=2574&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D', |
| 42 | + type: 'video', |
| 43 | + }, |
| 44 | + // remote video |
| 45 | + { |
| 46 | + path: 'https://cdn.pixabay.com/video/2024/02/09/199958-911694865_large.mp4', |
| 47 | + type: 'video', |
| 48 | + }, |
| 49 | +] |
| 50 | + |
| 51 | +// call to preview |
| 52 | +openPreview(media, 2, cropConfig) |
| 53 | +``` |
| 54 | + |
| 55 | +## `MediaPreview[]` |
| 56 | + |
| 57 | +`MediaPreview[]` is an array of media objects that you want to preview. Each object in the array should have the following properties:<br/> |
| 58 | + |
| 59 | +**NOTE**: You can also use [`Result[]`](/result) from openPicker's return result |
| 60 | + |
| 61 | +- `path`: A string representing the URL or file path of the media. |
| 62 | +- `type`: A string indicating the type of media, either `image` or `video`. |
| 63 | +- `thumbnail` (optional): A string representing the URL of the thumbnail image for videos. |
| 64 | +- `localIdentifier` (optional): A string representing the local identifier for media from device gallery. |
| 65 | + |
| 66 | +## `index` |
| 67 | + |
| 68 | +The `index` parameter in the `openPreview` function specifies the initial media item to display. It is a zero-based index, meaning that `0` will display the first item in the `MediaPreview` array. |
| 69 | + |
| 70 | +## `cropConfig` |
| 71 | + |
| 72 | +### [`language`](/config/#language) |
| 73 | + |
| 74 | +## Additional Information |
| 75 | + |
| 76 | +- Ensure that the media paths are accessible and correctly formatted. |
| 77 | +- The `openPreview` function is part of the `@baronha/react-native-multiple-image-picker` package, which should be installed and properly configured in your project. |
| 78 | + |
| 79 | +For more detailed information, refer to the [official documentation](https://github.com/baronha/react-native-multiple-image-picker). |
0 commit comments