From 4c3c10d7f892777e48faccd534441ac7d88df042 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Mon, 14 Oct 2024 16:06:23 -0500 Subject: Link cards (#5677) * New link card styles * Cleanup of consituent parts, add hover state * Fix gif alt text view * Fix alt text view more * Remove dupe * Update remove button * Remove added margin on gif --- src/view/com/composer/ExternalEmbedRemoveBtn.tsx | 38 ++-- src/view/com/composer/GifAltText.tsx | 4 +- src/view/com/util/post-embeds/ExternalGifEmbed.tsx | 40 +--- .../com/util/post-embeds/ExternalLinkEmbed.tsx | 219 +++++++++++---------- .../com/util/post-embeds/ExternalPlayerEmbed.tsx | 55 +----- src/view/com/util/post-embeds/GifEmbed.tsx | 28 ++- 6 files changed, 153 insertions(+), 231 deletions(-) (limited to 'src') diff --git a/src/view/com/composer/ExternalEmbedRemoveBtn.tsx b/src/view/com/composer/ExternalEmbedRemoveBtn.tsx index 57ccc2943..0dfa3ce09 100644 --- a/src/view/com/composer/ExternalEmbedRemoveBtn.tsx +++ b/src/view/com/composer/ExternalEmbedRemoveBtn.tsx @@ -1,34 +1,26 @@ import React from 'react' -import {TouchableOpacity} from 'react-native' -import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome' +import {View} from 'react-native' import {msg} from '@lingui/macro' import {useLingui} from '@lingui/react' -import {s} from 'lib/styles' +import {atoms as a} from '#/alf' +import {Button, ButtonIcon} from '#/components/Button' +import {TimesLarge_Stroke2_Corner0_Rounded as X} from '#/components/icons/Times' export function ExternalEmbedRemoveBtn({onRemove}: {onRemove: () => void}) { const {_} = useLingui() return ( - - - + + + ) } diff --git a/src/view/com/composer/GifAltText.tsx b/src/view/com/composer/GifAltText.tsx index 732bd4bd6..143d7b826 100644 --- a/src/view/com/composer/GifAltText.tsx +++ b/src/view/com/composer/GifAltText.tsx @@ -13,7 +13,7 @@ import {isAndroid} from '#/platform/detection' import {useResolveGifQuery} from '#/state/queries/resolve-link' import {Gif} from '#/state/queries/tenor' import {AltTextCounterWrapper} from '#/view/com/composer/AltTextCounterWrapper' -import {atoms as a, native, useTheme} from '#/alf' +import {atoms as a, useTheme} from '#/alf' import {Button, ButtonText} from '#/components/Button' import * as Dialog from '#/components/Dialog' import {DialogControlProps} from '#/components/Dialog' @@ -213,7 +213,7 @@ function AltTextInner({ isPreferredAltText={true} params={params} hideAlt - style={[native({maxHeight: 225})]} + style={[{height: 225}]} /> diff --git a/src/view/com/util/post-embeds/ExternalGifEmbed.tsx b/src/view/com/util/post-embeds/ExternalGifEmbed.tsx index 6f1c88dcd..6db4d6fef 100644 --- a/src/view/com/util/post-embeds/ExternalGifEmbed.tsx +++ b/src/view/com/util/post-embeds/ExternalGifEmbed.tsx @@ -4,7 +4,6 @@ import { GestureResponderEvent, LayoutChangeEvent, Pressable, - StyleSheet, } from 'react-native' import {Image, ImageLoadEventData} from 'expo-image' import {AppBskyEmbedExternal} from '@atproto/api' @@ -18,7 +17,6 @@ import {atoms as a, useTheme} from '#/alf' import {useDialogControl} from '#/components/Dialog' import {EmbedConsentDialog} from '#/components/dialogs/EmbedConsent' import {Fill} from '#/components/Fill' -import {MediaInsetBorder} from '#/components/MediaInsetBorder' import {PlayButtonIcon} from '#/components/video/PlayButtonIcon' export function ExternalGifEmbed({ @@ -116,8 +114,7 @@ export function ExternalGifEmbed({ )} - ) } - -const styles = StyleSheet.create({ - topRadius: { - borderTopLeftRadius: 6, - borderTopRightRadius: 6, - }, - layer: { - position: 'absolute', - top: 0, - left: 0, - right: 0, - bottom: 0, - }, - overlayContainer: { - flex: 1, - justifyContent: 'center', - alignItems: 'center', - }, - overlayLayer: { - zIndex: 2, - }, - gifContainer: { - width: '100%', - overflow: 'hidden', - }, -}) diff --git a/src/view/com/util/post-embeds/ExternalLinkEmbed.tsx b/src/view/com/util/post-embeds/ExternalLinkEmbed.tsx index eb03385d0..0399667b0 100644 --- a/src/view/com/util/post-embeds/ExternalLinkEmbed.tsx +++ b/src/view/com/util/post-embeds/ExternalLinkEmbed.tsx @@ -6,8 +6,6 @@ import {msg} from '@lingui/macro' import {useLingui} from '@lingui/react' import {parseAltFromGIFDescription} from '#/lib/gif-alt-text' -import {usePalette} from '#/lib/hooks/usePalette' -import {useWebMediaQueries} from '#/lib/hooks/useWebMediaQueries' import {shareUrl} from '#/lib/sharing' import {parseEmbedPlayerFromUrl} from '#/lib/strings/embed-player' import { @@ -17,13 +15,14 @@ import { import {toNiceDomain} from '#/lib/strings/url-helpers' import {isNative} from '#/platform/detection' import {useExternalEmbedsPrefs} from '#/state/preferences' -import {Link} from '#/view/com/util/Link' import {ExternalGifEmbed} from '#/view/com/util/post-embeds/ExternalGifEmbed' import {ExternalPlayer} from '#/view/com/util/post-embeds/ExternalPlayerEmbed' import {GifEmbed} from '#/view/com/util/post-embeds/GifEmbed' import {atoms as a, useTheme} from '#/alf' -import {MediaInsetBorder} from '#/components/MediaInsetBorder' -import {Text} from '../text/Text' +import {Divider} from '#/components/Divider' +import {Earth_Stroke2_Corner0_Rounded as Globe} from '#/components/icons/Globe' +import {Link} from '#/components/Link' +import {Text} from '#/components/Typography' export const ExternalLinkEmbed = ({ link, @@ -37,16 +36,13 @@ export const ExternalLinkEmbed = ({ hideAlt?: boolean }) => { const {_} = useLingui() - const pal = usePalette('default') const t = useTheme() - const {isMobile} = useWebMediaQueries() const externalEmbedPrefs = useExternalEmbedsPrefs() - + const niceUrl = toNiceDomain(link.uri) const starterPackParsed = parseStarterPackUri(link.uri) const imageUri = starterPackParsed ? getStarterPackOgCard(starterPackParsed.name, starterPackParsed.rkey) : link.thumb - const embedPlayerParams = React.useMemo(() => { const params = parseEmbedPlayerFromUrl(link.uri) @@ -54,122 +50,131 @@ export const ExternalLinkEmbed = ({ return params } }, [link.uri, externalEmbedPrefs]) + const hasMedia = Boolean(imageUri || embedPlayerParams) + + const onShareExternal = useCallback(() => { + if (link.uri && isNative) { + shareUrl(link.uri) + } + }, [link.uri]) if (embedPlayerParams?.source === 'tenor') { const parsedAlt = parseAltFromGIFDescription(link.description) return ( - + + + ) } return ( - - - {imageUri && !embedPlayerParams ? ( - + + {({hovered}) => ( + + {imageUri && !embedPlayerParams ? ( - - - ) : undefined} - {embedPlayerParams?.isGif ? ( - - ) : embedPlayerParams ? ( - - ) : undefined} - - - {toNiceDomain(link.uri)} - - - {!embedPlayerParams?.isGif && !embedPlayerParams?.dimensions && ( - - {link.title || link.uri} - - )} - {link.description ? ( - - {link.description} - ) : undefined} - - - - ) -} -function LinkWrapper({ - link, - onOpen, - style, - children, -}: { - link: AppBskyEmbedExternal.ViewExternal - onOpen?: () => void - style?: StyleProp - children: React.ReactNode -}) { - const onShareExternal = useCallback(() => { - if (link.uri && isNative) { - shareUrl(link.uri) - } - }, [link.uri]) + {embedPlayerParams?.isGif ? ( + + ) : embedPlayerParams ? ( + + ) : undefined} - return ( - - {children} + + + {!embedPlayerParams?.isGif && !embedPlayerParams?.dimensions && ( + + {link.title || link.uri} + + )} + {link.description ? ( + + {link.description} + + ) : undefined} + + + + + + + {toNiceDomain(link.uri)} + + + + + + )} ) } diff --git a/src/view/com/util/post-embeds/ExternalPlayerEmbed.tsx b/src/view/com/util/post-embeds/ExternalPlayerEmbed.tsx index 6d5eacd1a..8ac7ee499 100644 --- a/src/view/com/util/post-embeds/ExternalPlayerEmbed.tsx +++ b/src/view/com/util/post-embeds/ExternalPlayerEmbed.tsx @@ -29,7 +29,6 @@ import {atoms as a, useTheme} from '#/alf' import {useDialogControl} from '#/components/Dialog' import {EmbedConsentDialog} from '#/components/dialogs/EmbedConsent' import {Fill} from '#/components/Fill' -import {MediaInsetBorder} from '#/components/MediaInsetBorder' import {PlayButtonIcon} from '#/components/video/PlayButtonIcon' import {EventStopper} from '../EventStopper' @@ -59,7 +58,7 @@ function PlaceholderOverlay({ accessibilityLabel={_(msg`Play Video`)} accessibilityHint={_(msg`Play Video`)} onPress={onPress} - style={[styles.overlayContainer, styles.topRadius]}> + style={[styles.overlayContainer]}> {!isPlayerActive ? ( ) : ( @@ -108,16 +107,6 @@ function Player({ style={styles.webview} setSupportMultipleWindows={false} // Prevent any redirects from opening a new window (ads) /> - - ) } @@ -227,66 +216,34 @@ export function ExternalPlayer({ + style={[aspect, a.overflow_hidden]}> {link.thumb && (!isPlayerActive || isLoading) ? ( <> - ) : ( )} - + )} - {!hideAlt && isPreferredAltText && } -- cgit 1.4.1