Story Slides: Fix flipping stories on mobile (#4192)
This commit is contained in:
parent
febcd73629
commit
1664082be6
@ -8,6 +8,7 @@ import type { ApiStory } from '../../api/types';
|
|||||||
import { requestForcedReflow, requestMeasure, requestMutation } from '../../lib/fasterdom/fasterdom';
|
import { requestForcedReflow, requestMeasure, requestMutation } from '../../lib/fasterdom/fasterdom';
|
||||||
import buildClassName from '../../util/buildClassName';
|
import buildClassName from '../../util/buildClassName';
|
||||||
|
|
||||||
|
import useCurrentOrPrev from '../../hooks/useCurrentOrPrev';
|
||||||
import useLang from '../../hooks/useLang';
|
import useLang from '../../hooks/useLang';
|
||||||
import usePrevDuringAnimation from '../../hooks/usePrevDuringAnimation';
|
import usePrevDuringAnimation from '../../hooks/usePrevDuringAnimation';
|
||||||
import useShowTransition from '../../hooks/useShowTransition';
|
import useShowTransition from '../../hooks/useShowTransition';
|
||||||
@ -40,8 +41,9 @@ function StoryCaption({
|
|||||||
const textRef = useRef<HTMLDivElement>(null);
|
const textRef = useRef<HTMLDivElement>(null);
|
||||||
// eslint-disable-next-line no-null/no-null
|
// eslint-disable-next-line no-null/no-null
|
||||||
const showMoreButtonRef = useRef<HTMLDivElement>(null);
|
const showMoreButtonRef = useRef<HTMLDivElement>(null);
|
||||||
|
const renderingStory = useCurrentOrPrev(story, true);
|
||||||
|
|
||||||
const caption = story.content.text;
|
const caption = renderingStory?.content.text;
|
||||||
|
|
||||||
const [hasOverflow, setHasOverflow] = useState(false);
|
const [hasOverflow, setHasOverflow] = useState(false);
|
||||||
const prevIsExpanded = usePrevDuringAnimation(isExpanded || undefined, EXPAND_ANIMATION_DURATION_MS);
|
const prevIsExpanded = usePrevDuringAnimation(isExpanded || undefined, EXPAND_ANIMATION_DURATION_MS);
|
||||||
@ -131,19 +133,21 @@ function StoryCaption({
|
|||||||
ref={ref}
|
ref={ref}
|
||||||
className={buildClassName(styles.captionInner, 'allow-selection', 'custom-scroll')}
|
className={buildClassName(styles.captionInner, 'allow-selection', 'custom-scroll')}
|
||||||
>
|
>
|
||||||
{story.forwardInfo && (
|
{renderingStory?.forwardInfo && (
|
||||||
<EmbeddedStoryForward
|
<EmbeddedStoryForward
|
||||||
forwardInfo={story.forwardInfo}
|
forwardInfo={renderingStory.forwardInfo}
|
||||||
className={styles.forwardInfo}
|
className={styles.forwardInfo}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<div ref={textRef} className={styles.captionText}>
|
{renderingStory && (
|
||||||
<MessageText
|
<div ref={textRef} className={styles.captionText}>
|
||||||
messageOrStory={story}
|
<MessageText
|
||||||
withTranslucentThumbs
|
messageOrStory={renderingStory}
|
||||||
forcePlayback
|
withTranslucentThumbs
|
||||||
/>
|
forcePlayback
|
||||||
</div>
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{shouldRenderShowMore && (
|
{shouldRenderShowMore && (
|
||||||
|
|||||||
@ -6,7 +6,7 @@ import { getActions, getGlobal, withGlobal } from '../../global';
|
|||||||
import type { ApiPeerStories, ApiTypeStory } from '../../api/types';
|
import type { ApiPeerStories, ApiTypeStory } from '../../api/types';
|
||||||
import type { RealTouchEvent } from '../../util/captureEvents';
|
import type { RealTouchEvent } from '../../util/captureEvents';
|
||||||
|
|
||||||
import { ANIMATION_END_DELAY, EDITABLE_STORY_INPUT_ID } from '../../config';
|
import { EDITABLE_STORY_INPUT_ID } from '../../config';
|
||||||
import { requestMutation } from '../../lib/fasterdom/fasterdom';
|
import { requestMutation } from '../../lib/fasterdom/fasterdom';
|
||||||
import { getStoryKey } from '../../global/helpers';
|
import { getStoryKey } from '../../global/helpers';
|
||||||
import {
|
import {
|
||||||
@ -25,9 +25,7 @@ import {
|
|||||||
import focusEditableElement from '../../util/focusEditableElement';
|
import focusEditableElement from '../../util/focusEditableElement';
|
||||||
import { clamp } from '../../util/math';
|
import { clamp } from '../../util/math';
|
||||||
import { disableScrolling, enableScrolling } from '../../util/scrollLock';
|
import { disableScrolling, enableScrolling } from '../../util/scrollLock';
|
||||||
import {
|
import { IS_IOS } from '../../util/windowEnvironment';
|
||||||
IS_FIREFOX, IS_IOS, IS_SAFARI,
|
|
||||||
} from '../../util/windowEnvironment';
|
|
||||||
import { calculateOffsetX } from './helpers/dimensions';
|
import { calculateOffsetX } from './helpers/dimensions';
|
||||||
|
|
||||||
import useAppLayout from '../../hooks/useAppLayout';
|
import useAppLayout from '../../hooks/useAppLayout';
|
||||||
@ -64,7 +62,6 @@ interface StateProps {
|
|||||||
isArchive?: boolean;
|
isArchive?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ANIMATION_DURATION_MS = 350 + (IS_SAFARI || IS_FIREFOX ? ANIMATION_END_DELAY : 20);
|
|
||||||
const ACTIVE_SLIDE_VERTICAL_CORRECTION_REM = 1.75;
|
const ACTIVE_SLIDE_VERTICAL_CORRECTION_REM = 1.75;
|
||||||
const SWIPE_Y_THRESHOLD = 50;
|
const SWIPE_Y_THRESHOLD = 50;
|
||||||
const SCROLL_RELEASE_DELAY = 1500;
|
const SCROLL_RELEASE_DELAY = 1500;
|
||||||
@ -105,7 +102,6 @@ function StorySlides({
|
|||||||
const swipeDirectionRef = useRef<SwipeDirection | undefined>(undefined);
|
const swipeDirectionRef = useRef<SwipeDirection | undefined>(undefined);
|
||||||
const isReleasedRef = useRef(false);
|
const isReleasedRef = useRef(false);
|
||||||
const { isMobile } = useAppLayout();
|
const { isMobile } = useAppLayout();
|
||||||
const animationDuration = isMobile ? 0 : ANIMATION_DURATION_MS;
|
|
||||||
|
|
||||||
const rendersRef = useRef<Record<string, { current: HTMLDivElement | null }>>({});
|
const rendersRef = useRef<Record<string, { current: HTMLDivElement | null }>>({});
|
||||||
const [getIsAnimating, setIsAnimating] = useSignal(false);
|
const [getIsAnimating, setIsAnimating] = useSignal(false);
|
||||||
@ -158,6 +154,13 @@ function StorySlides({
|
|||||||
return renderingPeerIds.indexOf(currentPeerId);
|
return renderingPeerIds.indexOf(currentPeerId);
|
||||||
}, [currentPeerId, renderingPeerIds]);
|
}, [currentPeerId, renderingPeerIds]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!isMobile) return;
|
||||||
|
|
||||||
|
// If animation disabled, set rendering peer id to current peer
|
||||||
|
setRenderingPeerId(currentPeerId);
|
||||||
|
}, [currentPeerId, isMobile]);
|
||||||
|
|
||||||
// Handling the flipping of stories from a current user
|
// Handling the flipping of stories from a current user
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (renderingPeerId === currentPeerId && currentStoryId !== renderingStoryId) {
|
if (renderingPeerId === currentPeerId && currentStoryId !== renderingStoryId) {
|
||||||
@ -166,6 +169,7 @@ function StorySlides({
|
|||||||
}, [currentPeerId, currentStoryId, renderingPeerId, renderingStoryId]);
|
}, [currentPeerId, currentStoryId, renderingPeerId, renderingStoryId]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (isMobile) return undefined;
|
||||||
if (prevPeerId && prevPeerId !== currentPeerId) {
|
if (prevPeerId && prevPeerId !== currentPeerId) {
|
||||||
setIsAnimating(true);
|
setIsAnimating(true);
|
||||||
}
|
}
|
||||||
@ -173,7 +177,7 @@ function StorySlides({
|
|||||||
return () => {
|
return () => {
|
||||||
setIsAnimating(false);
|
setIsAnimating(false);
|
||||||
};
|
};
|
||||||
}, [prevPeerId, currentPeerId, setIsAnimating, animationDuration]);
|
}, [prevPeerId, currentPeerId, setIsAnimating, isMobile]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
return () => {
|
return () => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user