diff --git a/.cursor/rules/rn.mdc b/.cursor/rules/rn.mdc new file mode 100644 index 000000000..6f54ca323 --- /dev/null +++ b/.cursor/rules/rn.mdc @@ -0,0 +1,12 @@ +--- +description: +globs: apps/mobile/**/* +alwaysApply: false +--- +1. This is an app written in React native. + +2. You need to use @/apps/mobile/icons for icons, do not use other icon libraries. + +3. You need to use NativewindCSS to write styles, not external StyleSheet.create. + +4. You need to use https://github.com/Innei/apple-uikit-colors/tree/main/packages/react-native-uikit-colors for color design. \ No newline at end of file diff --git a/apps/mobile/src/modules/ai/summary.tsx b/apps/mobile/src/modules/ai/summary.tsx index 95f5425b8..74584724c 100644 --- a/apps/mobile/src/modules/ai/summary.tsx +++ b/apps/mobile/src/modules/ai/summary.tsx @@ -1,10 +1,20 @@ import { cn } from "@follow/utils" import MaskedView from "@react-native-masked-view/masked-view" +import * as Haptics from "expo-haptics" import { LinearGradient } from "expo-linear-gradient" import type { FC, ReactNode } from "react" import * as React from "react" import type { LayoutChangeEvent } from "react-native" -import { Pressable, StyleSheet, Text, TextInput, View } from "react-native" +import { + Clipboard, + Modal, + Pressable, + ScrollView, + StyleSheet, + Text, + TextInput, + View, +} from "react-native" import Animated, { useAnimatedStyle, useSharedValue, @@ -13,20 +23,25 @@ import Animated, { withSpring, withTiming, } from "react-native-reanimated" +import { useSafeAreaInsets } from "react-native-safe-area-context" import { useColor } from "react-native-uikit-colors" import { AiCuteReIcon } from "@/src/icons/ai_cute_re" +import { CloseCuteReIcon } from "@/src/icons/close_cute_re" +import { CopyCuteReIcon } from "@/src/icons/copy_cute_re" import { isAndroid } from "@/src/lib/platform" export const AISummary: FC<{ className?: string summary?: string | ReactNode pending?: boolean + rawSummaryForCopy?: string error?: string onRetry?: () => void -}> = ({ className, summary, pending = false, error, onRetry }) => { +}> = ({ className, summary, pending = false, rawSummaryForCopy, error, onRetry }) => { const opacity = useSharedValue(0.3) const height = useSharedValue(0) + const [isSheetOpen, setSheetOpen] = React.useState(false) React.useEffect(() => { if (pending) { @@ -62,9 +77,11 @@ export const AISummary: FC<{ // Check if summary is a React element or string const isReactElement = React.isValidElement(summary) const summaryText = typeof summary === "string" ? summary : "" + const summaryTextForSheet = rawSummaryForCopy || summaryText if (pending || (!summary && !error)) return null - return ( + + const mainContent = ( - - - - AI Summary - - } - > - - AI Summary - - + + + + + AI Summary + + } + > + + AI Summary + + + + {summaryTextForSheet && ( + setSheetOpen(true)} + className="bg-quaternary-system-fill rounded-full p-1.5 active:opacity-70" + hitSlop={{ top: 8, bottom: 8, left: 8, right: 8 }} + > + + + )} @@ -142,6 +170,105 @@ export const AISummary: FC<{ ) + + return ( + <> + setSheetOpen(true) : undefined}> + {mainContent} + + setSheetOpen(false)} + text={rawSummaryForCopy || summaryText} + /> + + ) +} + +const SelectableTextSheet: FC<{ + visible: boolean + onClose: () => void + text: string +}> = ({ visible, onClose, text }) => { + const insets = useSafeAreaInsets() + const translateY = useSharedValue(500) + const [isRendered, setIsRendered] = React.useState(visible) + + const textColor = useColor("label") + + const sheetAnimatedStyle = useAnimatedStyle(() => ({ + transform: [{ translateY: translateY.value }], + })) + + React.useEffect(() => { + if (visible) { + setIsRendered(true) + translateY.value = withSpring(0, { + damping: 20, + stiffness: 150, + overshootClamping: true, + }) + } else { + if (isRendered) { + translateY.value = withTiming(800, { duration: 250 }) + setTimeout(() => { + setIsRendered(false) + }, 250) + } + } + }, [visible, isRendered, translateY]) + + if (!isRendered) { + return null + } + + const handleClose = () => { + onClose() + } + + const handleCopyAll = () => { + Clipboard.setString(text) + Haptics.notificationAsync(Haptics.NotificationFeedbackType.Success) + handleClose() + } + + return ( + + + + + + + + + + AI Summary + + + + + + + + + + ) } const styles = StyleSheet.create({ @@ -149,4 +276,32 @@ const styles = StyleSheet.create({ borderWidth: 0.5, elevation: 2, }, + sheetContainer: { + position: "absolute", + bottom: 0, + left: 0, + right: 0, + maxHeight: "70%", + borderTopLeftRadius: 20, + borderTopRightRadius: 20, + paddingHorizontal: 16, + paddingTop: 16, + overflow: "hidden", + }, + sheetHeader: { + alignItems: "center", + paddingBottom: 10, + borderBottomWidth: StyleSheet.hairlineWidth, + }, + sheetTitle: { + fontSize: 18, + fontWeight: "600", + }, + textScrollView: { + marginVertical: 15, + }, + selectableText: { + fontSize: 16, + lineHeight: 24, + }, }) diff --git a/apps/mobile/src/modules/entry-content/EntryAISummary.tsx b/apps/mobile/src/modules/entry-content/EntryAISummary.tsx index b7e8196cf..b763f6ab6 100644 --- a/apps/mobile/src/modules/entry-content/EntryAISummary.tsx +++ b/apps/mobile/src/modules/entry-content/EntryAISummary.tsx @@ -47,14 +47,14 @@ export const EntryAISummary: FC<{ actionLanguage, enabled: showAISummary && !entry?.isShortContent, }) + const maybeMarkdown = showReadability + ? summary?.readabilitySummary || summary?.summary + : summary?.summary const summaryToShow = useMemo(() => { - const maybeMarkdown = showReadability - ? summary?.readabilitySummary || summary?.summary - : summary?.summary if (!maybeMarkdown) return null return renderMarkdown(maybeMarkdown) - }, [showReadability, summary?.readabilitySummary, summary?.summary]) + }, [maybeMarkdown]) const status = useSummaryStore((state) => state.generatingStatus[entryId]) if (!showAISummary) return null @@ -69,6 +69,7 @@ export const EntryAISummary: FC<{ > { navigation.pushControllerView(MarkdownScreen) }, }, + { + title: "Present Profile Modal", + onPress: () => { + navigation.presentControllerView(ProfileScreen, { userId: whoami()!.id }) + }, + }, ], }, ]