Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/DataLoader.Uno.Shared/DataLoaderView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ private void OnUnloaded(object sender, RoutedEventArgs e)
_controller.OnViewUnloaded();
}

protected override void OnApplyTemplate()
{
base.OnApplyTemplate();

_controller.OnControlTemplateApplied();
}

private void OnSourceChanged(IDataLoader dataLoader)
{
_controller.SetDataLoader(dataLoader);
Expand Down
15 changes: 11 additions & 4 deletions src/DataLoader.Uno.Shared/DataLoaderViewControllerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public abstract class DataLoaderViewControllerBase<TDispatcher>
private IDataLoaderState _lastState;
private DataLoaderViewState _lastViewState;
private bool _isLoaded;
private bool _isControlTemplateApplied;
private bool _isSubscribedToSource;
private bool _isVisualStateRefreshRequired;
private DateTimeOffset _lastUpdate = DateTimeOffset.MinValue; // This is a timestamp of when the last UI update was done.
Expand Down Expand Up @@ -145,6 +146,12 @@ public void OnViewUnloaded()
_isLoaded = false;
}

public void OnControlTemplateApplied()
{
_isControlTemplateApplied = true;
Update(_dataLoader?.State);
}

private void OnDataLoaderStateChanged(IDataLoader dataLoader, IDataLoaderState newState)
{
Update(newState);
Expand Down Expand Up @@ -190,7 +197,7 @@ private async void Update(IDataLoaderState newState, [CallerMemberName] string s
if (Object.Equals(_nextState, _lastState))
{
// When the states are equal, we usually skip the update, unless a visual state refresh is required. (That happens when the DataLoader changes state before the DataLoaderView is Loaded.)
if (_isVisualStateRefreshRequired && _isLoaded)
if (_isVisualStateRefreshRequired && _isLoaded && _isControlTemplateApplied)
{
await RunOnDispatcher(() =>
{
Expand Down Expand Up @@ -288,7 +295,7 @@ private void UpdateUI(IDataLoaderState newState)
var combinedVisualState = $"{dataVisualState}_{errorVisualState}_{loadingVisualState}";
GoToState(view, CombinedVisualGroup, combinedVisualState);

if (_isLoaded)
if (_isLoaded && _isControlTemplateApplied)
{
_isVisualStateRefreshRequired = false;

Expand Down Expand Up @@ -395,7 +402,7 @@ private void GoToState(Control control, string group, string visualState, bool u
if (currentState != visualState)
{
_currentGroupStates[group] = visualState;
if (_isLoaded)
if (_isLoaded && _isControlTemplateApplied)
{
VisualStateManager.GoToState(control, visualState, useTransitions);
}
Expand All @@ -404,7 +411,7 @@ private void GoToState(Control control, string group, string visualState, bool u
else
{
_currentGroupStates[group] = visualState;
if (_isLoaded)
if (_isLoaded && _isControlTemplateApplied)
{
VisualStateManager.GoToState(control, visualState, useTransitions);
}
Expand Down