Repository navigation
feat(mobile): show compact chat attachments with a swipeable image viewer #29642
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
niconicohu
wants to merge
40
commits into
stablyai:main
from
niconicohu:codex/mobile-message-attachments
+3,177
−306
Closed
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
7eb0116
feat(mobile): preview chat attachments in a compact swipeable gallery
niconicohu bd90ad4
fix(mobile): scope image failures and preserve attachment prose spacing
niconicohu feff5fc
fix(mobile): authorize stored attachment previews on their owning host
niconicohu 7e5d1da
fix(attachments): exclude agent messages from user file provenance
niconicohu 9489933
fix(mobile): preserve prose around stored attachment references
niconicohu 457251c
fix(mobile): keep inline attachment examples as literal code
niconicohu 9121ab4
Merge main and use parser rules and shared image viewer state
niconicohu cde193a
Keep Android image long-press actions on gallery thumbnails
niconicohu a55c93b
Type gallery host fixture with JSX children
niconicohu 1806245
Merge main row overlays and streaming while retaining the attachment …
niconicohu f27ea0d
Consolidate row overlay message type imports
niconicohu 8990655
fix(mobile): support Android gallery zoom and trim unrelated formatting
niconicohu a916181
fix(mobile): coordinate image pan and pinch transitions
niconicohu 07d1804
chore: remove unrelated formatting from attachments changes
niconicohu a757f7c
Merge queued editing while retaining host attachment reads and Window…
niconicohu bdf88cf
fix(chat): preserve image URLs outside the attachment store
niconicohu 0f6c0fe
Merge main and keep attachment gestures in the shared phone page
niconicohu 763bb92
fix(mobile): measure gallery pages and preserve web pinch and swiping
niconicohu b42cef0
test(mobile): follow gallery pages from web scroll events
niconicohu 20f8897
fix(mobile): anchor page image zoom below headers and safe insets
niconicohu 18a91ab
Merge main while preserving separate message attachments
niconicohu 33523a3
Keep attachment previews alongside the new mobile composer
niconicohu 45d679f
Route phone attachment previews to the execution host
niconicohu bc2f3f2
Merge main into mobile attachments
niconicohu f8add2d
fix(mobile): preview and zoom assistant images on their session host
niconicohu e8544ee
fix(mobile): retain tap-to-open policy for external chat images
niconicohu 678c11e
fix(mobile): admit only supported chat image sources
niconicohu c866856
Merge upstream main into mobile attachments
niconicohu f0330fc
Merge main and preserve chat image admission
niconicohu 31d013b
Merge main into mobile attachments and preserve tool disclosure
niconicohu b15020e
fix(mobile): clear held failure after accepted question answers
niconicohu 479fa8c
Merge upstream/main and preserve OMP question routing with attachment…
niconicohu de5bfa9
Merge main model and async-question support into chat attachments
niconicohu de29c03
Merge current main browser prop extraction into mobile attachments
niconicohu 04394c9
Merge main while retaining CJK and attachment parsing
niconicohu 21f8844
Merge main and retain independent mobile attachment capabilities
niconicohu fd90376
Merge main and follow relocated attachment grant types
niconicohu 771cef9
Merge main and compose mobile chat test fixtures
niconicohu eeb07ce
Merge upstream main and preserve mobile attachment rendering
niconicohu 5bd23f0
Merge main and update attachment grant filesystem mock
niconicohu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import { useState } from 'react' | ||
| import { Pressable, Text, View } from 'react-native' | ||
| import { FileText } from 'lucide-react-native' | ||
| import { colors } from '../theme/mobile-theme' | ||
| import { styles } from './mobile-native-chat-message-styles' | ||
|
|
||
| export function MobileNativeChatFileAttachments({ | ||
| files, | ||
| onOpenFile | ||
| }: { | ||
| files: readonly string[] | ||
| onOpenFile?: (path: string) => void | ||
| }) { | ||
| const [expanded, setExpanded] = useState(false) | ||
| return ( | ||
| <View style={[styles.imageGallery, expanded && styles.fileGallery]}> | ||
| {(expanded ? files : files.slice(0, 3)).map((path) => { | ||
| const name = path.split(/[\\/]/).at(-1) ?? path | ||
| return ( | ||
| <Pressable | ||
| key={path} | ||
| accessibilityRole="button" | ||
| accessibilityLabel={`Open file ${name}`} | ||
| disabled={!onOpenFile} | ||
| style={[styles.imageGalleryTile, styles.fileTile]} | ||
| onPress={() => onOpenFile?.(path)} | ||
| > | ||
| <FileText size={20} color={colors.textSecondary} /> | ||
| <Text numberOfLines={2} ellipsizeMode="middle" style={styles.fileName}> | ||
| {name} | ||
| </Text> | ||
| </Pressable> | ||
| ) | ||
| })} | ||
| {files.length > 3 ? ( | ||
| <Pressable | ||
| accessibilityRole="button" | ||
| accessibilityLabel={expanded ? 'Show fewer files' : `View all ${files.length} files`} | ||
| style={[styles.imageGalleryTile, styles.imageGalleryMore]} | ||
| onPress={() => setExpanded(!expanded)} | ||
| > | ||
| <Text style={styles.imageGalleryCount}>{expanded ? '−' : `+${files.length - 3}`}</Text> | ||
| </Pressable> | ||
| ) : null} | ||
| </View> | ||
| ) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| import { useContext, useEffect, useState } from 'react' | ||
| import { | ||
| ActivityIndicator, | ||
| Image, | ||
| Pressable, | ||
| Text, | ||
| View, | ||
| type ImageStyle, | ||
| type StyleProp, | ||
| type ImageResizeMode | ||
| } from 'react-native' | ||
| import { isAgentSessionAttachmentStorePath } from '../../../src/shared/agent-session-attachments' | ||
| import { colors } from '../theme/mobile-theme' | ||
| import { | ||
| MobileNativeChatAttachmentContext, | ||
| readMobileNativeChatAttachment | ||
| } from './mobile-native-chat-attachment-read' | ||
| import { isRenderableImageUri } from './mobile-native-chat-image-preview' | ||
| import { styles, TEXT_SIZE } from './mobile-native-chat-message-styles' | ||
|
|
||
| export function MobileNativeChatImage({ | ||
| uri, | ||
| alt, | ||
| fontScale, | ||
| imageStyle = styles.imageThumb, | ||
| resizeMode = 'contain' | ||
| }: { | ||
| uri: string | undefined | ||
| alt?: string | ||
| fontScale: number | ||
| imageStyle?: StyleProp<ImageStyle> | ||
| resizeMode?: ImageResizeMode | ||
| }) { | ||
| const client = useContext(MobileNativeChatAttachmentContext) | ||
| const direct = isRenderableImageUri(uri) | ||
| const remote = | ||
| !direct && client !== null && uri !== undefined && isAgentSessionAttachmentStorePath(uri) | ||
| const [attempt, setAttempt] = useState(0) | ||
| const [read, setRead] = useState<{ | ||
| client: typeof client | ||
| path: string | ||
| uri: string | null | ||
| } | null>(null) | ||
| const [failed, setFailed] = useState(false) | ||
| useEffect(() => { | ||
| if (!remote || !client || uri === undefined) { | ||
| return | ||
| } | ||
| let disposed = false | ||
| void readMobileNativeChatAttachment(client, uri) | ||
| .catch(() => null) | ||
| .then((image) => { | ||
| if (!disposed) { | ||
| setRead({ client, path: uri, uri: image }) | ||
| } | ||
| }) | ||
| return () => { | ||
| disposed = true | ||
| } | ||
| }, [client, uri, remote, attempt]) | ||
| const current = read?.client === client && read?.path === uri ? read : null | ||
| const imageUri = direct ? uri : current?.uri | ||
| if (imageUri && !failed) { | ||
| return ( | ||
| <Image | ||
| source={{ uri: imageUri }} | ||
| style={imageStyle} | ||
| resizeMode={resizeMode} | ||
| accessibilityLabel={alt ?? 'Attached image'} | ||
| onError={() => setFailed(true)} | ||
| /> | ||
| ) | ||
| } | ||
| if (remote && current === null) { | ||
| return ( | ||
| <View style={imageStyle}> | ||
| <ActivityIndicator color={colors.textSecondary} accessibilityLabel="Loading image" /> | ||
| </View> | ||
| ) | ||
| } | ||
| const label = ( | ||
| <Text style={[styles.imageRef, { fontSize: TEXT_SIZE * fontScale }]}> | ||
| {remote || failed ? 'Image unavailable · Tap to retry' : `🖼 ${alt ?? uri ?? 'image'}`} | ||
| </Text> | ||
| ) | ||
| return remote || failed ? ( | ||
| <Pressable | ||
| accessibilityLabel="Retry image" | ||
| accessibilityRole="button" | ||
| onPress={() => { | ||
| setRead(null) | ||
| setFailed(false) | ||
| setAttempt((value) => value + 1) | ||
| }} | ||
| > | ||
| {label} | ||
| </Pressable> | ||
| ) : ( | ||
| label | ||
| ) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import { useState } from 'react' | ||
| import { Pressable, Text, View } from 'react-native' | ||
| import type { NativeChatImageRefBlock } from '../../../src/shared/native-chat-types' | ||
| import { MobileNativeChatImage } from './MobileNativeChatImage' | ||
| import { MobileNativeChatImageViewer } from './MobileNativeChatImageViewer' | ||
| import { styles } from './mobile-native-chat-message-styles' | ||
|
|
||
| export function MobileNativeChatImageGallery({ | ||
| images, | ||
| alignToEnd = true | ||
| }: { | ||
| images: readonly NativeChatImageRefBlock[] | ||
| alignToEnd?: boolean | ||
| }) { | ||
| const [selected, setSelected] = useState<number | null>(null) | ||
| const occurrences = new Map<string, number>() | ||
| const thumbnails = images.slice(0, 3).map((image) => { | ||
| const identity = image.path ?? image.url ?? image.alt ?? 'image' | ||
| const occurrence = occurrences.get(identity) ?? 0 | ||
| occurrences.set(identity, occurrence + 1) | ||
| return { image, key: `${identity}:${occurrence}` } | ||
| }) | ||
| return ( | ||
| <View style={[styles.imageGallery, !alignToEnd && { justifyContent: 'flex-start' }]}> | ||
| {thumbnails.map(({ image, key }, index) => ( | ||
| <Pressable | ||
| key={key} | ||
| accessibilityRole="button" | ||
| accessibilityLabel={`Open image ${index + 1} of ${images.length}`} | ||
| style={styles.imageGalleryTile} | ||
| onPress={() => setSelected(index)} | ||
| > | ||
| <MobileNativeChatImage | ||
| uri={image.url ?? image.path} | ||
| alt={image.alt} | ||
| fontScale={1} | ||
| imageStyle={styles.imageGalleryFill} | ||
| resizeMode="cover" | ||
| /> | ||
| {index === 2 && images.length > 3 ? ( | ||
| <View pointerEvents="none" style={styles.imageGalleryScrim}> | ||
| <Text style={styles.imageGalleryOverflowCount}>+{images.length - 3}</Text> | ||
| </View> | ||
| ) : null} | ||
| </Pressable> | ||
| ))} | ||
| {selected !== null ? ( | ||
| <MobileNativeChatImageViewer | ||
| images={images} | ||
| initialIndex={selected} | ||
| onClose={() => setSelected(null)} | ||
| /> | ||
| ) : null} | ||
| </View> | ||
| ) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| import { useState } from 'react' | ||
| import { FlatList, Modal, Pressable, Text, View, useWindowDimensions } from 'react-native' | ||
| import { X } from 'lucide-react-native' | ||
| import type { NativeChatImageRefBlock } from '../../../src/shared/native-chat-types' | ||
| import { useWindowSafeAreaInsets } from '../layout/side-safe-area' | ||
| import { colors } from '../theme/mobile-theme' | ||
| import { MobileNativeChatImage } from './MobileNativeChatImage' | ||
| import { styles } from './mobile-native-chat-message-styles' | ||
|
|
||
| export function MobileNativeChatImageViewer({ | ||
| images, | ||
| initialIndex, | ||
| onClose | ||
| }: { | ||
| images: readonly NativeChatImageRefBlock[] | ||
| initialIndex: number | ||
| onClose: () => void | ||
| }) { | ||
| const insets = useWindowSafeAreaInsets() | ||
| const window = useWindowDimensions() | ||
| const width = Math.max(1, window.width - insets.left - insets.right) | ||
| const [index, setIndex] = useState(initialIndex) | ||
| return ( | ||
| <Modal visible presentationStyle="fullScreen" animationType="fade" onRequestClose={onClose}> | ||
| <View | ||
| style={[ | ||
| styles.imageViewer, | ||
| { | ||
| paddingTop: insets.top, | ||
| paddingBottom: insets.bottom, | ||
| paddingLeft: insets.left, | ||
| paddingRight: insets.right | ||
| } | ||
| ]} | ||
| > | ||
| <View style={styles.imageViewerHeader}> | ||
| <Text style={styles.imageViewerTitle}> | ||
| {index + 1} / {images.length} | ||
| </Text> | ||
| <Pressable | ||
| accessibilityRole="button" | ||
| accessibilityLabel="Close images" | ||
| hitSlop={8} | ||
| onPress={onClose} | ||
| style={styles.imageViewerClose} | ||
| > | ||
| <X size={20} color={colors.textPrimary} /> | ||
| </Pressable> | ||
| </View> | ||
| <FlatList | ||
| key={width} | ||
| horizontal | ||
| pagingEnabled | ||
| data={images} | ||
| initialScrollIndex={index} | ||
| initialNumToRender={1} | ||
| windowSize={3} | ||
| showsHorizontalScrollIndicator={false} | ||
| keyExtractor={(image, at) => `${at}:${image.url ?? image.path}`} | ||
| getItemLayout={(_data, at) => ({ length: width, offset: at * width, index: at })} | ||
| onMomentumScrollEnd={(event) => | ||
| setIndex( | ||
| Math.max( | ||
| 0, | ||
| Math.min(images.length - 1, Math.round(event.nativeEvent.contentOffset.x / width)) | ||
| ) | ||
| ) | ||
| } | ||
| renderItem={({ item }) => ( | ||
| <View style={{ width, flex: 1 }}> | ||
| <MobileNativeChatImage | ||
| uri={item.url ?? item.path} | ||
| alt={item.alt} | ||
| fontScale={1} | ||
| imageStyle={styles.imageGalleryFill} | ||
| /> | ||
| </View> | ||
| )} | ||
| /> | ||
| </View> | ||
| </Modal> | ||
| ) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.