Skip to content

Commit 1b22d9c

Browse files
committed
Fix Clock Animation
1 parent 624fa0e commit 1b22d9c

File tree

2 files changed

+87
-23
lines changed

2 files changed

+87
-23
lines changed

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,18 @@ private void OnLoaded(object sender, RoutedEventArgs _)
309309
break;
310310
}
311311
};
312+
// ✅ QueryTextBox.Text 변경 감지 (글자 수 1 이상일 때만 동작하도록 수정)
313+
QueryTextBox.TextChanged += (sender, e) => UpdateClockPanelVisibility();
314+
315+
// ✅ ContextMenu.Visibility 변경 감지
316+
DependencyPropertyDescriptor
317+
.FromProperty(UIElement.VisibilityProperty, typeof(ContextMenu))
318+
.AddValueChanged(ContextMenu, (s, e) => UpdateClockPanelVisibility());
319+
320+
// ✅ History.Visibility 변경 감지
321+
DependencyPropertyDescriptor
322+
.FromProperty(UIElement.VisibilityProperty, typeof(StackPanel)) // History는 StackPanel이라고 가정
323+
.AddValueChanged(History, (s, e) => UpdateClockPanelVisibility());
312324
}
313325

314326
private void InitializePosition()
@@ -614,6 +626,81 @@ public void WindowAnimator()
614626
windowsb.Begin(FlowMainWindow);
615627
}
616628

629+
private bool _isClockPanelAnimating = false; // 애니메이션 실행 중인지 여부
630+
631+
private void UpdateClockPanelVisibility()
632+
{
633+
if (QueryTextBox == null || ContextMenu == null || History == null || ClockPanel == null)
634+
return;
635+
636+
// ✅ `WindowAnimator`와 동일한 애니메이션 속도 설정 참조
637+
var animationLength = _settings.AnimationSpeed switch
638+
{
639+
AnimationSpeeds.Slow => 560,
640+
AnimationSpeeds.Medium => 360,
641+
AnimationSpeeds.Fast => 160,
642+
_ => _settings.CustomAnimationLength
643+
};
644+
645+
var animationDuration = TimeSpan.FromMilliseconds(animationLength * 2 / 3); // ✅ 같은 비율 적용
646+
647+
// ✅ 글자 수가 1 이상이면 애니메이션 추가 실행 방지
648+
if (QueryTextBox.Text.Length > 0 ||
649+
ContextMenu.Visibility != Visibility.Collapsed ||
650+
History.Visibility != Visibility.Collapsed)
651+
{
652+
if (ClockPanel.Visibility == Visibility.Hidden || _isClockPanelAnimating)
653+
return; // ✅ 이미 숨겨져 있거나 애니메이션 실행 중이면 다시 실행하지 않음
654+
655+
_isClockPanelAnimating = true;
656+
657+
// Opacity 애니메이션 적용 후 Visibility.Hidden 처리
658+
var fadeOut = new DoubleAnimation
659+
{
660+
From = 1.0,
661+
To = 0.0,
662+
Duration = animationDuration,
663+
FillBehavior = FillBehavior.Stop
664+
};
665+
666+
fadeOut.Completed += (s, e) =>
667+
{
668+
ClockPanel.Visibility = Visibility.Hidden;
669+
_isClockPanelAnimating = false;
670+
};
671+
672+
ClockPanel.BeginAnimation(UIElement.OpacityProperty, fadeOut);
673+
}
674+
else
675+
{
676+
if (ClockPanel.Visibility == Visibility.Visible || _isClockPanelAnimating)
677+
return; // ✅ 이미 표시 중이거나 애니메이션 실행 중이면 다시 실행하지 않음
678+
679+
_isClockPanelAnimating = true;
680+
681+
// ✅ Dispatcher를 사용하여 UI 업데이트 후 `ClockPanel` 표시
682+
System.Windows.Application.Current.Dispatcher.Invoke(() =>
683+
{
684+
ClockPanel.Visibility = Visibility.Visible;
685+
686+
// Opacity 애니메이션 적용
687+
var fadeIn = new DoubleAnimation
688+
{
689+
From = 0.0,
690+
To = 1.0,
691+
Duration = animationDuration,
692+
FillBehavior = FillBehavior.HoldEnd
693+
};
694+
695+
fadeIn.Completed += (s, e) => _isClockPanelAnimating = false;
696+
ClockPanel.BeginAnimation(UIElement.OpacityProperty, fadeIn);
697+
}, DispatcherPriority.Render);
698+
}
699+
}
700+
701+
702+
703+
617704

618705

619706
private void InitSoundEffects()

Flow.Launcher/Themes/Base.xaml

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -165,29 +165,6 @@
165165
BasedOn="{StaticResource BaseClockPanel}"
166166
TargetType="{x:Type StackPanel}">
167167
<Setter Property="Orientation" Value="Vertical" />
168-
<Setter Property="Visibility" Value="Collapsed" />
169-
<Style.Triggers>
170-
<MultiDataTrigger>
171-
<MultiDataTrigger.Conditions>
172-
<Condition Binding="{Binding ElementName=QueryTextBox, UpdateSourceTrigger=PropertyChanged, Path=Text.Length}" Value="0" />
173-
<Condition Binding="{Binding ElementName=ContextMenu, Path=Visibility}" Value="Collapsed" />
174-
<Condition Binding="{Binding ElementName=History, Path=Visibility}" Value="Collapsed" />
175-
</MultiDataTrigger.Conditions>
176-
<Setter Property="Visibility" Value="Visible" />
177-
<MultiDataTrigger.EnterActions>
178-
<BeginStoryboard>
179-
<Storyboard>
180-
<DoubleAnimation
181-
Storyboard.TargetProperty="Opacity"
182-
From="0.0"
183-
To="1"
184-
Duration="0:0:0.25" />
185-
</Storyboard>
186-
</BeginStoryboard>
187-
</MultiDataTrigger.EnterActions>
188-
</MultiDataTrigger>
189-
</Style.Triggers>
190-
191168
</Style>
192169

193170
<!-- Item Style -->

0 commit comments

Comments
 (0)