0dae24e78f
* add apple music embed * add vimeo embed * add logic for tenor and giphy embeds * keep it simple, use playerUri for images too * add gif embed player * lint, fix tests * remove links that can't produce a thumb * Revert "remove links that can't produce a thumb" This reverts commit985b92b4e6. * Revert "Revert "remove links that can't produce a thumb"" This reverts commit4895ded8b5. * Revert "Revert "Revert "remove links that can't produce a thumb""" This reverts commit36d04b517b. * properly obtain giphy metadata regardless of used url * test fixes * adjust gif player * add all twitch embed types * support m.youtube links * few logic adjustments * adjust spotify player height * prefetch gif before showing * use memory-disk cache policy on gifs * use `disk` cachePolicy on ios - can't start/stop animation * support pause/play on web * onLoad fix * remove extra pressable, add accessibility, fix scale issues * improve size of embed * add settings * fix(?) settings * add source to embed player params * update tests * better naming and settings options * consent modal * fix test id * why is webstorm adding .tsx * web modal * simplify types * adjust snap points * remove unnecessary yt embed library. just use the webview always * remove now useless WebGifStill 😭 * more type cleanup * more type cleanup * combine parse and prefs check in one memo * improve dimensions of youtube shorts * oops didn't commit the test 🫥 * add shorts as separate embed type * fix up schema * shorts modal * hide gif details * support localized spotify embeds * more cleanup * improve look and accessibility of gif embeds * Update routing for the external embeds settings page * Update and simplify the external embed preferences screen * Update copy in embedconsent modal and add 'allow all' button --------- Co-authored-by: Hailey <me@haileyok.com>
96 lines
2.7 KiB
TypeScript
96 lines
2.7 KiB
TypeScript
import React from 'react'
|
|
import {Image} from 'expo-image'
|
|
import {Text} from '../text/Text'
|
|
import {StyleSheet, View} from 'react-native'
|
|
import {usePalette} from 'lib/hooks/usePalette'
|
|
import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries'
|
|
import {AppBskyEmbedExternal} from '@atproto/api'
|
|
import {toNiceDomain} from 'lib/strings/url-helpers'
|
|
import {parseEmbedPlayerFromUrl} from 'lib/strings/embed-player'
|
|
import {ExternalPlayer} from 'view/com/util/post-embeds/ExternalPlayerEmbed'
|
|
import {ExternalGifEmbed} from 'view/com/util/post-embeds/ExternalGifEmbed'
|
|
import {useExternalEmbedsPrefs} from 'state/preferences'
|
|
|
|
export const ExternalLinkEmbed = ({
|
|
link,
|
|
}: {
|
|
link: AppBskyEmbedExternal.ViewExternal
|
|
}) => {
|
|
const pal = usePalette('default')
|
|
const {isMobile} = useWebMediaQueries()
|
|
const externalEmbedPrefs = useExternalEmbedsPrefs()
|
|
|
|
const embedPlayerParams = React.useMemo(() => {
|
|
const params = parseEmbedPlayerFromUrl(link.uri)
|
|
|
|
if (params && externalEmbedPrefs?.[params.source] !== 'hide') {
|
|
return params
|
|
}
|
|
}, [link.uri, externalEmbedPrefs])
|
|
|
|
return (
|
|
<View style={{flexDirection: 'column'}}>
|
|
{link.thumb && !embedPlayerParams ? (
|
|
<View
|
|
style={{
|
|
borderTopLeftRadius: 6,
|
|
borderTopRightRadius: 6,
|
|
width: '100%',
|
|
height: isMobile ? 200 : 300,
|
|
overflow: 'hidden',
|
|
}}>
|
|
<Image
|
|
style={styles.extImage}
|
|
source={{uri: link.thumb}}
|
|
accessibilityIgnoresInvertColors
|
|
/>
|
|
</View>
|
|
) : undefined}
|
|
{(embedPlayerParams?.isGif && (
|
|
<ExternalGifEmbed link={link} params={embedPlayerParams} />
|
|
)) ||
|
|
(embedPlayerParams && (
|
|
<ExternalPlayer link={link} params={embedPlayerParams} />
|
|
))}
|
|
<View
|
|
style={{
|
|
paddingHorizontal: isMobile ? 10 : 14,
|
|
paddingTop: 8,
|
|
paddingBottom: 10,
|
|
}}>
|
|
<Text
|
|
type="sm"
|
|
numberOfLines={1}
|
|
style={[pal.textLight, styles.extUri]}>
|
|
{toNiceDomain(link.uri)}
|
|
</Text>
|
|
{!embedPlayerParams?.isGif && (
|
|
<Text type="lg-bold" numberOfLines={4} style={[pal.text]}>
|
|
{link.title || link.uri}
|
|
</Text>
|
|
)}
|
|
{link.description && !embedPlayerParams?.hideDetails ? (
|
|
<Text
|
|
type="md"
|
|
numberOfLines={4}
|
|
style={[pal.text, styles.extDescription]}>
|
|
{link.description}
|
|
</Text>
|
|
) : undefined}
|
|
</View>
|
|
</View>
|
|
)
|
|
}
|
|
|
|
const styles = StyleSheet.create({
|
|
extImage: {
|
|
flex: 1,
|
|
},
|
|
extUri: {
|
|
marginTop: 2,
|
|
},
|
|
extDescription: {
|
|
marginTop: 4,
|
|
},
|
|
})
|