From aa25df7dbd192394f2d6d42ed07d1e1f43cc07f0 Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Fri, 9 Jul 2021 15:23:12 -0400 Subject: Fix mention box position, Fix image flickering --- src/components/common/TaggTypeahead.tsx | 44 +++++++++++++++++++++------ src/screens/profile/CaptionScreen.tsx | 53 ++++++++++++++++++++------------- src/utils/comments.tsx | 9 ++++-- 3 files changed, 75 insertions(+), 31 deletions(-) (limited to 'src') diff --git a/src/components/common/TaggTypeahead.tsx b/src/components/common/TaggTypeahead.tsx index 7967fdbc..7444e2d8 100644 --- a/src/components/common/TaggTypeahead.tsx +++ b/src/components/common/TaggTypeahead.tsx @@ -1,5 +1,5 @@ -import React, {Fragment, useEffect, useState} from 'react'; -import {ScrollView, StyleSheet, View} from 'react-native'; +import React, {Fragment, useEffect, useRef, useState} from 'react'; +import {LayoutChangeEvent, ScrollView, StyleSheet, View} from 'react-native'; import {Suggestion} from 'react-native-controlled-mentions'; import {useSelector} from 'react-redux'; import {SEARCH_ENDPOINT_MESSAGES} from '../../constants'; @@ -13,15 +13,19 @@ type TaggTypeaheadProps = { keyword: string | undefined; component: string | undefined; onSuggestionPress: (suggestion: Suggestion) => void; + isShowBelowStyle?: boolean; }; const TaggTypeahead: React.FC = ({ keyword, component, onSuggestionPress, + isShowBelowStyle = false, }) => { const {friends} = useSelector((state: RootState) => state.friends); const [results, setResults] = useState([]); + const [viewPx, setViewPx] = useState(0); + const viewRef = useRef(null); const [height, setHeight] = useState(0); const margin = component === 'comment' ? -10 : 0; @@ -33,6 +37,22 @@ const TaggTypeahead: React.FC = ({ } }, [keyword]); + const onLayout = (e: LayoutChangeEvent) => { + setHeight(e.nativeEvent.layout.height); + viewRef.current?.measure( + ( + _fx: number, + _fy: number, + _width: number, + _height: number, + px: number, + _py: number, + ) => { + setViewPx(px); + }, + ); + }; + const getQuerySuggested = async () => { if (keyword === undefined || keyword === '@') { return; @@ -50,14 +70,17 @@ const TaggTypeahead: React.FC = ({ } return ( - - + + {!isShowBelowStyle && } { - setHeight(event.nativeEvent.layout.height); - }} + onLayout={onLayout} keyboardShouldPersistTaps={'always'}> {results.map((user) => ( = ({ const styles = StyleSheet.create({ container: { + position: 'absolute', width: SCREEN_WIDTH, maxHeight: 264, backgroundColor: 'white', - position: 'absolute', alignSelf: 'center', zIndex: 1, }, @@ -95,6 +118,9 @@ const styles = StyleSheet.create({ bottom: 10, zIndex: -1, }, + topPadding: { + top: 30, + }, }); export default TaggTypeahead; diff --git a/src/screens/profile/CaptionScreen.tsx b/src/screens/profile/CaptionScreen.tsx index 9a1878aa..02b8caf2 100644 --- a/src/screens/profile/CaptionScreen.tsx +++ b/src/screens/profile/CaptionScreen.tsx @@ -1,6 +1,6 @@ import {RouteProp} from '@react-navigation/native'; import {StackNavigationProp} from '@react-navigation/stack'; -import React, {FC, useEffect, useState} from 'react'; +import React, {FC, useEffect, useMemo, useState} from 'react'; import { Alert, Image, @@ -293,27 +293,39 @@ const CaptionScreen: React.FC = ({route, navigation}) => { placeholderTextColor="white" value={caption} onChange={setCaption} - partTypes={mentionPartTypes('white', 'caption')} + partTypes={mentionPartTypes('white', 'caption', true)} /> - navigation.navigate('ChoosingCategoryScreen', {})} - /> - - navigation.navigate('TagFriendsScreen', { - media: { - uri: mediaUri, - isVideo: isMediaAVideo, - }, - selectedTags: tags, - }) - } - /> + {useMemo( + () => ( + + navigation.navigate('ChoosingCategoryScreen', {}) + } + /> + ), + [momentCategory], + )} + {useMemo( + () => ( + + navigation.navigate('TagFriendsScreen', { + media: { + uri: mediaUri, + isVideo: isMediaAVideo, + }, + selectedTags: tags, + }) + } + /> + ), + [taggedUsersText], + )} {momentCategory ? ( = ({ export const mentionPartTypes: ( theme: 'blue' | 'white', component: 'caption' | 'comment', -) => PartType[] = (theme, component) => { + isShowBelowStyle?: boolean, +) => PartType[] = (theme, component, isShowBelowStyle = false) => { return [ { trigger: '@', renderSuggestions: (props) => ( - + ), allowedSpacesCount: 0, isInsertSpaceAfterMention: true, -- cgit v1.2.3-70-g09d2