Transition: Allow static children

This commit is contained in:
Alexander Zinchuk 2022-02-25 22:52:19 +02:00
parent 59c402f0e3
commit 8b60cef7c2
16 changed files with 209 additions and 222 deletions

View File

@ -18,9 +18,7 @@ const MessageOutgoingStatus: FC<OwnProps> = ({ status }) => {
return ( return (
<div className="MessageOutgoingStatus"> <div className="MessageOutgoingStatus">
<Transition name="reveal" activeKey={Keys[status]}> <Transition name="reveal" activeKey={Keys[status]}>
{() => (
<i className={`icon-message-${status}`} /> <i className={`icon-message-${status}`} />
)}
</Transition> </Transition>
</div> </div>
); );

View File

@ -191,7 +191,7 @@ const ProfileInfo: FC<OwnProps & StateProps> = ({
<div className="photo-wrapper"> <div className="photo-wrapper">
{renderPhotoTabs()} {renderPhotoTabs()}
<Transition activeKey={currentPhotoIndex} name={slideAnimation} className="profile-slide-container"> <Transition activeKey={currentPhotoIndex} name={slideAnimation} className="profile-slide-container">
{renderPhoto} {renderPhoto()}
</Transition> </Transition>
{!isFirst && ( {!isFirst && (

View File

@ -27,7 +27,7 @@ const ConnectionStatusOverlay: FC<OwnProps> = ({
<Spinner color="black" /> <Spinner color="black" />
<div className="state-text"> <div className="state-text">
<Transition activeKey={connectionStatus} name="slide-fade"> <Transition activeKey={connectionStatus} name="slide-fade">
{() => connectionStatusText} {connectionStatusText}
</Transition> </Transition>
</div> </div>
<Button <Button

View File

@ -61,7 +61,7 @@ const Badge: FC<OwnProps> = ({ chat, isPinned, isMuted }) => {
return ( return (
<ShowTransition isCustom className="Badge-transition" isOpen={isShown}> <ShowTransition isCustom className="Badge-transition" isOpen={isShown}>
{renderContent} {renderContent()}
</ShowTransition> </ShowTransition>
); );
}; };

View File

@ -331,13 +331,11 @@ const LeftMainHeader: FC<OwnProps & StateProps> = ({
isCustom isCustom
className="connection-state-wrapper" className="connection-state-wrapper"
> >
{() => (
<ConnectionStatusOverlay <ConnectionStatusOverlay
connectionStatus={connectionStatus} connectionStatus={connectionStatus}
connectionStatusText={connectionStatusText!} connectionStatusText={connectionStatusText!}
onClick={toggleConnectionStatus} onClick={toggleConnectionStatus}
/> />
)}
</ShowTransition> </ShowTransition>
</div> </div>
</div> </div>

View File

@ -90,7 +90,7 @@ const LeftSearch: FC<OwnProps & StateProps> = ({
renderCount={TRANSITION_RENDER_COUNT} renderCount={TRANSITION_RENDER_COUNT}
activeKey={currentContent} activeKey={currentContent}
> >
{() => { {(() => {
switch (currentContent) { switch (currentContent) {
case GlobalSearchContent.ChatList: case GlobalSearchContent.ChatList:
if (chatId) { if (chatId) {
@ -136,7 +136,7 @@ const LeftSearch: FC<OwnProps & StateProps> = ({
default: default:
return undefined; return undefined;
} }
}} })()}
</Transition> </Transition>
</div> </div>
); );

View File

@ -461,8 +461,6 @@ const MediaViewer: FC<StateProps> = ({
className={isZoomed ? 'zoomed' : ''} className={isZoomed ? 'zoomed' : ''}
isOpen={isOpen} isOpen={isOpen}
> >
{() => (
<>
<div className="media-viewer-head" dir={lang.isRtl ? 'rtl' : undefined}> <div className="media-viewer-head" dir={lang.isRtl ? 'rtl' : undefined}>
{IS_SINGLE_COLUMN_LAYOUT && ( {IS_SINGLE_COLUMN_LAYOUT && (
<Button <Button
@ -477,7 +475,7 @@ const MediaViewer: FC<StateProps> = ({
</Button> </Button>
)} )}
<Transition activeKey={animationKey.current!} name={headerAnimation}> <Transition activeKey={animationKey.current!} name={headerAnimation}>
{renderSenderInfo} {renderSenderInfo()}
</Transition> </Transition>
<MediaViewerActions <MediaViewerActions
mediaData={fullMediaBlobUrl || previewBlobUrl} mediaData={fullMediaBlobUrl || previewBlobUrl}
@ -549,8 +547,6 @@ const MediaViewer: FC<StateProps> = ({
isShown={isZoomed} isShown={isZoomed}
onChangeZoom={handleZoomValue} onChangeZoom={handleZoomValue}
/> />
</>
)}
</ShowTransition> </ShowTransition>
); );
}; };

View File

@ -2,9 +2,9 @@ import React, { FC } from '../../lib/teact/teact';
import { IS_TOUCH_ENV } from '../../util/environment'; import { IS_TOUCH_ENV } from '../../util/environment';
import Transition, { TransitionProps } from '../ui/Transition'; import Transition, { ChildrenFn, TransitionProps } from '../ui/Transition';
const SlideTransition: FC<TransitionProps> = ({ children, ...props }) => { const SlideTransition: FC<TransitionProps & { children: ChildrenFn }> = ({ children, ...props }) => {
if (IS_TOUCH_ENV) return children(true, true, 1); if (IS_TOUCH_ENV) return children(true, true, 1);
// eslint-disable-next-line react/jsx-props-no-spreading // eslint-disable-next-line react/jsx-props-no-spreading
return <Transition {...props}>{children}</Transition>; return <Transition {...props}>{children}</Transition>;

View File

@ -397,8 +397,6 @@ const MiddleColumn: FC<StateProps> = ({
cleanupExceptionKey={cleanupExceptionKey} cleanupExceptionKey={cleanupExceptionKey}
onStop={handleSlideStop} onStop={handleSlideStop}
> >
{() => (
<>
<MessageList <MessageList
key={`${renderingChatId}-${renderingThreadId}-${renderingMessageListType}`} key={`${renderingChatId}-${renderingThreadId}-${renderingMessageListType}`}
chatId={renderingChatId} chatId={renderingChatId}
@ -500,8 +498,6 @@ const MiddleColumn: FC<StateProps> = ({
<SeenByModal isOpen={isSeenByModalOpen} /> <SeenByModal isOpen={isSeenByModalOpen} />
<ReactorListModal isOpen={isReactorListModalOpen} /> <ReactorListModal isOpen={isReactorListModalOpen} />
</div> </div>
</>
)}
</Transition> </Transition>
<ScrollDownButton <ScrollDownButton

View File

@ -371,7 +371,7 @@ const MiddleHeader: FC<OwnProps & StateProps> = ({
name={shouldSkipHistoryAnimations ? 'none' : 'slide-fade'} name={shouldSkipHistoryAnimations ? 'none' : 'slide-fade'}
activeKey={currentTransitionKey} activeKey={currentTransitionKey}
> >
{renderInfo} {renderInfo()}
</Transition> </Transition>
<GroupCallTopPane <GroupCallTopPane

View File

@ -322,11 +322,9 @@ const Invoice: FC<OwnProps & StateProps & GlobalStateProps> = ({
</div> </div>
{step !== undefined ? ( {step !== undefined ? (
<Transition name="slide" activeKey={step}> <Transition name="slide" activeKey={step}>
{() => (
<div className="content custom-scroll"> <div className="content custom-scroll">
{renderModalContent(step)} {renderModalContent(step)}
</div> </div>
)}
</Transition> </Transition>
) : ( ) : (
<div className="empty-content"> <div className="empty-content">

View File

@ -445,7 +445,7 @@ const Profile: FC<OwnProps & StateProps> = ({
onStart={applyTransitionFix} onStart={applyTransitionFix}
onStop={handleTransitionStop} onStop={handleTransitionStop}
> >
{renderContent} {renderContent()}
</Transition> </Transition>
<TabList big activeTab={activeTab} tabs={tabs} onSwitchTab={setActiveTab} /> <TabList big activeTab={activeTab} tabs={tabs} onSwitchTab={setActiveTab} />
</div> </div>

View File

@ -428,7 +428,7 @@ const RightHeader: FC<OwnProps & StateProps> = ({
name={(shouldSkipTransition || shouldSkipAnimation) ? 'none' : 'slide-fade'} name={(shouldSkipTransition || shouldSkipAnimation) ? 'none' : 'slide-fade'}
activeKey={renderingContentKey} activeKey={renderingContentKey}
> >
{renderHeaderContent} {renderHeaderContent()}
</Transition> </Transition>
</div> </div>
); );

View File

@ -134,9 +134,7 @@ const SearchInput: FC<OwnProps> = ({
/> />
<i className="icon-search" /> <i className="icon-search" />
<ShowTransition isOpen={Boolean(isLoading)} className="slow"> <ShowTransition isOpen={Boolean(isLoading)} className="slow">
{() => (
<Loading color={spinnerColor} backgroundColor={spinnerBackgroundColor} onClick={onSpinnerClick} /> <Loading color={spinnerColor} backgroundColor={spinnerBackgroundColor} onClick={onSpinnerClick} />
)}
</ShowTransition> </ShowTransition>
{!isLoading && (value || canClose) && onReset && ( {!isLoading && (value || canClose) && onReset && (
<Button <Button

View File

@ -4,7 +4,6 @@ import useShowTransition from '../../hooks/useShowTransition';
import usePrevious from '../../hooks/usePrevious'; import usePrevious from '../../hooks/usePrevious';
import buildClassName from '../../util/buildClassName'; import buildClassName from '../../util/buildClassName';
type ChildrenFn = () => any;
type OwnProps = { type OwnProps = {
isOpen: boolean; isOpen: boolean;
@ -12,7 +11,7 @@ type OwnProps = {
id?: string; id?: string;
className?: string; className?: string;
onClick?: (e: React.MouseEvent<HTMLElement, MouseEvent>) => void; onClick?: (e: React.MouseEvent<HTMLElement, MouseEvent>) => void;
children: ChildrenFn; children: React.ReactNode;
}; };
const ShowTransition: FC<OwnProps> = ({ const ShowTransition: FC<OwnProps> = ({
@ -23,7 +22,7 @@ const ShowTransition: FC<OwnProps> = ({
); );
const prevIsOpen = usePrevious(isOpen); const prevIsOpen = usePrevious(isOpen);
const prevChildren = usePrevious(children); const prevChildren = usePrevious(children);
const fromChildrenRef = useRef<ChildrenFn>(); const fromChildrenRef = useRef<React.ReactNode>();
if (prevIsOpen && !isOpen) { if (prevIsOpen && !isOpen) {
fromChildrenRef.current = prevChildren; fromChildrenRef.current = prevChildren;
@ -32,7 +31,7 @@ const ShowTransition: FC<OwnProps> = ({
return ( return (
shouldRender && ( shouldRender && (
<div id={id} className={buildClassName(className, transitionClassNames)} onClick={onClick}> <div id={id} className={buildClassName(className, transitionClassNames)} onClick={onClick}>
{isOpen ? children() : fromChildrenRef.current!()} {isOpen ? children : fromChildrenRef.current!}
</div> </div>
) )
); );

View File

@ -15,7 +15,7 @@ import { dispatchHeavyAnimationEvent } from '../../hooks/useHeavyAnimationCheck'
import './Transition.scss'; import './Transition.scss';
type ChildrenFn = (isActive: boolean, isFrom: boolean, currentKey: number) => any; export type ChildrenFn = (isActive: boolean, isFrom: boolean, currentKey: number) => React.ReactNode;
export type TransitionProps = { export type TransitionProps = {
ref?: RefObject<HTMLDivElement>; ref?: RefObject<HTMLDivElement>;
activeKey: number; activeKey: number;
@ -33,7 +33,7 @@ export type TransitionProps = {
className?: string; className?: string;
onStart?: NoneToVoidFunction; onStart?: NoneToVoidFunction;
onStop?: NoneToVoidFunction; onStop?: NoneToVoidFunction;
children: ChildrenFn; children: React.ReactNode | ChildrenFn;
}; };
const classNames = { const classNames = {
@ -65,7 +65,7 @@ const Transition: FC<TransitionProps> = ({
containerRef = ref; containerRef = ref;
} }
const rendersRef = useRef<Record<number, ChildrenFn>>({}); const rendersRef = useRef<Record<number, React.ReactNode | ChildrenFn>>({});
const prevActiveKey = usePrevious<any>(activeKey); const prevActiveKey = usePrevious<any>(activeKey);
const forceUpdate = useForceUpdate(); const forceUpdate = useForceUpdate();
@ -257,7 +257,11 @@ const Transition: FC<TransitionProps> = ({
} }
return ( return (
<div key={key} teactOrderKey={key}>{render(key === activeKey, key === prevActiveKey, activeKey)}</div> <div key={key} teactOrderKey={key}>{
typeof render === 'function'
? render(key === activeKey, key === prevActiveKey, activeKey)
: render
}</div>
); );
}); });