From 379779735e4845857fcfd9bd3468f2181f2ff818 Mon Sep 17 00:00:00 2001 From: austinried <4966622+austinried@users.noreply.github.com> Date: Wed, 30 Jun 2021 09:13:35 +0900 Subject: [PATCH] made gradient background move with scroll --- src/components/common/AlbumView.tsx | 12 ++++----- src/components/common/GradientBackground.tsx | 26 ++++++++++++++++++++ src/components/common/GradientFlatList.tsx | 19 ++++++++++++++ src/components/library/AlbumsTab.tsx | 17 ++++++------- src/components/library/ArtistsTab.tsx | 11 ++++----- src/components/library/PlaylistsTab.tsx | 5 ++-- 6 files changed, 65 insertions(+), 25 deletions(-) create mode 100644 src/components/common/GradientBackground.tsx create mode 100644 src/components/common/GradientFlatList.tsx diff --git a/src/components/common/AlbumView.tsx b/src/components/common/AlbumView.tsx index 8fd1311..15c1610 100644 --- a/src/components/common/AlbumView.tsx +++ b/src/components/common/AlbumView.tsx @@ -8,7 +8,7 @@ import { albumAtomFamily } from '../../state/music'; import colors from '../../styles/colors'; import text from '../../styles/text'; import AlbumCover from './AlbumCover'; -import TopTabContainer from './TopTabContainer'; +import GradientBackground from './GradientBackground'; function secondsToTime(s: number): string { const seconds = s % 60; @@ -142,7 +142,9 @@ const AlbumDetails: React.FC<{ alignItems: 'center', paddingTop: coverSize / 8, }} + overScrollMode='never' > + - Loading...}> - - - + Loading...}> + + ); }; diff --git a/src/components/common/GradientBackground.tsx b/src/components/common/GradientBackground.tsx new file mode 100644 index 0000000..23e5c52 --- /dev/null +++ b/src/components/common/GradientBackground.tsx @@ -0,0 +1,26 @@ +import React from 'react'; +import { useWindowDimensions } from 'react-native'; +import LinearGradient from 'react-native-linear-gradient'; +import colors from '../../styles/colors'; + +const GradientBackground: React.FC<{ + height?: number | string; + width?: number | string; + position?: 'relative' | 'absolute'; +}> = ({ height, width, position }) => { + const layout = useWindowDimensions(); + + return ( + + ); +}; + +export default GradientBackground; diff --git a/src/components/common/GradientFlatList.tsx b/src/components/common/GradientFlatList.tsx new file mode 100644 index 0000000..9b16a15 --- /dev/null +++ b/src/components/common/GradientFlatList.tsx @@ -0,0 +1,19 @@ +import React from 'react'; +import { FlatList, FlatListProps, useWindowDimensions } from 'react-native'; +import GradientBackground from './GradientBackground'; + +function GradientFlatList(props: FlatListProps) { + const layout = useWindowDimensions(); + + return ( + } + ListHeaderComponentStyle={{ + marginBottom: -layout.height, + }} + /> + ); +}; + +export default GradientFlatList; diff --git a/src/components/library/AlbumsTab.tsx b/src/components/library/AlbumsTab.tsx index efff9da..2483ec4 100644 --- a/src/components/library/AlbumsTab.tsx +++ b/src/components/library/AlbumsTab.tsx @@ -1,14 +1,12 @@ import { useNavigation } from '@react-navigation/native'; import { useAtomValue } from 'jotai/utils'; import React, { useEffect } from 'react'; -import { FlatList, Pressable, Text, View } from 'react-native'; -import FastImage from 'react-native-fast-image'; -import LinearGradient from 'react-native-linear-gradient'; +import { Pressable, Text, View } from 'react-native'; import { Album } from '../../models/music'; import { albumsAtom, albumsUpdatingAtom, useUpdateAlbums } from '../../state/music'; import textStyles from '../../styles/text'; import AlbumCover from '../common/AlbumCover'; -import TopTabContainer from '../common/TopTabContainer'; +import GradientFlatList from '../common/GradientFlatList'; const AlbumItem: React.FC<{ id: string; @@ -76,7 +74,7 @@ const AlbumsList = () => { return ( - item.id} @@ -84,17 +82,16 @@ const AlbumsList = () => { removeClippedSubviews={true} refreshing={updating} onRefresh={updateAlbums} + overScrollMode='never' /> ); } const AlbumsTab = () => ( - - Loading...}> - - - + Loading...}> + + ); export default React.memo(AlbumsTab); diff --git a/src/components/library/ArtistsTab.tsx b/src/components/library/ArtistsTab.tsx index 5c71fc4..af4349e 100644 --- a/src/components/library/ArtistsTab.tsx +++ b/src/components/library/ArtistsTab.tsx @@ -1,10 +1,10 @@ import { useAtomValue } from 'jotai/utils'; import React, { useEffect } from 'react'; -import { FlatList, Image, Text, View } from 'react-native'; +import { Image, Text, View } from 'react-native'; import { Artist } from '../../models/music'; import { artistsAtom, artistsUpdatingAtom, useUpdateArtists } from '../../state/music'; import textStyles from '../../styles/text'; -import TopTabContainer from '../common/TopTabContainer'; +import GradientFlatList from '../common/GradientFlatList'; const ArtistItem: React.FC<{ item: Artist } > = ({ item }) => ( { ); return ( - item.id} onRefresh={updateArtists} refreshing={updating} + overScrollMode='never' /> ); } const ArtistsTab = () => ( - - - + ); export default ArtistsTab; diff --git a/src/components/library/PlaylistsTab.tsx b/src/components/library/PlaylistsTab.tsx index 9755a71..3a68fd9 100644 --- a/src/components/library/PlaylistsTab.tsx +++ b/src/components/library/PlaylistsTab.tsx @@ -1,9 +1,8 @@ import React from 'react'; -import TopTabContainer from '../common/TopTabContainer'; +import GradientBackground from '../common/GradientBackground'; const PlaylistsTab = () => ( - - + ); export default PlaylistsTab;