diff options
Diffstat (limited to 'src/screens/profile/ProfileScreen.tsx')
-rw-r--r-- | src/screens/profile/ProfileScreen.tsx | 43 |
1 files changed, 34 insertions, 9 deletions
diff --git a/src/screens/profile/ProfileScreen.tsx b/src/screens/profile/ProfileScreen.tsx index 7d11fa2a..9579a696 100644 --- a/src/screens/profile/ProfileScreen.tsx +++ b/src/screens/profile/ProfileScreen.tsx @@ -3,7 +3,7 @@ import {StatusBar} from 'react-native'; import Animated from 'react-native-reanimated'; import {Content, Cover, TabsGradient} from '../../components'; import {RouteProp} from '@react-navigation/native'; -import {ProfileStackParams} from '../../routes/profile'; +import {ProfileStackParams, ProfileProvider} from '../../routes/'; /** * Profile Screen for a user's profile @@ -17,15 +17,40 @@ interface ProfileOnboardingProps { } const ProfileScreen: React.FC<ProfileOnboardingProps> = ({route}) => { - const {isProfileView} = route.params; + const {isProfileView, username, userId} = route.params; const y = Animated.useValue(0); - return ( - <> - <StatusBar /> - <Cover {...{y, isProfileView}} /> - <Content {...{y, isProfileView}} /> - <TabsGradient /> - </> + + const profileView = () => { + return ( + <> + <StatusBar /> + <Cover {...{y, isProfileView}} /> + <Content {...{y, isProfileView}} /> + <TabsGradient /> + </> + ); + }; + + /** + * Every profile to have it's own ProfileContext if a profile is being visited by the logged in user. + * Pass userid and username of the user whose profile needs to be viewed and the information gets loaded to the ProfileContext. + * Now this profile context is local to every user being viewed. + * This comes with BENEFITS and CAVEATS + * BENEFITS : + * 1 - The app now remembers which user was visited last. + * 2 - The Search and Profile stacks (and potentially more stacks in the future) now have totally unrelated stacks of profiles being visited. + * 3 - This will help us manage the navigation stack better if we introduce a feature to go back to the last profile visited. + * CAVEATS : + * 1 - Since the ProfileContext is not global, whenever we navigate to some component that is not in the child tree of the ProfileProvider, we would not be able to use anything in the context (It would basically have default values). + * 2 - For example, the followers list (FollowersListScreen) and profile picture on the Taggs screen (AvatarTile) now no longer have access to the ProfileContext. + * 3 - Components like these now have to have data passed in via props, instead of using the context. + */ + return isProfileView ? ( + <ProfileProvider uId={userId} uname={username}> + {profileView()} + </ProfileProvider> + ) : ( + profileView() ); }; |