Skip to content

Commit

Permalink
fix(iOS): PersonPicture late binding
Browse files Browse the repository at this point in the history
  • Loading branch information
ajpinedam committed Oct 25, 2024
1 parent 4b2df27 commit 6944ff1
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,23 +203,33 @@ void UpdateIfReady()

var templateSettings = TemplateSettings;
templateSettings.ActualInitials = initials;
if (imageSrc != null)

if (imageSrc is not null)
{
var imageBrush = templateSettings.ActualImageBrush;
if (imageBrush == null)
if (templateSettings.ActualImageBrush is ImageBrush imageBrush)
{
imageBrush = new ImageBrush();
imageBrush.Stretch = Stretch.UniformToFill;
templateSettings.ActualImageBrush = imageBrush;
imageBrush.ImageSource = imageSrc;
}
else
{
templateSettings.ActualImageBrush = new ImageBrush()
{
ImageSource = imageSrc,
Stretch = Stretch.UniformToFill
};
}

imageBrush.ImageSource = imageSrc;
}
else
{
templateSettings.ActualImageBrush = null;
}

#if __IOS__
if (templateSettings.ActualImageBrush is ImageBrush brush)
{
brush.ImageOpened += RefreshPhoto;
}
#endif
// If the control is converted to 'Group-mode', we'll clear individual-specific information.
// When IsGroup evaluates to false, we will restore state.
if (IsGroup)
Expand All @@ -228,7 +238,11 @@ void UpdateIfReady()
}
else
{
if (imageSrc != null)
if (imageSrc is not null
#if __IOS__
&& imageSrc.IsOpened
#endif
)
{
VisualStateManager.GoToState(this, "Photo", false);
}
Expand All @@ -245,6 +259,18 @@ void UpdateIfReady()
UpdateAutomationName();
}

#if __IOS__
void RefreshPhoto(object sender, RoutedEventArgs e)
{
VisualStateManager.GoToState(this, "Photo", false);

if (TemplateSettings.ActualImageBrush is { } brush)
{
brush.ImageOpened -= RefreshPhoto;
}
}
#endif

void UpdateBadge()
{
if (BadgeImageSource != null)
Expand Down
6 changes: 0 additions & 6 deletions src/Uno.UI/UI/Xaml/Media/ImageSource.crossruntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,6 @@ internal IDisposable Subscribe(Action<ImageData> onSourceOpened)
return Disposable.Create(() => _subscriptions.Remove(onSourceOpened));
}

/// <summary>
/// Indicates that this source has already been opened
/// (So the onSourceOpened callback of Subscribe will be invoked synchronously!)
/// </summary>
internal bool IsOpened => _imageData.HasData;

private protected void InvalidateSource()
{
_imageData = default;
Expand Down
5 changes: 5 additions & 0 deletions src/Uno.UI/UI/Xaml/Media/ImageSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ private set
}
}

/// <summary>
/// Indicates that this source has already been opened
/// (So the onSourceOpened callback of Subscribe will be invoked synchronously!)
/// </summary>
internal bool IsOpened => _imageData.HasData;
partial void SetImageLoader();

internal void UnloadImageData()
Expand Down

0 comments on commit 6944ff1

Please sign in to comment.