1- import { useProfileUser } from '@audius/common/api'
1+ import { useCallback } from 'react'
2+
3+ import { useCurrentUserId , useProfileUser } from '@audius/common/api'
4+ import { ShareSource } from '@audius/common/models'
5+ import { modalsActions , shareModalUIActions } from '@audius/common/store'
26import { BlurView } from '@react-native-community/blur'
37import { StyleSheet } from 'react-native'
48import { useCurrentTabScrollY } from 'react-native-collapsible-tab-view'
59import Animated , {
610 interpolate ,
711 useAnimatedStyle
812} from 'react-native-reanimated'
13+ import { useSafeAreaInsets } from 'react-native-safe-area-context'
14+ import { useDispatch } from 'react-redux'
915
10- import { Flex } from '@audius/harmony-native'
16+ import {
17+ Flex ,
18+ IconButton ,
19+ IconCaretLeft ,
20+ IconKebabHorizontal ,
21+ IconShare
22+ } from '@audius/harmony-native'
1123import BadgeArtist from 'app/assets/images/badgeArtist.svg'
1224import { CoverPhoto } from 'app/components/image/CoverPhoto'
25+ import { useNavigation } from 'app/hooks/useNavigation'
1326import { makeStyles } from 'app/styles'
1427
28+ const { requestOpen : requestOpenShareModal } = shareModalUIActions
29+ const { setVisibility } = modalsActions
30+
1531const AnimatedBlurView = Animated . createAnimatedComponent ( BlurView )
1632
33+ // Height below the status bar. The avatar is 80px tall and is positioned so
34+ // it extends ~32px below the cover photo, matching the Figma spec.
35+ const COVER_PHOTO_CONTENT_HEIGHT = 96
36+
1737const useStyles = makeStyles ( ( { spacing } ) => ( {
18- coverPhoto : {
19- height : 96
38+ darkOverlay : {
39+ ...StyleSheet . absoluteFillObject ,
40+ backgroundColor : 'rgba(0, 0, 0, 0.2)'
41+ } ,
42+ actionsRow : {
43+ position : 'absolute' ,
44+ left : 0 ,
45+ right : 0 ,
46+ paddingHorizontal : spacing ( 4 ) ,
47+ paddingVertical : spacing ( 2 )
2048 } ,
2149 artistBadge : {
2250 position : 'absolute' ,
23- top : spacing ( 3 ) ,
24- right : spacing ( 3 )
51+ right : spacing ( 4 ) ,
52+ bottom : spacing ( 2 )
2553 }
2654} ) )
2755
2856export const ProfileCoverPhoto = ( ) => {
2957 const styles = useStyles ( )
58+ const insets = useSafeAreaInsets ( )
59+ const dispatch = useDispatch ( )
60+ const navigation = useNavigation ( )
61+ const { data : accountId } = useCurrentUserId ( )
62+
3063 const { user_id, track_count } =
3164 useProfileUser ( {
3265 select : ( user ) => ( {
@@ -37,7 +70,9 @@ export const ProfileCoverPhoto = () => {
3770
3871 const scrollY = useCurrentTabScrollY ( )
3972
40- const isArtist = track_count && track_count > 0
73+ const isArtist = ! ! track_count && track_count > 0
74+ const isOwner = ! ! user_id && user_id === accountId
75+ const coverPhotoHeight = insets . top + COVER_PHOTO_CONTENT_HEIGHT
4176
4277 const blurViewStyle = useAnimatedStyle ( ( ) => ( {
4378 ...StyleSheet . absoluteFillObject ,
@@ -49,7 +84,6 @@ export const ProfileCoverPhoto = () => {
4984 } ) )
5085
5186 const badgeStyle = useAnimatedStyle ( ( ) => ( {
52- ...styles . artistBadge ,
5387 transform : [
5488 {
5589 translateY : interpolate ( scrollY . value , [ - 200 , 0 ] , [ - 200 , 0 ] , {
@@ -60,19 +94,70 @@ export const ProfileCoverPhoto = () => {
6094 ]
6195 } ) )
6296
97+ const handleBack = useCallback ( ( ) => {
98+ navigation . goBack ( )
99+ } , [ navigation ] )
100+
101+ const handlePressActions = useCallback ( ( ) => {
102+ if ( ! user_id ) return
103+ if ( ! isOwner ) {
104+ dispatch (
105+ setVisibility ( {
106+ modal : 'ProfileActions' ,
107+ visible : true
108+ } )
109+ )
110+ } else {
111+ dispatch (
112+ requestOpenShareModal ( {
113+ type : 'profile' ,
114+ profileId : user_id ,
115+ source : ShareSource . PAGE
116+ } )
117+ )
118+ }
119+ } , [ dispatch , isOwner , user_id ] )
120+
63121 if ( ! user_id ) return null
64122
65123 return (
66- < Flex pointerEvents = 'none' h = { 96 } backgroundColor = 'surface2' >
67- < CoverPhoto style = { styles . coverPhoto } userId = { user_id } >
124+ < Flex
125+ pointerEvents = 'box-none'
126+ h = { coverPhotoHeight }
127+ backgroundColor = 'surface2'
128+ >
129+ < CoverPhoto style = { { height : coverPhotoHeight } } userId = { user_id } >
68130 < AnimatedBlurView
69131 blurType = 'dark'
70132 blurAmount = { 100 }
71133 style = { blurViewStyle }
72134 />
135+ { isArtist ? < Animated . View style = { styles . darkOverlay } /> : null }
73136 </ CoverPhoto >
137+ < Flex
138+ direction = 'row'
139+ justifyContent = 'space-between'
140+ alignItems = 'center'
141+ pointerEvents = 'box-none'
142+ style = { [ styles . actionsRow , { top : insets . top } ] }
143+ >
144+ < IconButton
145+ icon = { IconCaretLeft }
146+ color = 'staticWhite'
147+ shadow = 'emphasis'
148+ onPress = { handleBack }
149+ aria-label = 'Back'
150+ />
151+ < IconButton
152+ icon = { isOwner ? IconShare : IconKebabHorizontal }
153+ color = 'staticWhite'
154+ shadow = 'emphasis'
155+ onPress = { handlePressActions }
156+ aria-label = { isOwner ? 'Share profile' : 'Profile actions' }
157+ />
158+ </ Flex >
74159 { isArtist ? (
75- < Animated . View style = { badgeStyle } >
160+ < Animated . View style = { [ styles . artistBadge , badgeStyle ] } >
76161 < BadgeArtist />
77162 </ Animated . View >
78163 ) : null }
0 commit comments