Profile: Expand on avatar click (#6334)

This commit is contained in:
zubiden 2025-10-08 12:33:44 +02:00 committed by Alexander Zinchuk
parent 84db07b582
commit 0d910da7b2
4 changed files with 43 additions and 10 deletions

View File

@ -76,6 +76,7 @@ type OwnProps = {
isForSettings?: boolean; isForSettings?: boolean;
canPlayVideo: boolean; canPlayVideo: boolean;
isForMonoforum?: boolean; isForMonoforum?: boolean;
onExpand?: NoneToVoidFunction;
}; };
type StateProps = { type StateProps = {
@ -130,6 +131,7 @@ const ProfileInfo = ({
theme, theme,
isPlain, isPlain,
savedGifts, savedGifts,
onExpand,
}: OwnProps & StateProps) => { }: OwnProps & StateProps) => {
const { const {
openMediaViewer, openMediaViewer,
@ -279,6 +281,15 @@ const ProfileInfo = ({
} }
}); });
const handleMinimizedAvatarClick = useLastCallback(() => {
if (isForSettings) {
handleProfilePhotoClick();
return;
}
onExpand?.();
});
function handleSelectFallbackPhoto() { function handleSelectFallbackPhoto() {
if (!isFirst) return; if (!isFirst) return;
setHasSlideAnimation(true); setHasSlideAnimation(true);
@ -565,7 +576,7 @@ const ProfileInfo = ({
size="jumbo" size="jumbo"
peer={peer} peer={peer}
style={createVtnStyle('avatar', true)} style={createVtnStyle('avatar', true)}
onClick={isForSettings ? handleProfilePhotoClick : undefined} onClick={handleMinimizedAvatarClick}
/> />
)} )}

View File

@ -215,7 +215,12 @@ const ChatList: FC<OwnProps> = ({
toggleStoryRibbon({ isShown: false, isArchived }); toggleStoryRibbon({ isShown: false, isArchived });
}); });
useTopOverscroll(containerRef, handleShowStoryRibbon, handleHideStoryRibbon, isSaved); useTopOverscroll({
containerRef,
onOverscroll: handleShowStoryRibbon,
onReset: handleHideStoryRibbon,
isDisabled: isSaved,
});
function renderChats() { function renderChats() {
const viewportOffset = orderedIds!.indexOf(viewportIds![0]); const viewportOffset = orderedIds!.indexOf(viewportIds![0]);

View File

@ -627,9 +627,13 @@ const Profile = ({
resetGiftProfileFilter({ peerId: chatId }); resetGiftProfileFilter({ peerId: chatId });
}); });
useTopOverscroll( useTopOverscroll({
containerRef, handleExpandProfile, handleCollapseProfile, !hasAvatar || !shouldRenderProfileInfo, containerRef,
); onOverscroll: handleExpandProfile,
onReset: handleCollapseProfile,
isOverscrolled: isProfileExpanded,
isDisabled: !hasAvatar || !shouldRenderProfileInfo,
});
useEffect(() => { useEffect(() => {
if (!transitionRef.current || !IS_TOUCH_ENV) { if (!transitionRef.current || !IS_TOUCH_ENV) {
@ -1055,6 +1059,7 @@ const Profile = ({
peerId={peerId} peerId={peerId}
canPlayVideo={isReady} canPlayVideo={isReady}
isForMonoforum={Boolean(monoforumChannel)} isForMonoforum={Boolean(monoforumChannel)}
onExpand={handleExpandProfile}
/> />
<ChatExtra <ChatExtra
chatOrUserId={profileId} chatOrUserId={profileId}

View File

@ -30,11 +30,19 @@ const initialActiveScrollContext: ActiveScrollContext = {
timeout: undefined, timeout: undefined,
}; };
export default function useTopOverscroll( export default function useTopOverscroll({
containerRef: ElementRef<HTMLDivElement>, containerRef,
onOverscroll?: AnyToVoidFunction, isOverscrolled,
onReset?: AnyToVoidFunction, isDisabled,
isDisabled?: boolean, onOverscroll,
onReset,
}: {
containerRef: ElementRef<HTMLDivElement>;
isOverscrolled?: boolean;
onOverscroll?: AnyToVoidFunction;
onReset?: AnyToVoidFunction;
isDisabled?: boolean;
},
) { ) {
const [getState, setState] = useSignal<State>('normal'); const [getState, setState] = useSignal<State>('normal');
const activeScrollRef = useRef<ActiveScrollContext>({ ...initialActiveScrollContext }); const activeScrollRef = useRef<ActiveScrollContext>({ ...initialActiveScrollContext });
@ -197,6 +205,10 @@ export default function useTopOverscroll(
}; };
}, [containerRef, isDisabled, getState]); }, [containerRef, isDisabled, getState]);
useEffect(() => {
setState(isOverscrolled ? 'overscroll' : 'normal');
}, [isOverscrolled, setState]);
useEffect(() => { useEffect(() => {
const container = containerRef.current; const container = containerRef.current;
if (isDisabled || !container) { if (isDisabled || !container) {