From eb672872d85f203085c96005758314d5dba359f2 Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Fri, 11 Jun 2021 15:30:56 -0400 Subject: Simplify scroll logic, Cleanup code --- src/components/moments/MomentPostContent.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/components') diff --git a/src/components/moments/MomentPostContent.tsx b/src/components/moments/MomentPostContent.tsx index eb89fd03..da04211f 100644 --- a/src/components/moments/MomentPostContent.tsx +++ b/src/components/moments/MomentPostContent.tsx @@ -49,7 +49,8 @@ const MomentPostContent: React.FC = ({ ); const [commentPreview, setCommentPreview] = useState(moment.comment_preview); - const {keyboardVisible, setScrollToTargetIndex} = useContext(MomentContext); + const {keyboardVisible, currentScrollToIndex, scrollTo} = + useContext(MomentContext); useEffect(() => { setTags(momentTags); @@ -96,7 +97,7 @@ const MomentPostContent: React.FC = ({ /> )} - {!keyboardVisible && ( + {(!keyboardVisible || currentScrollToIndex !== index) && ( <> {moment.caption !== '' && renderTextWithMentions({ @@ -129,7 +130,7 @@ const MomentPostContent: React.FC = ({ comment: message, }) } - onFocus={() => setScrollToTargetIndex(index)} + onFocus={() => scrollTo(index)} theme={'dark'} /> {getTimePosted(moment.date_created)} -- cgit v1.2.3-70-g09d2