From cd9ae9633cc9fa0c61131ff01b6473f2b1508717 Mon Sep 17 00:00:00 2001 From: austinried <4966622+austinried@users.noreply.github.com> Date: Fri, 9 Jul 2021 20:39:14 +0900 Subject: [PATCH] add stacks for home/search so they can access album/artist/etc screen --- app/components/PressableOpacity.tsx | 5 ++ app/navigation/BottomTabNavigator.tsx | 103 ++++++++++++++++++++-- app/navigation/LibraryTopTabNavigator.tsx | 75 ++-------------- app/screens/Home.tsx | 1 - app/screens/LibraryAlbums.tsx | 7 +- app/screens/NowPlayingLayout.tsx | 2 +- index.js | 3 + 7 files changed, 113 insertions(+), 83 deletions(-) diff --git a/app/components/PressableOpacity.tsx b/app/components/PressableOpacity.tsx index a442312..89e3190 100644 --- a/app/components/PressableOpacity.tsx +++ b/app/components/PressableOpacity.tsx @@ -15,6 +15,11 @@ const PressableOpacity: React.FC = props => { props.disabled === true ? setOpacity(0.3) : setOpacity(1) }, [props.disabled]) + props = { + ...props, + unstable_pressDelay: props.unstable_pressDelay === undefined ? 60 : props.unstable_pressDelay, + } + return ( +type TabMainScreenRouteProp = RouteProp +type TabMainScreenProps = { + route: TabMainScreenRouteProp + navigation: TabMainScreenNavigationProp +} + +type AlbumScreenNavigationProp = NativeStackNavigationProp +type AlbumScreenRouteProp = RouteProp +type AlbumScreenProps = { + route: AlbumScreenRouteProp + navigation: AlbumScreenNavigationProp +} + +const AlbumScreen: React.FC = ({ route }) => ( + +) + +type ArtistScreenNavigationProp = NativeStackNavigationProp +type ArtistScreenRouteProp = RouteProp +type ArtistScreenProps = { + route: ArtistScreenRouteProp + navigation: ArtistScreenNavigationProp +} + +const ArtistScreen: React.FC = ({ route }) => ( + +) + +const styles = StyleSheet.create({ + stackheaderStyle: { + backgroundColor: colors.gradient.high, + }, + stackheaderTitleStyle: { + fontSize: 18, + fontFamily: font.semiBold, + color: colors.text.primary, + }, +}) + +const itemScreenOptions = { + title: '', + headerStyle: styles.stackheaderStyle, + headerHideShadow: true, + headerTintColor: 'white', + headerTitleStyle: styles.stackheaderTitleStyle, +} + +function createTabStackNavigator(Component: React.ComponentType) { + const Stack = createNativeStackNavigator() + + const Navigator: React.FC<{ navigation: BottomTabNavigationProp<{ a: undefined }, 'a'> }> = ({ navigation }) => { + useEffect(() => { + return navigation.addListener('tabPress', () => { + navigation.dispatch(StackActions.popToTop()) + }) + }) + + return ( + + + + + + ) + } + + return Navigator +} + +const HomeTab = createTabStackNavigator(Home) +const LibraryTab = createTabStackNavigator(LibraryTopTabNavigator) +const SearchTab = createTabStackNavigator(ArtistsList) const Tab = createBottomTabNavigator() const BottomTabNavigator = () => { return ( - - - + + + ) diff --git a/app/navigation/LibraryTopTabNavigator.tsx b/app/navigation/LibraryTopTabNavigator.tsx index a36eb1f..7701457 100644 --- a/app/navigation/LibraryTopTabNavigator.tsx +++ b/app/navigation/LibraryTopTabNavigator.tsx @@ -1,44 +1,12 @@ -import React from 'react' -import { StatusBar, StyleSheet, View } from 'react-native' -import { createMaterialTopTabNavigator } from '@react-navigation/material-top-tabs' import AlbumsTab from '@app/screens/LibraryAlbums' import ArtistsTab from '@app/screens/LibraryArtists' import PlaylistsTab from '@app/screens/LibraryPlaylists' -import { createNativeStackNavigator, NativeStackNavigationProp } from 'react-native-screens/native-stack' -import AlbumView from '@app/screens/AlbumView' -import { RouteProp } from '@react-navigation/native' -import font from '@app/styles/font' import colors from '@app/styles/colors' -import ArtistView from '@app/screens/ArtistView' import dimensions from '@app/styles/dimensions' - -type LibraryStackParamList = { - LibraryTopTabs: undefined - AlbumView: { id: string; title: string } - ArtistView: { id: string; title: string } -} - -type AlbumScreenNavigationProp = NativeStackNavigationProp -type AlbumScreenRouteProp = RouteProp -type AlbumScreenProps = { - route: AlbumScreenRouteProp - navigation: AlbumScreenNavigationProp -} - -const AlbumScreen: React.FC = ({ route }) => ( - -) - -type ArtistScreenNavigationProp = NativeStackNavigationProp -type ArtistScreenRouteProp = RouteProp -type ArtistScreenProps = { - route: ArtistScreenRouteProp - navigation: ArtistScreenNavigationProp -} - -const ArtistScreen: React.FC = ({ route }) => ( - -) +import font from '@app/styles/font' +import { createMaterialTopTabNavigator } from '@react-navigation/material-top-tabs' +import React from 'react' +import { StatusBar, StyleSheet } from 'react-native' const Tab = createMaterialTopTabNavigator() @@ -55,40 +23,7 @@ const LibraryTopTabNavigator = () => ( ) -const Stack = createNativeStackNavigator() - -const LibraryStackNavigator = () => { - const itemScreenOptions = { - title: '', - headerStyle: styles.stackheaderStyle, - headerHideShadow: true, - headerTintColor: 'white', - headerTitleStyle: styles.stackheaderTitleStyle, - } - - return ( - - - - - - - - ) -} - const styles = StyleSheet.create({ - stackContainer: { - flex: 1, - }, - stackheaderStyle: { - backgroundColor: colors.gradient.high, - }, - stackheaderTitleStyle: { - fontSize: 18, - fontFamily: font.semiBold, - color: colors.text.primary, - }, tabBar: { height: dimensions.header, marginTop: StatusBar.currentHeight, @@ -109,4 +44,4 @@ const styles = StyleSheet.create({ }, }) -export default LibraryStackNavigator +export default LibraryTopTabNavigator diff --git a/app/screens/Home.tsx b/app/screens/Home.tsx index 1b66db1..e0665da 100644 --- a/app/screens/Home.tsx +++ b/app/screens/Home.tsx @@ -33,7 +33,6 @@ const Category: React.FC<{ {list.map(album => ( navigation.navigate('AlbumView', { id: album.id, title: album.name })} - unstable_pressDelay={50} key={album.id} style={styles.item}> navigation.navigate('AlbumView', { id, title: name })}> @@ -31,7 +32,7 @@ const AlbumItem: React.FC<{ {artist} - + ) } const MemoAlbumItem = React.memo(AlbumItem) diff --git a/app/screens/NowPlayingLayout.tsx b/app/screens/NowPlayingLayout.tsx index 210316f..7270b53 100644 --- a/app/screens/NowPlayingLayout.tsx +++ b/app/screens/NowPlayingLayout.tsx @@ -2,7 +2,6 @@ import { useNavigation } from '@react-navigation/native' import { useAtomValue } from 'jotai/utils' import React, { useEffect } from 'react' import { StatusBar, StyleSheet, Text, View } from 'react-native' -import { NativeStackScreenProps } from 'react-native-screens/lib/typescript/native-stack' import { State } from 'react-native-track-player' import IconFA from 'react-native-vector-icons/FontAwesome' import IconFA5 from 'react-native-vector-icons/FontAwesome5' @@ -26,6 +25,7 @@ import CoverArt from '@app/components/CoverArt' import ImageGradientBackground from '@app/components/ImageGradientBackground' import PressableOpacity from '@app/components/PressableOpacity' import dimensions from '@app/styles/dimensions' +import { NativeStackScreenProps } from 'react-native-screens/native-stack' const NowPlayingHeader = () => { const queueName = useAtomValue(queueNameAtom) diff --git a/index.js b/index.js index 014195f..48b4682 100644 --- a/index.js +++ b/index.js @@ -4,6 +4,9 @@ import 'react-native-get-random-values' import { enableScreens } from 'react-native-screens' enableScreens() +import { LogBox } from 'react-native' +LogBox.ignoreLogs(["The action 'POP_TO_TOP'"]) + import { AppRegistry } from 'react-native' import App from '@app/App' import { name as appName } from '@app/app.json'