React Native · Components
MediaEditor
Image and video editor: full screen, dark, suited to finger use.
Live example
The preview runs in the browser with the web component; the native component takes the same props and looks the same on iOS and Android.
Preview
Code
Events
- Events appear here when you interact with the preview.
FileUpload + edit: pick, edit, add (like WhatsApp)
Profile photo: square, circular crop, crop + adjust only
Import
MediaEditor
componentImage and video editor: full screen, dark, suited to finger use. The same tools and the same edit format (MediaEdits) as MediaEditor on web; an edit saved on one platform gives the same result on the other.
- Image: cropping (free, original, preset ratios or a fixed ratio; a circle for profiles), 90° rotation, flipping, drawing with a pen and a highlighter, a blur (pixelate) brush, texts that can be dragged and resized from the corner (plain or boxed), preset looks and brightness/contrast/saturation/temperature adjustments.
- Video: range selection with two handles on a frame strip (a duration limit with
maxDuration), muting, play/pause; all image tools apply to videos too and are visible while playing in the preview. - Multiple: a thumbnail strip at the bottom for multiple items; each item has its own edits and undo history. Edited ones are marked.
- Non-destructive editing: edits are returned in the result together with the original file; a file with no changes is not reprocessed.
- Performance: the preview and the output are drawn on the GPU with the same native code (Android OpenGL ES, iOS Core Image); video is processed with the device's hardware encoder, and processing can be cancelled.
- Mobile: the back button closes the text first, then the operation, then the editor; a text is deleted by dragging it onto the trash; tools are at the bottom within thumb reach.
The native module is added to the build automatically when @yasinsensoy/native/media-editor is imported.
Examples
mediaFilterPresets
constantBuilt-in looks. Their names are written to MediaAdjustments.preset; the on-screen names come from the preset_<name> keys in the mediaEditor texts.
hasMediaEdits
functionWhether the edits change the appearance; if not, the file isn't reprocessed (no quality loss and no waiting).
defaultMediaEditorMessages
constantTurkish texts of MediaEditor.
enMediaEditorMessages
constantBuilt-in English texts for MediaEditorMessages.
canRenderMedia
functionWhether media processing is in this build. When the MediaEditor feature is used (when this subpath is imported), the native module is added to the build automatically.
renderImage
functionApplies edits to an image and produces a new file (in the app's cache folder). The editor calls it itself on "Done"; it can also be used directly to apply stored edits later.
Examples
renderVideo
functionApplies edits to a video and produces a new MP4 (H.264) file. Cropping, rotation, flipping, color, drawing, text and blur are applied to every frame; trimming and muting are applied. Processing uses the device's hardware encoder, faster than real time, and can be cancelled.
On Android the audio is not re-encoded (no quality loss); on iOS the bit rate is chosen by the system (bitrate applies only on Android).
Examples
MediaEditorMessages
interfaceMediaEditor texts. Placeholders like {name} are filled in. Changed app-wide in the dictionary's ui.mediaEditor namespace, or for one editor with the messages prop.
| Name | Type | Description |
|---|---|---|
title | string | Screen reader name of the window. |
close | string | Close button. |
done | string | Done button. |
undo | string | Undo. |
redo | string | Redo. |
crop | string | Crop tool. |
draw | string | Draw tool. |
blur | string | Blur tool. |
text | string | Text tool. |
adjust | string | Color adjustment tool. |
mute | string | Mute the video's audio. |
unmute | string | Unmute the video. |
cropArea | string | Crop area (moved with arrow keys). |
rotate | string | Rotate left. |
flip | string | Mirror. |
reset | string | Reset the tool's edits. |
aspectFree | string | Free crop ratio. |
aspectOriginal | string | Original crop ratio. |
pen | string | Pen brush. |
marker | string | Highlighter brush. |
size | string | Brush size. |
color | string | Color selection. |
textPlaceholder | string | Placeholder of the text box. |
textSize | string | Text size slider. |
textStyle | string | Button that changes the text style. |
deleteText | string | Text delete zone. |
textHandle | string | Move hint for text (screen reader): {text}. |
presets | string | Built-in looks tab. |
adjustments | string | Settings tab. |
brightness | string | Brightness. |
contrast | string | Contrast. |
saturation | string | Saturation. |
warmth | string | Warmth. |
preset | { /** Original. */ none: string; /** Vivid. */ vivid: string; /** Warm. */ warm: string; /** Cool. */ cool: string; /** Faded. */ fade: string; /** Dramatik. */ drama: string; /** Black and white. */ mono: string; /** Noir. */ noir: string; /** Sepya. */ sepia: string; } | Built-in look names (by mediaFilterPresets keys). |
play | string | Play. |
pause | string | Pause. |
trimStart | string | Trim start handle. |
trimEnd | string | Trim end handle. |
maxDuration | string | Maximum trimmed duration: {duration}. |
itemOf | string | Name of the file in the queue: {index}, {count}. |
remove | string | Remove the file from the list: {name}. |
edited | string | Screen reader state of an edited file. |
items | string | Name of the file strip. |
processing | string | While processing. |
processingOf | string | Processing percentage: {index}, {count}, {percent}. |
cancel | string | Cancel processing. |
discardTitle | string | Question when closing with unsaved changes. |
discardDescription | string | Description of the close question. |
discard | string | Discard changes and close. |
loadError | string | The file could not be opened. |
renderError | string | The file could not be processed. |
MediaRect
interfaceRectangle given as fractions (0 – 1) of the source. Regardless of rotation and mirroring it is always in the coordinates of the original image/video, so it shows the same region even when rotated later.
| Name | Type | Description |
|---|---|---|
x | number | Left edge (0 – 1). |
y | number | Top edge (0 – 1). |
width | number | Width (0 – 1). |
height | number | Height (0 – 1). |
MediaRotation
typeClockwise rotation angle.
MediaBrush
typeBrush kind.
pen: plain pen.marker: semi-transparent, thick highlighter.blur: pixelates where it passes (to hide faces, plates, addresses).
MediaStroke
interfaceA brush stroke. Points are fractions of the original source.
| Name | Type | Description |
|---|---|---|
brush | MediaBrush | Brush. See MediaBrush. |
color | string | Color (CSS color); not used for blur. |
size | number | Thickness: fraction of the source's short edge (e.g. 0.01). |
points | number[] | Points in order [x0, y0, x1, y1, …] (0 – 1). |
MediaTextStyle
typeText style.
plain: plain text with a shadow.box: text inside a colored box (text color black or white depending on the box).
MediaText
interfaceText added over the image.
| Name | Type | Description |
|---|---|---|
id | string | Unique key. |
text | string | Text; lines are separated with \n. |
x | number | Center of the text: fractions of the original source (0 – 1). |
y | number | Center of the text (vertical). |
size | number | Font size: fraction of the source's short edge (e.g. 0.06). |
color | string | Color (CSS color). |
style | MediaTextStyle | Style. See MediaTextStyle. |
Built-in look name.
MediaAdjustments
interfaceColor adjustments. Each is between -1 and 1 around 0 (unchanged); preset picks a built-in look and the adjustments are added on top.
| Name | Type | Description |
|---|---|---|
preset? | string | undefined | Built-in look name (e.g. "vivid"). See mediaFilterPresets. |
brightness? | number | undefined | Brightness. |
contrast? | number | undefined | Contrast. |
saturation? | number | undefined | Saturation. |
warmth? | number | undefined | Warmth: negative is cool (blue), positive warm (yellow). |
MediaEdits
interfaceEdits of an image or video. Stored non-destructively (the original file is untouched); the same edits can be reopened and changed later, or applied on the server. An empty object means no edits.
| Name | Type | Default | Description |
|---|---|---|---|
rotation? | MediaRotation | undefined | 0 | Clockwise rotation. |
flip? | boolean | undefined | Horizontal mirroring (after rotation). | |
crop? | MediaRect | undefined | Cropped region (relative to the original source). Everything when absent. | |
adjust? | MediaAdjustments | undefined | Color adjustments. | |
strokes? | readonly MediaStroke[] | undefined | Drawings (in the order added). | |
texts? | readonly MediaText[] | undefined | Texts. | |
trim? | { start: number; end: number; } | undefined | Trimmed range of a video (seconds). | |
muted? | boolean | undefined | The video is muted. |
MediaKind
typeMedia type.
MediaAspectRatio
typeCrop ratio option: a number (width / height), "original" (the original ratio) or "free".
MediaCropOptions
interfaceCrop tool options.
| Name | Type | Default | Description |
|---|---|---|---|
aspectRatio? | number | Fixed ratio (e.g. 1 for a profile picture). When given, the user can't change the ratio and the editor center-crops to it on open. | |
aspectRatios? | readonly MediaAspectRatio[] | ["free", "original", 1, 4 / 5, 16 / 9] | Ratios the user can choose. |
shape? | "rect" | "circle" | Show the crop area as a circle (profile picture). The output is still square. | |
rotate? | boolean | true | Rotate and mirror buttons. |
MediaTrimOptions
interfaceVideo trim tool options.
| Name | Type | Default | Description |
|---|---|---|---|
maxDuration? | number | Maximum duration (seconds). Longer videos are trimmed to it on open. | |
minDuration? | number | 0.5 | Minimum duration (seconds). |
MediaImageTools
interfaceTools available for images. Each is true (default) or false; crop can also take an options object.
| Name | Type | Description |
|---|---|---|
crop? | boolean | MediaCropOptions | Crop, rotate, mirror. See MediaCropOptions. |
draw? | boolean | Pen drawing. |
blur? | boolean | Blur (pixelate) brush. |
text? | boolean | Adding text. |
adjust? | boolean | Built-in looks and brightness/contrast/saturation/warmth. |
MediaVideoTools
interfaceTools available for videos; trim and sound in addition to the image tools.
Extends: MediaImageTools
| Name | Type | Description |
|---|---|---|
trim? | boolean | MediaTrimOptions | Trimming by selecting a range. See MediaTrimOptions. |
mute? | boolean | Mute button. |
MediaEditorTools
interfaceWhich tools are enabled for which type. true enables all tools, false means that type isn't edited; an object picks tool by tool.
| Name | Type | Default | Description |
|---|---|---|---|
image? | boolean | MediaImageTools | true | Image tools. |
video? | boolean | MediaVideoTools | true | Video tools. |
Examples
MediaImageOutput
interfaceImage output options.
| Name | Type | Default | Description |
|---|---|---|---|
type? | "auto" | "image/jpeg" | "image/png" | "image/webp" | "auto" | File type. "auto" keeps the original type (JPEG, PNG, WebP) and makes everything else JPEG. |
quality? | number | 0.92 | JPEG/WebP quality (0 – 1). |
maxSize? | number | 4096 | Maximum size of the long edge (pixels); larger images are downscaled. |
MediaVideoOutput
interfaceVideo output options.
| Name | Type | Default | Description |
|---|---|---|---|
render? | boolean | true | Render the edits into a new video in the browser? Rendering is real time (a 10 s clip takes ≈ 10 s). With false the original file and edits are returned and the server applies the edits (e.g. ffmpeg). |
maxSize? | number | 1920 | Maximum size of the long edge (pixels). |
bitrate? | number | Bitrate (bits/s). Chosen from the resolution when omitted. | |
frameRate? | number | 30 | Frame rate. |
MediaEditorOutput
interfaceOutput options for edited files.
| Name | Type | Description |
|---|---|---|
image? | MediaImageOutput | Images. See MediaImageOutput. |
video? | MediaVideoOutput | Videos. See MediaVideoOutput. |
MediaEditorItem
interfaceA file given to the editor. A FileSystem.pickMedia result can be passed directly.
| Name | Type | Description |
|---|---|---|
id? | string | Unique key; returned unchanged in the result. Defaults to the index. |
uri | string | Address of the file: file://, content:// on Android, or http(s)://. |
name? | string | null | File name. If omitted it is derived from the address. |
type? | string | null | MIME type; the kind (image/video) is picked from it (or from the extension). |
headers? | Record<string, string> | Request headers for a remote address (protected files). |
edits? | MediaEdits | Previous edits; the editor opens with them and they can be undone. |
MediaEditorResult
interfaceThe result the editor returns for a file.
| Name | Type | Description |
|---|---|---|
id | string | The item's id (the index if not given). |
kind | MediaKind | Image or video. |
file | MediaFile | Result file: a new file (in the app's cache folder) if edited, otherwise the original file. For a video with output.video.render false it is the original file; the edits are in edits. |
original | MediaFile | The original file; keep it together with edits for re-editing. |
edits | MediaEdits | Applied edits (an empty object: no edits). |
edited | boolean | Whether the look changed. |
rendered | boolean | Whether file contains the edits (false: the server applies them). |
MediaEditorProps
interfaceProps of the MediaEditor component.
| Name | Type | Default | Description |
|---|---|---|---|
open | boolean | Whether it is open. While closed nothing is drawn and the state resets. | |
onOpenChange | (open: boolean) => void | Called when the open state wants to change (close, cancel, done). | |
items | readonly MediaEditorItem[] | Images and videos to edit. A single item opens the single view; multiple items open the multi view with a thumbnail strip at the bottom. Files other than images and videos are ignored. Changes while open are not taken into account. | |
tools? | MediaEditorTools | Which tools are enabled. See MediaEditorTools. | |
output? | MediaEditorOutput | Output settings (type, quality, size, video processing). See MediaEditorOutput. | |
onDone | (results: MediaEditorResult[]) => unknown | Called when "Done" is pressed, after the files are processed. If it returns a Promise the editor stays open until it finishes. | |
onCancel? | () => void | Called when the user gives up editing. | |
removable? | boolean | true | In the multi view files can be removed from the strip (removed ones are not in the result). |
doneLabel? | ReactNode | a check icon | Content of the done button. |
defaultIndex? | number | 0 | Index of the item opened first. |
confirmDiscard? | boolean | true | Ask before closing with unsaved changes? |
messages? | Partial<MediaEditorMessages> | Texts. See MediaEditorMessages; enMediaEditorMessages for English. | |
testID? | string | Test id. |
MediaFile
interfaceA file the editor reads or produces.
| Name | Type | Description |
|---|---|---|
uri | string | Address: file://, content:// on Android, or http(s)://. |
name | string | File name. |
type | string | MIME type. |
width? | number | Width (pixels); if known. |
height? | number | Height (pixels); if known. |
size? | number | Bytes; if known. |
duration? | number | Video duration (s); if known. |
MediaSource
typeSource to process: an address or file info.
RenderVideoOptions
interfaceOptions of renderVideo.
Extends: Omit<MediaVideoOutput, "render">
| Name | Type | Description |
|---|---|---|
signal? | AbortSignal | Cancels processing; the promise rejects with an error named AbortError. |
onProgress? | (progress: number) => void | Progress (0 – 1). |