From 22dd4947f7d88166350c13367f2af7a51a55a36b Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 8 Nov 2024 02:52:03 +0000 Subject: [Lightbox] Add border radius to avatars (#6136) * Preserve shape in lightbox * Rename shapes to semantic meanings It looks like after all I do want to fork based on those. * Round avatars on the web * Oops --- src/screens/Profile/Header/Shell.tsx | 1 + src/view/com/lightbox/ImageViewing/@types/index.ts | 1 + .../components/ImageItem/ImageItem.android.tsx | 14 +- .../components/ImageItem/ImageItem.ios.tsx | 5 +- src/view/com/lightbox/Lightbox.web.tsx | 142 +++++++++++++-------- src/view/com/profile/ProfileSubpageHeader.tsx | 1 + src/view/com/util/post-embeds/index.tsx | 5 +- 7 files changed, 108 insertions(+), 61 deletions(-) (limited to 'src') diff --git a/src/screens/Profile/Header/Shell.tsx b/src/screens/Profile/Header/Shell.tsx index 925066d72..fe325c1e5 100644 --- a/src/screens/Profile/Header/Shell.tsx +++ b/src/screens/Profile/Header/Shell.tsx @@ -64,6 +64,7 @@ let ProfileHeaderShell = ({ height: 1000, width: 1000, }, + type: 'circle-avi', }, ], index: 0, diff --git a/src/view/com/lightbox/ImageViewing/@types/index.ts b/src/view/com/lightbox/ImageViewing/@types/index.ts index f5ab8bba9..dc636a449 100644 --- a/src/view/com/lightbox/ImageViewing/@types/index.ts +++ b/src/view/com/lightbox/ImageViewing/@types/index.ts @@ -21,4 +21,5 @@ export type ImageSource = { thumbUri: string alt?: string dimensions: Dimensions | null + type: 'image' | 'circle-avi' | 'rect-avi' } diff --git a/src/view/com/lightbox/ImageViewing/components/ImageItem/ImageItem.android.tsx b/src/view/com/lightbox/ImageViewing/components/ImageItem/ImageItem.android.tsx index 17c386771..f882dcf9e 100644 --- a/src/view/com/lightbox/ImageViewing/components/ImageItem/ImageItem.android.tsx +++ b/src/view/com/lightbox/ImageViewing/components/ImageItem/ImageItem.android.tsx @@ -302,6 +302,11 @@ const ImageItem = ({ committedTransform.value = withClampedSpring(finalTransform) }) + const innerStyle = useAnimatedStyle(() => ({ + width: '100%', + aspectRatio: imageAspect, + })) + const composedGesture = isScrollViewBeingDragged ? // If the parent is not at rest, provide a no-op gesture. Gesture.Manual() @@ -312,6 +317,9 @@ const ImageItem = ({ singleTap, ) + const type = imageSrc.type + const borderRadius = + type === 'circle-avi' ? 1e5 : type === 'rect-avi' ? 20 : 0 return ( @@ -326,7 +334,7 @@ const ImageItem = ({ source={{uri: imageSrc.uri}} placeholderContentFit="contain" placeholder={{uri: imageSrc.thumbUri}} - style={[styles.image]} + style={[innerStyle, {borderRadius}]} accessibilityLabel={imageSrc.alt} accessibilityHint="" accessibilityIgnoresInvertColors @@ -342,9 +350,7 @@ const styles = StyleSheet.create({ container: { height: '100%', overflow: 'hidden', - }, - image: { - flex: 1, + justifyContent: 'center', }, loading: { position: 'absolute', diff --git a/src/view/com/lightbox/ImageViewing/components/ImageItem/ImageItem.ios.tsx b/src/view/com/lightbox/ImageViewing/components/ImageItem/ImageItem.ios.tsx index b4bbfb4d5..e876479a3 100644 --- a/src/view/com/lightbox/ImageViewing/components/ImageItem/ImageItem.ios.tsx +++ b/src/view/com/lightbox/ImageViewing/components/ImageItem/ImageItem.ios.tsx @@ -143,6 +143,9 @@ const ImageItem = ({ singleTap, ) + const type = imageSrc.type + const borderRadius = + type === 'circle-avi' ? 1e5 : type === 'rect-avi' ? 20 : 0 return ( void }) { @@ -101,6 +97,8 @@ function LightboxInner({ return isTabletOrDesktop ? 32 : 24 }, [isTabletOrDesktop]) + const img = imgs[index] + const isAvi = img.type === 'circle-avi' || img.type === 'rect-avi' return ( - - - {canGoLeft && ( - - - - )} - {canGoRight && ( - - - - )} - + {isAvi ? ( + + {img.alt} + + ) : ( + + + {canGoLeft && ( + + + + )} + {canGoRight && ( + + + + )} + + )} - {imgs[index].alt ? ( + {img.alt ? ( - {imgs[index].alt} + {img.alt} @@ -203,6 +222,19 @@ const styles = StyleSheet.create({ height: '100%', resizeMode: 'contain', }, + aviCenterer: { + flex: 1, + alignItems: 'center', + justifyContent: 'center', + }, + avi: { + // @ts-ignore web-only + maxWidth: `calc(min(400px, 100vw))`, + // @ts-ignore web-only + maxHeight: `calc(min(400px, 100vh))`, + padding: 16, + boxSizing: 'border-box', + }, icon: { color: colors.white, }, diff --git a/src/view/com/profile/ProfileSubpageHeader.tsx b/src/view/com/profile/ProfileSubpageHeader.tsx index b712b346b..5208224c5 100644 --- a/src/view/com/profile/ProfileSubpageHeader.tsx +++ b/src/view/com/profile/ProfileSubpageHeader.tsx @@ -80,6 +80,7 @@ export function ProfileSubpageHeader({ height: 1000, width: 1000, }, + type: 'rect-avi', }, ], index: 0, diff --git a/src/view/com/util/post-embeds/index.tsx b/src/view/com/util/post-embeds/index.tsx index d686d2bd3..ea0badab0 100644 --- a/src/view/com/util/post-embeds/index.tsx +++ b/src/view/com/util/post-embeds/index.tsx @@ -152,7 +152,10 @@ export function PostEmbeds({ thumbDims: MeasuredDimensions | null, ) => { openLightbox({ - images: items, + images: items.map(item => ({ + ...item, + type: 'image', + })), index, thumbDims, }) -- cgit 1.4.1