Skip to content

feat: thumbnail image custom styles #232

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion docs/docs/api/styles.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ The `react-native-video-player` component allows you to customize its appearance
- **Description**: Styles the background of the seek bar.

### `thumbnail`
- **Description**: Styles the video thumbnail shown before playback starts.
- **Description**: Styles the video thumbnail container shown before playback starts.

### `thumbnailImage`
- **Description**: Styles the video thumbnail image shown before playback starts.

### `playButton`
- **Description**: Styles the start button overlaying the thumbnail.
Expand Down Expand Up @@ -81,6 +84,7 @@ const App = () => (
wrapper: styles.wrapper,
playControl: styles.playControl,
seekBarKnob: styles.seekBarKnob,
thumbnailImage: styles.thumbnailImage
}}
/>
</View>
Expand All @@ -96,6 +100,10 @@ const styles = StyleSheet.create({
seekBarKnob: {
// ...
},
thumbnailImage: {
resizeMode: 'contain',
// ...
},
});

export default App;
Expand Down
5 changes: 5 additions & 0 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
enabled: false,
}}
>
<Text style={{ fontSize: 22, marginTop: 22 }}>

Check warning on line 24 in example/src/App.tsx

View workflow job for this annotation

GitHub Actions / lint

Inline style: { fontSize: 22, marginTop: 22 }
React Native Video Player
</Text>
<VideoPlayer
Expand All @@ -29,6 +29,11 @@
thumbnail={{
uri: 'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/images/BigBuckBunny.jpg',
}}
customStyles={{
thumbnailImage: {
resizeMode: 'cover',
},
}}
// pauseOnPress={true}
// autoplay={true}
// repeat={true}
Expand All @@ -37,7 +42,7 @@
}}
renderLoader={() => (
<View
style={{

Check warning on line 45 in example/src/App.tsx

View workflow job for this annotation

GitHub Actions / lint

Inline style: { flex: 1, backgroundColor: 'black', justifyContent: 'center' }
flex: 1,
backgroundColor: 'black',
justifyContent: 'center',
Expand Down
3 changes: 3 additions & 0 deletions src/Thumbnail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ interface ThumbnailProps extends StartButtonProps {
sizeStyles: { height: number; width: number };
onStart: () => void;
customStylesThumbnail: CustomStyles['thumbnail'];
customStylesThumbnailImage: CustomStyles['thumbnailImage'];
customStylesPlayButton: CustomStyles['playButton'];
customStylesPlayArrow: CustomStyles['playArrow'];
}
Expand Down Expand Up @@ -49,12 +50,14 @@ export const Thumbnail = memo(
sizeStyles,
onStart,
customStylesThumbnail,
customStylesThumbnailImage,
customStylesPlayButton,
customStylesPlayArrow,
}: ThumbnailProps) => {
return (
<ImageBackground
source={thumbnailSource}
imageStyle={customStylesThumbnailImage}
style={[styles.thumbnail, sizeStyles, style, customStylesThumbnail]}
>
<StartButton
Expand Down
6 changes: 4 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export interface CustomStyles {
seekBarKnobSeeking?: StyleProp<ViewStyle>;
seekBarBackground?: StyleProp<ViewStyle>;
thumbnail?: StyleProp<ViewStyle>;
thumbnailImage?: StyleProp<ImageStyle>;
playButton?: StyleProp<ViewStyle>;
playArrow?: StyleProp<ImageStyle>;
durationText?: StyleProp<TextStyle>;
Expand Down Expand Up @@ -146,8 +147,8 @@ const VideoPlayer = forwardRef<VideoPlayerRef, VideoPlayerProps>(
}, [onEnd, endWithThumbnail, endThumbnail, setIsStarted, setHasEnded]);

const onLayout = useCallback((event: LayoutChangeEvent) => {
const { width } = event.nativeEvent.layout;
setWidth(width);
const { width: containerWidth } = event.nativeEvent.layout;
setWidth(containerWidth);
}, []);

const renderContent = useCallback(() => {
Expand All @@ -161,6 +162,7 @@ const VideoPlayer = forwardRef<VideoPlayerRef, VideoPlayerProps>(
sizeStyles={sizeStyles}
onStart={_onStart}
customStylesThumbnail={customStyles.thumbnail}
customStylesThumbnailImage={customStyles.thumbnailImage}
customStylesPlayButton={customStyles.playButton}
customStylesPlayArrow={customStyles.playArrow}
/>
Expand Down
Loading