diff options
Diffstat (limited to 'src/components')
| -rw-r--r-- | src/components/messages/ChatInput.tsx | 6 | ||||
| -rw-r--r-- | src/components/profile/BadgeTutorialScreen.tsx | 81 | ||||
| -rw-r--r-- | src/components/profile/ProfileHeader.tsx | 71 | ||||
| -rw-r--r-- | src/components/profile/UniversityIcon.tsx | 3 |
4 files changed, 148 insertions, 13 deletions
diff --git a/src/components/messages/ChatInput.tsx b/src/components/messages/ChatInput.tsx index bde5fc12..2ae220c6 100644 --- a/src/components/messages/ChatInput.tsx +++ b/src/components/messages/ChatInput.tsx @@ -84,12 +84,12 @@ const ChatInput: React.FC< source={require('../../assets/images/camera.png')} /> </TouchableOpacity> */} - <TouchableOpacity onPress={() => setText('/')}> + {/* <TouchableOpacity onPress={() => setText('/')}> <Image style={{width: normalize(23), height: normalize(23)}} source={require('../../assets/images/gif.png')} /> - </TouchableOpacity> + </TouchableOpacity> */} <ChatInputSubmit onPress={sendMessage} outlined={text.length === 0} /> </View> </View> @@ -132,7 +132,7 @@ const styles = StyleSheet.create({ actionButtons: { height: normalize(30) + 10, flexDirection: 'row', - justifyContent: 'space-evenly', + justifyContent: 'flex-end', alignItems: 'center', marginRight: 10, width: 100, diff --git a/src/components/profile/BadgeTutorialScreen.tsx b/src/components/profile/BadgeTutorialScreen.tsx new file mode 100644 index 00000000..45831fc6 --- /dev/null +++ b/src/components/profile/BadgeTutorialScreen.tsx @@ -0,0 +1,81 @@ +import React, {useState} from 'react'; +import { + Image, + Modal, + StyleSheet, + Text, + TouchableOpacity, + View, +} from 'react-native'; +import {PROFILE_CUTOUT_TOP_Y} from '../../constants'; +import {normalize} from '../../utils'; +import {UniversityIcon} from './'; +import {UniversityIconProps} from './UniversityIcon'; + +interface BadgeTutorialScreenProps { + uniIconProps: UniversityIconProps; + setShowBadgeTutorial: Function; +} + +const BadgeTutorialScreen: React.FC<BadgeTutorialScreenProps> = ({ + uniIconProps, + setShowBadgeTutorial, +}) => { + const [showModal, setShowModal] = useState(true); + const {layout, university, university_class} = uniIconProps; + return ( + <Modal + animationType="fade" + transparent + visible={showModal} + presentationStyle="overFullScreen"> + <TouchableOpacity + onPress={() => { + setShowBadgeTutorial(false); + setShowModal(false); + }} + style={styles.viewWrapper}> + <View style={styles.textContainerStyles}> + <Text style={styles.textStyles}> + Tap on the univeristy icon to edit your badges! + </Text> + </View> + <View + style={{ + left: layout.left, + top: PROFILE_CUTOUT_TOP_Y * 1.02 - layout.top, + width: layout.width, + height: layout.height, + }}> + <UniversityIcon + {...{ + university, + university_class, + needsShadow: true, + }} + /> + <Image source={require('../../assets/images/badgeTutorial.png')} /> + </View> + </TouchableOpacity> + </Modal> + ); +}; +const styles = StyleSheet.create({ + viewWrapper: { + flex: 1, + backgroundColor: 'rgba(0, 0, 0, 0.5)', + }, + modalView: { + backgroundColor: '#fff', + }, + textContainerStyles: {top: '30%', width: '60%', alignSelf: 'center'}, + textStyles: { + color: 'white', + fontWeight: '700', + fontSize: normalize(20), + lineHeight: normalize(25), + textAlign: 'center', + }, +}); + +export default BadgeTutorialScreen; diff --git a/src/components/profile/ProfileHeader.tsx b/src/components/profile/ProfileHeader.tsx index 494b33bd..82eda258 100644 --- a/src/components/profile/ProfileHeader.tsx +++ b/src/components/profile/ProfileHeader.tsx @@ -1,13 +1,14 @@ -import React, {useState} from 'react'; +import React, {useLayoutEffect, useRef, useState} from 'react'; import {StyleSheet, Text, View} from 'react-native'; import {TouchableOpacity} from 'react-native-gesture-handler'; -import {useSelector} from 'react-redux'; +import {useSelector, useStore} from 'react-redux'; import {PROFILE_CUTOUT_TOP_Y} from '../../constants'; import {RootState} from '../../store/rootreducer'; import {ScreenType} from '../../types'; -import {normalize} from '../../utils'; +import {hasSeenBadgeTutorial, normalize} from '../../utils'; import BadgeDetailView from '../common/BadgeDetailView'; import Avatar from './Avatar'; +import BadgeTutorialScreen from './BadgeTutorialScreen'; import FriendsCount from './FriendsCount'; import ProfileMoreInfoDrawer from './ProfileMoreInfoDrawer'; import UniversityIcon from './UniversityIcon'; @@ -29,11 +30,14 @@ const ProfileHeader: React.FC<ProfileHeaderProps> = ({ }) => { const { profile: {name = '', university_class = 2021, university}, - user: {username: userXName = ''}, + user: {username: userXName = '', userId}, } = useSelector((state: RootState) => userXId ? state.userX[screenType][userXId] : state.user, ); + const state: RootState = useStore().getState(); + const loggedInUserId = state.user.user.userId; + const { user: {username = ''}, } = useSelector((state: RootState) => state.user); @@ -41,8 +45,36 @@ const ProfileHeader: React.FC<ProfileHeaderProps> = ({ const [showBadgeView, setBadgeViewVisible] = useState(false); const [firstName, lastName] = [...name.split(' ')]; + const containerRef = useRef(null); + const childRef = useRef(null); + const [measure, setMeasure] = useState(null); + const [showBadgeTutorial, setShowBadgeTutorial] = useState(false); + useLayoutEffect(() => { + setTimeout(() => { + measureStuff(); + }, 1000); + }, []); + + const measureStuff = async () => { + const badgeSeen = await hasSeenBadgeTutorial(); + if (!badgeSeen && containerRef.current && childRef.current) { + childRef?.current?.measureLayout( + containerRef.current, + (left, top, width, height) => { + console.log(left, top, width, height); + setMeasure({left, top, width, height}); + setShowBadgeTutorial(true); + }, + (error) => { + setShowBadgeTutorial(false); + console.log(error); + }, + ); + } + }; + return ( - <View style={styles.container}> + <View ref={containerRef} style={styles.container}> <ProfileMoreInfoDrawer isOpen={drawerVisible} isBlocked={isBlocked} @@ -51,7 +83,16 @@ const ProfileHeader: React.FC<ProfileHeaderProps> = ({ userXName={userXName} setIsOpen={setDrawerVisible} /> - + {userId === loggedInUserId && measure && ( + <BadgeTutorialScreen + uniIconProps={{ + university: university, + university_class: university_class, + layout: measure, + }} + setShowBadgeTutorial={setShowBadgeTutorial} + /> + )} <View style={styles.row}> <Avatar style={styles.avatar} @@ -67,6 +108,7 @@ const ProfileHeader: React.FC<ProfileHeaderProps> = ({ <Text style={styles.name}>{lastName}</Text> </View> )} + <View style={styles.friendsAndUniversity}> <FriendsCount screenType={screenType} userXId={userXId} /> <TouchableOpacity @@ -75,9 +117,19 @@ const ProfileHeader: React.FC<ProfileHeaderProps> = ({ setBadgeViewVisible(true); } }}> - <UniversityIcon - {...{university, university_class, needsShadow: true}} - /> + <View ref={childRef}> + {userId === loggedInUserId && showBadgeTutorial === true ? ( + <View style={styles.emptyContainer} /> + ) : ( + <UniversityIcon + {...{ + university, + university_class, + needsShadow: true, + }} + /> + )} + </View> </TouchableOpacity> {showBadgeView && ( <BadgeDetailView @@ -126,6 +178,7 @@ const styles = StyleSheet.create({ width: '100%', height: 50, }, + emptyContainer: {backgroundColor: 'white', width: 50, height: 50}, }); export default ProfileHeader; diff --git a/src/components/profile/UniversityIcon.tsx b/src/components/profile/UniversityIcon.tsx index cfe1366d..560a771e 100644 --- a/src/components/profile/UniversityIcon.tsx +++ b/src/components/profile/UniversityIcon.tsx @@ -1,14 +1,15 @@ import React from 'react'; import {ImageStyle, StyleProp, StyleSheet, ViewProps} from 'react-native'; import {Image, Text, View} from 'react-native-animatable'; -import {getUniversityBadge, getUniversityClass, normalize} from '../../utils'; import {UniversityType} from '../../types'; +import {getUniversityBadge, getUniversityClass, normalize} from '../../utils'; export interface UniversityIconProps extends ViewProps { university: UniversityType; university_class?: number; imageStyle?: StyleProp<ImageStyle>; needsShadow?: boolean; + layout?: object | null; } /** |
