Skip to content

Opening the editor ​

ts
showEditor(filePath: string, config: EditorOptions): void

showEditor() presents the native trimmer full screen. filePath can be a local path, a file:// URI, or an HTTPS URL if you installed the https FFmpegKit package. Every option is optional, but always pass an object ({} is fine).

ts
import { showEditor } from 'react-native-video-trim';

showEditor(videoUri, {
  maxDuration: 60_000,
  minDuration: 3_000,
  autoplay: true,
  saveToPhoto: true,
  openShareSheetOnFinish: true,
  headerText: 'Trim your video',
});

The function returns immediately. What happens next is reported through events: onShow, onLoad, onStartTrimming, onFinishTrimming, onCancel, onHide and so on. Call closeEditor() to dismiss it from code.

The options are typed as EditorOptions. The tables below group the most useful ones; the API reference for EditorConfig lists every field.

Media and output ​

OptionTypeDefaultDescription
type'video' | 'audio''video'Media type. 'audio' shows a waveform.
outputExtstring'mp4'Output file extension, for example 'mov', 'wav', 'm4a'.
maxDurationnumber-1 (no limit)Longest allowed selection, in ms.
minDurationnumber-1Shortest allowed selection, in ms. The editor never allows less than 1 s.
enablePreciseTrimmingbooleanfalseRe-encode for frame-accurate cuts. See Precise trimming.
removeAudiobooleanfalseRemove the audio from the output. The editor opens muted, and the output stays silent even if the user unmutes. See Speed and mute.
speednumber1.0Initial speed, 0.25 to 4.

Playback ​

OptionTypeDefaultDescription
autoplaybooleanfalseStart playing when the media is loaded.
jumpToPositionOnLoadnumber-1Seek to this position (ms) after loading.
zoomOnWaitingDurationnumber5000When the user holds a handle still, the timeline zooms in to show this many ms around it for finer adjustment.
enableHapticFeedbackbooleantrueHaptic feedback while dragging the handles and when they reach either end.
enableEditToolsbooleantrueShow the toolbar (flip, rotate, crop, mute, speed, undo, redo). Video only.

When the user saves ​

OptionTypeDefaultDescription
saveToPhotobooleanfalseSave the output to the photo library. Needs permission.
openDocumentsOnFinishbooleanfalseOpen the system document picker so the user can save the output.
openShareSheetOnFinishbooleanfalseOpen the share sheet with the output.
closeWhenFinishbooleantrueDismiss the editor after a successful trim.
removeAfterSavedToPhotobooleanfalseDelete the output after saving it to Photos.
removeAfterFailedToSavePhotobooleanfalseDelete the output if saving to Photos failed.
removeAfterSavedToDocumentsbooleanfalseDelete the output after saving it through the document picker.
removeAfterFailedToSaveDocumentsbooleanfalseDelete the output if saving to documents failed.
removeAfterSharedbooleanfalseDelete the output after sharing (iOS only).
removeAfterFailedToSharebooleanfalseDelete the output if sharing failed (iOS only).

Text and appearance ​

OptionTypeDefaultDescription
theme'dark' | 'light''dark'Editor theme. See Theming.
headerTextstring''Title at the top of the editor.
headerTextSizenumber16Title size in sp/pt.
headerTextColorcolor stringtheme basedTitle color.
trimmerColorcolor string'#f1d247'Color of the trimmer frame and handles.
handleIconColorcolor stringtheme basedColor of the chevrons on the handles.
cancelButtonTextstring'Cancel'Cancel button label.
saveButtonTextstring'Save'Save button label.
trimmingTextstring'Trimming video...'Text in the progress dialog.
durationFormatstring'mm:ss.SSS'Format of the time labels, see below.
fullScreenModalIOSbooleanfalseiOS: present as a full-screen modal instead of a sheet.
changeStatusBarColorOnOpenbooleanfalseAndroid: make the status bar black while the editor is open.

Time label format ​

durationFormat controls the start, current and end labels. It does not change event payloads, which are always raw milliseconds.

ValueExample
'mm:ss'01:23
'mm:ss.SS'01:23.45
'mm:ss.SSS' (default)01:23.456
'hh:mm:ss'00:01:23
'hh:mm:ss.SSS'00:01:23.456

Unknown values fall back to the default.

Confirmation dialogs ​

Every dialog can be switched off or reworded, which is also how you localize the editor.

DialogSwitchText options
Cancel the editorenableCancelDialog (true)cancelDialogTitle, cancelDialogMessage, cancelDialogCancelText, cancelDialogConfirmText
SaveenableSaveDialog (true)saveDialogTitle, saveDialogMessage, saveDialogCancelText, saveDialogConfirmText
Cancel a running trimenableCancelTrimmingDialog (true)cancelTrimmingDialogTitle, cancelTrimmingDialogMessage, cancelTrimmingDialogCancelText, cancelTrimmingDialogConfirmText
Media failed to loadalertOnFailToLoad (true)alertOnFailTitle, alertOnFailMessage, alertOnFailCloseText
ts
showEditor(videoUri, {
  cancelButtonText: 'Quay lại',
  saveButtonText: 'Xong',
  saveDialogTitle: 'Lưu video?',
  saveDialogMessage: 'Đoạn video đã chọn sẽ được lưu.',
  saveDialogCancelText: 'Không',
  saveDialogConfirmText: 'Lưu',
});

Progress and cancelling ​

Progress dialog while trimmingConfirmation before cancelling a trim

While the file is being processed, the editor shows a progress dialog with trimmingText. When enableCancelTrimming is true (the default), the user can stop the trim; the editor then emits onCancelTrimming.

ts
showEditor(videoUri, {
  trimmingText: 'Processing video...',
  enableCancelTrimming: true,
  cancelTrimmingButtonText: 'Stop',
  enableCancelTrimmingDialog: true,
});

To show your own progress UI elsewhere, listen to onStatistics, which carries FFmpeg's position (time, in ms) and speed. See Events.

A complete configuration ​

ts
showEditor(videoUri, {
  // range
  maxDuration: 60_000,
  minDuration: 3_000,

  // output
  saveToPhoto: true,
  removeAfterSavedToPhoto: true,
  openShareSheetOnFinish: true,

  // audio and speed
  removeAudio: false,
  speed: 1.0,

  // appearance
  theme: 'light',
  headerText: 'Trim your video',
  cancelButtonText: 'Back',
  saveButtonText: 'Done',
  trimmerColor: '#007AFF',

  // behaviour
  autoplay: true,
  enableCancelTrimming: true,
});

Released under the MIT License.