diff --git a/packages/mobile/ios/AudiusReactNative.xcodeproj/project.pbxproj b/packages/mobile/ios/AudiusReactNative.xcodeproj/project.pbxproj index b4fbde5fe32..2b9c128b845 100644 --- a/packages/mobile/ios/AudiusReactNative.xcodeproj/project.pbxproj +++ b/packages/mobile/ios/AudiusReactNative.xcodeproj/project.pbxproj @@ -18,6 +18,7 @@ 43C373D295154DA6B89272D5 /* Colors.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 04F6B3542BF84180BC937315 /* Colors.xcassets */; }; 5983D8FED74747CCA45F8FC4 /* AvenirNextLTPro-Medium.otf in Resources */ = {isa = PBXBuildFile; fileRef = 33E11CC84EEA4109B8A1AE2C /* AvenirNextLTPro-Medium.otf */; }; 5CE1A0022EA1000000A1B2C3 /* SceneDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5CE1A0012EA1000000A1B2C3 /* SceneDelegate.mm */; }; + 5CE1B0022EA1000000A1B2C3 /* AudiusHinge.m in Sources */ = {isa = PBXBuildFile; fileRef = 5CE1B0012EA1000000A1B2C3 /* AudiusHinge.m */; }; 7103C3ED2929C6B5002B9072 /* BootSplash.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7103C3EC2929C6B5002B9072 /* BootSplash.storyboard */; }; 717F36E82733C73F0017511F /* AvenirNextLTPro-DemiBold.otf in Resources */ = {isa = PBXBuildFile; fileRef = 717F36E72733C73F0017511F /* AvenirNextLTPro-DemiBold.otf */; }; 838AABE023CE3813004B2DA3 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 838AABDF23CE3813004B2DA3 /* GoogleService-Info.plist */; }; @@ -78,6 +79,8 @@ 453FC09EC343ACA359EB312C /* Pods-AudiusReactNative.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AudiusReactNative.release.xcconfig"; path = "Target Support Files/Pods-AudiusReactNative/Pods-AudiusReactNative.release.xcconfig"; sourceTree = ""; }; 5CE1A0002EA1000000A1B2C3 /* SceneDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SceneDelegate.h; path = AudiusReactNative/SceneDelegate.h; sourceTree = ""; }; 5CE1A0012EA1000000A1B2C3 /* SceneDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = SceneDelegate.mm; path = AudiusReactNative/SceneDelegate.mm; sourceTree = ""; }; + 5CE1B0002EA1000000A1B2C3 /* AudiusHinge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AudiusHinge.h; path = AudiusReactNative/AudiusHinge.h; sourceTree = ""; }; + 5CE1B0012EA1000000A1B2C3 /* AudiusHinge.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AudiusHinge.m; path = AudiusReactNative/AudiusHinge.m; sourceTree = ""; }; 622045C334F0F16E3CF4011F /* libPods-AudiusReactNative.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-AudiusReactNative.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 6F65A9A9BAD047FABD240C59 /* AvenirNextLTPro-Regular.otf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = unknown; name = "AvenirNextLTPro-Regular.otf"; path = "../src/assets/fonts/AvenirNextLTPro-Regular.otf"; sourceTree = ""; }; 7103C3EC2929C6B5002B9072 /* BootSplash.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = BootSplash.storyboard; path = AudiusReactNative/BootSplash.storyboard; sourceTree = ""; }; @@ -145,6 +148,8 @@ 13B07FB01A68108700A75B9A /* AppDelegate.mm */, 5CE1A0002EA1000000A1B2C3 /* SceneDelegate.h */, 5CE1A0012EA1000000A1B2C3 /* SceneDelegate.mm */, + 5CE1B0002EA1000000A1B2C3 /* AudiusHinge.h */, + 5CE1B0012EA1000000A1B2C3 /* AudiusHinge.m */, 13B07FB51A68108700A75B9A /* Images.xcassets */, 13B07FB61A68108700A75B9A /* Info.plist */, 7103C3EC2929C6B5002B9072 /* BootSplash.storyboard */, @@ -475,6 +480,7 @@ 253BCCFA2B324974007DC74C /* NSureSDK.m in Sources */, 13B07FBC1A68108700A75B9A /* AppDelegate.mm in Sources */, 5CE1A0022EA1000000A1B2C3 /* SceneDelegate.mm in Sources */, + 5CE1B0022EA1000000A1B2C3 /* AudiusHinge.m in Sources */, 83F7359F23C55C2D0040A4C5 /* AirplayViewManager.m in Sources */, 13B32CE723D2782B002F0526 /* SampleSwiftFile.swift in Sources */, 83F735A523C64C950040A4C5 /* AirplayEvent.m in Sources */, diff --git a/packages/mobile/ios/AudiusReactNative/AudiusHinge.h b/packages/mobile/ios/AudiusReactNative/AudiusHinge.h new file mode 100644 index 00000000000..027d594e112 --- /dev/null +++ b/packages/mobile/ios/AudiusReactNative/AudiusHinge.h @@ -0,0 +1,11 @@ +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface AudiusHinge : NSObject + ++ (void)observeHingeForView:(UIView *)view; + +@end + +NS_ASSUME_NONNULL_END diff --git a/packages/mobile/ios/AudiusReactNative/AudiusHinge.m b/packages/mobile/ios/AudiusReactNative/AudiusHinge.m new file mode 100644 index 00000000000..9b38100808e --- /dev/null +++ b/packages/mobile/ios/AudiusReactNative/AudiusHinge.m @@ -0,0 +1,108 @@ +#import "AudiusHinge.h" + +#import +#import + +static NSString *const AudiusHingeDidChangeNotification = @"AudiusHingeDidChange"; +static NSDictionary *latestHingeState = nil; + +@interface AudiusHingeEmitter : RCTEventEmitter +@end + +@implementation AudiusHinge + ++ (void)observeHingeForView:(UIView *)view +{ +#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 270100 + if (@available(iOS 27.1, *)) { + UIHingeInteraction *interaction = [[UIHingeInteraction alloc] + initWithUpdateHandler:^(UIHingeInteraction *_, UIHingeInteractionUpdate *update) { + UIHinge *hinge = update.hinge; + NSDictionary *state; + if (hinge == nil) { + state = @{@"available" : @NO}; + } else { + NSString *status; + switch (hinge.status) { + case UIHingeStatusClosed: + status = @"closed"; + break; + case UIHingeStatusPartiallyOpen: + status = @"partiallyOpen"; + break; + case UIHingeStatusFullyOpen: + status = @"fullyOpen"; + break; + default: + status = @"unknown"; + break; + } + state = @{ + @"available" : @YES, + @"status" : status, + @"angle" : @(hinge.angle * 180.0 / M_PI) + }; + } + latestHingeState = state; + [[NSNotificationCenter defaultCenter] postNotificationName:AudiusHingeDidChangeNotification + object:nil + userInfo:state]; + }]; + [view addInteraction:interaction]; + } +#endif +} + +@end + +@implementation AudiusHingeEmitter { + BOOL _hasListeners; +} + +RCT_EXPORT_MODULE(AudiusHinge); + ++ (BOOL)requiresMainQueueSetup +{ + return YES; +} + +- (dispatch_queue_t)methodQueue +{ + return dispatch_get_main_queue(); +} + +- (NSArray *)supportedEvents +{ + return @[ @"hingeChanged" ]; +} + +- (void)startObserving +{ + _hasListeners = YES; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(hingeDidChange:) + name:AudiusHingeDidChangeNotification + object:nil]; +} + +- (void)stopObserving +{ + _hasListeners = NO; + [[NSNotificationCenter defaultCenter] removeObserver:self]; +} + +- (void)hingeDidChange:(NSNotification *)notification +{ + if (_hasListeners) { + [self sendEventWithName:@"hingeChanged" body:notification.userInfo]; + } +} + +RCT_EXPORT_METHOD(getState + : (RCTPromiseResolveBlock)resolve rejecter + : (RCTPromiseRejectBlock)reject) +{ + resolve(latestHingeState ?: @{@"available" : @NO}); +} + +@end diff --git a/packages/mobile/ios/AudiusReactNative/SceneDelegate.mm b/packages/mobile/ios/AudiusReactNative/SceneDelegate.mm index 02de38479a9..81ed3608ca9 100644 --- a/packages/mobile/ios/AudiusReactNative/SceneDelegate.mm +++ b/packages/mobile/ios/AudiusReactNative/SceneDelegate.mm @@ -1,5 +1,6 @@ #import "SceneDelegate.h" #import "AppDelegate.h" +#import "AudiusHinge.h" #import #import @@ -16,6 +17,7 @@ - (void)scene:(UIScene *)scene AppDelegate *appDelegate = (AppDelegate *)UIApplication.sharedApplication.delegate; self.window = [appDelegate loadReactNativeWindowInScene:(UIWindowScene *)scene connectionOptions:connectionOptions]; + [AudiusHinge observeHingeForView:self.window]; // React Native reads the launch URL from launchOptions. TikTok still needs // to see it here. diff --git a/packages/mobile/src/components/bottom-tab-bar/BottomTabBar.tsx b/packages/mobile/src/components/bottom-tab-bar/BottomTabBar.tsx index fcd60cc29d9..b8ffe898c75 100644 --- a/packages/mobile/src/components/bottom-tab-bar/BottomTabBar.tsx +++ b/packages/mobile/src/components/bottom-tab-bar/BottomTabBar.tsx @@ -6,12 +6,7 @@ import type { BottomTabBarProps as RNBottomTabBarProps } from '@react-navigation/bottom-tabs' import type { NavigationHelpers, ParamListBase } from '@react-navigation/native' -import { - Animated, - Pressable, - StyleSheet, - useWindowDimensions -} from 'react-native' +import { Animated, Pressable, StyleSheet } from 'react-native' import type { SharedValue } from 'react-native-reanimated' import Reanimated, { interpolate, @@ -24,8 +19,9 @@ import { useSafeAreaInsets } from 'react-native-safe-area-context' import { Flex, IconSearch } from '@audius/harmony-native' import { GlassSurface } from 'app/components/core/Screen/GlassSurface' import { LiquidGlassView } from 'app/components/core/Screen/LiquidGlass' -import { FULL_DRAWER_HEIGHT } from 'app/components/drawer' +import { useFullDrawerHeight } from 'app/components/drawer' import { PLAY_BAR_HEIGHT } from 'app/components/now-playing-drawer' +import { useContentWidth } from 'app/hooks/useContentWidth' import { useIsTabBarCollapsed, useTabBarHiddenProgress @@ -61,18 +57,16 @@ export const bottomTabBarButtons = { const interpolatePostion = ( translationAnim: Animated.Value, - bottomInset: number + bottomInset: number, + fullDrawerHeight: number ) => ({ transform: [ { translateY: translationAnim.interpolate({ inputRange: [ 0, - FULL_DRAWER_HEIGHT - - bottomInset - - BOTTOM_BAR_HEIGHT - - PLAY_BAR_HEIGHT, - FULL_DRAWER_HEIGHT + fullDrawerHeight - bottomInset - BOTTOM_BAR_HEIGHT - PLAY_BAR_HEIGHT, + fullDrawerHeight ], outputRange: [bottomInset + BOTTOM_BAR_HEIGHT, 0, 0] }) @@ -97,6 +91,7 @@ export const BottomTabBar = (props: BottomTabBarProps) => { const { translationAnim, navigation, state } = props const { routes, index: activeIndex } = state const insets = useSafeAreaInsets() + const fullDrawerHeight = useFullDrawerHeight() const floating = useFloatingTabBar() const handlePress = useCallback( @@ -153,7 +148,7 @@ export const BottomTabBar = (props: BottomTabBarProps) => { style={[ styles.floatingRoot, { height: BOTTOM_BAR_HEIGHT + insets.bottom }, - interpolatePostion(translationAnim, insets.bottom) + interpolatePostion(translationAnim, insets.bottom, fullDrawerHeight) ]} > { {/* @@ -207,7 +202,7 @@ const FloatingPill = (props: FloatingPillProps) => { const { bottom, activeIndex, tabCount, onPressSearch, children } = props const isDarkMode = isDarkTheme(useThemeVariant()) const colorScheme = isDarkMode ? 'dark' : 'light' - const { width: windowWidth } = useWindowDimensions() + const windowWidth = useContentWidth() const hidden = useTabBarHiddenProgress() const isCollapsed = useIsTabBarCollapsed() const index = useSharedValue(activeIndex) diff --git a/packages/mobile/src/components/collapsible-tabs/Container.tsx b/packages/mobile/src/components/collapsible-tabs/Container.tsx index 4ca5e8e99a5..af8f49d3639 100644 --- a/packages/mobile/src/components/collapsible-tabs/Container.tsx +++ b/packages/mobile/src/components/collapsible-tabs/Container.tsx @@ -1,5 +1,5 @@ import React from 'react' -import { StyleSheet, useWindowDimensions, View } from 'react-native' +import { StyleSheet, View } from 'react-native' import PagerView from 'react-native-pager-view' import Animated, { useAnimatedReaction, @@ -32,6 +32,7 @@ import { IndexChangeEventData, TabName } from './types' +import { useContentWidth } from 'app/hooks/useContentWidth' const AnimatedPagerView = Animated.createAnimatedComponent(PagerView) @@ -67,7 +68,7 @@ export const Container = React.memo( const [refMap, setRef] = useAnimatedDynamicRefs() - const windowWidth = useWindowDimensions().width + const windowWidth = useContentWidth() const width = customWidth ?? windowWidth const [containerHeight, getContainerLayoutHeight] = useLayoutHeight() diff --git a/packages/mobile/src/components/collapsible-tabs/MaterialTabBar/TabBar.tsx b/packages/mobile/src/components/collapsible-tabs/MaterialTabBar/TabBar.tsx index 16ff5328402..760c899aa99 100644 --- a/packages/mobile/src/components/collapsible-tabs/MaterialTabBar/TabBar.tsx +++ b/packages/mobile/src/components/collapsible-tabs/MaterialTabBar/TabBar.tsx @@ -1,7 +1,6 @@ import React, { useLayoutEffect } from 'react' import { StyleSheet, - useWindowDimensions, LayoutChangeEvent } from 'react-native' import Animated, { @@ -18,6 +17,7 @@ import { Indicator } from './Indicator' import { MaterialTabItem } from './TabItem' import { MaterialTabBarProps, ItemLayout } from './types' import { TabName } from '../types' +import { useContentWidth } from 'app/hooks/useContentWidth' export const TABBAR_HEIGHT = 48 @@ -41,7 +41,7 @@ const MaterialTabBar = ({ keepActiveTabCentered }: MaterialTabBarProps): React.ReactElement => { const tabBarRef = useAnimatedRef() - const windowWidth = useWindowDimensions().width + const windowWidth = useContentWidth() const width = customWidth ?? windowWidth const isFirstRender = React.useRef(true) const itemLayoutGathering = React.useRef(new Map()) diff --git a/packages/mobile/src/components/drawer/Drawer.tsx b/packages/mobile/src/components/drawer/Drawer.tsx index 558712d7852..6c2b0b30d99 100644 --- a/packages/mobile/src/components/drawer/Drawer.tsx +++ b/packages/mobile/src/components/drawer/Drawer.tsx @@ -25,7 +25,7 @@ import { makeStyles } from 'app/styles' import { attachToDy } from 'app/utils/animation' import { DrawerHeader } from './DrawerHeader' -import { FULL_DRAWER_HEIGHT } from './constants' +import { getFullDrawerHeight, useFullDrawerHeight } from './constants' const MAX_SHADOW_OPACITY = 0.15 const ON_MOVE_RESPONDER_DY = 10 @@ -152,8 +152,10 @@ export const springToValue = ({ friction = 25 break case DrawerAnimationStyle.SPRINGY: - tension = 70 + 60 * (1 - Math.min(drawerHeight / FULL_DRAWER_HEIGHT, 1)) - friction = 10 + 2 * (1 - Math.min(drawerHeight / FULL_DRAWER_HEIGHT, 1)) + tension = + 70 + 60 * (1 - Math.min(drawerHeight / getFullDrawerHeight(), 1)) + friction = + 10 + 2 * (1 - Math.min(drawerHeight / getFullDrawerHeight(), 1)) break } Animated.spring(animation, { @@ -203,6 +205,7 @@ export const Drawer: DrawerComponent = ({ }: DrawerProps) => { const styles = useStyles() const insets = useSafeAreaInsets() + const FULL_DRAWER_HEIGHT = useFullDrawerHeight() const [drawerHeight, setDrawerHeight] = useState( isFullscreen ? FULL_DRAWER_HEIGHT : 0 @@ -506,6 +509,7 @@ export const Drawer: DrawerComponent = ({ } }), [ + FULL_DRAWER_HEIGHT, translationAnim, drawerHeight, initialOffsetOpenPosition, diff --git a/packages/mobile/src/components/drawer/constants.ts b/packages/mobile/src/components/drawer/constants.ts index ee842aa16b8..8666e5ad671 100644 --- a/packages/mobile/src/components/drawer/constants.ts +++ b/packages/mobile/src/components/drawer/constants.ts @@ -1,5 +1,9 @@ -import { Dimensions } from 'react-native' +import { Dimensions, Platform, useWindowDimensions } from 'react-native' -const { height } = Dimensions.get('screen') +export const getFullDrawerHeight = () => + Dimensions.get(Platform.OS === 'ios' ? 'window' : 'screen').height -export const FULL_DRAWER_HEIGHT = height +export const useFullDrawerHeight = () => { + useWindowDimensions() + return getFullDrawerHeight() +} diff --git a/packages/mobile/src/components/fold/FoldLayoutContext.tsx b/packages/mobile/src/components/fold/FoldLayoutContext.tsx new file mode 100644 index 00000000000..d41caf8082b --- /dev/null +++ b/packages/mobile/src/components/fold/FoldLayoutContext.tsx @@ -0,0 +1,50 @@ +import type { ReactNode } from 'react' +import { createContext, useContext, useMemo } from 'react' + +import { useWindowDimensions } from 'react-native' + +import { useHinge } from './useHinge' + +export const WIDE_LAYOUT_MIN_WIDTH = 600 + +export type FoldPosture = 'phone' | 'open' | 'book' + +type FoldLayout = { + posture: FoldPosture + isWide: boolean + windowWidth: number +} + +const FoldLayoutContext = createContext({ + posture: 'phone', + isWide: false, + windowWidth: 0 +}) + +export const FoldLayoutProvider = ({ children }: { children: ReactNode }) => { + const { width, height } = useWindowDimensions() + const hinge = useHinge() + const isWide = width >= WIDE_LAYOUT_MIN_WIDTH + const isBook = + isWide && + width > height && + hinge.available && + hinge.status === 'partiallyOpen' + + const value = useMemo( + () => ({ + posture: (isBook ? 'book' : isWide ? 'open' : 'phone') as FoldPosture, + isWide, + windowWidth: width + }), + [isBook, isWide, width] + ) + + return ( + + {children} + + ) +} + +export const useFoldLayout = () => useContext(FoldLayoutContext) diff --git a/packages/mobile/src/components/fold/index.ts b/packages/mobile/src/components/fold/index.ts new file mode 100644 index 00000000000..7a2342d0339 --- /dev/null +++ b/packages/mobile/src/components/fold/index.ts @@ -0,0 +1,2 @@ +export * from './FoldLayoutContext' +export * from './useHinge' diff --git a/packages/mobile/src/components/fold/useHinge.ts b/packages/mobile/src/components/fold/useHinge.ts new file mode 100644 index 00000000000..e4c87c08c2f --- /dev/null +++ b/packages/mobile/src/components/fold/useHinge.ts @@ -0,0 +1,39 @@ +import { useEffect, useState } from 'react' + +import { NativeEventEmitter, NativeModules, Platform } from 'react-native' + +export type HingeStatus = 'unknown' | 'closed' | 'partiallyOpen' | 'fullyOpen' + +export type HingeState = { + available: boolean + status?: HingeStatus + angle?: number +} + +const UNAVAILABLE: HingeState = { available: false } + +const HingeModule = + Platform.OS === 'ios' ? NativeModules.AudiusHinge : undefined +const emitter = HingeModule ? new NativeEventEmitter(HingeModule) : null + +export const useHinge = () => { + const [hinge, setHinge] = useState(UNAVAILABLE) + + useEffect(() => { + if (!HingeModule || !emitter) return + let cancelled = false + HingeModule.getState?.().then((state: HingeState) => { + if (!cancelled) setHinge(state) + }) + const subscription = emitter.addListener( + 'hingeChanged', + (state: HingeState) => setHinge(state) + ) + return () => { + cancelled = true + subscription.remove() + } + }, []) + + return hinge +} diff --git a/packages/mobile/src/components/now-playing-drawer/Artwork.tsx b/packages/mobile/src/components/now-playing-drawer/Artwork.tsx index c3fd0916228..59d9587da9f 100644 --- a/packages/mobile/src/components/now-playing-drawer/Artwork.tsx +++ b/packages/mobile/src/components/now-playing-drawer/Artwork.tsx @@ -7,9 +7,10 @@ import type { Track } from '@audius/common/models' import { averageColorSelectors, playbackSelectors } from '@audius/common/store' import type { CommonState } from '@audius/common/store' import type { Nullable } from '@audius/common/utils' -import { Dimensions, View } from 'react-native' +import { View } from 'react-native' import { useSelector } from 'react-redux' +import { useContentWidth } from 'app/hooks/useContentWidth' import { makeStyles } from 'app/styles' import { TrackImage } from '../image/TrackImage' @@ -19,14 +20,12 @@ import { mostSaturated } from './useDominantArtworkColors' const { getPreviewing } = playbackSelectors const { getDominantColorsByTrack } = averageColorSelectors -const dimensions = Dimensions.get('window') const spacing = 24 const useStyles = makeStyles(({ palette }) => ({ root: { marginLeft: spacing, marginRight: spacing, - maxHeight: dimensions.width - spacing * 2, alignSelf: 'center', backgroundColor: palette.white, borderRadius: 8, @@ -53,10 +52,12 @@ const useStyles = makeStyles(({ palette }) => ({ type ArtworkProps = { track: Nullable isOpen: boolean + maxSize?: number } -export const Artwork = ({ track, isOpen }: ArtworkProps) => { +export const Artwork = ({ track, isOpen, maxSize }: ArtworkProps) => { const styles = useStyles() + const contentWidth = useContentWidth() const dominantColors = useSelector((state: CommonState) => getDominantColorsByTrack(state, { @@ -86,7 +87,13 @@ export const Artwork = ({ track, isOpen }: ArtworkProps) => { isPreviewing || canPurchase || shouldDisplayPremiumDownloadLocked return ( - + { +export const usePlaybackPosition = (isActive: boolean, mediaKey: string) => { const [position, setPosition] = useState(0) const seek = useSelector(getSeek) const seekCounter = useSelector(getSeekCounter) @@ -121,6 +121,7 @@ const Bubble = ({ }) => { const navigation = useNavigation() const { open } = useCommentDrawer() + const contentWidth = useContentWidth() const { data: name } = useUser(comment.userId, { select: (user) => user.name }) @@ -152,7 +153,7 @@ const Bubble = ({ style={{ paddingVertical: 2, borderRadius: 999, - maxWidth: BUBBLE_MAX_WIDTH + maxWidth: contentWidth * 0.85 }} > diff --git a/packages/mobile/src/components/now-playing-drawer/Logo.tsx b/packages/mobile/src/components/now-playing-drawer/Logo.tsx index ea5da004209..a69386ed619 100644 --- a/packages/mobile/src/components/now-playing-drawer/Logo.tsx +++ b/packages/mobile/src/components/now-playing-drawer/Logo.tsx @@ -3,7 +3,7 @@ import { StyleSheet, Animated } from 'react-native' import AudiusLogoHorizontal from 'app/assets/images/audiusLogoHorizontalDeprecated.svg' import { useThemeColors } from 'app/utils/theme' -import { NOW_PLAYING_HEIGHT } from './constants' +import { useNowPlayingHeight } from './constants' const styles = StyleSheet.create({ root: { @@ -18,6 +18,7 @@ type LogoProps = { export const Logo = ({ translationAnim }: LogoProps) => { const { neutralLight4 } = useThemeColors() + const NOW_PLAYING_HEIGHT = useNowPlayingHeight() return ( ({ container: { paddingTop: 0, - height: FULL_DRAWER_HEIGHT, justifyContent: 'space-evenly' }, playBarContainer: { @@ -137,15 +125,14 @@ export const NowPlayingDrawer = memo(function NowPlayingDrawer( const navigation = useNavigation({ customNavigation: contextNavigation }) - const dispatch = useDispatch() const insets = useSafeAreaInsets() const staticTopInset = useRef(insets.top) const styles = useStyles() + const FULL_DRAWER_HEIGHT = useFullDrawerHeight() const { isOpen, onOpen, onClose } = useDrawer('NowPlaying') const tabBarHidden = useTabBarHiddenProgress() const { isOpen: isCommentDrawerOpen } = useCommentDrawer() - const playCounter = useSelector(getCounter) const currentTrackId = useSelector(getTrackId) const isPlaying = useSelector(getPlaying) const isBuffering = useSelector(getBuffering) @@ -280,24 +267,19 @@ export const NowPlayingDrawer = memo(function NowPlayingDrawer( const [isGestureEnabled, setIsGestureEnabled] = useState(true) - const track = useCurrentTrack() - const trackDuration = useCurrentTrackDuration() - const trackId = track?.track_id - - const { data: user } = useUser(track?.owner_id) - const [mediaKey, setMediaKey] = useState(0) - - const { isEnabled: isNowPlayingCommentsEnabled } = useFeatureFlag( - FeatureFlags.NOW_PLAYING_COMMENTS - ) - const { isEnabled: isWaveformEnabled } = useFeatureFlag( - FeatureFlags.NOW_PLAYING_WAVEFORM - ) - useDominantArtworkColors(trackId, isWaveformEnabled && isOpen) - const timestampedComments = useTimestampedComments( + const { + track, trackId, - (isNowPlayingCommentsEnabled || isWaveformEnabled) && isOpen - ) + user, + trackDuration, + mediaKey, + isLongFormContent, + isNowPlayingCommentsEnabled, + isWaveformEnabled, + timestampedComments, + onNext, + onPrevious + } = useNowPlayingControls(isOpen) const commentMarkers = useMemo( () => trackDuration > 0 && timestampedComments.length > 0 @@ -308,41 +290,6 @@ export const NowPlayingDrawer = memo(function NowPlayingDrawer( [timestampedComments, trackDuration] ) - useEffect(() => { - setMediaKey((mediaKey) => mediaKey + 1) - }, [playCounter, currentTrackId]) - - const onNext = useCallback(async () => { - const isLongFormContent = - track?.genre === Genre.Podcasts || track?.genre === Genre.Audiobooks - if (isLongFormContent) { - const { position: currentPosition } = await TrackPlayer.getProgress() - const newPosition = currentPosition + SKIP_DURATION_SEC - dispatch(seek({ seconds: Math.min(track.duration, newPosition) })) - } else { - dispatch(next({ skip: true })) - setMediaKey((mediaKey) => mediaKey + 1) - } - }, [dispatch, setMediaKey, track]) - - const onPrevious = useCallback(async () => { - const { position: currentPosition } = await TrackPlayer.getProgress() - const isLongFormContent = - track?.genre === Genre.Podcasts || track?.genre === Genre.Audiobooks - if (isLongFormContent) { - const newPosition = currentPosition - SKIP_DURATION_SEC - dispatch(seek({ seconds: Math.max(0, newPosition) })) - } else { - const shouldGoToPrevious = currentPosition < RESTART_THRESHOLD_SEC - if (shouldGoToPrevious) { - dispatch(previous()) - setMediaKey((mediaKey) => mediaKey + 1) - } else { - dispatch(reset({ shouldAutoplay: true })) - } - } - }, [dispatch, setMediaKey, track]) - const onPressScrubberIn = useCallback(() => { setIsGestureEnabled(false) }, [setIsGestureEnabled]) @@ -362,7 +309,7 @@ export const NowPlayingDrawer = memo(function NowPlayingDrawer( const playBar = ( ) : ( ) : null} {isWaveformEnabled ? ( @@ -477,10 +425,7 @@ export const NowPlayingDrawer = memo(function NowPlayingDrawer( diff --git a/packages/mobile/src/components/now-playing-drawer/PlayBar.tsx b/packages/mobile/src/components/now-playing-drawer/PlayBar.tsx index 2cac8f93f2b..51a1203b66c 100644 --- a/packages/mobile/src/components/now-playing-drawer/PlayBar.tsx +++ b/packages/mobile/src/components/now-playing-drawer/PlayBar.tsx @@ -42,7 +42,7 @@ import { TrackImage } from '../image/TrackImage' import { PlayButton } from './PlayButton' import { TrackingBar } from './TrackingBar' -import { NOW_PLAYING_HEIGHT, PLAY_BAR_HEIGHT } from './constants' +import { PLAY_BAR_HEIGHT, useNowPlayingHeight } from './constants' const { getPreviewing } = playbackSelectors const QUEUE_BUTTON_WIDTH = 32 @@ -201,6 +201,7 @@ export const PlayBar = (props: PlayBarProps) => { 'clamp' ) })) + const NOW_PLAYING_HEIGHT = useNowPlayingHeight() const queueStyle = useAnimatedStyle(() => { const shrink = interpolate( hidden.value, diff --git a/packages/mobile/src/components/now-playing-drawer/TrackingBar.tsx b/packages/mobile/src/components/now-playing-drawer/TrackingBar.tsx index f1ade64cda8..b6d030f32e5 100644 --- a/packages/mobile/src/components/now-playing-drawer/TrackingBar.tsx +++ b/packages/mobile/src/components/now-playing-drawer/TrackingBar.tsx @@ -3,7 +3,7 @@ import { useCallback, useEffect, useRef } from 'react' import { useCurrentTrack } from '@audius/common/hooks' import { playbackSelectors, playbackRateValueMap } from '@audius/common/store' import { Genre } from '@audius/common/utils' -import { Animated, Dimensions } from 'react-native' +import { Animated, useWindowDimensions } from 'react-native' import TrackPlayer, { useIsPlaying } from 'react-native-track-player' import { useSelector } from 'react-redux' import { useAsync } from 'react-use' @@ -14,9 +14,7 @@ import type { LinearAnimation } from 'app/utils/animation' import { animateLinear } from 'app/utils/animation' import { useThemeColors } from 'app/utils/theme' -import { NOW_PLAYING_HEIGHT } from './constants' - -const width = Dimensions.get('window').width +import { useNowPlayingHeight } from './constants' const { getSeek, getPaused, getBuffering } = playbackSelectors @@ -113,6 +111,8 @@ export const TrackingBar = (props: TrackingBarProps) => { useEffect(() => () => currentAnimation.current?.stop(), []) + const NOW_PLAYING_HEIGHT = useNowPlayingHeight() + const { width } = useWindowDimensions() const rootOpacity = translateYAnimation.interpolate({ inputRange: [0, 0.9 * NOW_PLAYING_HEIGHT, NOW_PLAYING_HEIGHT], outputRange: [0, 0, 2] diff --git a/packages/mobile/src/components/now-playing-drawer/constants.ts b/packages/mobile/src/components/now-playing-drawer/constants.ts index 8a1ad233d3d..c3f3b04d05c 100644 --- a/packages/mobile/src/components/now-playing-drawer/constants.ts +++ b/packages/mobile/src/components/now-playing-drawer/constants.ts @@ -1,6 +1,7 @@ import { BOTTOM_BAR_HEIGHT } from 'app/components/bottom-tab-bar' -import { FULL_DRAWER_HEIGHT } from 'app/components/drawer' +import { useFullDrawerHeight } from 'app/components/drawer' export const PLAY_BAR_HEIGHT = 52 -export const NOW_PLAYING_HEIGHT = - FULL_DRAWER_HEIGHT - BOTTOM_BAR_HEIGHT - PLAY_BAR_HEIGHT + +export const useNowPlayingHeight = () => + useFullDrawerHeight() - BOTTOM_BAR_HEIGHT - PLAY_BAR_HEIGHT diff --git a/packages/mobile/src/components/now-playing-drawer/useNowPlayingControls.ts b/packages/mobile/src/components/now-playing-drawer/useNowPlayingControls.ts new file mode 100644 index 00000000000..33bf1153032 --- /dev/null +++ b/packages/mobile/src/components/now-playing-drawer/useNowPlayingControls.ts @@ -0,0 +1,102 @@ +import { useCallback, useEffect, useState } from 'react' + +import { useTimestampedComments, useUser } from '@audius/common/api' +import { useCurrentTrack, useFeatureFlag } from '@audius/common/hooks' +import { FeatureFlags } from '@audius/common/services' +import { playbackActions, playbackSelectors } from '@audius/common/store' +import { Genre } from '@audius/common/utils' +import TrackPlayer from 'react-native-track-player' +import { useDispatch, useSelector } from 'react-redux' + +import { + RESTART_THRESHOLD_SEC, + SKIP_DURATION_SEC +} from 'app/components/audio/constants' + +import { useCurrentTrackDuration } from './useCurrentTrackDuration' +import { useDominantArtworkColors } from './useDominantArtworkColors' + +const { seekTo: seek, reset, next, previous } = playbackActions +const { getPlaying, getTrackId, getCounter, getBuffering } = playbackSelectors + +export const useNowPlayingControls = (isVisible: boolean) => { + const dispatch = useDispatch() + const playCounter = useSelector(getCounter) + const currentTrackId = useSelector(getTrackId) + const isPlaying = useSelector(getPlaying) + const isBuffering = useSelector(getBuffering) + const track = useCurrentTrack() + const trackDuration = useCurrentTrackDuration() + const trackId = track?.track_id + const { data: user } = useUser(track?.owner_id) + const [mediaKey, setMediaKey] = useState(0) + + const { isEnabled: isNowPlayingCommentsEnabled } = useFeatureFlag( + FeatureFlags.NOW_PLAYING_COMMENTS + ) + const { isEnabled: isWaveformEnabled } = useFeatureFlag( + FeatureFlags.NOW_PLAYING_WAVEFORM + ) + useDominantArtworkColors(trackId, !!isWaveformEnabled && isVisible) + const timestampedComments = useTimestampedComments( + trackId, + (!!isNowPlayingCommentsEnabled || !!isWaveformEnabled) && isVisible + ) + + useEffect(() => { + setMediaKey((key) => key + 1) + }, [playCounter, currentTrackId]) + + const isLongFormContent = + track?.genre === Genre.Podcasts || track?.genre === Genre.Audiobooks + + const onNext = useCallback(async () => { + if (isLongFormContent && track) { + const { position } = await TrackPlayer.getProgress() + dispatch( + seek({ + seconds: Math.min(track.duration, position + SKIP_DURATION_SEC) + }) + ) + } else { + dispatch(next({ skip: true })) + setMediaKey((key) => key + 1) + } + }, [dispatch, isLongFormContent, track]) + + const onPrevious = useCallback(async () => { + const { position } = await TrackPlayer.getProgress() + if (isLongFormContent) { + dispatch(seek({ seconds: Math.max(0, position - SKIP_DURATION_SEC) })) + } else if (position < RESTART_THRESHOLD_SEC) { + dispatch(previous()) + setMediaKey((key) => key + 1) + } else { + dispatch(reset({ shouldAutoplay: true })) + } + }, [dispatch, isLongFormContent]) + + const onSeek = useCallback( + (seconds: number) => { + dispatch(seek({ seconds })) + }, + [dispatch] + ) + + return { + track, + trackId, + user, + trackDuration, + mediaKey: `${mediaKey}`, + isPlaying, + isBuffering, + isLongFormContent, + isNowPlayingCommentsEnabled: !!isNowPlayingCommentsEnabled, + isWaveformEnabled: !!isWaveformEnabled, + timestampedComments, + onNext, + onPrevious, + onSeek + } +} diff --git a/packages/mobile/src/components/now-playing-panel/Gatefold.tsx b/packages/mobile/src/components/now-playing-panel/Gatefold.tsx new file mode 100644 index 00000000000..27fd9afa653 --- /dev/null +++ b/packages/mobile/src/components/now-playing-panel/Gatefold.tsx @@ -0,0 +1,324 @@ +import { + useCallback, + useContext, + useEffect, + useMemo, + useRef, + useState +} from 'react' + +import { useUser } from '@audius/common/api' +import type { TimestampedComment } from '@audius/common/api' +import type { LayoutChangeEvent } from 'react-native' +import { FlatList, Pressable, View } from 'react-native' +import { useSafeAreaInsets } from 'react-native-safe-area-context' + +import { + Flex, + IconButton, + IconClose, + Text, + useTheme +} from '@audius/harmony-native' +import { ProfilePicture } from 'app/components/core' +import { Artwork } from 'app/components/now-playing-drawer/Artwork' +import { AudioControls } from 'app/components/now-playing-drawer/AudioControls' +import { usePlaybackPosition } from 'app/components/now-playing-drawer/CommentBubble' +import { TrackInfo } from 'app/components/now-playing-drawer/TrackInfo' +import { WaveformScrubber } from 'app/components/now-playing-drawer/WaveformScrubber' +import { useNowPlayingControls } from 'app/components/now-playing-drawer/useNowPlayingControls' +import { Scrubber } from 'app/components/scrubber' +import { ContentWidthContext } from 'app/hooks/useContentWidth' +import { useNavigation } from 'app/hooks/useNavigation' +import { AppTabNavigationContext } from 'app/screens/app-screen/AppTabNavigationProvider' + +import { UpNext } from './NowPlayingPanel' + +const HINGE_GUTTER = 32 +const COMMENT_ROW_HEIGHT = 64 +const ARTWORK_MARGIN = 24 + +const messages = { + comments: 'Comments', + commentsHint: 'Moments listeners called out, in time with the music', + upNextHint: 'No timed comments on this track yet', + close: 'Back to browsing' +} + +const formatTimestamp = (seconds: number) => { + const whole = Math.max(0, Math.floor(seconds)) + const minutes = Math.floor(whole / 60) + return `${minutes}:${String(whole % 60).padStart(2, '0')}` +} + +type GatefoldProps = { + width: number + onClose: () => void +} + +export const Gatefold = ({ width, onClose }: GatefoldProps) => { + const { color, spacing } = useTheme() + const insets = useSafeAreaInsets() + const [measuredWidth, setMeasuredWidth] = useState(width) + const [artworkBox, setArtworkBox] = useState({ width: 0, height: 0 }) + const { + track, + trackId, + user, + trackDuration, + mediaKey, + isPlaying, + isBuffering, + isLongFormContent, + isWaveformEnabled, + timestampedComments, + onNext, + onPrevious, + onSeek + } = useNowPlayingControls(true) + const { navigation: tabNavigation } = useContext(AppTabNavigationContext) + const navigation = useNavigation({ customNavigation: tabNavigation }) + const pageWidth = measuredWidth / 2 + const artworkSize = Math.max( + 0, + Math.min(artworkBox.width - ARTWORK_MARGIN * 2, artworkBox.height) + ) + + const handleLayout = useCallback((e: LayoutChangeEvent) => { + setMeasuredWidth(e.nativeEvent.layout.width) + }, []) + + const handleArtworkLayout = useCallback((e: LayoutChangeEvent) => { + const { width, height } = e.nativeEvent.layout + setArtworkBox({ width, height }) + }, []) + + const handlePressTitle = useCallback(() => { + if (!trackId) return + onClose() + navigation?.push('Track', { trackId }) + }, [navigation, onClose, trackId]) + + return ( + + + + + {artworkSize > 0 ? ( + + + + ) : null} + + + + + {isWaveformEnabled && trackId ? ( + + ) : ( + + )} + + + + + + + + {messages.comments} + + + {timestampedComments.length > 0 + ? messages.commentsHint + : messages.upNextHint} + + + + + {timestampedComments.length > 0 && trackId ? ( + + ) : ( + + )} + + + + ) +} + +const noop = () => {} + +type SyncedCommentsProps = { + comments: TimestampedComment[] + isActive: boolean + mediaKey: string + onSeek: (seconds: number) => void + bottomInset: number +} + +const SyncedComments = (props: SyncedCommentsProps) => { + const { comments, isActive, mediaKey, onSeek, bottomInset } = props + const { spacing } = useTheme() + const position = usePlaybackPosition(isActive, mediaKey) + const listRef = useRef>(null) + + const activeIndex = useMemo(() => { + let found = -1 + comments.forEach((comment, i) => { + if (comment.trackTimestampS <= position) found = i + }) + return found + }, [comments, position]) + + useEffect(() => { + if (activeIndex < 0) return + listRef.current?.scrollToIndex({ + index: activeIndex, + viewPosition: 0.35, + animated: true + }) + }, [activeIndex]) + + const getItemLayout = useCallback( + (_: ArrayLike | null | undefined, index: number) => ({ + length: COMMENT_ROW_HEIGHT, + offset: COMMENT_ROW_HEIGHT * index, + index + }), + [] + ) + + return ( + `${comment.id}`} + getItemLayout={getItemLayout} + showsVerticalScrollIndicator={false} + contentContainerStyle={{ + paddingTop: spacing.xl, + paddingBottom: bottomInset + spacing['4xl'] + }} + renderItem={({ item, index }) => ( + onSeek(item.trackTimestampS)} + /> + )} + /> + ) +} + +type SyncedCommentRowProps = { + comment: TimestampedComment + state: 'past' | 'active' | 'upcoming' + onPress: () => void +} + +const SyncedCommentRow = ({ + comment, + state, + onPress +}: SyncedCommentRowProps) => { + const { data: name } = useUser(comment.userId, { + select: (user) => user.name + }) + const isActive = state === 'active' + + return ( + + + + + + {formatTimestamp(comment.trackTimestampS)} + {name ? ` ยท ${name}` : ''} + + + {comment.message} + + + + + ) +} diff --git a/packages/mobile/src/components/now-playing-panel/NowPlayingPanel.tsx b/packages/mobile/src/components/now-playing-panel/NowPlayingPanel.tsx new file mode 100644 index 00000000000..7b5e868e394 --- /dev/null +++ b/packages/mobile/src/components/now-playing-panel/NowPlayingPanel.tsx @@ -0,0 +1,202 @@ +import { useCallback, useContext, useState } from 'react' + +import { playbackActions, playbackSelectors } from '@audius/common/store' +import type { LayoutChangeEvent } from 'react-native' +import { Pressable, ScrollView, View } from 'react-native' +import { useSafeAreaInsets } from 'react-native-safe-area-context' +import { useDispatch, useSelector } from 'react-redux' + +import { Flex, Text, useTheme } from '@audius/harmony-native' +import { ActionsBar } from 'app/components/now-playing-drawer/ActionsBar' +import { Artwork } from 'app/components/now-playing-drawer/Artwork' +import { AudioControls } from 'app/components/now-playing-drawer/AudioControls' +import { CommentBubble } from 'app/components/now-playing-drawer/CommentBubble' +import { TrackInfo } from 'app/components/now-playing-drawer/TrackInfo' +import { WaveformScrubber } from 'app/components/now-playing-drawer/WaveformScrubber' +import { useNowPlayingControls } from 'app/components/now-playing-drawer/useNowPlayingControls' +import { MiniTrackRow } from 'app/components/queue-drawer/QueueDrawer' +import { Scrubber } from 'app/components/scrubber' +import { ContentWidthContext } from 'app/hooks/useContentWidth' +import { useNavigation } from 'app/hooks/useNavigation' +import { AppTabNavigationContext } from 'app/screens/app-screen/AppTabNavigationProvider' + +const { getPlaybackQueue, getPlaybackIndex } = playbackSelectors +const { playTrackAt } = playbackActions + +const UP_NEXT_LIMIT = 8 +const ARTWORK_GUTTER = 48 + +const messages = { + nowPlaying: 'Now Playing', + upNext: 'Up Next' +} + +type NowPlayingPanelProps = { + width: number +} + +export const NowPlayingPanel = ({ width }: NowPlayingPanelProps) => { + const { color, spacing } = useTheme() + const insets = useSafeAreaInsets() + const [panelHeight, setPanelHeight] = useState(0) + const [artworkBox, setArtworkBox] = useState({ width: 0, height: 0 }) + const artworkSize = Math.max( + 0, + Math.min(artworkBox.width - ARTWORK_GUTTER, artworkBox.height) + ) + const controls = useNowPlayingControls(true) + const { + track, + trackId, + user, + trackDuration, + mediaKey, + isPlaying, + isBuffering, + isLongFormContent, + isNowPlayingCommentsEnabled, + isWaveformEnabled, + timestampedComments, + onNext, + onPrevious + } = controls + const { navigation: tabNavigation } = useContext(AppTabNavigationContext) + const navigation = useNavigation({ customNavigation: tabNavigation }) + + const handlePressTitle = useCallback(() => { + if (trackId) navigation?.push('Track', { trackId }) + }, [navigation, trackId]) + + const handlePanelLayout = useCallback((e: LayoutChangeEvent) => { + setPanelHeight(e.nativeEvent.layout.height) + }, []) + + const handleArtworkLayout = useCallback((e: LayoutChangeEvent) => { + const { width, height } = e.nativeEvent.layout + setArtworkBox({ width, height }) + }, []) + + return ( + + + + + + + {messages.nowPlaying} + + + + {artworkSize > 0 ? ( + + + + ) : null} + + + + + + {isWaveformEnabled && trackId ? ( + + ) : ( + + )} + + {isNowPlayingCommentsEnabled && trackId ? ( + + ) : null} + + + + + + + + + + + ) +} + +const noop = () => {} + +export const UpNext = ({ limit = UP_NEXT_LIMIT }: { limit?: number }) => { + const dispatch = useDispatch() + const queue = useSelector(getPlaybackQueue) + const index = useSelector(getPlaybackIndex) + const upcoming = queue + .map((item, queueIndex) => ({ trackId: item.trackId, queueIndex })) + .slice(index + 1, index + 1 + limit) + + if (upcoming.length === 0) return null + + return ( + + + + {messages.upNext} + + + {upcoming.map(({ trackId, queueIndex }) => ( + dispatch(playTrackAt({ index: queueIndex }))} + /> + ))} + + ) +} diff --git a/packages/mobile/src/components/queue-drawer/QueueDrawer.tsx b/packages/mobile/src/components/queue-drawer/QueueDrawer.tsx index adb67288e03..5f85f468493 100644 --- a/packages/mobile/src/components/queue-drawer/QueueDrawer.tsx +++ b/packages/mobile/src/components/queue-drawer/QueueDrawer.tsx @@ -7,7 +7,7 @@ import type { QueueSource } from '@audius/common/store' import { playbackActions, playbackSelectors } from '@audius/common/store' import { useQueryClient } from '@tanstack/react-query' import { make, useRecord } from 'common/store/analytics/actions' -import { Dimensions, Pressable, View } from 'react-native' +import { Pressable, useWindowDimensions, View } from 'react-native' import DraggableFlatList from 'react-native-draggable-flatlist' import { useDispatch, useSelector } from 'react-redux' @@ -44,8 +44,6 @@ const { const DRAWER_NAME = 'Queue' -const SCREEN_HEIGHT = Dimensions.get('window').height -const COLLAPSED_HEIGHT = Math.round(SCREEN_HEIGHT * 0.85) const ROW_HEIGHT = 64 const messages = { @@ -90,7 +88,7 @@ type RowProps = { onDragHandleLongPress?: () => void } -const MiniTrackRow = ({ +export const MiniTrackRow = ({ trackId, variant, isPlaying, @@ -276,6 +274,7 @@ export const QueueDrawer = () => { const index = useSelector(getPlaybackIndex) const isPlaying = useSelector(getIsPlaying) const { spacing, color } = useTheme() + const { height: windowHeight } = useWindowDimensions() const { trackIds: nextFromIds, sourceKey } = useNextFromSourceMobile() const record = useRecord() @@ -531,7 +530,7 @@ export const QueueDrawer = () => { diff --git a/packages/mobile/src/components/suggested-follows/SuggestedFollows.tsx b/packages/mobile/src/components/suggested-follows/SuggestedFollows.tsx index 81e8545a7d6..6c44c344556 100644 --- a/packages/mobile/src/components/suggested-follows/SuggestedFollows.tsx +++ b/packages/mobile/src/components/suggested-follows/SuggestedFollows.tsx @@ -6,7 +6,7 @@ import { usersSocialActions } from '@audius/common/store' import { useQueryClient } from '@tanstack/react-query' import * as signOnActions from 'common/store/pages/signon/actions' import { getFollowIds } from 'common/store/pages/signon/selectors' -import { Dimensions, FlatList, ScrollView, View } from 'react-native' +import { FlatList, ScrollView, useWindowDimensions, View } from 'react-native' import { useDispatch, useSelector } from 'react-redux' import { Text } from 'app/components/core' @@ -15,12 +15,9 @@ import { makeStyles } from 'app/styles' import { ContinueButton } from './ContinueButton' import { SuggestedArtistsList } from './SuggestedArtistsList' -const { height } = Dimensions.get('window') - const useStyles = makeStyles(({ spacing, palette }) => ({ root: { - flex: 1, - height: height - 220 + flex: 1 }, header: { paddingHorizontal: spacing(4), @@ -48,6 +45,7 @@ const messages = { export const SuggestedFollows = () => { const styles = useStyles() + const { height } = useWindowDimensions() const dispatch = useDispatch() const queryClient = useQueryClient() @@ -80,7 +78,7 @@ export const SuggestedFollows = () => { ) return ( - + { const horizontalPadding = Math.max(6 - state.routes.length, 0) * HORIZONTAL_PADDING - const screenWidth = Dimensions.get('screen').width + const screenWidth = useContentWidth() const tabsWidth = screenWidth - horizontalPadding * 2 const tabWidth = tabsWidth / state.routes.length diff --git a/packages/mobile/src/components/top-tab-bar/TopTabBar.tsx b/packages/mobile/src/components/top-tab-bar/TopTabBar.tsx index ceb56a4b83c..f446dc9462d 100644 --- a/packages/mobile/src/components/top-tab-bar/TopTabBar.tsx +++ b/packages/mobile/src/components/top-tab-bar/TopTabBar.tsx @@ -1,6 +1,7 @@ -import { Animated, Dimensions, TouchableOpacity, View } from 'react-native' +import { Animated, TouchableOpacity, View } from 'react-native' import { Text } from '@audius/harmony-native' +import { useContentWidth } from 'app/hooks/useContentWidth' import { makeStyles } from 'app/styles' import { useThemeColors } from 'app/utils/theme' @@ -74,7 +75,7 @@ const useStyles = makeStyles(({ palette, spacing }) => ({ export const TopTabBar = ({ state, descriptors, navigation, position }) => { const horizontalPadding = Math.max(6 - state.routes.length, 0) * HORIZONTAL_PADDING - const screenWidth = Dimensions.get('screen').width + const screenWidth = useContentWidth() const tabsWidth = screenWidth - horizontalPadding * 2 const tabWidth = tabsWidth / state.routes.length diff --git a/packages/mobile/src/hooks/useContentWidth.tsx b/packages/mobile/src/hooks/useContentWidth.tsx new file mode 100644 index 00000000000..aba2c156712 --- /dev/null +++ b/packages/mobile/src/hooks/useContentWidth.tsx @@ -0,0 +1,11 @@ +import { createContext, useContext } from 'react' + +import { useWindowDimensions } from 'react-native' + +export const ContentWidthContext = createContext(null) + +export const useContentWidth = () => { + const { width } = useWindowDimensions() + const contentWidth = useContext(ContentWidthContext) + return contentWidth ?? width +} diff --git a/packages/mobile/src/screens/app-drawer-screen/AppDrawerScreen.tsx b/packages/mobile/src/screens/app-drawer-screen/AppDrawerScreen.tsx index fd370c54084..205d8d7b6ba 100644 --- a/packages/mobile/src/screens/app-drawer-screen/AppDrawerScreen.tsx +++ b/packages/mobile/src/screens/app-drawer-screen/AppDrawerScreen.tsx @@ -4,6 +4,7 @@ import type { DrawerContentComponentProps } from '@react-navigation/drawer' import { createDrawerNavigator } from '@react-navigation/drawer' import { useNavigation } from '@react-navigation/native' import { Platform, View, StyleSheet } from 'react-native' +import { useSafeAreaInsets } from 'react-native-safe-area-context' import { IconAudiusLogoHorizontal } from '@audius/harmony-native' import { AudioPlayer } from 'app/components/audio/AudioPlayer' @@ -16,6 +17,8 @@ import { AppDrawerContextProvider } from './AppDrawerContext' import { LeftNavDrawer } from './left-nav-drawer' const DRAWER_SWIPE_EDGE_WIDTH = 40 +const ISLAND_LOGO_TOP = 14 +const ISLAND_LOGO_HEIGHT = 25 const Drawer = createDrawerNavigator() @@ -53,6 +56,9 @@ export const AppDrawerScreen = memo(() => { const [gesturesDisabled, setGesturesDisabled] = useState(false) const [isAtStackRoot, setIsAtStackRootState] = useState(true) const { isOpen: isNowPlayingDrawerOpen } = useDrawer('NowPlaying') + const insets = useSafeAreaInsets() + const showIslandLogo = + Platform.OS === 'ios' && insets.top >= ISLAND_LOGO_TOP + ISLAND_LOGO_HEIGHT const drawerHelpersRef = useRef< DrawerContentComponentProps['navigation'] | null >(null) @@ -109,9 +115,13 @@ export const AppDrawerScreen = memo(() => { push/pop transitions instead of fading with the leaving screen. pointerEvents=none lets touches pass through to the navigator below. */} - {Platform.OS === 'ios' ? ( + {showIslandLogo ? ( - + ) : null} @@ -121,7 +131,7 @@ export const AppDrawerScreen = memo(() => { const styles = StyleSheet.create({ dynamicIslandLogo: { position: 'absolute', - top: 14, + top: ISLAND_LOGO_TOP, left: 0, right: 0, alignItems: 'center', diff --git a/packages/mobile/src/screens/app-screen/AppTabBar.tsx b/packages/mobile/src/screens/app-screen/AppTabBar.tsx index 81e49204a0f..5a79226fab7 100644 --- a/packages/mobile/src/screens/app-screen/AppTabBar.tsx +++ b/packages/mobile/src/screens/app-screen/AppTabBar.tsx @@ -1,7 +1,7 @@ -import { useRef } from 'react' +import { useContext, useEffect, useRef } from 'react' import type { BottomTabBarProps } from '@react-navigation/bottom-tabs' -import { Animated, StyleSheet } from 'react-native' +import { Animated, StatusBar, StyleSheet } from 'react-native' import Reanimated, { useAnimatedStyle } from 'react-native-reanimated' import { useSafeAreaInsets } from 'react-native-safe-area-context' @@ -10,9 +10,12 @@ import { BOTTOM_BAR_HEIGHT, useFloatingTabBar } from 'app/components/bottom-tab-bar' -import { FULL_DRAWER_HEIGHT } from 'app/components/drawer' +import { SetPlayBarVisibilityContext } from 'app/components/core/BottomBarInsetContext' +import { getFullDrawerHeight } from 'app/components/drawer' +import { useFoldLayout } from 'app/components/fold' import { NowPlayingDrawer } from 'app/components/now-playing-drawer' import { OtaUpdateBanner } from 'app/components/ota-update-banner/OtaUpdateBanner' +import { useDrawer } from 'app/hooks/useDrawer' import { useTabBarHiddenProgress } from './TabBarAutoHideContext' @@ -23,12 +26,25 @@ export const AppTabBar = (props: TabBarProps) => { const insets = useSafeAreaInsets() const hidden = useTabBarHiddenProgress() const floating = useFloatingTabBar() + const { isWide } = useFoldLayout() + const setPlayBarVisible = useContext(SetPlayBarVisibilityContext) + const { isOpen: isNowPlayingOpen, onClose: closeNowPlaying } = + useDrawer('NowPlaying') const translationAnimRef = useRef(null) if (translationAnimRef.current === null) { - translationAnimRef.current = new Animated.Value(FULL_DRAWER_HEIGHT) + translationAnimRef.current = new Animated.Value(getFullDrawerHeight()) } const translationAnim = translationAnimRef.current + useEffect(() => { + if (!isWide) return + setPlayBarVisible(false) + if (isNowPlayingOpen) { + closeNowPlaying() + StatusBar.setHidden(false, 'fade') + } + }, [isWide, isNowPlayingOpen, closeNowPlaying, setPlayBarVisible]) + const hideStyle = useAnimatedStyle( () => ({ transform: [ @@ -44,7 +60,7 @@ export const AppTabBar = (props: TabBarProps) => { return ( <> - + {isWide ? null : } } +const { getTrackId } = playbackSelectors + const Tab = createBottomTabNavigator() +const PANEL_MAX_WIDTH = 420 +const PANEL_WIDTH_RATIO = 0.42 + const screenOptions = { headerShown: false } const tabBar = (props: BottomTabBarProps) => @@ -38,20 +53,82 @@ export const AppTabsScreen = () => { usePrefetchNotifications() return ( - - - - - - - - - - - + + + + + + + + ) +} + +const SplitLayout = () => { + const { isWide, posture, windowWidth } = useFoldLayout() + const hasTrack = !!useSelector(getTrackId) + const [isGatefoldDismissed, setIsGatefoldDismissed] = useState(false) + + useEffect(() => { + if (posture !== 'book') setIsGatefoldDismissed(false) + }, [posture]) + + const handleCloseGatefold = useCallback(() => { + setIsGatefoldDismissed(true) + }, []) + + const showPanel = isWide && hasTrack + const panelWidth = + posture === 'book' + ? Math.round(windowWidth / 2) + : Math.min(PANEL_MAX_WIDTH, Math.round(windowWidth * PANEL_WIDTH_RATIO)) + const showGatefold = posture === 'book' && hasTrack && !isGatefoldDismissed + + return ( + + + + + + + + + + + + + {showPanel && !showGatefold ? ( + + ) : null} + + + + + + ) } + +const styles = StyleSheet.create({ + row: { + flex: 1, + flexDirection: 'row' + }, + content: { + flex: 1, + overflow: 'hidden' + } +}) diff --git a/packages/mobile/src/screens/app-screen/CompactHeader.tsx b/packages/mobile/src/screens/app-screen/CompactHeader.tsx index 01f896d0121..1dcc12cf32b 100644 --- a/packages/mobile/src/screens/app-screen/CompactHeader.tsx +++ b/packages/mobile/src/screens/app-screen/CompactHeader.tsx @@ -1,7 +1,7 @@ import type { ReactNode } from 'react' import { useState } from 'react' -import { ScrollView, StyleSheet, Text, useWindowDimensions } from 'react-native' +import { ScrollView, StyleSheet, Text } from 'react-native' import type { SharedValue } from 'react-native-reanimated' import Animated, { runOnJS, @@ -13,6 +13,7 @@ import { useSafeAreaInsets } from 'react-native-safe-area-context' import { GlassCapsule } from 'app/components/core/Screen/GlassCapsule' import { isLiquidGlassAvailable } from 'app/components/core/Screen/LiquidGlass' +import { useContentWidth } from 'app/hooks/useContentWidth' import { makeStyles } from 'app/styles' import { useThemeColors } from 'app/utils/theme' import { zIndex } from 'app/utils/zIndex' @@ -121,7 +122,7 @@ export const CompactControls = (props: CompactControlsProps) => { const floating = useSharedValue(1) const tint = useCompactTint() const top = insets.top + COMPACT_TOP_GAP - const { width } = useWindowDimensions() + const width = useContentWidth() const { isShown, frameStyle, contentStyle } = useCompactFade(progress) return ( diff --git a/packages/mobile/src/screens/chat-screen/ChatMessageListItem.tsx b/packages/mobile/src/screens/chat-screen/ChatMessageListItem.tsx index 4f1999880f6..c933f9e84e1 100644 --- a/packages/mobile/src/screens/chat-screen/ChatMessageListItem.tsx +++ b/packages/mobile/src/screens/chat-screen/ChatMessageListItem.tsx @@ -15,7 +15,7 @@ import type { ReactionTypes, ChatMessageReaction } from '@audius/sdk' import { css } from '@emotion/native' import { find } from 'linkifyjs' import type { ViewStyle, StyleProp } from 'react-native' -import { Dimensions, Keyboard } from 'react-native' +import { Keyboard } from 'react-native' import { useSelector } from 'react-redux' import { Flex, spacing, Text } from '@audius/harmony-native' @@ -25,6 +25,7 @@ import { ProfilePicture, UserGeneratedText } from 'app/components/core' +import { useContentWidth } from 'app/hooks/useContentWidth' import { makeStyles } from 'app/styles' import { useThemeColors } from 'app/utils/theme' import { zIndex } from 'app/utils/zIndex' @@ -119,7 +120,7 @@ const useStyles = makeStyles(({ spacing, palette }) => ({ marginLeft: GROUP_AVATAR_SIZE + GROUP_AVATAR_GAP }, unfurl: { - width: Dimensions.get('window').width - 48, + width: 0, minHeight: 72, borderRadius: 0 } @@ -244,13 +245,16 @@ export const ChatMessageListItem = memo(function ChatMessageListItem( }, [linkValue]) const { secondaryDark1, neutralLight7 } = useThemeColors() + const contentWidth = useContentWidth() const borderBottomColor = isAuthor ? secondaryDark1 : neutralLight7 const borderBottomWidth = hideMessage || isCollection || isTrack ? 0 : 1 + const unfurlWidth = contentWidth - 48 const unfurlStyles = { ...styles.unfurl, + width: unfurlWidth, ...(isGroupOther - ? { width: styles.unfurl.width - GROUP_AVATAR_SIZE - GROUP_AVATAR_GAP } + ? { width: unfurlWidth - GROUP_AVATAR_SIZE - GROUP_AVATAR_GAP } : null), borderBottomColor, borderBottomWidth diff --git a/packages/mobile/src/screens/chat-screen/ReactionPopup.tsx b/packages/mobile/src/screens/chat-screen/ReactionPopup.tsx index 28463829f60..4f5aa6833c2 100644 --- a/packages/mobile/src/screens/chat-screen/ReactionPopup.tsx +++ b/packages/mobile/src/screens/chat-screen/ReactionPopup.tsx @@ -8,9 +8,10 @@ import { chatActions } from '@audius/common/store' import type { Nullable } from '@audius/common/utils' import { OptionalId } from '@audius/sdk' import Clipboard from '@react-native-clipboard/clipboard' -import { Dimensions, Pressable, Animated } from 'react-native' +import { Pressable, Animated } from 'react-native' import { useDispatch } from 'react-redux' +import { useContentWidth } from 'app/hooks/useContentWidth' import { usePopupAnimation } from 'app/hooks/usePopupAnimation' import { useToast } from 'app/hooks/useToast' import { makeStyles } from 'app/styles' @@ -62,7 +63,6 @@ const useStyles = makeStyles(({ spacing, palette, typography }) => ({ borderRadius: spacing(12), borderColor: palette.neutralLight9, zIndex: zIndex.CHAT_REACTIONS_POPUP_CONTENT, - width: Dimensions.get('window').width - spacing(10), backgroundColor: palette.white, marginHorizontal: spacing(5), shadowColor: 'black', @@ -72,7 +72,6 @@ const useStyles = makeStyles(({ spacing, palette, typography }) => ({ }, popupChatMessage: { position: 'absolute', - maxWidth: Dimensions.get('window').width - spacing(12), zIndex: zIndex.CHAT_REACTIONS_POPUP_CONTENT }, emoji: { @@ -105,6 +104,7 @@ export const ReactionPopup = ({ onClose }: ReactionPopupProps) => { const styles = useStyles() + const contentWidth = useContentWidth() const dispatch = useDispatch() const { data: userId } = useCurrentUserId() const { toast } = useToast() @@ -195,6 +195,7 @@ export const ReactionPopup = ({ style={[ styles.popupChatMessage, { + maxWidth: contentWidth - spacing(12), top: messageTop - containerTop, right: isAuthor ? spacing(6) : undefined, left: !isAuthor ? spacing(6) : undefined @@ -217,6 +218,7 @@ export const ReactionPopup = ({ style={[ styles.reactionsContainer, { + width: contentWidth - spacing(10), top: Math.max( messageTop - containerTop - REACTION_CONTAINER_HEIGHT, containerTop - diff --git a/packages/mobile/src/screens/explore-screen/components/FeaturedRemixContests.tsx b/packages/mobile/src/screens/explore-screen/components/FeaturedRemixContests.tsx index 4b3c1215860..bd4ec7406dd 100644 --- a/packages/mobile/src/screens/explore-screen/components/FeaturedRemixContests.tsx +++ b/packages/mobile/src/screens/explore-screen/components/FeaturedRemixContests.tsx @@ -2,11 +2,11 @@ import React from 'react' import { useAllRemixContests } from '@audius/common/api' import { exploreMessages as messages } from '@audius/common/messages' -import { useWindowDimensions } from 'react-native' import { useTheme } from '@audius/harmony-native' import { ContestCard, ContestCardSkeleton } from 'app/components/contest-card' import { CardList } from 'app/components/core' +import { useContentWidth } from 'app/hooks/useContentWidth' import { useDeferredElement } from '../../../hooks/useDeferredElement' @@ -16,7 +16,7 @@ const CONTEST_CARD_PEEK = 48 export const FeaturedRemixContests = () => { const { spacing } = useTheme() - const { width: windowWidth } = useWindowDimensions() + const windowWidth = useContentWidth() const contestCardWidth = windowWidth - CONTEST_CARD_PEEK const { InViewWrapper, inView } = useDeferredElement() const { data: allContestTrackIds, isPending: isAllContestsPending } = diff --git a/packages/mobile/src/screens/sign-on-screen/components/AccountHeader.tsx b/packages/mobile/src/screens/sign-on-screen/components/AccountHeader.tsx index 0ab9bbd949c..34ba5c8af04 100644 --- a/packages/mobile/src/screens/sign-on-screen/components/AccountHeader.tsx +++ b/packages/mobile/src/screens/sign-on-screen/components/AccountHeader.tsx @@ -9,7 +9,7 @@ import { import type { ImageFieldValue } from '@audius/web/src/pages/sign-up-page/components/ImageField' import { css } from '@emotion/native' import { isEmpty } from 'lodash' -import { Pressable, Dimensions } from 'react-native' +import { Pressable, useWindowDimensions } from 'react-native' import type { ImageSourcePropType } from 'react-native' import { useSelector } from 'react-redux' @@ -42,6 +42,7 @@ type AccountHeaderProps = { } export const AccountHeader = (props: AccountHeaderProps) => { + const { width: windowWidth } = useWindowDimensions() const { onSelectCoverPhoto, onSelectProfilePicture, @@ -70,7 +71,7 @@ export const AccountHeader = (props: AccountHeaderProps) => { position: 'absolute', left: spacing.unit4, top: spacing.unit10, - width: Dimensions.get('window').width - spacing.unit16 + width: windowWidth - spacing.unit16 })} > { ...other } = props const insets = useSafeAreaInsets() + const { width: windowWidth } = useWindowDimensions() const { spacing } = useTheme() const { handleSubmit, dirty, isValid } = useFormikContext() ?? {} @@ -107,7 +108,7 @@ export const PageFooter = (props: PageFooterProps) => { return (