diff --git a/packages/block-editor/src/components/page-template-picker/picker.native.js b/packages/block-editor/src/components/page-template-picker/picker.native.js index 25bb4b772ec242..b6193b4bc14715 100644 --- a/packages/block-editor/src/components/page-template-picker/picker.native.js +++ b/packages/block-editor/src/components/page-template-picker/picker.native.js @@ -4,10 +4,20 @@ import { useState, useEffect, useRef } from '@wordpress/element'; import { useDispatch, useSelect } from '@wordpress/data'; +/** + * Internal dependencies + */ +import Tooltip from './tooltip'; + /** * External dependencies */ -import { logUserEvent, userEvents } from 'react-native-gutenberg-bridge'; +import { + logUserEvent, + userEvents, + requestStarterPageTemplatesTooltipShown, + setStarterPageTemplatesTooltipShown, +} from 'react-native-gutenberg-bridge'; import { Animated, Dimensions, Keyboard } from 'react-native'; /** @@ -36,13 +46,16 @@ const __experimentalPageTemplatePicker = ( { const [ templatePreview, setTemplatePreview ] = useState(); const [ pickerVisible, setPickerVisible ] = useState( visible ); + const [ tooltipVisible, setTooltipVisible ] = useState( false ); const contentOpacity = useRef( new Animated.Value( 0 ) ).current; useEffect( () => { if ( shouldShowPicker() && visible && ! pickerVisible ) { setPickerVisible( true ); } + startPickerAnimation( visible ); + shouldShowTooltip(); Keyboard.addListener( 'keyboardDidShow', onKeyboardDidShow ); Keyboard.addListener( 'keyboardDidHide', onKeyboardDidHide ); @@ -53,6 +66,12 @@ const __experimentalPageTemplatePicker = ( { }; }, [ visible ] ); + useEffect( () => { + if ( tooltipVisible && templatePreview ) { + setTooltipVisible( false ); + } + }, [ templatePreview ] ); + const onKeyboardDidShow = () => { if ( visible ) { startPickerAnimation( shouldShowPicker() ); @@ -73,6 +92,15 @@ const __experimentalPageTemplatePicker = ( { return PICKER_HEIGHT_OFFSET < windowHeight / 3; }; + const shouldShowTooltip = () => { + requestStarterPageTemplatesTooltipShown( ( tooltipShown ) => { + if ( ! tooltipShown ) { + setTooltipVisible( true ); + setStarterPageTemplatesTooltipShown( true ); + } + } ); + }; + const onApply = () => { editPost( { title: title || templatePreview.name, @@ -84,6 +112,10 @@ const __experimentalPageTemplatePicker = ( { setTemplatePreview( undefined ); }; + const onTooltipHidden = () => { + setTooltipVisible( false ); + }; + const startPickerAnimation = ( isVisible ) => { Animated.timing( contentOpacity, { toValue: isVisible ? 1 : 0, @@ -102,6 +134,9 @@ const __experimentalPageTemplatePicker = ( { return ( + { tooltipVisible && ( + + ) } { templates.map( ( template ) => (