-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Refactor notification avatar to remove OnUpdate
#34668
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
OnUpdate
| IconContent.Masking = true; | ||
| IconContent.CornerRadius = CORNER_RADIUS; | ||
| IconContent.ChangeChildDepth(IconDrawable, float.MinValue); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this still be applied outside the null check? Seems like the default avatar may look weird otherwise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand what you're referring to - it's still inside the null check.
If this is confusing, we can revert the moving of Avatar outside of here. I was just looking at a protected member that's actually accessed (usually Avatar.Colour = ...) and saw that potentially resulting in a nullref.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or are you referring to the code in Update()? In the case the user's null, there won't be any avatar. I'm not sure if it makes sense to do the width setting in that case so I decided to not change the semantics.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Referring to the IconContainer alterations. Not immediately obvious the avatar is just not being added to the hierarchy (a bit weird to me)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is how it looks with a null user in this PR:
Can we go with this instead?
diff --git a/osu.Game/Overlays/Notifications/UserAvatarNotification.cs b/osu.Game/Overlays/Notifications/UserAvatarNotification.cs
index c283d36468..7dbecbf11e 100644
--- a/osu.Game/Overlays/Notifications/UserAvatarNotification.cs
+++ b/osu.Game/Overlays/Notifications/UserAvatarNotification.cs
@@ -26,26 +26,20 @@ protected UserAvatarNotification(APIUser? user, LocalisableString text = default
[BackgroundDependencyLoader]
private void load()
{
- Avatar = new DrawableAvatar(user)
- {
- FillMode = FillMode.Fill,
- };
+ IconContent.Masking = true;
+ IconContent.CornerRadius = CORNER_RADIUS;
+ IconContent.ChangeChildDepth(IconDrawable, float.MinValue);
- if (user != null)
+ LoadComponentAsync(Avatar = new DrawableAvatar(user)
{
- IconContent.Masking = true;
- IconContent.CornerRadius = CORNER_RADIUS;
- IconContent.ChangeChildDepth(IconDrawable, float.MinValue);
- LoadComponentAsync(Avatar, IconContent.Add);
- }
+ FillMode = FillMode.Fill,
+ }, IconContent.Add);
}
protected override void Update()
{
base.Update();
-
- if (user != null)
- IconContent.Width = IconContent.DrawHeight;
+ IconContent.Width = IconContent.DrawHeight;
}
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The null user is the case where multiple friends come online at the same time. Does it even make sense to display an avatar in that case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be clear, I don't mind if you do that. It's just something you should be aware of.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be cool to show a little mosaic / cascade of each user's avatars in the future.
I think either what I have or having the drawable as nullable. I really get weirded about by a drawable created but not added ever.
As mentioned in #34533 (comment).
Bundled another change in here, which is to make
Avatar(expected to be non-null in all external usages) truly non-null (as far as we expect from o!f).