From fc1e3f4fd17faf1503b6b3d7cc604dbe1bc659c1 Mon Sep 17 00:00:00 2001 From: Jonathan Jacobs Date: Sat, 10 May 2025 16:45:11 +0200 Subject: [PATCH] feat(web): allow `style` prop overrides (#4528) Co-authored-by: Jonathan Jacobs --- package.json | 2 ++ src/Video.web.tsx | 23 +++++++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index c46170fa..3e218c3b 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "@release-it/conventional-changelog": "^7.0.2", "@types/jest": "^28.1.2", "@types/react": "~19.0.0", + "@types/react-native-web": "^0.19.1", "@typescript-eslint/eslint-plugin": "^6.7.4", "eslint": "^8.19.0", "eslint-plugin-jest": "^27.4.2", @@ -27,6 +28,7 @@ "prettier": "^2.4.1", "react": "18.2.0", "react-native": "0.78.2", + "react-native-web": "0.20.0", "react-native-windows": "^0.61.0-0", "release-it": "^16.2.1", "typescript": "5.1.6" diff --git a/src/Video.web.tsx b/src/Video.web.tsx index 5c1075e3..cfd58639 100644 --- a/src/Video.web.tsx +++ b/src/Video.web.tsx @@ -6,9 +6,27 @@ import React, { useRef, useState, type RefObject, + type CSSProperties, } from 'react'; +import {StyleProp, ViewStyle} from 'react-native'; +import {unstable_createElement} from 'react-native-web'; import type {ReactVideoProps, VideoMetadata, VideoRef} from './types'; +// Define a style prop that is accepted and transformed by React Native Web +// for the native `video` element. +interface WebVideoElementProps + extends Omit, 'style'> { + style?: StyleProp; +} + +// Wrap the native `video` element to accept both React Native styles and CSS +// styles. +// +// See +function WebVideo(props: WebVideoElementProps) { + return unstable_createElement('video', props); +} + // stolen from https://stackoverflow.com/a/77278013/21726244 const isDeepEqual = (a: T, b: T): boolean => { if (a === b) { @@ -28,6 +46,7 @@ const isDeepEqual = (a: T, b: T): boolean => { const Video = forwardRef( ( { + style, source, paused, muted, @@ -306,7 +325,7 @@ const Video = forwardRef( useMediaSession(src?.metadata, nativeRef, showNotificationControls); return ( -