more robust centering of the play button (#181)

Co-authored-by: Aryan Goharzad <arrygoo@gmail.com>
This commit is contained in:
Paul Frazee
2023-02-09 16:37:59 -06:00
committed by GitHub
parent 04b3ebbf63
commit 22820372df
3 changed files with 20 additions and 10 deletions
@@ -8,19 +8,19 @@ import {PresentedExternal} from '@atproto/api/dist/client/types/app/bsky/embed/e
const ExternalLinkEmbed = ({ const ExternalLinkEmbed = ({
link, link,
onImagePress, onImagePress,
imageChild,
}: { }: {
link: PresentedExternal link: PresentedExternal
onImagePress: () => void onImagePress: () => void
imageChild: React.ReactNode
}) => { }) => {
const pal = usePalette('default') const pal = usePalette('default')
return ( return (
<> <>
{link.thumb ? ( {link.thumb ? (
<Image <Image uri={link.thumb} style={styles.extImage} onPress={onImagePress}>
uri={link.thumb} {imageChild}
style={styles.extImage} </Image>
onPress={onImagePress}
/>
) : undefined} ) : undefined}
<View style={styles.extInner}> <View style={styles.extInner}>
<Text type="md-bold" numberOfLines={2} style={[pal.text]}> <Text type="md-bold" numberOfLines={2} style={[pal.text]}>
+12 -5
View File
@@ -49,15 +49,22 @@ const YoutubeEmbed = ({
return () => sub && sub.remove() return () => sub && sub.remove()
}, [displayVideoPlayer, store]) }, [displayVideoPlayer, store])
const imageChild = (
<Pressable onPress={handlePlayButtonPressed} style={styles.playButton}>
<FontAwesomeIcon icon="play" size={24} color="white" />
</Pressable>
)
if (!displayVideoPlayer) { if (!displayVideoPlayer) {
return ( return (
<View <View
style={[styles.extOuter, pal.view, pal.border]} style={[styles.extOuter, pal.view, pal.border]}
onLayout={handleOnLayout}> onLayout={handleOnLayout}>
<ExternalLinkEmbed link={link} onImagePress={handlePlayButtonPressed} /> <ExternalLinkEmbed
<Pressable onPress={handlePlayButtonPressed} style={styles.playButton}> link={link}
<FontAwesomeIcon icon="play" size={24} color="white" /> onImagePress={handlePlayButtonPressed}
</Pressable> imageChild={imageChild}
/>
</View> </View>
) )
} }
@@ -93,9 +100,9 @@ const styles = StyleSheet.create({
}, },
playButton: { playButton: {
position: 'absolute', position: 'absolute',
top: '20%',
alignSelf: 'center', alignSelf: 'center',
alignItems: 'center', alignItems: 'center',
top: '44%',
justifyContent: 'center', justifyContent: 'center',
backgroundColor: 'black', backgroundColor: 'black',
padding: 10, padding: 10,
+3
View File
@@ -14,12 +14,14 @@ export function Image({
onLongPress, onLongPress,
onPressIn, onPressIn,
style, style,
children = null,
}: { }: {
uri: string uri: string
onPress?: () => void onPress?: () => void
onLongPress?: () => void onLongPress?: () => void
onPressIn?: () => void onPressIn?: () => void
style?: StyleProp<ViewStyle> style?: StyleProp<ViewStyle>
children?: React.ReactNode
}) { }) {
const [aspectRatio, setAspectRatio] = React.useState<number>(1) const [aspectRatio, setAspectRatio] = React.useState<number>(1)
const onLoad = (e: OnLoadEvent) => { const onLoad = (e: OnLoadEvent) => {
@@ -44,6 +46,7 @@ export function Image({
defaultSource={LOADING} defaultSource={LOADING}
onLoad={onLoad} onLoad={onLoad}
/> />
{children}
</TouchableOpacity> </TouchableOpacity>
) )
} }