From caf544069e66101e6624c05059a53dd152ecb556 Mon Sep 17 00:00:00 2001 From: austinried <4966622+austinried@users.noreply.github.com> Date: Mon, 4 Apr 2022 12:48:10 +0900 Subject: [PATCH] switch to useSafeAreaInsets().top (#85) StatusBar.currentHeight seems just broken on some devices --- app/components/GradientScrollView.tsx | 4 ++- app/components/HeaderBar.tsx | 18 ++++++------ app/components/ImageGradientScrollView.tsx | 4 ++- app/navigation/LibraryTopTabNavigator.tsx | 34 ++++++++++++---------- app/screens/Home.tsx | 11 ++++--- app/screens/Search.tsx | 10 +++---- app/screens/ServerView.tsx | 5 +--- app/screens/Settings.tsx | 10 +++---- app/styles/dimensions.ts | 4 --- 9 files changed, 49 insertions(+), 51 deletions(-) diff --git a/app/components/GradientScrollView.tsx b/app/components/GradientScrollView.tsx index ad04afa..e240e4e 100644 --- a/app/components/GradientScrollView.tsx +++ b/app/components/GradientScrollView.tsx @@ -4,6 +4,7 @@ import dimensions from '@app/styles/dimensions' import React, { ForwardedRef, PropsWithChildren } from 'react' import { ScrollView, ScrollViewProps, useWindowDimensions } from 'react-native' import Animated from 'react-native-reanimated' +import { useSafeAreaInsets } from 'react-native-safe-area-context' export type GradientScrollViewProps = PropsWithChildren< Animated.AnimateProps & { @@ -13,8 +14,9 @@ export type GradientScrollViewProps = PropsWithChildren< const GradientScrollView = React.forwardRef((props, ref) => { const layout = useWindowDimensions() + const paddingTop = useSafeAreaInsets().top - const minHeight = layout.height - (dimensions.top() + dimensions.bottom()) + const minHeight = layout.height - (dimensions.header + paddingTop + dimensions.bottom()) return ( (({ title, headerStyle, HeaderCenter, contextItem }) => { const navigation = useNavigation() + const top = useSafeAreaInsets().top const back = useCallback(() => { navigation.goBack() @@ -61,7 +63,7 @@ const HeaderBar = React.memo<{ const _headerStyle = Array.isArray(headerStyle) ? headerStyle : [headerStyle] return ( - + @@ -81,8 +83,6 @@ const HeaderBar = React.memo<{ const styles = StyleSheet.create({ container: { - height: dimensions.top(), - paddingTop: StatusBar.currentHeight, backgroundColor: colors.gradient.high, width: '100%', flexDirection: 'row', diff --git a/app/components/ImageGradientScrollView.tsx b/app/components/ImageGradientScrollView.tsx index 8156ec5..f72d244 100644 --- a/app/components/ImageGradientScrollView.tsx +++ b/app/components/ImageGradientScrollView.tsx @@ -3,11 +3,13 @@ import colors from '@app/styles/colors' import dimensions from '@app/styles/dimensions' import React from 'react' import { ScrollView, ScrollViewProps, useWindowDimensions } from 'react-native' +import { useSafeAreaInsets } from 'react-native-safe-area-context' const ImageGradientScrollView: React.FC = props => { const layout = useWindowDimensions() + const paddingTop = useSafeAreaInsets().top - const minHeight = layout.height - (dimensions.top() + dimensions.bottom()) + const minHeight = layout.height - (dimensions.header + paddingTop + dimensions.bottom()) return ( ( - - - - - -) +const LibraryTopTabNavigator = () => { + const marginTop = useSafeAreaInsets().top + + return ( + + + + + + ) +} const styles = StyleSheet.create({ tabBar: { height: dimensions.header, - marginTop: StatusBar.currentHeight, backgroundColor: colors.gradient.high, elevation: 0, justifyContent: 'center', diff --git a/app/screens/Home.tsx b/app/screens/Home.tsx index 42ecd07..fb2f9a4 100644 --- a/app/screens/Home.tsx +++ b/app/screens/Home.tsx @@ -12,7 +12,8 @@ import { useNavigation } from '@react-navigation/native' import equal from 'fast-deep-equal/es6/react' import produce from 'immer' import React, { useCallback, useState } from 'react' -import { RefreshControl, ScrollView, StatusBar, StyleSheet, Text, View } from 'react-native' +import { RefreshControl, ScrollView, StyleSheet, Text, View } from 'react-native' +import { useSafeAreaInsets } from 'react-native-safe-area-context' import create, { StateSelector } from 'zustand' const titles: { [key in GetAlbumListType]?: string } = { @@ -111,6 +112,7 @@ const Home = () => { const types = useStoreDeep(store => store.settings.screens.home.listTypes) const fetchAlbumList = useStore(store => store.fetchAlbumList) const setList = useHomeStore(store => store.setList) + const paddingTop = useSafeAreaInsets().top const refresh = useCallback(async () => { setRefreshing(true) @@ -135,13 +137,13 @@ const Home = () => { return ( }> @@ -157,9 +159,6 @@ const styles = StyleSheet.create({ scroll: { flex: 1, }, - scrollContentContainer: { - paddingTop: StatusBar.currentHeight, - }, content: { paddingBottom: 20, }, diff --git a/app/screens/Search.tsx b/app/screens/Search.tsx index fc9cad1..2ab12c0 100644 --- a/app/screens/Search.tsx +++ b/app/screens/Search.tsx @@ -5,7 +5,7 @@ import ListItem from '@app/components/ListItem' import NothingHere from '@app/components/NothingHere' import TextInput from '@app/components/TextInput' import { useActiveServerRefresh } from '@app/hooks/settings' -import { Song, Album, Artist, SearchResults } from '@app/models/library' +import { Album, Artist, SearchResults, Song } from '@app/models/library' import { useStore, useStoreDeep } from '@app/state/store' import colors from '@app/styles/colors' import font from '@app/styles/font' @@ -17,11 +17,11 @@ import { ActivityIndicator, InteractionManager, ScrollView, - StatusBar, StyleSheet, TextInput as ReactTextInput, View, } from 'react-native' +import { useSafeAreaInsets } from 'react-native-safe-area-context' const SongItem = React.memo<{ item: Song }>(({ item }) => { const setQueue = useStore(store => store.setQueue) @@ -110,6 +110,7 @@ const Search = () => { const [text, setText] = useState('') const searchBarRef = useRef(null) const scrollRef = useRef(null) + const paddingTop = useSafeAreaInsets().top useFocusEffect( useCallback(() => { @@ -153,7 +154,7 @@ const Search = () => { const resultsCount = results.albums.length + results.artists.length + results.songs.length return ( - + + Address { }) const Settings = () => { + const paddingTop = useSafeAreaInsets().top + return ( - + ) @@ -307,9 +310,6 @@ const styles = StyleSheet.create({ scroll: { flex: 1, }, - scrollContentContainer: { - paddingTop: StatusBar.currentHeight, - }, content: { paddingHorizontal: 20, paddingBottom: 40, diff --git a/app/styles/dimensions.ts b/app/styles/dimensions.ts index 3ba8b69..9dbebf2 100644 --- a/app/styles/dimensions.ts +++ b/app/styles/dimensions.ts @@ -1,14 +1,10 @@ -import { StatusBar } from 'react-native' - const header = 56 const tabBar = 54 -const top = () => header + (StatusBar.currentHeight || 0) const bottom = () => tabBar export default { header, tabBar, - top, bottom, }