Skip to content

Commit

Permalink
Close active elements on state change (bluesky-social#677)
Browse files Browse the repository at this point in the history
  • Loading branch information
renahlee authored May 17, 2023
1 parent 09bb2f5 commit 656baa7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/view/com/lightbox/Lightbox.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ interface Img {

export const Lightbox = observer(function Lightbox() {
const store = useStores()

const onClose = useCallback(() => store.shell.closeLightbox(), [store.shell])

if (!store.shell.isLightboxActive) {
return null
}
Expand All @@ -29,8 +32,6 @@ export const Lightbox = observer(function Lightbox() {
const initialIndex =
activeLightbox instanceof models.ImagesLightbox ? activeLightbox.index : 0

const onClose = () => store.shell.closeLightbox()

let imgs: Img[] | undefined
if (activeLightbox instanceof models.ProfileImageLightbox) {
const opts = activeLightbox
Expand Down
12 changes: 11 additions & 1 deletion src/view/shell/index.web.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
import React, {useEffect} from 'react'
import {observer} from 'mobx-react-lite'
import {View, StyleSheet, TouchableOpacity} from 'react-native'
import {useStores} from 'state/index'
Expand All @@ -14,11 +14,21 @@ import {RoutesContainer, FlatNavigator} from '../../Navigation'
import {DrawerContent} from './Drawer'
import {useWebMediaQueries} from '../../lib/hooks/useWebMediaQueries'
import {BottomBarWeb} from './bottom-bar/BottomBarWeb'
import {useNavigation} from '@react-navigation/native'
import {NavigationProp} from 'lib/routes/types'

const ShellInner = observer(() => {
const store = useStores()
const {isDesktop} = useWebMediaQueries()

const navigator = useNavigation<NavigationProp>()

useEffect(() => {
navigator.addListener('state', () => {
store.shell.closeAnyActiveElement()
})
}, [navigator, store.shell])

return (
<>
<View style={s.hContentRegion}>
Expand Down

0 comments on commit 656baa7

Please sign in to comment.