Skip to content

Commit

Permalink
- add rest of the platforms effects
Browse files Browse the repository at this point in the history
  • Loading branch information
PureWeen committed Jul 8, 2021
1 parent ff83f22 commit 063dfb4
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 56 deletions.
55 changes: 0 additions & 55 deletions src/Controls/samples/Controls.Sample/Pages/Core/Effects.xaml.cs

This file was deleted.

Expand Up @@ -2,7 +2,7 @@
<views:BasePage
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Controls.Sample.Pages.Effects"
x:Class="Maui.Controls.Sample.Pages.EffectsPage"
xmlns:views="clr-namespace:Maui.Controls.Sample.Pages.Base"
xmlns:local="clr-namespace:Maui.Controls.Sample.Pages"
Title="Alerts">
Expand Down
139 changes: 139 additions & 0 deletions src/Controls/samples/Controls.Sample/Pages/Core/EffectsPage.xaml.cs
@@ -0,0 +1,139 @@
using System;
using System.ComponentModel;
using System.Diagnostics;
using Microsoft.Maui;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.Platform;

namespace Maui.Controls.Sample.Pages
{
public partial class EffectsPage
{
public EffectsPage()
{
InitializeComponent();
}
}

public class FocusRoutingEffect : RoutingEffect
{
}

#if WINDOWS
public class FocusPlatformEffect : PlatformEffect
{
public FocusPlatformEffect() : base()
{
}

protected override void OnAttached()
{
try
{
(Control as Microsoft.UI.Xaml.Controls.Control).Background = new Microsoft.UI.Xaml.Media.SolidColorBrush(Microsoft.UI.Colors.Cyan);
(Control as MauiTextBox).BackgroundFocusBrush = new Microsoft.UI.Xaml.Media.SolidColorBrush(Microsoft.UI.Colors.White);
}
catch (Exception ex)
{
Debug.WriteLine("Cannot set property on attached control. Error: ", ex.Message);
}

}

protected override void OnDetached()
{
}
}
#elif __ANDROID__
public class FocusPlatformEffect : PlatformEffect
{
Android.Graphics.Color originalBackgroundColor = new Android.Graphics.Color(0, 0, 0, 0);
Android.Graphics.Color backgroundColor;

protected override void OnAttached()
{
try
{
backgroundColor = Android.Graphics.Color.LightGreen;
Control.SetBackgroundColor(backgroundColor);
}
catch (Exception ex)
{
Console.WriteLine("Cannot set property on attached control. Error: ", ex.Message);
}
}

protected override void OnDetached()
{
}

protected override void OnElementPropertyChanged(PropertyChangedEventArgs args)
{
base.OnElementPropertyChanged(args);
try
{
if (args.PropertyName == "IsFocused")
{
if (((Android.Graphics.Drawables.ColorDrawable)Control.Background).Color == backgroundColor)
{
Control.SetBackgroundColor(originalBackgroundColor);
}
else
{
Control.SetBackgroundColor(backgroundColor);
}
}
}
catch (Exception ex)
{
Console.WriteLine("Cannot set property on attached control. Error: ", ex.Message);
}
}
}
#elif __IOS__
public class FocusPlatformEffect : PlatformEffect
{
UIKit.UIColor backgroundColor;

protected override void OnAttached()
{
try
{
Control.BackgroundColor = backgroundColor = UIKit.UIColor.FromRGB(204, 153, 255);
}
catch (Exception ex)
{
Console.WriteLine("Cannot set property on attached control. Error: ", ex.Message);
}
}

protected override void OnDetached()
{
}

protected override void OnElementPropertyChanged(PropertyChangedEventArgs args)
{
base.OnElementPropertyChanged(args);

try
{
if (args.PropertyName == "IsFocused")
{
if (Control.BackgroundColor == backgroundColor)
{
Control.BackgroundColor = UIKit.UIColor.White;
}
else
{
Control.BackgroundColor = backgroundColor;
}
}
}
catch (Exception ex)
{
Console.WriteLine("Cannot set property on attached control. Error: ", ex.Message);
}
}
}
#endif
}

0 comments on commit 063dfb4

Please sign in to comment.