From b4eb9200d8f214734b51cd863df5acd4ba04bf42 Mon Sep 17 00:00:00 2001 From: Innei Date: Mon, 30 Jun 2025 19:58:18 +0800 Subject: [PATCH] feat(lightbox): enhance image viewing experience with save and share functionality - Updated ImageDefaultHeader to include save and share buttons for the current image. - Refactored ImageView to pass current image URI to the header. - Cleaned up unused code and improved footer rendering logic. - Updated Info.plist to reflect new app version. Signed-off-by: Innei --- apps/mobile/ios/Folo/Info.plist | 2 +- .../components/ImageDefaultHeader.tsx | 93 +++++++++++++--- .../lightbox/ImageViewing/index.tsx | 103 ++++++------------ apps/mobile/src/initialize/analytics.ts | 4 +- apps/mobile/src/lib/api-fetch.ts | 3 + 5 files changed, 115 insertions(+), 90 deletions(-) diff --git a/apps/mobile/ios/Folo/Info.plist b/apps/mobile/ios/Folo/Info.plist index 9b8a621dc..f56e1df08 100644 --- a/apps/mobile/ios/Folo/Info.plist +++ b/apps/mobile/ios/Folo/Info.plist @@ -53,7 +53,7 @@ CFBundleVersion - 1 + 110 ITSAppUsesNonExemptEncryption LSApplicationCategoryType diff --git a/apps/mobile/src/components/lightbox/ImageViewing/components/ImageDefaultHeader.tsx b/apps/mobile/src/components/lightbox/ImageViewing/components/ImageDefaultHeader.tsx index 1944cfd5e..40876e7c5 100644 --- a/apps/mobile/src/components/lightbox/ImageViewing/components/ImageDefaultHeader.tsx +++ b/apps/mobile/src/components/lightbox/ImageViewing/components/ImageDefaultHeader.tsx @@ -10,38 +10,97 @@ import { StyleSheet, TouchableOpacity, View } from "react-native" import { useSafeAreaInsets } from "react-native-safe-area-context" import { CloseCuteReIcon } from "@/src/icons/close_cute_re" +import { Download2CuteReIcon } from "@/src/icons/download_2_cute_re" +import { ShareForwardCuteReIcon } from "@/src/icons/share_forward_cute_re" type Props = { onRequestClose: () => void + onPressSave: (uri: string) => void + onPressShare: (uri: string) => void + currentImageUri?: string } -const ImageDefaultHeader = ({ onRequestClose }: Props) => { +const ImageDefaultHeader = ({ + onRequestClose, + onPressSave, + onPressShare, + currentImageUri, +}: Props) => { const insets = useSafeAreaInsets() + return ( - - - - + + {/* Left side - Close button */} + + + + + + + {/* Right side - Save and Share buttons */} + + {currentImageUri && ( + <> + onPressSave(currentImageUri)} + hitSlop={16} + accessibilityRole="button" + accessibilityLabel="Save image" + accessibilityHint="Saves image to photo library" + > + + + + onPressShare(currentImageUri)} + hitSlop={16} + accessibilityRole="button" + accessibilityLabel="Share image" + accessibilityHint="Shares image with other apps" + > + + + + )} + ) } const styles = StyleSheet.create({ root: { - alignItems: "flex-end", + flexDirection: "row", + justifyContent: "space-between", + alignItems: "flex-start", + paddingHorizontal: 16, + paddingTop: 16, pointerEvents: "box-none", }, - closeButton: { - marginRight: 10, - marginTop: 10, + leftActions: { + flexDirection: "row", + alignItems: "center", + }, + rightActions: { + flexDirection: "row", + alignItems: "center", + gap: 12, + }, + actionButton: { width: 44, height: 44, alignItems: "center", diff --git a/apps/mobile/src/components/lightbox/ImageViewing/index.tsx b/apps/mobile/src/components/lightbox/ImageViewing/index.tsx index 14d8eff74..4ddc6e65a 100644 --- a/apps/mobile/src/components/lightbox/ImageViewing/index.tsx +++ b/apps/mobile/src/components/lightbox/ImageViewing/index.tsx @@ -11,15 +11,7 @@ // import * as ScreenOrientation from "expo-screen-orientation" import * as React from "react" import { useCallback, useMemo, useState } from "react" -import { - LayoutAnimation, - PixelRatio, - Pressable, - ScrollView, - StyleSheet, - Text, - View, -} from "react-native" +import { LayoutAnimation, PixelRatio, ScrollView, StyleSheet, Text, View } from "react-native" import { SystemBars } from "react-native-edge-to-edge" import { Gesture } from "react-native-gesture-handler" import PagerView from "react-native-pager-view" @@ -40,8 +32,6 @@ import Animated, { } from "react-native-reanimated" import { useSafeAreaFrame, useSafeAreaInsets } from "react-native-safe-area-context" -import { Download2CuteReIcon } from "@/src/icons/download_2_cute_re" -import { ShareForwardCuteReIcon } from "@/src/icons/share_forward_cute_re" import { isIOS } from "@/src/lib/platform" import type { Lightbox } from "../lightboxState" @@ -210,6 +200,10 @@ function ImageView({ const dismissSwipeTranslateY = useSharedValue(0) const isFlyingAway = useSharedValue(false) + // Get current image URI for the header buttons + const currentImage = images[imageIndex] + const currentImageUri = currentImage?.uri + const containerStyle = useAnimatedStyle(() => { if (openProgress.get() < 1) { return { @@ -349,7 +343,12 @@ function ImageView({ - + setAltExpanded((e) => !e)} - onPressSave={onPressSave} - onPressShare={onPressShare} /> @@ -519,25 +516,22 @@ function LightboxFooter({ index, isAltExpanded, toggleAltExpanded, - onPressSave, - onPressShare, }: { images: ImageSource[] index: number isAltExpanded: boolean toggleAltExpanded: () => void - onPressSave: (uri: string) => void - onPressShare: (uri: string) => void }) { const insets = useSafeAreaInsets() const image = images.at(index) const altText = image?.alt - const uri = image?.uri const isMomentumScrolling = React.useRef(false) - if (!image || !uri) { - // If the image is not available, we don't render the footer. + + // If there's no alt text, don't render the footer + if (!altText) { return null } + return ( - {altText ? ( - - { - if (isMomentumScrolling.current) { - return - } - LayoutAnimation.configureNext({ - duration: 450, - update: { type: "spring", springDamping: 1 }, - }) - toggleAltExpanded() - }} - onLongPress={() => {}} - > - {altText} - - - ) : null} - - onPressSave(uri)} + + { + if (isMomentumScrolling.current) { + return + } + LayoutAnimation.configureNext({ + duration: 450, + update: { type: "spring", springDamping: 1 }, + }) + toggleAltExpanded() + }} + onLongPress={() => {}} > - - Save - - onPressShare(uri)} - > - - Share - + {altText} + @@ -658,17 +632,6 @@ const styles = StyleSheet.create({ footerText: { paddingBottom: isIOS ? 20 : 16, }, - footerBtns: { - flexDirection: "row", - justifyContent: "center", - gap: 8, - }, - footerBtn: { - flexDirection: "row", - alignItems: "center", - gap: 8, - backgroundColor: "transparent", - }, }) function interpolatePx(px: number, inputRange: readonly number[], outputRange: readonly number[]) { diff --git a/apps/mobile/src/initialize/analytics.ts b/apps/mobile/src/initialize/analytics.ts index c7f7b045a..d8f318d4b 100644 --- a/apps/mobile/src/initialize/analytics.ts +++ b/apps/mobile/src/initialize/analytics.ts @@ -1,13 +1,13 @@ import { whoami } from "@follow/store/user/getters" import { setFirebaseTracker, setPostHogTracker, tracker } from "@follow/tracker" +import { getAnalytics } from "@react-native-firebase/analytics" import { nativeApplicationVersion, nativeBuildVersion } from "expo-application" import PostHog from "posthog-react-native" -import { ga4 } from "../lib/ga4" import { proxyEnv } from "../lib/proxy-env" export const initAnalytics = async () => { - setFirebaseTracker(ga4) + setFirebaseTracker(getAnalytics()) const user = whoami() if (user) { diff --git a/apps/mobile/src/lib/api-fetch.ts b/apps/mobile/src/lib/api-fetch.ts index 5bb94ddcd..aa83e2f40 100644 --- a/apps/mobile/src/lib/api-fetch.ts +++ b/apps/mobile/src/lib/api-fetch.ts @@ -6,6 +6,7 @@ import { FetchError, ofetch } from "ofetch" import { InvitationScreen } from "../screens/(modal)/InvitationScreen" import { getCookie } from "./auth" +import { getClientId, getSessionId } from "./client-session" import { getUserAgent } from "./native/user-agent" import { Navigation } from "./navigation/Navigation" import { proxyEnv } from "./proxy-env" @@ -68,6 +69,8 @@ export const apiClient = hc(proxyEnv.API_URL, { "X-App-Name": "Folo Mobile", cookie: getCookie(), "User-Agent": await getUserAgent(), + "X-Client-Id": getClientId(), + "X-Session-Id": getSessionId(), } }, })