Layouts

DefaultLayout

The DefaultLayout component provides a ready-to-use, opinionated layout for the video player. It includes standard controls like a play/pause button, progress bar, time display, and settings menu, arranged in a familiar and intuitive way.

Usage

You can use DefaultLayout by passing it as a child to the VideoPlayer component.

VideoPlayer.tsx
import { VideoPlayer, DefaultLayout } from 'react-native-video-toolkit';

export const Player = () => {
  return (
    <VideoPlayer source={{ uri: 'https://example.com/video.mp4' }}>
      <DefaultLayout title="My Awesome Video" subtitle="An example of the DefaultLayout" />
    </VideoPlayer>
  );
};

Props

PropTypeDefaultDescription
titlestringThe main title of the video, displayed in the top-left corner.
subtitlestringA subtitle or secondary text, displayed below the main title.
slotsobjectAn object that allows you to render custom components in predefined slots.

Slots

The slots prop allows you to inject your own components or elements into specific areas of the layout. This is useful for adding extra functionality or customizing the UI without having to rebuild the entire layout.

The slots prop provides a powerful way to extend the DefaultLayout while maintaining its overall structure.

Here are the available slots:

SlotDescription
beforeSettingsButtonRenders a component before the settings button.
afterSettingsButtonRenders a component after the settings button.
beforeSubtitleToggleButtonRenders a component before the subtitle toggle button.
afterSubtitleToggleButtonRenders a component after the subtitle toggle button.
beforeProgressBarRenders a component above the progress bar.
afterProgressBarRenders a component below the progress bar.
beforeTimeDisplayRenders a component before the time display.
afterTimeDisplayRenders a component after the time display.
beforeMuteButtonRenders a component before the mute button.
afterMuteButtonRenders a component after the mute button.
beforeFullscreenButtonRenders a component before the fullscreen button.
afterFullscreenButtonRenders a component after the fullscreen button.
beforeCenterPlayButtonRenders a component before the center play button.
afterCenterPlayButtonRenders a component after the center play button.

Examples

Basic Usage

Here's a basic example of how to use the DefaultLayout with a title and subtitle.

Player.tsx
import { VideoPlayer, DefaultLayout } from 'react-native-video-toolkit';

export const Player = () => {
  return (
    <VideoPlayer source={{ uri: 'https://example.com/video.mp4' }}>
      <DefaultLayout title="My Awesome Video" subtitle="An example of the DefaultLayout" />
    </VideoPlayer>
  );
};

Using Slots

This example demonstrates how to use the slots prop to add a custom "Like" button next to the fullscreen button.

PlayerWithCustomButton.tsx
import { VideoPlayer, DefaultLayout, BaseIconButton } from 'react-native-video-toolkit';
import { Heart } from 'lucide-react-native';

const LikeButton = () => (
  <BaseIconButton IconComponent={Heart} onTap={() => console.log('Liked!')} size={24} color="white" />
);

export const PlayerWithCustomButton = () => {
  return (
    <VideoPlayer source={{ uri: 'https://example.com/video.mp4' }}>
      <DefaultLayout
        title="My Awesome Video"
        slots={{
          beforeFullscreenButton: <LikeButton />,
        }}
      />
    </VideoPlayer>
  );
};