Quote post legibility (#486)

zio/stable
Ollie Hsieh 2023-04-18 10:53:47 -07:00 committed by GitHub
parent 10621e86e4
commit c2a4ffc99f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 69 deletions

View File

@ -1,5 +1,4 @@
import {Dimensions} from 'lib/media/types' import React, {useMemo, useState} from 'react'
import React, {useState} from 'react'
import { import {
LayoutChangeEvent, LayoutChangeEvent,
StyleProp, StyleProp,
@ -9,10 +8,11 @@ import {
ViewStyle, ViewStyle,
} from 'react-native' } from 'react-native'
import {Image, ImageStyle} from 'expo-image' import {Image, ImageStyle} from 'expo-image'
import {Dimensions} from 'lib/media/types'
export const DELAY_PRESS_IN = 500 export const DELAY_PRESS_IN = 500
export type ImageLayoutGridType = 'two' | 'three' | 'four' export type ImageLayoutGridType = number
export function ImageLayoutGrid({ export function ImageLayoutGrid({
type, type,
@ -69,8 +69,8 @@ function ImageLayoutGridInner({
onPressIn?: (index: number) => void onPressIn?: (index: number) => void
containerInfo: Dimensions containerInfo: Dimensions
}) { }) {
const size1 = React.useMemo<ImageStyle>(() => { const size1 = useMemo<ImageStyle>(() => {
if (type === 'three') { if (type === 3) {
const size = (containerInfo.width - 10) / 3 const size = (containerInfo.width - 10) / 3
return {width: size, height: size, resizeMode: 'cover', borderRadius: 4} return {width: size, height: size, resizeMode: 'cover', borderRadius: 4}
} else { } else {
@ -79,7 +79,7 @@ function ImageLayoutGridInner({
} }
}, [type, containerInfo]) }, [type, containerInfo])
const size2 = React.useMemo<ImageStyle>(() => { const size2 = React.useMemo<ImageStyle>(() => {
if (type === 'three') { if (type === 3) {
const size = ((containerInfo.width - 10) / 3) * 2 + 5 const size = ((containerInfo.width - 10) / 3) * 2 + 5
return {width: size, height: size, resizeMode: 'cover', borderRadius: 4} return {width: size, height: size, resizeMode: 'cover', borderRadius: 4}
} else { } else {
@ -88,7 +88,7 @@ function ImageLayoutGridInner({
} }
}, [type, containerInfo]) }, [type, containerInfo])
if (type === 'two') { if (type === 2) {
return ( return (
<View style={styles.flexRow}> <View style={styles.flexRow}>
<TouchableOpacity <TouchableOpacity
@ -109,7 +109,7 @@ function ImageLayoutGridInner({
</View> </View>
) )
} }
if (type === 'three') { if (type === 3) {
return ( return (
<View style={styles.flexRow}> <View style={styles.flexRow}>
<TouchableOpacity <TouchableOpacity
@ -140,7 +140,7 @@ function ImageLayoutGridInner({
</View> </View>
) )
} }
if (type === 'four') { if (type === 4) {
return ( return (
<View style={styles.flexRow}> <View style={styles.flexRow}>
<View> <View>

View File

@ -35,7 +35,7 @@ export function QuoteEmbed({
) )
return ( return (
<Link <Link
style={[styles.container, pal.border, style]} style={[styles.container, pal.borderDark, style]}
href={itemHref} href={itemHref}
title={itemTitle}> title={itemTitle}>
<PostMeta <PostMeta
@ -46,15 +46,11 @@ export function QuoteEmbed({
postHref={itemHref} postHref={itemHref}
timestamp={quote.indexedAt} timestamp={quote.indexedAt}
/> />
<Text type="post-text" style={pal.text} numberOfLines={6}> {!isEmpty ? (
{isEmpty ? ( <Text type="post-text" style={pal.text} numberOfLines={6}>
<Text style={pal.link} lineHeight={1.5}> {quote.text}
View post </Text>
</Text> ) : null}
) : (
quote.text
)}
</Text>
{AppBskyEmbedImages.isView(imagesEmbed) && ( {AppBskyEmbedImages.isView(imagesEmbed) && (
<PostEmbeds embed={imagesEmbed} /> <PostEmbeds embed={imagesEmbed} />
)} )}
@ -70,7 +66,8 @@ export default QuoteEmbed
const styles = StyleSheet.create({ const styles = StyleSheet.create({
container: { container: {
borderRadius: 8, borderRadius: 8,
paddingVertical: 8, marginTop: 8,
paddingVertical: 12,
paddingHorizontal: 12, paddingHorizontal: 12,
borderWidth: 1, borderWidth: 1,
}, },

View File

@ -107,54 +107,31 @@ export function PostEmbeds({
}) })
} }
if (embed.images.length === 4) { switch (embed.images.length) {
return ( case 1:
<View style={[styles.imagesContainer, style]}> return (
<ImageLayoutGrid <View style={[styles.imagesContainer, style]}>
type="four" <AutoSizedImage
uris={embed.images.map(img => img.thumb)} uri={embed.images[0].thumb}
onPress={openLightbox} onPress={() => openLightbox(0)}
onLongPress={onLongPress} onLongPress={() => onLongPress(0)}
onPressIn={onPressIn} onPressIn={() => onPressIn(0)}
/> style={styles.singleImage}
</View> />
) </View>
} else if (embed.images.length === 3) { )
return ( default:
<View style={[styles.imagesContainer, style]}> return (
<ImageLayoutGrid <View style={[styles.imagesContainer, style]}>
type="three" <ImageLayoutGrid
uris={embed.images.map(img => img.thumb)} type={embed.images.length}
onPress={openLightbox} uris={embed.images.map(img => img.thumb)}
onLongPress={onLongPress} onPress={openLightbox}
onPressIn={onPressIn} onLongPress={onLongPress}
/> onPressIn={onPressIn}
</View> />
) </View>
} else if (embed.images.length === 2) { )
return (
<View style={[styles.imagesContainer, style]}>
<ImageLayoutGrid
type="two"
uris={embed.images.map(img => img.thumb)}
onPress={openLightbox}
onLongPress={onLongPress}
onPressIn={onPressIn}
/>
</View>
)
} else {
return (
<View style={[styles.imagesContainer, style]}>
<AutoSizedImage
uri={embed.images[0].thumb}
onPress={() => openLightbox(0)}
onLongPress={() => onLongPress(0)}
onPressIn={() => onPressIn(0)}
style={styles.singleImage}
/>
</View>
)
} }
} }
} }
@ -184,7 +161,7 @@ const styles = StyleSheet.create({
gap: 6, gap: 6,
}, },
imagesContainer: { imagesContainer: {
marginTop: 4, marginTop: 8,
}, },
singleImage: { singleImage: {
borderRadius: 8, borderRadius: 8,