import React from 'react' import {StyleSheet, StyleProp, View, ViewStyle} from 'react-native' import {AppBskyEmbedImages, AppBskyEmbedExternal} from '@atproto/api' import LinearGradient from 'react-native-linear-gradient' import {Link} from '../util/Link' import {Text} from './text/Text' import {AutoSizedImage} from './images/AutoSizedImage' import {ImageLayoutGrid} from './images/ImageLayoutGrid' import {ImagesLightbox} from '../../../state/models/shell-ui' import {useStores} from '../../../state' import {usePalette} from '../../lib/hooks/usePalette' import {gradients} from '../../lib/styles' type Embed = | AppBskyEmbedImages.Presented | AppBskyEmbedExternal.Presented | {$type: string; [k: string]: unknown} export function PostEmbeds({ embed, style, }: { embed?: Embed style?: StyleProp }) { const pal = usePalette('default') const store = useStores() if (AppBskyEmbedImages.isPresented(embed)) { if (embed.images.length > 0) { const uris = embed.images.map(img => img.fullsize) const openLightbox = (index: number) => { store.shell.openLightbox(new ImagesLightbox(uris, index)) } if (embed.images.length === 4) { return ( img.thumb)} onPress={openLightbox} /> ) } else if (embed.images.length === 3) { return ( img.thumb)} onPress={openLightbox} /> ) } else if (embed.images.length === 2) { return ( img.thumb)} onPress={openLightbox} /> ) } else { return ( openLightbox(0)} containerStyle={styles.singleImage} /> ) } } } if (AppBskyEmbedExternal.isPresented(embed)) { const link = embed.external return ( {link.thumb ? ( ) : ( )} {link.title || link.uri} {link.uri} {link.description ? ( {link.description} ) : undefined} ) } return } const styles = StyleSheet.create({ imagesContainer: { marginTop: 4, }, singleImage: { borderRadius: 8, }, extOuter: { borderWidth: 1, borderRadius: 8, marginTop: 4, }, extInner: { padding: 10, }, extImage: { borderTopLeftRadius: 6, borderTopRightRadius: 6, width: '100%', maxHeight: 200, }, extImageFallback: { height: 160, }, extUri: { marginTop: 2, }, extDescription: { marginTop: 4, }, })