-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RNMobile] - Tooltip for template selection buttons (#21974)
* RNMobile - Starter Page Templates Picker - Tooltip
- Loading branch information
Gerardo Pacheco
authored
May 26, 2020
1 parent
a917162
commit a9ac328
Showing
3 changed files
with
170 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
packages/block-editor/src/components/page-template-picker/tooltip/index.native.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { | ||
Animated, | ||
Easing, | ||
Text, | ||
TouchableWithoutFeedback, | ||
View, | ||
Dimensions, | ||
} from 'react-native'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { useEffect, useRef, useState } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import styles from './style.scss'; | ||
|
||
const Tooltip = ( { onTooltipHidden } ) => { | ||
const [ visible, setVisible ] = useState( true ); | ||
const animationValue = useRef( new Animated.Value( 0 ) ).current; | ||
|
||
useEffect( () => { | ||
startAnimation(); | ||
}, [ visible ] ); | ||
|
||
const onHide = () => { | ||
setVisible( false ); | ||
}; | ||
|
||
const startAnimation = () => { | ||
Animated.timing( animationValue, { | ||
toValue: visible ? 1 : 0, | ||
duration: visible ? 300 : 150, | ||
useNativeDriver: true, | ||
delay: visible ? 500 : 0, | ||
easing: Easing.out( Easing.quad ), | ||
} ).start( () => { | ||
if ( ! visible && onTooltipHidden ) { | ||
onTooltipHidden(); | ||
} | ||
} ); | ||
}; | ||
|
||
const stylesOverlay = [ | ||
styles.overlay, | ||
{ height: Dimensions.get( 'window' ).height }, | ||
]; | ||
|
||
return ( | ||
<> | ||
<TouchableWithoutFeedback onPress={ onHide }> | ||
<View style={ stylesOverlay } /> | ||
</TouchableWithoutFeedback> | ||
<Animated.View | ||
style={ { | ||
opacity: animationValue, | ||
transform: [ | ||
{ | ||
translateY: animationValue.interpolate( { | ||
inputRange: [ 0, 1 ], | ||
outputRange: [ visible ? 4 : -8, -8 ], | ||
} ), | ||
}, | ||
], | ||
} } | ||
> | ||
<TouchableWithoutFeedback onPress={ onHide }> | ||
<View | ||
style={ [ | ||
styles.tooltip, | ||
{ | ||
shadowColor: styles.tooltipShadow.color, | ||
shadowOffset: { | ||
width: 0, | ||
height: 2, | ||
}, | ||
shadowOpacity: 0.25, | ||
shadowRadius: 2, | ||
elevation: 2, | ||
}, | ||
] } | ||
> | ||
<Text style={ styles.text }> | ||
{ __( 'Try a starter layout' ) } | ||
</Text> | ||
<View style={ styles.arrow } /> | ||
</View> | ||
</TouchableWithoutFeedback> | ||
</Animated.View> | ||
</> | ||
); | ||
}; | ||
|
||
export default Tooltip; |
34 changes: 34 additions & 0 deletions
34
packages/block-editor/src/components/page-template-picker/tooltip/style.native.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
$tooltipColor: #121212; | ||
|
||
.overlay { | ||
width: 100%; | ||
} | ||
|
||
.tooltip { | ||
background-color: $tooltipColor; | ||
border-radius: 4px; | ||
left: 12px; | ||
padding: 12px 16px; | ||
position: absolute; | ||
top: -36px; | ||
} | ||
|
||
.tooltipShadow { | ||
color: $black; | ||
} | ||
|
||
.text { | ||
color: $white; | ||
} | ||
|
||
.arrow { | ||
z-index: 1; | ||
position: absolute; | ||
bottom: -5px; | ||
width: 0; | ||
height: 0; | ||
border-style: solid; | ||
border-width: 6px 6px 0 6px; | ||
left: 16px; | ||
border-color: $tooltipColor transparent transparent transparent; | ||
} |