Message List: Fix frozen scroll when animations are turned off
This commit is contained in:
parent
27ebe2309a
commit
974acff927
@ -52,6 +52,7 @@ import usePrevDuringAnimation from '../../hooks/usePrevDuringAnimation';
|
|||||||
import useLang from '../../hooks/useLang';
|
import useLang from '../../hooks/useLang';
|
||||||
import useHistoryBack from '../../hooks/useHistoryBack';
|
import useHistoryBack from '../../hooks/useHistoryBack';
|
||||||
import usePrevious from '../../hooks/usePrevious';
|
import usePrevious from '../../hooks/usePrevious';
|
||||||
|
import useForceUpdate from '../../hooks/useForceUpdate';
|
||||||
import calculateMiddleFooterTransforms from './helpers/calculateMiddleFooterTransforms';
|
import calculateMiddleFooterTransforms from './helpers/calculateMiddleFooterTransforms';
|
||||||
|
|
||||||
import Transition from '../ui/Transition';
|
import Transition from '../ui/Transition';
|
||||||
@ -163,7 +164,6 @@ const MiddleColumn: FC<StateProps & DispatchProps> = ({
|
|||||||
const [isFabShown, setIsFabShown] = useState<boolean | undefined>();
|
const [isFabShown, setIsFabShown] = useState<boolean | undefined>();
|
||||||
const [isNotchShown, setIsNotchShown] = useState<boolean | undefined>();
|
const [isNotchShown, setIsNotchShown] = useState<boolean | undefined>();
|
||||||
const [isUnpinModalOpen, setIsUnpinModalOpen] = useState(false);
|
const [isUnpinModalOpen, setIsUnpinModalOpen] = useState(false);
|
||||||
const [isReady, setIsReady] = useState(!IS_SINGLE_COLUMN_LAYOUT || animationLevel === ANIMATION_LEVEL_MIN);
|
|
||||||
|
|
||||||
const hasTools = hasPinnedOrAudioPlayer && (
|
const hasTools = hasPinnedOrAudioPlayer && (
|
||||||
windowWidth < MOBILE_SCREEN_MAX_WIDTH
|
windowWidth < MOBILE_SCREEN_MAX_WIDTH
|
||||||
@ -189,14 +189,15 @@ const MiddleColumn: FC<StateProps & DispatchProps> = ({
|
|||||||
const renderingIsChannel = usePrevDuringAnimation(isChannel, CLOSE_ANIMATION_DURATION);
|
const renderingIsChannel = usePrevDuringAnimation(isChannel, CLOSE_ANIMATION_DURATION);
|
||||||
|
|
||||||
const prevTransitionKey = usePrevious(currentTransitionKey);
|
const prevTransitionKey = usePrevious(currentTransitionKey);
|
||||||
const willSwitchMessageList = prevTransitionKey !== undefined && prevTransitionKey !== currentTransitionKey;
|
|
||||||
if (willSwitchMessageList) {
|
|
||||||
setIsReady(false);
|
|
||||||
}
|
|
||||||
const cleanupExceptionKey = (
|
const cleanupExceptionKey = (
|
||||||
prevTransitionKey !== undefined && prevTransitionKey < currentTransitionKey ? prevTransitionKey : undefined
|
prevTransitionKey !== undefined && prevTransitionKey < currentTransitionKey ? prevTransitionKey : undefined
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const { isReady, handleOpenEnd, handleSlideStop } = useIsReady(
|
||||||
|
animationLevel, currentTransitionKey, prevTransitionKey, chatId,
|
||||||
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
return chatId
|
return chatId
|
||||||
? captureEscKeyListener(() => {
|
? captureEscKeyListener(() => {
|
||||||
@ -211,12 +212,6 @@ const MiddleColumn: FC<StateProps & DispatchProps> = ({
|
|||||||
setIsNotchShown(undefined);
|
setIsNotchShown(undefined);
|
||||||
}, [chatId]);
|
}, [chatId]);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (animationLevel === ANIMATION_LEVEL_MIN) {
|
|
||||||
setIsReady(true);
|
|
||||||
}
|
|
||||||
}, [animationLevel]);
|
|
||||||
|
|
||||||
// Fix for mobile virtual keyboard
|
// Fix for mobile virtual keyboard
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const { visualViewport } = window as any;
|
const { visualViewport } = window as any;
|
||||||
@ -239,12 +234,6 @@ const MiddleColumn: FC<StateProps & DispatchProps> = ({
|
|||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleTransitionEnd = (e: React.TransitionEvent<HTMLDivElement>) => {
|
|
||||||
if (e.propertyName === 'transform' && e.target === e.currentTarget) {
|
|
||||||
setIsReady(Boolean(chatId));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isPrivate) {
|
if (isPrivate) {
|
||||||
loadUser({ userId: chatId });
|
loadUser({ userId: chatId });
|
||||||
@ -359,7 +348,7 @@ const MiddleColumn: FC<StateProps & DispatchProps> = ({
|
|||||||
<div
|
<div
|
||||||
id="MiddleColumn"
|
id="MiddleColumn"
|
||||||
className={className}
|
className={className}
|
||||||
onTransitionEnd={handleTransitionEnd}
|
onTransitionEnd={handleOpenEnd}
|
||||||
// @ts-ignore teact-feature
|
// @ts-ignore teact-feature
|
||||||
style={`
|
style={`
|
||||||
--composer-hidden-scale: ${composerHiddenScale};
|
--composer-hidden-scale: ${composerHiddenScale};
|
||||||
@ -387,14 +376,14 @@ const MiddleColumn: FC<StateProps & DispatchProps> = ({
|
|||||||
chatId={renderingChatId}
|
chatId={renderingChatId}
|
||||||
threadId={renderingThreadId}
|
threadId={renderingThreadId}
|
||||||
messageListType={renderingMessageListType}
|
messageListType={renderingMessageListType}
|
||||||
isReady={isReady && !willSwitchMessageList}
|
isReady={isReady}
|
||||||
/>
|
/>
|
||||||
<Transition
|
<Transition
|
||||||
name={shouldSkipHistoryAnimations ? 'none' : animationLevel === ANIMATION_LEVEL_MAX ? 'slide' : 'fade'}
|
name={shouldSkipHistoryAnimations ? 'none' : animationLevel === ANIMATION_LEVEL_MAX ? 'slide' : 'fade'}
|
||||||
activeKey={currentTransitionKey}
|
activeKey={currentTransitionKey}
|
||||||
shouldCleanup
|
shouldCleanup
|
||||||
cleanupExceptionKey={cleanupExceptionKey}
|
cleanupExceptionKey={cleanupExceptionKey}
|
||||||
onStop={() => setIsReady(true)}
|
onStop={handleSlideStop}
|
||||||
>
|
>
|
||||||
{() => (
|
{() => (
|
||||||
<>
|
<>
|
||||||
@ -407,7 +396,7 @@ const MiddleColumn: FC<StateProps & DispatchProps> = ({
|
|||||||
hasTools={renderingHasTools}
|
hasTools={renderingHasTools}
|
||||||
onFabToggle={setIsFabShown}
|
onFabToggle={setIsFabShown}
|
||||||
onNotchToggle={setIsNotchShown}
|
onNotchToggle={setIsNotchShown}
|
||||||
isReady={isReady && !willSwitchMessageList}
|
isReady={isReady}
|
||||||
withBottomShift={withMessageListBottomShift}
|
withBottomShift={withMessageListBottomShift}
|
||||||
/>
|
/>
|
||||||
<div className={footerClassName}>
|
<div className={footerClassName}>
|
||||||
@ -418,7 +407,7 @@ const MiddleColumn: FC<StateProps & DispatchProps> = ({
|
|||||||
messageListType={renderingMessageListType}
|
messageListType={renderingMessageListType}
|
||||||
dropAreaState={dropAreaState}
|
dropAreaState={dropAreaState}
|
||||||
onDropHide={handleHideDropArea}
|
onDropHide={handleHideDropArea}
|
||||||
isReady={isReady && !willSwitchMessageList}
|
isReady={isReady}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{isPinnedMessageList && (
|
{isPinnedMessageList && (
|
||||||
@ -604,3 +593,44 @@ export default memo(withGlobal(
|
|||||||
'closePaymentModal', 'clearReceipt', 'joinChannel', 'sendBotCommand', 'restartBot',
|
'closePaymentModal', 'clearReceipt', 'joinChannel', 'sendBotCommand', 'restartBot',
|
||||||
]),
|
]),
|
||||||
)(MiddleColumn));
|
)(MiddleColumn));
|
||||||
|
|
||||||
|
function useIsReady(
|
||||||
|
animationLevel?: number,
|
||||||
|
currentTransitionKey?: number,
|
||||||
|
prevTransitionKey?: number,
|
||||||
|
chatId?: string,
|
||||||
|
) {
|
||||||
|
const [isReady, setIsReady] = useState(!IS_SINGLE_COLUMN_LAYOUT);
|
||||||
|
const forceUpdate = useForceUpdate();
|
||||||
|
|
||||||
|
const willSwitchMessageList = prevTransitionKey !== undefined && prevTransitionKey !== currentTransitionKey;
|
||||||
|
if (willSwitchMessageList) {
|
||||||
|
if (animationLevel !== ANIMATION_LEVEL_MIN) {
|
||||||
|
setIsReady(false);
|
||||||
|
} else {
|
||||||
|
forceUpdate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (animationLevel === ANIMATION_LEVEL_MIN) {
|
||||||
|
setIsReady(true);
|
||||||
|
}
|
||||||
|
}, [animationLevel]);
|
||||||
|
|
||||||
|
function handleOpenEnd(e: React.TransitionEvent<HTMLDivElement>) {
|
||||||
|
if (e.propertyName === 'transform' && e.target === e.currentTarget) {
|
||||||
|
setIsReady(Boolean(chatId));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleSlideStop() {
|
||||||
|
setIsReady(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
isReady: isReady && !willSwitchMessageList,
|
||||||
|
handleOpenEnd: animationLevel !== ANIMATION_LEVEL_MIN ? handleOpenEnd : undefined,
|
||||||
|
handleSlideStop: animationLevel !== ANIMATION_LEVEL_MIN ? handleSlideStop : undefined,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user