Declare LightboxFooter outside Lightbox
This commit is contained in:
@@ -15,13 +15,48 @@ import * as MediaLibrary from 'expo-media-library'
|
|||||||
|
|
||||||
export const Lightbox = observer(function Lightbox() {
|
export const Lightbox = observer(function Lightbox() {
|
||||||
const store = useStores()
|
const store = useStores()
|
||||||
const [isAltExpanded, setAltExpanded] = React.useState(false)
|
|
||||||
const [permissionResponse, requestPermission] = MediaLibrary.usePermissions()
|
|
||||||
|
|
||||||
const onClose = React.useCallback(() => {
|
const onClose = React.useCallback(() => {
|
||||||
store.shell.closeLightbox()
|
store.shell.closeLightbox()
|
||||||
}, [store])
|
}, [store])
|
||||||
|
|
||||||
|
if (!store.shell.activeLightbox) {
|
||||||
|
return null
|
||||||
|
} else 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}
|
||||||
|
FooterComponent={LightboxFooter}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
} else if (store.shell.activeLightbox.name === 'images') {
|
||||||
|
const opts = store.shell.activeLightbox as models.ImagesLightbox
|
||||||
|
return (
|
||||||
|
<ImageView
|
||||||
|
images={opts.images.map(img => ({...img}))}
|
||||||
|
imageIndex={opts.index}
|
||||||
|
visible
|
||||||
|
onRequestClose={onClose}
|
||||||
|
FooterComponent={LightboxFooter}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const LightboxFooter = observer(function LightboxFooter({
|
||||||
|
imageIndex,
|
||||||
|
}: {
|
||||||
|
imageIndex: number
|
||||||
|
}) {
|
||||||
|
const store = useStores()
|
||||||
|
const [isAltExpanded, setAltExpanded] = React.useState(false)
|
||||||
|
const [permissionResponse, requestPermission] = MediaLibrary.usePermissions()
|
||||||
|
|
||||||
const saveImageToAlbumWithToasts = React.useCallback(
|
const saveImageToAlbumWithToasts = React.useCallback(
|
||||||
async (uri: string) => {
|
async (uri: string) => {
|
||||||
if (!permissionResponse || permissionResponse.granted === false) {
|
if (!permissionResponse || permissionResponse.granted === false) {
|
||||||
@@ -46,8 +81,6 @@ export const Lightbox = observer(function Lightbox() {
|
|||||||
[permissionResponse, requestPermission],
|
[permissionResponse, requestPermission],
|
||||||
)
|
)
|
||||||
|
|
||||||
const LightboxFooter = React.useCallback(
|
|
||||||
({imageIndex}: {imageIndex: number}) => {
|
|
||||||
const lightbox = store.shell.activeLightbox
|
const lightbox = store.shell.activeLightbox
|
||||||
if (!lightbox) {
|
if (!lightbox) {
|
||||||
return null
|
return null
|
||||||
@@ -99,37 +132,6 @@ export const Lightbox = observer(function Lightbox() {
|
|||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
},
|
|
||||||
[store.shell.activeLightbox, isAltExpanded, saveImageToAlbumWithToasts],
|
|
||||||
)
|
|
||||||
|
|
||||||
if (!store.shell.activeLightbox) {
|
|
||||||
return null
|
|
||||||
} else 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}
|
|
||||||
FooterComponent={LightboxFooter}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
} else if (store.shell.activeLightbox.name === 'images') {
|
|
||||||
const opts = store.shell.activeLightbox as models.ImagesLightbox
|
|
||||||
return (
|
|
||||||
<ImageView
|
|
||||||
images={opts.images.map(img => ({...img}))}
|
|
||||||
imageIndex={opts.index}
|
|
||||||
visible
|
|
||||||
onRequestClose={onClose}
|
|
||||||
FooterComponent={LightboxFooter}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
|
|||||||
Reference in New Issue
Block a user