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

Fix up relevant CA1416 warnings #26593

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,17 @@ static ContextActionsCell()
{
var rect = new RectangleF(0, 0, 1, 1);
var size = rect.Size;

UIGraphics.BeginImageContext(size);
var context = UIGraphics.GetCurrentContext();
context.SetFillColor(Microsoft.Maui.Platform.ColorExtensions.Red.CGColor);
context.FillRect(rect);
DestructiveBackground = UIGraphics.GetImageFromCurrentImageContext();

context.SetFillColor(Microsoft.Maui.Platform.ColorExtensions.LightGray.CGColor);
context.FillRect(rect);

NormalBackground = UIGraphics.GetImageFromCurrentImageContext();

context.Dispose();
using var renderer = new UIGraphicsImageRenderer(size);
DestructiveBackground = renderer.CreateImage((UIGraphicsImageRendererContext ctx) => {
var context = ctx.CGContext;
context.SetFillColor(Microsoft.Maui.Platform.ColorExtensions.Red.CGColor);
context.FillRect(rect);
});
NormalBackground = renderer.CreateImage((UIGraphicsImageRendererContext ctx) => {
var context = ctx.CGContext;
context.SetFillColor(Microsoft.Maui.Platform.ColorExtensions.LightGray.CGColor);
context.FillRect(rect);
});
}

public ContextActionsCell() : base(UITableViewCellStyle.Default, Key)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,29 +448,25 @@ UIImage DrawHamburger()
return img;

var rect = new CGRect(0, 0, 23f, 23f);
using var renderer = new UIGraphicsImageRenderer(rect.Size);
var renderedImage = renderer.CreateImage((UIGraphicsImageRendererContext ctx) => {
var context = ctx.CGContext;
context.SaveState();
context.SetStrokeColor(UIColor.Blue.CGColor);

float size = 3f;
float start = 4f;
context.SetLineWidth(size);
for (int i = 0; i < 3; i++)
{
context.MoveTo(1f, start + i * (size * 2));
context.AddLineToPoint(22f, start + i * (size * 2));
context.StrokePath();
}

UIGraphics.BeginImageContextWithOptions(rect.Size, false, 0);
var ctx = UIGraphics.GetCurrentContext();
ctx.SaveState();
ctx.SetStrokeColor(UIColor.Blue.CGColor);

float size = 3f;
float start = 4f;
ctx.SetLineWidth(size);

for (int i = 0; i < 3; i++)
{
ctx.MoveTo(1f, start + i * (size * 2));
ctx.AddLineToPoint(22f, start + i * (size * 2));
ctx.StrokePath();
}

ctx.RestoreState();
img = UIGraphics.GetImageFromCurrentImageContext();
UIGraphics.EndImageContext();

_nSCache.SetObjectforKey(img, (NSString)hamburgerKey);
return img;
context.RestoreState();
});
return renderedImage;
}

void OnToolbarItemsChanged(object sender, NotifyCollectionChangedEventArgs e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,11 @@ public static UIImage GetBackgroundImage(this UIView control, Brush brush)
if (backgroundLayer == null)
return null;

UIGraphics.BeginImageContextWithOptions(backgroundLayer.Bounds.Size, false, UIScreen.MainScreen.Scale);

if (UIGraphics.GetCurrentContext() == null)
return null;

backgroundLayer.RenderInContext(UIGraphics.GetCurrentContext());
UIImage gradientImage = UIGraphics.GetImageFromCurrentImageContext();
UIGraphics.EndImageContext();

var size = new CGSize(backgroundLayer.Bounds.Size.Width * UIScreen.MainScreen.Scale, backgroundLayer.Bounds.Size.Height * UIScreen.MainScreen.Scale);
var renderer = new UIGraphicsImageRenderer(size);
var gradientImage = renderer.CreateImage((UIGraphicsImageRendererContext ctx) => {
backgroundLayer.RenderInContext(ctx.CGContext);
});
return gradientImage;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,14 @@ public static partial void MapCloseWindow(ApplicationHandler handler, IApplicati
}
}

[SupportedOSPlatform("maccatalyst13.0")]
public static partial void MapActivateWindow(ApplicationHandler handler, IApplication application, object? args)
{
// ActivateSceneSession requires 17+
if (!OperatingSystem.IsIOSVersionAtLeast(17) && !OperatingSystem.IsMacCatalystVersionAtLeast(17))
{
return;
}

if (args is IWindow window)
{
var sceneSession = (window.Handler?.PlatformView as UIWindow)?.WindowScene?.Session;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,33 @@ static UIImage MaxResizeSwipeItemIconImage(UIImage sourceImage, nfloat maxWidth,

var width = maxResizeFactor * sourceSize.Width;
var height = maxResizeFactor * sourceSize.Height;
UIGraphics.BeginImageContextWithOptions(new CGSize((nfloat)width, (nfloat)height), false, 0);
sourceImage.Draw(new CGRect(0, 0, (nfloat)width, (nfloat)height));
var resultImage = UIGraphics.GetImageFromCurrentImageContext();
UIGraphics.EndImageContext();

return resultImage;
if (!OperatingSystem.IsIOSVersionAtLeast(17))
{
UIGraphics.BeginImageContextWithOptions(new CGSize((nfloat)width, (nfloat)height), false, 0);
sourceImage.Draw(new CGRect(0, 0, (nfloat)width, (nfloat)height));
var resultImage = UIGraphics.GetImageFromCurrentImageContext();
UIGraphics.EndImageContext();

return resultImage;
}

var format = new UIGraphicsImageRendererFormat
{
Opaque = false,
Scale = 0
};

using (var renderer = new UIGraphicsImageRenderer(new CGSize(width, height), format))
{
var resultImage = renderer.CreateImage((UIGraphicsImageRendererContext imageContext) =>
{
var cgcontext = imageContext.CGContext;
cgcontext.DrawImage(new CGRect(0, 0, (nfloat)width, (nfloat)height), sourceImage.CGImage);
});

return resultImage;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,9 @@ static void OnConfigureLifeCycle(IiOSLifecycleBuilder iOS)
app.GetWindow()?.Stopped();
});


// Pre iOS 13 doesn't support scenes
if (!OperatingSystem.IsIOSVersionAtLeast(13))
return;


iOS
.SceneWillEnterForeground(scene =>
{
if (!OperatingSystem.IsIOSVersionAtLeast(13))
return;

if (scene.Delegate is IUIWindowSceneDelegate windowScene &&
scene.ActivationState != UISceneActivationState.Unattached)
{
Expand All @@ -69,50 +60,31 @@ static void OnConfigureLifeCycle(IiOSLifecycleBuilder iOS)
})
.SceneOnActivated(scene =>
{
if (!OperatingSystem.IsIOSVersionAtLeast(13))
return;

if (scene.Delegate is IUIWindowSceneDelegate sd)
sd.GetWindow().GetWindow()?.Activated();
})
.SceneOnResignActivation(scene =>
{
if (!OperatingSystem.IsIOSVersionAtLeast(13))
return;

if (scene.Delegate is IUIWindowSceneDelegate sd)
sd.GetWindow().GetWindow()?.Deactivated();
})
.SceneDidEnterBackground(scene =>
{
if (!OperatingSystem.IsIOSVersionAtLeast(13))
return;

if (scene.Delegate is IUIWindowSceneDelegate sd)
sd.GetWindow().GetWindow()?.Stopped();
})
.SceneDidDisconnect(scene =>
{
if (!OperatingSystem.IsIOSVersionAtLeast(13))
return;

if (scene.Delegate is IUIWindowSceneDelegate sd)
sd.GetWindow().GetWindow()?.Destroying();
});
}

static void OnConfigureWindow(IiOSLifecycleBuilder iOS)
{
// Pre iOS 13 doesn't support scenes
if (!OperatingSystem.IsIOSVersionAtLeast(13))
return;

iOS = iOS
.WindowSceneDidUpdateCoordinateSpace((windowScene, _, _, _) =>
{
if (!OperatingSystem.IsIOSVersionAtLeast(13))
return;

if (windowScene.Delegate is not IUIWindowSceneDelegate wsd ||
wsd.GetWindow() is not UIWindow platformWindow)
return;
Expand Down
25 changes: 11 additions & 14 deletions src/Core/src/ImageSources/iOS/ImageSourceExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,17 @@ public static partial class ImageSourceExtensions
return null;
}

UIGraphics.BeginImageContextWithOptions(imagesize, false, scale);
var ctx = new NSStringDrawingContext();

var boundingRect = attString.GetBoundingRect(imagesize, 0, ctx);
attString.DrawString(new CGRect(
imagesize.Width / 2 - boundingRect.Size.Width / 2,
imagesize.Height / 2 - boundingRect.Size.Height / 2,
imagesize.Width,
imagesize.Height));

var image = UIGraphics.GetImageFromCurrentImageContext();
UIGraphics.EndImageContext();

return image.ImageWithRenderingMode(UIImageRenderingMode.Automatic);
var renderer = new UIGraphicsImageRenderer(imagesize);
var rendererImage = renderer.CreateImage((UIGraphicsImageRendererContext renderContext) => {
var ctx = new NSStringDrawingContext();
var boundingRect = attString.GetBoundingRect(imagesize, 0, ctx);
attString.DrawString(new CGRect(
imagesize.Width / 2 - boundingRect.Size.Width / 2,
imagesize.Height / 2 - boundingRect.Size.Height / 2,
imagesize.Width,
imagesize.Height));
});
return rendererImage;
}

internal static UIImage? GetPlatformImage(this IFileImageSource imageSource)
Expand Down
91 changes: 11 additions & 80 deletions src/Core/src/Platform/iOS/ColorExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,126 +14,57 @@ public static class ColorExtensions

internal static UIColor LabelColor
{
get
{
if (OperatingSystem.IsIOSVersionAtLeast(13) || OperatingSystem.IsTvOSVersionAtLeast(13))
return UIColor.Label;

return UIColor.Black;
}
get => UIColor.Label;
}

internal static UIColor PlaceholderColor
{
get
{

if (OperatingSystem.IsIOSVersionAtLeast(13) || OperatingSystem.IsTvOSVersionAtLeast(13))
return UIColor.PlaceholderText;

return SeventyPercentGrey;
}
get => UIColor.PlaceholderText;
}

internal static UIColor SecondaryLabelColor
{
get
{

if (OperatingSystem.IsIOSVersionAtLeast(13) || OperatingSystem.IsTvOSVersionAtLeast(13))
return UIColor.SecondaryLabel;

return new Color(.32f, .4f, .57f).ToPlatform();
}
get => UIColor.SecondaryLabel;
}

internal static UIColor BackgroundColor
{
get
{

if (OperatingSystem.IsIOSVersionAtLeast(13))
return UIColor.SystemBackground;

return UIColor.White;
}
get => UIColor.SystemBackground;
}

internal static UIColor SeparatorColor
{
get
{
if (OperatingSystem.IsIOSVersionAtLeast(13) || OperatingSystem.IsTvOSVersionAtLeast(13))
return UIColor.Separator;

return UIColor.Gray;
}
get => UIColor.Separator;
}

internal static UIColor OpaqueSeparatorColor
{
get
{
if (OperatingSystem.IsIOSVersionAtLeast(13) || OperatingSystem.IsTvOSVersionAtLeast(13))
return UIColor.OpaqueSeparator;

return UIColor.Black;
}
get => UIColor.OpaqueSeparator;
}

internal static UIColor GroupedBackground
{
get
{
if (OperatingSystem.IsIOSVersionAtLeast(13))
return UIColor.SystemGroupedBackground;

return new UIColor(247f / 255f, 247f / 255f, 247f / 255f, 1);
}
get => UIColor.SystemGroupedBackground;
}

internal static UIColor AccentColor
{
get
{
if (OperatingSystem.IsIOSVersionAtLeast(13) || OperatingSystem.IsTvOSVersionAtLeast(13))
return UIColor.SystemBlue;

return Color.FromRgba(50, 79, 133, 255).ToPlatform();
}
get => UIColor.SystemBlue;
}

internal static UIColor Red
{
get
{
if (OperatingSystem.IsIOSVersionAtLeast(13) || OperatingSystem.IsTvOSVersionAtLeast(13))
return UIColor.SystemRed;

return UIColor.FromRGBA(255, 0, 0, 255);
}
get => UIColor.SystemRed;
}

internal static UIColor Gray
{
get
{
if (OperatingSystem.IsIOSVersionAtLeast(13) || OperatingSystem.IsTvOSVersionAtLeast(13))
return UIColor.SystemGray;

return UIColor.Gray;
}
get => UIColor.SystemGray;
}

internal static UIColor LightGray
{
get
{
if (OperatingSystem.IsIOSVersionAtLeast(13))
return UIColor.SystemGray2;

return UIColor.LightGray;
}
get => UIColor.SystemGray2;
}

public static CGColor ToCGColor(this Color color)
Expand Down
Loading
Loading