diff --git a/apps/mobile/.gitignore b/apps/mobile/.gitignore index 4359542..7e0c02a 100644 --- a/apps/mobile/.gitignore +++ b/apps/mobile/.gitignore @@ -1,7 +1,7 @@ -ios/ -android/ +/ios/ +/android/ # @generated expo-cli sync-2b81b286409207a5da26e14c78851eb30d8ccbdb # The following patterns were generated by expo-cli expo-env.d.ts -# @end expo-cli \ No newline at end of file +# @end expo-cli diff --git a/apps/mobile/app.json b/apps/mobile/app.json index 54025c2..03cbba5 100644 --- a/apps/mobile/app.json +++ b/apps/mobile/app.json @@ -27,7 +27,9 @@ "monochromeImage": "./assets/android-icon-monochrome.png", "foregroundImage": "./assets/android-icon-foreground.png", "backgroundColor": "#C60322" - } + }, + "userInterfaceStyle": "dark", + "softwareKeyboardLayoutMode": "resize" }, "plugins": [ "expo-router", @@ -49,12 +51,23 @@ ], "expo-image", "expo-status-bar", - "expo-app-intents" + "expo-app-intents", + "./plugins/with-android-colors", + [ + "expo-navigation-bar", + { + "enforceContrast": false, + "style": "light" + } + ] ], "experiments": { "typedRoutes": true, "inlineModules": { - "watchedDirectories": ["app-intents"] + "watchedDirectories": [ + "app-intents", + "native" + ] } }, "extra": { diff --git a/apps/mobile/app/(app)/(tabs)/_layout.tsx b/apps/mobile/app/(app)/(tabs)/_layout.tsx index 352876f..051a11c 100644 --- a/apps/mobile/app/(app)/(tabs)/_layout.tsx +++ b/apps/mobile/app/(app)/(tabs)/_layout.tsx @@ -1,37 +1,50 @@ +import { NavigationBar } from "expo-navigation-bar" +import { + AndroidTabThemeProvider, + useAndroidTabPalette, + useAndroidTabSelectedColor, +} from "@/contexts/android-tab-theme" import { DarkTheme, DefaultTheme, ThemeProvider } from "expo-router" import { NativeTabs } from "expo-router/native-tabs" -import { DynamicColorIOS, Platform, useColorScheme } from "react-native" +import { DynamicColorIOS, Platform, View } from "react-native" import { useMemo } from "react" -import { TabBottomAccessory } from "@/components/mini-player" +import { AndroidMiniPlayer, TabBottomAccessory } from "@/components/mini-player" +import { useAndroidKeyboardVisible } from "@/hooks/use-android-keyboard-visible" import { usePlaybackQueue } from "@/contexts/playback" -import { appleMusic, colors } from "@/lib/theme" +import { appleMusic, colors, miniPlayerHeight, useIsDark } from "@/lib/theme" export const unstable_settings = { anchor: "library" } function useRouterTheme() { - const isDark = useColorScheme() === "dark" + const themeIsDark = useIsDark() + const androidPalette = useAndroidTabPalette() + const isDark = Platform.OS === "android" ? androidPalette.isDark : themeIsDark return useMemo(() => { const palette = isDark ? colors.dark : colors.light + const android = Platform.OS === "android" ? androidPalette : null const base = isDark ? DarkTheme : DefaultTheme return { ...base, colors: { ...base.colors, - background: palette.background, - card: palette.card, - text: palette.foreground, - border: palette.border, - primary: palette.primary, + background: android?.background ?? palette.background, + card: android?.surface ?? palette.card, + text: android?.foreground ?? palette.foreground, + border: android?.divider ?? palette.border, + primary: android?.accentText ?? palette.primary, }, } - }, [isDark]) + }, [isDark, androidPalette]) } function useNativeTabColors() { - const isDark = useColorScheme() === "dark" + const selectedColor = useAndroidTabSelectedColor() + const themeIsDark = useIsDark() + const androidPalette = useAndroidTabPalette() + const isDark = Platform.OS === "android" ? androidPalette.isDark : themeIsDark const inactive = appleMusic.tabInactive const iconColor = @@ -41,24 +54,23 @@ function useNativeTabColors() { selected: appleMusic.pink, } : { - default: isDark ? inactive : "#636366", - selected: appleMusic.pink, + default: androidPalette.secondaryForeground, + selected: selectedColor, } const labelColor = Platform.OS === "ios" ? DynamicColorIOS({ dark: inactive, light: "#636366" }) - : isDark - ? inactive - : "#636366" + : androidPalette.secondaryForeground return { isDark, + tintColor: Platform.OS === "android" ? selectedColor : appleMusic.pink, iconColor, labelStyle: { default: { color: labelColor, fontSize: 10 }, selected: { - color: appleMusic.pink, + color: Platform.OS === "android" ? selectedColor : appleMusic.pink, fontSize: 10, fontWeight: "600" as const, }, @@ -67,57 +79,93 @@ function useNativeTabColors() { ? "systemChromeMaterialDark" : "systemChromeMaterialLight", backgroundColor: - Platform.OS === "ios" - ? undefined - : isDark - ? appleMusic.background - : colors.light.background, + Platform.OS === "ios" ? undefined : androidPalette.background, } } -export default function TabsLayout() { +function TabsContent() { + const keyboardVisible = useAndroidKeyboardVisible() const routerTheme = useRouterTheme() const tabColors = useNativeTabColors() const { currentSong, queueSongIds } = usePlaybackQueue() const showBottomAccessory = Boolean(currentSong && queueSongIds.length > 0) + // NativeTabs already owns the tab bar and system navigation insets. + const androidContentStyle = + Platform.OS === "android" + ? { + paddingBottom: + showBottomAccessory && !keyboardVisible ? miniPlayerHeight : 0, + } + : undefined + return ( - - {showBottomAccessory ? ( - - - + + {Platform.OS === "android" ? ( + ) : null} + + {Platform.OS === "ios" && showBottomAccessory ? ( + + + + ) : null} - - - Home - + + + Home + - - - Library - + + + Library + - - - Search - - + + + Search + + + {!keyboardVisible ? : null} + ) } + +export default function TabsLayout() { + if (Platform.OS !== "android") return + return ( + + + + ) +} diff --git a/apps/mobile/app/(app)/(tabs)/home/_layout.tsx b/apps/mobile/app/(app)/(tabs)/home/_layout.tsx index 87b926d..195b95a 100644 --- a/apps/mobile/app/(app)/(tabs)/home/_layout.tsx +++ b/apps/mobile/app/(app)/(tabs)/home/_layout.tsx @@ -1,4 +1,5 @@ import { Stack } from "expo-router" +import { Platform } from "react-native" import { ProfileHeaderButton } from "@/components/profile-header-button" import { tabStackScreenTitles, useStackScreenOptions } from "@/lib/navigation" @@ -14,6 +15,10 @@ export default function HomeLayout() { ({ ...baseOptions, + ...(Platform.OS === "android" && + (route.name === "album/[id]" || route.name === "playlist/[id]") + ? { animation: "none" as const } + : {}), title: tabStackScreenTitles[route.name] ?? "Home", headerRight: route.name === "index" ? () => : undefined, diff --git a/apps/mobile/app/(app)/(tabs)/home/album/[id].tsx b/apps/mobile/app/(app)/(tabs)/home/album/[id].tsx index 8c7c878..9a71030 100644 --- a/apps/mobile/app/(app)/(tabs)/home/album/[id].tsx +++ b/apps/mobile/app/(app)/(tabs)/home/album/[id].tsx @@ -1,8 +1,16 @@ +import { useAndroidScreenPalette } from "@/contexts/android-tab-theme" import { MusicEntityView } from "@/components/music-entity-view" import { Stack, useIsFocused, useLocalSearchParams } from "expo-router" import { StatusBar } from "expo-status-bar" import { memo, useCallback, useEffect, useMemo } from "react" -import { FlatList, Pressable, StyleSheet, Text, View } from "react-native" +import { + FlatList, + Platform, + Pressable, + StyleSheet, + Text, + View, +} from "react-native" import { Ionicons } from "@expo/vector-icons" import { @@ -57,10 +65,11 @@ export default function AlbumScreen() { const isFocused = useIsFocused() const coverUri = config && typeof id === "string" ? albumCoverUrl(config.serverUrl, id) : "" - const { palette, settled } = useCoverPalette( + const { palette: artworkPalette, settled } = useCoverPalette( coverUri, album ? album.cover != null : album === null ? false : undefined ) + const { palette, onLayout } = useAndroidScreenPalette(artworkPalette) const songIds = useMemo( () => album?.tracks.map((track) => track.id as Id<"songs">) ?? [], [album] @@ -147,6 +156,14 @@ export default function AlbumScreen() { title: "", headerLargeTitle: false, headerTintColor: palette.foreground, + ...(Platform.OS === "android" + ? { + headerStyle: { backgroundColor: palette.background }, + statusBarStyle: palette.isDark + ? ("light" as const) + : ("dark" as const), + } + : {}), headerRight: () => ( { rememberSongs(songs) @@ -146,6 +148,7 @@ export default function PlaylistScreen() { return ( void playlist: BrowsePlaylistDetail songs: BrowseSong[] allSongIds: Id<"songs">[] | undefined @@ -269,6 +274,14 @@ function PlaylistContent({ title: "", headerLargeTitle: false, headerTintColor: palette.foreground, + ...(Platform.OS === "android" + ? { + headerStyle: { backgroundColor: palette.background }, + statusBarStyle: palette.isDark + ? ("light" as const) + : ("dark" as const), + } + : {}), headerRight: () => ( {user.isAdmin ? ( {subtitle} ) : null} - + ) } diff --git a/apps/mobile/app/(app)/(tabs)/library/_layout.tsx b/apps/mobile/app/(app)/(tabs)/library/_layout.tsx index e3d9b68..1620b26 100644 --- a/apps/mobile/app/(app)/(tabs)/library/_layout.tsx +++ b/apps/mobile/app/(app)/(tabs)/library/_layout.tsx @@ -1,4 +1,5 @@ import { Stack } from "expo-router" +import { Platform } from "react-native" import { ProfileHeaderButton } from "@/components/profile-header-button" import { tabStackScreenTitles, useStackScreenOptions } from "@/lib/navigation" @@ -14,6 +15,10 @@ export default function LibraryLayout() { ({ ...baseOptions, + ...(Platform.OS === "android" && + (route.name === "album/[id]" || route.name === "playlist/[id]") + ? { animation: "none" as const } + : {}), title: tabStackScreenTitles[route.name] ?? "Library", headerRight: route.name === "index" ? () => : undefined, diff --git a/apps/mobile/app/(app)/(tabs)/search/_layout.tsx b/apps/mobile/app/(app)/(tabs)/search/_layout.tsx index 288328a..dcea4b1 100644 --- a/apps/mobile/app/(app)/(tabs)/search/_layout.tsx +++ b/apps/mobile/app/(app)/(tabs)/search/_layout.tsx @@ -1,4 +1,5 @@ import { Stack } from "expo-router" +import { Platform } from "react-native" import { ProfileHeaderButton } from "@/components/profile-header-button" import { tabStackScreenTitles, useStackScreenOptions } from "@/lib/navigation" @@ -14,6 +15,10 @@ export default function SearchLayout() { ({ ...baseOptions, + ...(Platform.OS === "android" && + (route.name === "album/[id]" || route.name === "playlist/[id]") + ? { animation: "none" as const } + : {}), title: tabStackScreenTitles[route.name] ?? "Search", headerRight: route.name === "index" ? () => : undefined, diff --git a/apps/mobile/app/(app)/(tabs)/search/index.tsx b/apps/mobile/app/(app)/(tabs)/search/index.tsx index 7cb6756..1dc5e39 100644 --- a/apps/mobile/app/(app)/(tabs)/search/index.tsx +++ b/apps/mobile/app/(app)/(tabs)/search/index.tsx @@ -1,3 +1,5 @@ +import { Platform } from "react-native" +import { useThemeColors } from "@/lib/theme" import { Stack } from "expo-router" import { useCallback } from "react" @@ -5,6 +7,7 @@ import { SearchResults } from "@/components/search-results" import { useDebouncedSearch } from "@/hooks/use-debounced-search" export default function SearchScreen() { + const colors = useThemeColors() const { searchQuery, onQueryChange, onSearchSubmit } = useDebouncedSearch() const handleChangeText = useCallback( @@ -21,6 +24,15 @@ export default function SearchScreen() { onChangeText={handleChangeText} onSearchButtonPress={onSearchSubmit} autoCapitalize="none" + {...(Platform.OS === "android" + ? { + barTintColor: colors.background, + textColor: colors.foreground, + tintColor: colors.primary, + hintTextColor: colors.mutedForeground, + headerIconColor: colors.foreground, + } + : {})} /> diff --git a/apps/mobile/app/(app)/_layout.tsx b/apps/mobile/app/(app)/_layout.tsx index 186accd..5efd2ff 100644 --- a/apps/mobile/app/(app)/_layout.tsx +++ b/apps/mobile/app/(app)/_layout.tsx @@ -66,7 +66,8 @@ export default function AppLayout() { (null) @@ -216,6 +218,14 @@ export default function PlayerScreen() { return ( + {Platform.OS === "android" ? ( + <> + + + + ) : null} - - } - trailing={ - - } - /> + {volumeAvailable ? ( + + } + trailing={ + + } + /> + ) : null} - - - + + return ( + + + + ) +} diff --git a/apps/mobile/app/_layout.tsx b/apps/mobile/app/_layout.tsx index 51c5f71..40c8ce4 100644 --- a/apps/mobile/app/_layout.tsx +++ b/apps/mobile/app/_layout.tsx @@ -1,7 +1,7 @@ import { useConvexAuth } from "@convex-dev/auth/react" import { DarkTheme, Stack, ThemeProvider } from "expo-router" import { StatusBar } from "expo-status-bar" -import { useColorScheme } from "react-native" +import { useIsDark } from "@/lib/theme" import { GestureHandlerRootView } from "react-native-gesture-handler" import { SafeAreaProvider } from "react-native-safe-area-context" @@ -47,14 +47,14 @@ function RootNavigator() { } export default function RootLayout() { - const colorScheme = useColorScheme() + const isDark = useIsDark() return ( - + diff --git a/apps/mobile/app/server.tsx b/apps/mobile/app/server.tsx index 036c79b..6433fc3 100644 --- a/apps/mobile/app/server.tsx +++ b/apps/mobile/app/server.tsx @@ -1,13 +1,9 @@ import { useState } from "react" -import { - KeyboardAvoidingView, - Platform, - StyleSheet, - Text, - View, -} from "react-native" +import { StyleSheet, Text, View } from "react-native" import { SafeAreaView } from "react-native-safe-area-context" +import { KeyboardForm } from "@/components/keyboard-form" + import { Button, Card, Input } from "@/components/ui/primitives" import { useServerConfig } from "@/contexts/server-config" import { spacing, useThemeColors } from "@/lib/theme" @@ -41,10 +37,7 @@ export default function ServerScreen() { return ( - + oTunes @@ -82,7 +75,7 @@ export default function ServerScreen() { onPress={() => void handleContinue()} /> - + ) } diff --git a/apps/mobile/components/android-sheet.tsx b/apps/mobile/components/android-sheet.tsx new file mode 100644 index 0000000..840bc8e --- /dev/null +++ b/apps/mobile/components/android-sheet.tsx @@ -0,0 +1,15 @@ +import type { PropsWithChildren } from "react" +import { KeyboardAvoidingView, Platform } from "react-native" +import { SafeAreaView } from "react-native-safe-area-context" + +/** RN modals have their own window; protect their actions from navigation and IME. */ +export function AndroidSheet({ children }: PropsWithChildren) { + if (Platform.OS !== "android") return children + return ( + + + {children} + + + ) +} diff --git a/apps/mobile/components/audio-output-button.tsx b/apps/mobile/components/audio-output-button.tsx new file mode 100644 index 0000000..d0952ad --- /dev/null +++ b/apps/mobile/components/audio-output-button.tsx @@ -0,0 +1,71 @@ +import { + requireNativeView, + requireOptionalNativeModule, + type NativeModule, +} from "expo" +import { + Platform, + Pressable, + type StyleProp, + type ViewProps, + type ViewStyle, +} from "react-native" + +import { PlayerSymbol } from "@/components/player-symbol" +import { showError } from "@/lib/toast" + +type AudioOutputModule = NativeModule & { + showPicker: () => Promise +} + +const audioOutput = + requireOptionalNativeModule("AudioOutput") +const AirPlayPicker = + Platform.OS === "ios" && audioOutput + ? requireNativeView("AudioOutput") + : null + +export function AudioOutputButton({ + color, + style, +}: { + color: string + style: StyleProp +}) { + if (AirPlayPicker) { + return + } + + const available = + Platform.OS === "android" && Platform.Version >= 33 && audioOutput !== null + + async function showPicker() { + try { + if (!(await audioOutput?.showPicker())) { + showError("Audio output selection is unavailable on this device.") + } + } catch { + showError("Audio output selection could not be opened.") + } + } + + return ( + + + + ) +} diff --git a/apps/mobile/components/auth-form.tsx b/apps/mobile/components/auth-form.tsx index 407acfd..42b0792 100644 --- a/apps/mobile/components/auth-form.tsx +++ b/apps/mobile/components/auth-form.tsx @@ -2,16 +2,11 @@ import { useAuthActions } from "@convex-dev/auth/react" import { Link } from "expo-router" import { useQuery } from "convex/react" import { useState } from "react" -import { - KeyboardAvoidingView, - Platform, - Pressable, - StyleSheet, - Text, - View, -} from "react-native" +import { Pressable, StyleSheet, Text, View } from "react-native" import { SafeAreaView } from "react-native-safe-area-context" +import { KeyboardForm } from "@/components/keyboard-form" + import { Button, Card, Input } from "@/components/ui/primitives" import { useServerConfig } from "@/contexts/server-config" import { api } from "@otunes/convex/_generated/api" @@ -92,14 +87,15 @@ export function AuthForm({ flow }: { flow: AuthFlow }) { return ( - + - {text.title} - + + {text.title} + + {text.description} {config ? ( @@ -111,8 +107,8 @@ export function AuthForm({ flow }: { flow: AuthFlow }) { {signupsDisabled ? ( - New account registration is currently disabled. Contact an administrator if you need - access. + New account registration is currently disabled. Contact an + administrator if you need access. ) : ( @@ -137,16 +133,28 @@ export function AuthForm({ flow }: { flow: AuthFlow }) { onChangeText={setPassword} placeholder="Password" secureTextEntry - autoComplete={flow === "signIn" ? "current-password" : "new-password"} + autoComplete={ + flow === "signIn" ? "current-password" : "new-password" + } + /> + {error ? ( + {error} + ) : null} +