Lightbox status bar behaviour (#6637)
* lightbox status bar * add hideTransitionAnimation="slide" * move navigation bar logic to util
This commit is contained in:
@@ -0,0 +1,18 @@
|
|||||||
|
import * as NavigationBar from 'expo-navigation-bar'
|
||||||
|
|
||||||
|
import {isAndroid} from '#/platform/detection'
|
||||||
|
import {Theme} from '../types'
|
||||||
|
|
||||||
|
export function setNavigationBar(themeType: 'theme' | 'lightbox', t: Theme) {
|
||||||
|
if (isAndroid) {
|
||||||
|
if (themeType === 'theme') {
|
||||||
|
NavigationBar.setBackgroundColorAsync(t.atoms.bg.backgroundColor)
|
||||||
|
NavigationBar.setBorderColorAsync(t.atoms.bg.backgroundColor)
|
||||||
|
NavigationBar.setButtonStyleAsync(t.name !== 'light' ? 'light' : 'dark')
|
||||||
|
} else {
|
||||||
|
NavigationBar.setBackgroundColorAsync('black')
|
||||||
|
NavigationBar.setBorderColorAsync('black')
|
||||||
|
NavigationBar.setButtonStyleAsync('light')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
// Original code copied and simplified from the link below as the codebase is currently not maintained:
|
// Original code copied and simplified from the link below as the codebase is currently not maintained:
|
||||||
// https://github.com/jobtoday/react-native-image-viewing
|
// https://github.com/jobtoday/react-native-image-viewing
|
||||||
|
|
||||||
import React, {useCallback, useState} from 'react'
|
import React, {useCallback, useEffect, useState} from 'react'
|
||||||
import {
|
import {
|
||||||
LayoutAnimation,
|
LayoutAnimation,
|
||||||
PixelRatio,
|
PixelRatio,
|
||||||
@@ -40,6 +40,7 @@ import {
|
|||||||
useSafeAreaFrame,
|
useSafeAreaFrame,
|
||||||
useSafeAreaInsets,
|
useSafeAreaInsets,
|
||||||
} from 'react-native-safe-area-context'
|
} from 'react-native-safe-area-context'
|
||||||
|
import {StatusBar} from 'expo-status-bar'
|
||||||
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
|
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
|
||||||
import {Trans} from '@lingui/macro'
|
import {Trans} from '@lingui/macro'
|
||||||
|
|
||||||
@@ -50,6 +51,8 @@ import {Lightbox} from '#/state/lightbox'
|
|||||||
import {Button} from '#/view/com/util/forms/Button'
|
import {Button} from '#/view/com/util/forms/Button'
|
||||||
import {Text} from '#/view/com/util/text/Text'
|
import {Text} from '#/view/com/util/text/Text'
|
||||||
import {ScrollView} from '#/view/com/util/Views'
|
import {ScrollView} from '#/view/com/util/Views'
|
||||||
|
import {ios, useTheme} from '#/alf'
|
||||||
|
import {setNavigationBar} from '#/alf/util/navigationBar'
|
||||||
import {PlatformInfo} from '../../../../../modules/expo-bluesky-swiss-army'
|
import {PlatformInfo} from '../../../../../modules/expo-bluesky-swiss-army'
|
||||||
import {ImageSource, Transform} from './@types'
|
import {ImageSource, Transform} from './@types'
|
||||||
import ImageDefaultHeader from './components/ImageDefaultHeader'
|
import ImageDefaultHeader from './components/ImageDefaultHeader'
|
||||||
@@ -276,8 +279,26 @@ function ImageView({
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// style nav bar on android
|
||||||
|
const t = useTheme()
|
||||||
|
useEffect(() => {
|
||||||
|
setNavigationBar('lightbox', t)
|
||||||
|
return () => {
|
||||||
|
setNavigationBar('theme', t)
|
||||||
|
}
|
||||||
|
}, [t])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Animated.View style={[styles.container, containerStyle]}>
|
<Animated.View style={[styles.container, containerStyle]}>
|
||||||
|
<StatusBar
|
||||||
|
animated
|
||||||
|
style="light"
|
||||||
|
hideTransitionAnimation="slide"
|
||||||
|
backgroundColor="black"
|
||||||
|
// hiding causes layout shifts on android,
|
||||||
|
// so avoid until we add edge-to-edge mode
|
||||||
|
hidden={ios(isScaled || !showControls)}
|
||||||
|
/>
|
||||||
<Animated.View
|
<Animated.View
|
||||||
style={[styles.backdrop, backdropStyle]}
|
style={[styles.backdrop, backdropStyle]}
|
||||||
renderToHardwareTextureAndroid
|
renderToHardwareTextureAndroid
|
||||||
|
|||||||
+18
-32
@@ -1,18 +1,15 @@
|
|||||||
import React from 'react'
|
import {useCallback, useEffect} from 'react'
|
||||||
import {BackHandler, StyleSheet, useWindowDimensions, View} from 'react-native'
|
import {BackHandler, useWindowDimensions, View} from 'react-native'
|
||||||
import {Drawer} from 'react-native-drawer-layout'
|
import {Drawer} from 'react-native-drawer-layout'
|
||||||
import {useSafeAreaInsets} from 'react-native-safe-area-context'
|
import {useSafeAreaInsets} from 'react-native-safe-area-context'
|
||||||
import * as NavigationBar from 'expo-navigation-bar'
|
|
||||||
import {StatusBar} from 'expo-status-bar'
|
import {StatusBar} from 'expo-status-bar'
|
||||||
import {useNavigation, useNavigationState} from '@react-navigation/native'
|
import {useNavigation, useNavigationState} from '@react-navigation/native'
|
||||||
|
|
||||||
import {useDedupe} from '#/lib/hooks/useDedupe'
|
import {useDedupe} from '#/lib/hooks/useDedupe'
|
||||||
import {useIntentHandler} from '#/lib/hooks/useIntentHandler'
|
import {useIntentHandler} from '#/lib/hooks/useIntentHandler'
|
||||||
import {useNotificationsHandler} from '#/lib/hooks/useNotificationHandler'
|
import {useNotificationsHandler} from '#/lib/hooks/useNotificationHandler'
|
||||||
import {usePalette} from '#/lib/hooks/usePalette'
|
|
||||||
import {useNotificationsRegistration} from '#/lib/notifications/notifications'
|
import {useNotificationsRegistration} from '#/lib/notifications/notifications'
|
||||||
import {isStateAtTabRoot} from '#/lib/routes/helpers'
|
import {isStateAtTabRoot} from '#/lib/routes/helpers'
|
||||||
import {useTheme} from '#/lib/ThemeContext'
|
|
||||||
import {isAndroid, isIOS} from '#/platform/detection'
|
import {isAndroid, isIOS} from '#/platform/detection'
|
||||||
import {useDialogStateControlContext} from '#/state/dialogs'
|
import {useDialogStateControlContext} from '#/state/dialogs'
|
||||||
import {useSession} from '#/state/session'
|
import {useSession} from '#/state/session'
|
||||||
@@ -25,30 +22,31 @@ import {useCloseAnyActiveElement} from '#/state/util'
|
|||||||
import {Lightbox} from '#/view/com/lightbox/Lightbox'
|
import {Lightbox} from '#/view/com/lightbox/Lightbox'
|
||||||
import {ModalsContainer} from '#/view/com/modals/Modal'
|
import {ModalsContainer} from '#/view/com/modals/Modal'
|
||||||
import {ErrorBoundary} from '#/view/com/util/ErrorBoundary'
|
import {ErrorBoundary} from '#/view/com/util/ErrorBoundary'
|
||||||
import {atoms as a, select, useTheme as useNewTheme} from '#/alf'
|
import {atoms as a, select, useTheme} from '#/alf'
|
||||||
|
import {setNavigationBar} from '#/alf/util/navigationBar'
|
||||||
import {MutedWordsDialog} from '#/components/dialogs/MutedWords'
|
import {MutedWordsDialog} from '#/components/dialogs/MutedWords'
|
||||||
import {SigninDialog} from '#/components/dialogs/Signin'
|
import {SigninDialog} from '#/components/dialogs/Signin'
|
||||||
import {Outlet as PortalOutlet} from '#/components/Portal'
|
import {Outlet as PortalOutlet} from '#/components/Portal'
|
||||||
|
import {RoutesContainer, TabsNavigator} from '#/Navigation'
|
||||||
import {BottomSheetOutlet} from '../../../modules/bottom-sheet'
|
import {BottomSheetOutlet} from '../../../modules/bottom-sheet'
|
||||||
import {updateActiveViewAsync} from '../../../modules/expo-bluesky-swiss-army/src/VisibilityView'
|
import {updateActiveViewAsync} from '../../../modules/expo-bluesky-swiss-army/src/VisibilityView'
|
||||||
import {RoutesContainer, TabsNavigator} from '../../Navigation'
|
|
||||||
import {Composer} from './Composer'
|
import {Composer} from './Composer'
|
||||||
import {DrawerContent} from './Drawer'
|
import {DrawerContent} from './Drawer'
|
||||||
|
|
||||||
function ShellInner() {
|
function ShellInner() {
|
||||||
const t = useNewTheme()
|
const t = useTheme()
|
||||||
const isDrawerOpen = useIsDrawerOpen()
|
const isDrawerOpen = useIsDrawerOpen()
|
||||||
const isDrawerSwipeDisabled = useIsDrawerSwipeDisabled()
|
const isDrawerSwipeDisabled = useIsDrawerSwipeDisabled()
|
||||||
const setIsDrawerOpen = useSetDrawerOpen()
|
const setIsDrawerOpen = useSetDrawerOpen()
|
||||||
const winDim = useWindowDimensions()
|
const winDim = useWindowDimensions()
|
||||||
const insets = useSafeAreaInsets()
|
const insets = useSafeAreaInsets()
|
||||||
|
|
||||||
const renderDrawerContent = React.useCallback(() => <DrawerContent />, [])
|
const renderDrawerContent = useCallback(() => <DrawerContent />, [])
|
||||||
const onOpenDrawer = React.useCallback(
|
const onOpenDrawer = useCallback(
|
||||||
() => setIsDrawerOpen(true),
|
() => setIsDrawerOpen(true),
|
||||||
[setIsDrawerOpen],
|
[setIsDrawerOpen],
|
||||||
)
|
)
|
||||||
const onCloseDrawer = React.useCallback(
|
const onCloseDrawer = useCallback(
|
||||||
() => setIsDrawerOpen(false),
|
() => setIsDrawerOpen(false),
|
||||||
[setIsDrawerOpen],
|
[setIsDrawerOpen],
|
||||||
)
|
)
|
||||||
@@ -59,7 +57,7 @@ function ShellInner() {
|
|||||||
useNotificationsRegistration()
|
useNotificationsRegistration()
|
||||||
useNotificationsHandler()
|
useNotificationsHandler()
|
||||||
|
|
||||||
React.useEffect(() => {
|
useEffect(() => {
|
||||||
if (isAndroid) {
|
if (isAndroid) {
|
||||||
const listener = BackHandler.addEventListener('hardwareBackPress', () => {
|
const listener = BackHandler.addEventListener('hardwareBackPress', () => {
|
||||||
return closeAnyActiveElement()
|
return closeAnyActiveElement()
|
||||||
@@ -79,7 +77,7 @@ function ShellInner() {
|
|||||||
// To be certain though, we will also dedupe these calls.
|
// To be certain though, we will also dedupe these calls.
|
||||||
const navigation = useNavigation()
|
const navigation = useNavigation()
|
||||||
const dedupe = useDedupe(1000)
|
const dedupe = useDedupe(1000)
|
||||||
React.useEffect(() => {
|
useEffect(() => {
|
||||||
if (!isAndroid) return
|
if (!isAndroid) return
|
||||||
const onFocusOrBlur = () => {
|
const onFocusOrBlur = () => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@@ -132,24 +130,18 @@ function ShellInner() {
|
|||||||
|
|
||||||
export const Shell: React.FC = function ShellImpl() {
|
export const Shell: React.FC = function ShellImpl() {
|
||||||
const {fullyExpandedCount} = useDialogStateControlContext()
|
const {fullyExpandedCount} = useDialogStateControlContext()
|
||||||
const theme = useTheme()
|
const t = useTheme()
|
||||||
const pal = usePalette('default')
|
|
||||||
useIntentHandler()
|
useIntentHandler()
|
||||||
|
|
||||||
React.useEffect(() => {
|
useEffect(() => {
|
||||||
if (isAndroid) {
|
setNavigationBar('theme', t)
|
||||||
NavigationBar.setBackgroundColorAsync(theme.palette.default.background)
|
}, [t])
|
||||||
NavigationBar.setBorderColorAsync(theme.palette.default.background)
|
|
||||||
NavigationBar.setButtonStyleAsync(
|
|
||||||
theme.colorScheme === 'dark' ? 'light' : 'dark',
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}, [theme])
|
|
||||||
return (
|
return (
|
||||||
<View testID="mobileShellView" style={[styles.outerContainer, pal.view]}>
|
<View testID="mobileShellView" style={[a.h_full, t.atoms.bg]}>
|
||||||
<StatusBar
|
<StatusBar
|
||||||
style={
|
style={
|
||||||
theme.colorScheme === 'dark' || (isIOS && fullyExpandedCount > 0)
|
t.name !== 'light' || (isIOS && fullyExpandedCount > 0)
|
||||||
? 'light'
|
? 'light'
|
||||||
: 'dark'
|
: 'dark'
|
||||||
}
|
}
|
||||||
@@ -161,9 +153,3 @@ export const Shell: React.FC = function ShellImpl() {
|
|||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
|
||||||
outerContainer: {
|
|
||||||
height: '100%',
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|||||||
Reference in New Issue
Block a user