Skip to content
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

Refactor internal frame tracking & time handling #29

Merged
merged 19 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Prev Previous commit
Next Next commit
use new FrameTracker implementation
  • Loading branch information
DavidVollmers committed Sep 27, 2023
commit cabef598f1a35eda44ccb049e4891e651034489e
6 changes: 3 additions & 3 deletions packages/Ignis.Components/FrameTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void ExecuteOnNextFrame(IgnisComponentBase target, Action action)
{
_target = target ?? throw new ArgumentNullException(nameof(target));
_action = action ?? throw new ArgumentNullException(nameof(action));

// If we're server-side, we can just execute the action on the next render, otherwise we need to wait for the second render. (WebAssembly)
_frameToExecuteOn = _currentFrame + (_hostContext.IsServerSide ? 1 : 2);
}
Expand All @@ -30,7 +30,7 @@ public void OnAfterRender()
if (_currentFrame >= _frameToExecuteOn)
{
_frameToExecuteOn = null;

_action?.Invoke();

_action = null;
Expand All @@ -39,7 +39,7 @@ public void OnAfterRender()
{
_target?.Update();
}

++_currentFrame;
}
}
4 changes: 2 additions & 2 deletions packages/Tailwind/Ignis.Components.HeadlessUI/Dialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public void Open(Action? continueWith = null)

var __ = IsOpenChanged.InvokeAsync(_isOpen = true);

if (continueWith != null) FrameTracker.ExecuteOnNextFrame(continueWith, Update);
if (continueWith != null) FrameTracker.ExecuteOnNextFrame(this, continueWith);

Update();
}
Expand All @@ -206,7 +206,7 @@ private void CloseCore(Action? continueWith, bool async = false)
{
var __ = IsOpenChanged.InvokeAsync(_isOpen = false);

if (continueWith != null) FrameTracker.ExecuteOnNextFrame(continueWith, Update);
if (continueWith != null) FrameTracker.ExecuteOnNextFrame(this, continueWith);

Update(async);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public void Open(Action? continueWith = null)
_ = IsOpenChanged.InvokeAsync(_isOpen = true);

if (_transition != null)
FrameTracker.ExecuteOnNextFrame(() => _transition.Show(() => OnAfterOpen(continueWith)), Update);
else if (continueWith != null) FrameTracker.ExecuteOnNextFrame(() => OnAfterOpen(continueWith), Update);
FrameTracker.ExecuteOnNextFrame(this, () => _transition.Show(() => OnAfterOpen(continueWith)));
else if (continueWith != null) FrameTracker.ExecuteOnNextFrame(this, () => OnAfterOpen(continueWith));

Update();
}
Expand Down Expand Up @@ -73,7 +73,7 @@ private void CloseCore(Action? continueWith, bool async = false)
{
_ = IsOpenChanged.InvokeAsync(_isOpen = false);

if (continueWith != null) FrameTracker.ExecuteOnNextFrame(continueWith, Update);
if (continueWith != null) FrameTracker.ExecuteOnNextFrame(this, continueWith);

Update(async);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private void UpdateState(TransitionState state, Action? continueWith)

_state = state;

if (continueWith != null) FrameTracker.ExecuteOnNextFrame(continueWith, Update);
if (continueWith != null) FrameTracker.ExecuteOnNextFrame(this, continueWith);

Update(async: true);
}
Expand Down