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

View File

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

View File

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

View File

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