Split value change callbacks out to separate methods

This commit is contained in:
Bartłomiej Dach 2021-05-17 18:53:09 +02:00
parent 555e3e2db3
commit 7befcf74ff
2 changed files with 34 additions and 30 deletions

View File

@ -153,28 +153,30 @@ namespace osu.Game.Overlays.News.Sidebar
{
base.LoadComplete();
IsOpen.BindValueChanged(open =>
{
ClearTransforms(true);
if (open.NewValue)
{
AutoSizeAxes = Axes.Y;
content.FadeIn(animation_duration, Easing.OutQuint);
}
else
{
AutoSizeAxes = Axes.None;
this.ResizeHeightTo(0, animation_duration, Easing.OutQuint);
content.FadeOut(animation_duration, Easing.OutQuint);
}
}, true);
IsOpen.BindValueChanged(_ => updateState(), true);
// First state change should be instant.
FinishTransforms(true);
}
private void updateState()
{
ClearTransforms(true);
if (IsOpen.Value)
{
AutoSizeAxes = Axes.Y;
content.FadeIn(animation_duration, Easing.OutQuint);
}
else
{
AutoSizeAxes = Axes.None;
this.ResizeHeightTo(0, animation_duration, Easing.OutQuint);
content.FadeOut(animation_duration, Easing.OutQuint);
}
}
private bool shouldUpdateAutosize = true;
// Workaround to allow the dropdown to be opened immediately since FinishTransforms doesn't work for AutosizeDuration.

View File

@ -56,23 +56,25 @@ namespace osu.Game.Overlays.News.Sidebar
{
base.LoadComplete();
metadata.BindValueChanged(m =>
metadata.BindValueChanged(_ => recreateDrawables(), true);
}
private void recreateDrawables()
{
yearsFlow.Clear();
if (metadata.Value == null)
{
yearsFlow.Clear();
Hide();
return;
}
if (m.NewValue == null)
{
Hide();
return;
}
var currentYear = metadata.Value.CurrentYear;
var currentYear = m.NewValue.CurrentYear;
foreach (var y in metadata.Value.Years)
yearsFlow.Add(new YearButton(y, y == currentYear));
foreach (var y in m.NewValue.Years)
yearsFlow.Add(new YearButton(y, y == currentYear));
Show();
}, true);
Show();
}
public class YearButton : OsuHoverContainer