From 12e194bfd276766998cdf822352b0d3253e71525 Mon Sep 17 00:00:00 2001 From: Jason Johnston Date: Thu, 11 May 2023 04:08:17 -0400 Subject: [PATCH] [RNMobile] VideoPress Android WebView (#30521) * Update player status when WebView loads * add changelog * Update changelog * Update native player overlay Render a Pressable component to send the embed content to a native WebView. * Update changelog * Add changelog * Move styles to external file * Use attribute title * Fix nitpicks * Fix double import --------- Co-authored-by: jhnstn --- .../videopress-rnmobile-android-webview | 4 +++ .../video/components/player/index.native.js | 28 +++++++++++++++---- .../video/components/player/style.native.scss | 4 +++ 3 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 projects/packages/videopress/changelog/videopress-rnmobile-android-webview diff --git a/projects/packages/videopress/changelog/videopress-rnmobile-android-webview b/projects/packages/videopress/changelog/videopress-rnmobile-android-webview new file mode 100644 index 0000000000000..bebc59bbd9903 --- /dev/null +++ b/projects/packages/videopress/changelog/videopress-rnmobile-android-webview @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Use native embed WebView for the VideoPress editor preview on Android diff --git a/projects/packages/videopress/src/client/block-editor/blocks/video/components/player/index.native.js b/projects/packages/videopress/src/client/block-editor/blocks/video/components/player/index.native.js index 709830fd75d10..1214202fc29c6 100644 --- a/projects/packages/videopress/src/client/block-editor/blocks/video/components/player/index.native.js +++ b/projects/packages/videopress/src/client/block-editor/blocks/video/components/player/index.native.js @@ -4,12 +4,13 @@ import { SandBox, Icon } from '@wordpress/components'; import { store as coreStore } from '@wordpress/core-data'; import { useDispatch } from '@wordpress/data'; -import { useState, useEffect, useRef, useCallback } from '@wordpress/element'; +import { useState, useEffect, useRef, useCallback, Platform } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; +import { requestEmbedFullscreenPreview } from '@wordpress/react-native-bridge'; /** * External dependencies */ -import { View, Text, Platform } from 'react-native'; +import { View, Text, Pressable } from 'react-native'; /** * Internal dependencies */ @@ -22,7 +23,7 @@ import style from './style.scss'; const VIDEO_PREVIEW_ATTEMPTS_LIMIT = 10; const DEFAULT_PLAYER_ASPECT_RATIO = 16 / 9; // This is the observed default aspect ratio from VideoPress embeds. - +const IS_ANDROID = Platform.isAndroid; /** * VideoPlayer react component * @@ -43,6 +44,7 @@ export default function Player( { isSelected, attributes } ) { seekbarColor, seekbarLoadingColor, seekbarPlayedColor, + title, } = attributes; const iconStyle = style[ 'videopress-player__loading-icon' ]; @@ -130,7 +132,7 @@ export default function Player( { isSelected, attributes } ) { // Android does not receive a 'videopress_ready' event, // so we need to set the player as ready when the WebView loads. const onLoadEnd = useCallback( () => { - Platform.OS === 'android' && setIsPlayerReady( true ); + IS_ANDROID && setIsPlayerReady( true ); }, [] ); const loadingOverlay = ( @@ -144,6 +146,22 @@ export default function Player( { isSelected, attributes } ) { ); + let overlay = ! isSelected && ; + + // On Android render an overlay to send the embed markup to a native WebView. + if ( isSelected && IS_ANDROID ) { + overlay = ( + + { + requestEmbedFullscreenPreview( html, title ); + } } + /> + + ); + } + // Show the loading overlay when: // 1. Player is not ready // 2. Player is loaded but preview is not ready @@ -151,7 +169,7 @@ export default function Player( { isSelected, attributes } ) { return ( - { ! isSelected && } + { overlay } { showLoadingOverlay && loadingOverlay } { html && (