fix: ensure poster works as expected and add it to the sample (#3643)
* fix: ensure poster works as expected and add it to the sample * chore: drop audioOnly property as not implemented on any platform * fix(ios): do not save pause state before seeking * fix(ts): onPlaybackRateChangeData was not correctly typed
This commit is contained in:
@@ -121,6 +121,8 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
|
||||
setRestoreUserInterfaceForPIPStopCompletionHandler,
|
||||
] = useState<boolean | undefined>();
|
||||
|
||||
const hasPoster = !!poster;
|
||||
|
||||
const posterStyle = useMemo<StyleProp<ImageStyle>>(
|
||||
() => ({
|
||||
...StyleSheet.absoluteFillObject,
|
||||
@@ -286,19 +288,20 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
|
||||
|
||||
const onVideoLoadStart = useCallback(
|
||||
(e: NativeSyntheticEvent<OnLoadStartData>) => {
|
||||
hasPoster && setShowPoster(true);
|
||||
onLoadStart?.(e.nativeEvent);
|
||||
},
|
||||
[onLoadStart],
|
||||
[hasPoster, onLoadStart],
|
||||
);
|
||||
|
||||
const onVideoLoad = useCallback(
|
||||
(e: NativeSyntheticEvent<OnLoadData>) => {
|
||||
if (Platform.OS === 'windows') {
|
||||
setShowPoster(false);
|
||||
hasPoster && setShowPoster(false);
|
||||
}
|
||||
onLoad?.(e.nativeEvent);
|
||||
},
|
||||
[onLoad, setShowPoster],
|
||||
[onLoad, hasPoster, setShowPoster],
|
||||
);
|
||||
|
||||
const onVideoError = useCallback(
|
||||
@@ -388,9 +391,9 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
|
||||
);
|
||||
|
||||
const _onReadyForDisplay = useCallback(() => {
|
||||
setShowPoster(false);
|
||||
hasPoster && setShowPoster(false);
|
||||
onReadyForDisplay?.();
|
||||
}, [setShowPoster, onReadyForDisplay]);
|
||||
}, [setShowPoster, hasPoster, onReadyForDisplay]);
|
||||
|
||||
const _onPictureInPictureStatusChanged = useCallback(
|
||||
(e: NativeSyntheticEvent<OnPictureInPictureStatusChangedData>) => {
|
||||
@@ -567,7 +570,7 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
|
||||
_onReceiveAdEvent as (e: NativeSyntheticEvent<object>) => void
|
||||
}
|
||||
/>
|
||||
{showPoster ? (
|
||||
{hasPoster && showPoster ? (
|
||||
<Image style={posterStyle} source={{uri: poster}} />
|
||||
) : null}
|
||||
</View>
|
||||
|
Reference in New Issue
Block a user