Files
bsky-social-app/src/view/com/lightbox/Lightbox.tsx
T
Aryan Goharzad 10c9b26475 Saves image on long press (#83)
* Saves image on long press

* Adds save on long press

* Forking lightbox

* move to wrapper only to the bottom sheet to reduce impact of this change

* lint

* lint

* lint

* Use official `share` API

* Clean up cache after download

* comment

* comment

* Reduce swipe close velocity

* Updates per feedback

* lint

* bugfix

* Adds delayed press-in for TouchableOpacity
2023-01-25 17:25:34 -06:00

47 lines
1.2 KiB
TypeScript

import React from 'react'
import {View} from 'react-native'
import {observer} from 'mobx-react-lite'
import ImageView from './ImageViewing'
import {useStores} from '../../../state'
import * as models from '../../../state/models/shell-ui'
import {saveImageModal} from '../../../lib/images'
export const Lightbox = observer(function Lightbox() {
const store = useStores()
if (!store.shell.isLightboxActive) {
return null
}
const onClose = () => {
store.shell.closeLightbox()
}
const onLongPress = ({uri}: {uri: string}) => {
saveImageModal({uri})
}
if (store.shell.activeLightbox?.name === 'profile-image') {
const opts = store.shell.activeLightbox as models.ProfileImageLightbox
return (
<ImageView
images={[{uri: opts.profileView.avatar}]}
imageIndex={0}
visible
onRequestClose={onClose}
/>
)
} else if (store.shell.activeLightbox?.name === 'images') {
const opts = store.shell.activeLightbox as models.ImagesLightbox
return (
<ImageView
images={opts.uris.map(uri => ({uri}))}
imageIndex={opts.index}
visible
onRequestClose={onClose}
onLongPress={onLongPress}
/>
)
} else {
return <View />
}
})