From adb803c7a9b41d60e27f9965e470ee83921bae70 Mon Sep 17 00:00:00 2001
From: Salman Ahmed <frenzibyte@gmail.com>
Date: Sun, 14 Jul 2024 15:19:26 +0300
Subject: [PATCH] Force recreating sections container when loading new user to
 avoid weird UX when scrolled away

---
 osu.Game/Overlays/UserProfileOverlay.cs | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/osu.Game/Overlays/UserProfileOverlay.cs b/osu.Game/Overlays/UserProfileOverlay.cs
index c8b64bf2f1..8c750b5d83 100644
--- a/osu.Game/Overlays/UserProfileOverlay.cs
+++ b/osu.Game/Overlays/UserProfileOverlay.cs
@@ -99,9 +99,8 @@ namespace osu.Game.Overlays
             if (user.OnlineID == Header.User.Value?.User.Id && ruleset?.MatchesOnlineID(Header.User.Value?.Ruleset) == true)
                 return;
 
-            sectionsContainer?.ScrollToTop();
-            sectionsContainer?.Clear();
-            tabs?.Clear();
+            if (sectionsContainer != null)
+                sectionsContainer.ExpandableHeader = null;
 
             userReq?.Cancel();
             lastSection = null;
@@ -119,7 +118,7 @@ namespace osu.Game.Overlays
                 }
                 : Array.Empty<ProfileSection>();
 
-            setupBaseContent(OverlayColourScheme.Pink);
+            setupBaseContent(OverlayColourScheme.Pink, forceContentRecreation: true);
 
             if (API.State.Value != APIState.Offline)
             {
@@ -138,7 +137,7 @@ namespace osu.Game.Overlays
             // reuse header and content if same colour scheme, otherwise recreate both.
             var profileScheme = (OverlayColourScheme?)loadedUser.ProfileHue ?? OverlayColourScheme.Pink;
             if (profileScheme != ColourProvider.ColourScheme)
-                setupBaseContent(profileScheme);
+                setupBaseContent(profileScheme, forceContentRecreation: false);
 
             var actualRuleset = rulesets.GetRuleset(userRuleset?.ShortName ?? loadedUser.PlayMode).AsNonNull();
 
@@ -164,17 +163,19 @@ namespace osu.Game.Overlays
             loadingLayer.Hide();
         }
 
-        private void setupBaseContent(OverlayColourScheme colourScheme)
+        private void setupBaseContent(OverlayColourScheme colourScheme, bool forceContentRecreation)
         {
             var previousColourScheme = ColourProvider.ColourScheme;
             ColourProvider.ChangeColourScheme(colourScheme);
 
-            if (sectionsContainer != null && colourScheme == previousColourScheme)
+            if (colourScheme != previousColourScheme)
+            {
+                RecreateHeader();
+                UpdateColours();
+            }
+            else if (!forceContentRecreation)
                 return;
 
-            RecreateHeader();
-            UpdateColours();
-
             Child = new OsuContextMenuContainer
             {
                 RelativeSizeAxes = Axes.Both,