[Perf] Message List: Adjust focus animation params

This commit is contained in:
Alexander Zinchuk 2021-07-14 19:56:11 +03:00
parent 0acbc6ce15
commit b3f9fc0f12
4 changed files with 25 additions and 17 deletions

View File

@ -1,9 +1,8 @@
import { useLayoutEffect } from '../../../../lib/teact/teact';
import fastSmoothScroll from '../../../../util/fastSmoothScroll';
import { FocusDirection } from '../../../../types'; import { FocusDirection } from '../../../../types';
// This is the max scroll offset within existing viewport. import { useLayoutEffect } from '../../../../lib/teact/teact';
const FOCUS_MAX_OFFSET = 1200; import fastSmoothScroll from '../../../../util/fastSmoothScroll';
// This is used when the viewport was replaced. // This is used when the viewport was replaced.
const RELOCATED_FOCUS_OFFSET = 1000; const RELOCATED_FOCUS_OFFSET = 1000;
const FOCUS_MARGIN = 20; const FOCUS_MARGIN = 20;
@ -25,7 +24,7 @@ export default function useFocusMessage(
// `noFocusHighlight` always called from “scroll-to-bottom” buttons // `noFocusHighlight` always called from “scroll-to-bottom” buttons
noFocusHighlight ? 'end' : 'centerOrTop', noFocusHighlight ? 'end' : 'centerOrTop',
FOCUS_MARGIN, FOCUS_MARGIN,
focusDirection === undefined ? FOCUS_MAX_OFFSET : RELOCATED_FOCUS_OFFSET, focusDirection !== undefined ? RELOCATED_FOCUS_OFFSET : undefined,
focusDirection, focusDirection,
); );
} }

View File

@ -92,6 +92,11 @@ export const LOCAL_MESSAGE_ID_BASE = 1e9;
export const ANIMATION_END_DELAY = 100; export const ANIMATION_END_DELAY = 100;
export const FAST_SMOOTH_MAX_DISTANCE = 1500;
export const FAST_SMOOTH_MIN_DURATION = 250;
export const FAST_SMOOTH_MAX_DURATION = 600;
export const FAST_SMOOTH_SHORT_TRANSITION_MAX_DISTANCE = 500; // px
export const STICKER_SIZE_INLINE_DESKTOP_FACTOR = 13; export const STICKER_SIZE_INLINE_DESKTOP_FACTOR = 13;
export const STICKER_SIZE_INLINE_MOBILE_FACTOR = 11; export const STICKER_SIZE_INLINE_MOBILE_FACTOR = 11;
export const STICKER_SIZE_AUTH = 160; export const STICKER_SIZE_AUTH = 160;

View File

@ -3,6 +3,8 @@ import { addReducer, getGlobal, setGlobal } from '../../../lib/teact/teactn';
import { MAIN_THREAD_ID } from '../../../api/types'; import { MAIN_THREAD_ID } from '../../../api/types';
import { FocusDirection } from '../../../types'; import { FocusDirection } from '../../../types';
import { ANIMATION_END_DELAY, FAST_SMOOTH_MAX_DURATION } from '../../../config';
import { IS_TOUCH_ENV } from '../../../util/environment';
import { import {
enterMessageSelectMode, enterMessageSelectMode,
toggleMessageSelection, toggleMessageSelection,
@ -21,13 +23,15 @@ import {
selectChatMessages, selectChatMessages,
selectAllowedMessageActions, selectAllowedMessageActions,
selectMessageIdsByGroupId, selectMessageIdsByGroupId,
selectForwardedMessageIdsByGroupId, selectIsViewportNewest, selectReplyingToId, selectReplyStack, selectForwardedMessageIdsByGroupId,
selectIsViewportNewest,
selectReplyingToId,
selectReplyStack,
} from '../../selectors'; } from '../../selectors';
import { findLast } from '../../../util/iteratees'; import { findLast } from '../../../util/iteratees';
import { IS_TOUCH_ENV } from '../../../util/environment';
const FOCUS_DURATION = 1500; const FOCUS_DURATION = 1500;
const FOCUS_NO_HIGHLIGHT_DURATION = 500; // Matches `fastSmoothScroll:MAX_JS_DURATION` const FOCUS_NO_HIGHLIGHT_DURATION = FAST_SMOOTH_MAX_DURATION + ANIMATION_END_DELAY;
const POLL_RESULT_OPEN_DELAY_MS = 450; const POLL_RESULT_OPEN_DELAY_MS = 450;
let blurTimeout: number | undefined; let blurTimeout: number | undefined;

View File

@ -2,16 +2,15 @@ import { getGlobal } from '../lib/teact/teactn';
import { FocusDirection } from '../types'; import { FocusDirection } from '../types';
import { ANIMATION_LEVEL_MIN } from '../config'; import {
ANIMATION_LEVEL_MIN,
FAST_SMOOTH_MAX_DISTANCE, FAST_SMOOTH_MAX_DURATION, FAST_SMOOTH_MIN_DURATION,
FAST_SMOOTH_SHORT_TRANSITION_MAX_DISTANCE,
} from '../config';
import { dispatchHeavyAnimationEvent } from '../hooks/useHeavyAnimationCheck'; import { dispatchHeavyAnimationEvent } from '../hooks/useHeavyAnimationCheck';
import { fastRaf } from './schedulers'; import { fastRaf } from './schedulers';
import { animateSingle } from './animation'; import { animateSingle } from './animation';
const MAX_DISTANCE = 1200;
const MIN_JS_DURATION = 250;
const MAX_JS_DURATION = 500;
const SHORT_CURVE_THRESHOLD = 150; // px
let isAnimating = false; let isAnimating = false;
export default function fastSmoothScroll( export default function fastSmoothScroll(
@ -19,7 +18,7 @@ export default function fastSmoothScroll(
element: HTMLElement, element: HTMLElement,
position: ScrollLogicalPosition | 'centerOrTop', position: ScrollLogicalPosition | 'centerOrTop',
margin = 0, margin = 0,
maxDistance = MAX_DISTANCE, maxDistance = FAST_SMOOTH_MAX_DISTANCE,
forceDirection?: FocusDirection, forceDirection?: FocusDirection,
forceDuration?: number, forceDuration?: number,
forceCurrentContainerHeight?: boolean, forceCurrentContainerHeight?: boolean,
@ -119,9 +118,10 @@ function scrollWithJs(
} }
const absPath = Math.abs(path); const absPath = Math.abs(path);
const transition = absPath < SHORT_CURVE_THRESHOLD ? shortTransition : longTransition; const transition = absPath < FAST_SMOOTH_SHORT_TRANSITION_MAX_DISTANCE ? shortTransition : longTransition;
const duration = forceDuration || ( const duration = forceDuration || (
MIN_JS_DURATION + (absPath / MAX_DISTANCE) * (MAX_JS_DURATION - MIN_JS_DURATION) FAST_SMOOTH_MIN_DURATION
+ (absPath / FAST_SMOOTH_MAX_DISTANCE) * (FAST_SMOOTH_MAX_DURATION - FAST_SMOOTH_MIN_DURATION)
); );
const startAt = Date.now(); const startAt = Date.now();