Skip to content

Commit e2d8071

Browse files
committed
1.修正了设置Border后边缘泛光问题
2.添加AndroidPerfect属性,启用后将会解决内容泛光问题,但也增加了系统开销
1 parent 1743fc0 commit e2d8071

14 files changed

+347
-505
lines changed

AcrylicView.Samples/AcrylicView.Samples.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@
105105
<ProjectReference Include="..\AcrylicView\AcrylicView.csproj" />
106106
</ItemGroup>
107107

108+
<ItemGroup>
109+
<MauiXaml Update="NewPage1.xaml">
110+
<Generator>MSBuild:Compile</Generator>
111+
</MauiXaml>
112+
</ItemGroup>
113+
108114
<ProjectExtensions><VisualStudio><UserProperties XamarinHotReloadWrongLinkerErrorInfoBarAcrylicViewSamplesHideInfoBar="True" /></VisualStudio></ProjectExtensions>
109115

110116

AcrylicView.Samples/MainPage.xaml

Lines changed: 132 additions & 294 deletions
Large diffs are not rendered by default.

AcrylicView.Samples/MainPage.xaml.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ public partial class MainPage : ContentPage
77
public MainPage()
88
{
99
InitializeComponent();
10-
11-
1210
}
1311

1412

AcrylicView.Samples/NewPage1.xaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
x:Class="AcrylicView.Samples.NewPage1"
5+
xmlns:ui="clr-namespace:Xe.AcrylicView;assembly=Xe.AcrylicView"
6+
Title="NewPage1">
7+
<Grid>
8+
<Image Aspect="AspectFill" Source="nature.jpg"/>
9+
<Grid RowDefinitions="2*,*">
10+
11+
12+
<ui:AcrylicView WidthRequest="200" HeightRequest="200" HorizontalOptions="Center" VerticalOptions="Center" BorderColor="OrangeRed" BorderThickness="10" CornerRadius="15">
13+
14+
</ui:AcrylicView>
15+
16+
</Grid>
17+
</Grid>
18+
</ContentPage>

AcrylicView.Samples/NewPage1.xaml.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using Microsoft.Maui.Platform;
2+
3+
namespace AcrylicView.Samples;
4+
5+
public partial class NewPage1 : ContentPage
6+
{
7+
public NewPage1()
8+
{
9+
InitializeComponent();
10+
11+
}
12+
}

AcrylicView/AcrylicView.csproj

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,16 @@
2626
AcrylicView, Windows,Android,iOS,Mac
2727

2828
</Description>
29-
<Version>1.12</Version>
29+
<Version>1.2</Version>
3030
<PackageProjectUrl>https://github.com/sswi/AcrylicView.MAUI</PackageProjectUrl>
3131
<RepositoryUrl>https://github.com/sswi/AcrylicView.MAUI</RepositoryUrl>
3232
<PackageReadmeFile>README.md</PackageReadmeFile>
3333
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
3434
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
3535
<!--<PackageIcon>ico.png</PackageIcon>-->
3636
<PackageId>AcrylicView.Maui</PackageId>
37+
<PackageIcon>ico.png</PackageIcon>
38+
<RepositoryType>git</RepositoryType>
3739
</PropertyGroup>
3840

3941
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net7.0-ios|AnyCPU'">
@@ -60,6 +62,13 @@ AcrylicView, Windows,Android,iOS,Mac
6062
<Folder Include="Platforms\Tizen\" />
6163
</ItemGroup>
6264

65+
<ItemGroup>
66+
<None Include="..\ico.png">
67+
<Pack>True</Pack>
68+
<PackagePath>\</PackagePath>
69+
</None>
70+
</ItemGroup>
71+
6372
<!--<ItemGroup>
6473
<None Include="..\..\..\..\..\Desktop\Nuget\ico.png">
6574
<Pack>True</Pack>

AcrylicView/Controls/AcrylicView.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ public partial class AcrylicView : ContentView, IAcrylicView
2828
typeof(double),
2929
typeof(AcrylicView), 0.0);
3030

31+
32+
public static readonly BindableProperty AndroidPerfectProperty = BindableProperty.Create(
33+
nameof(AndroidPerfect),
34+
typeof(bool),
35+
typeof(AcrylicView), false);
36+
3137
public Color BorderColor
3238
{
3339
get => (Color)GetValue(BorderColorProperty);
@@ -62,5 +68,17 @@ public double TintOpacity
6268
get => (double)GetValue(TintOpacityProperty);
6369
set => SetValue(TintOpacityProperty, value);
6470
}
71+
72+
/// <summary>
73+
/// Warning!!!|注意啦!
74+
/// OnlyAndroid/仅安卓系统可用
75+
/// Enabling this option will affect system performance/启用此项会完美显示,不会泛光,同时将会影响系统性能,因为会不停地对区域进行监听绘制
76+
/// </summary>
77+
public bool AndroidPerfect
78+
{
79+
get => (bool)GetValue(AndroidPerfectProperty);
80+
set => SetValue(AndroidPerfectProperty, value);
81+
}
82+
6583
}
6684
}

AcrylicView/Controls/AcrylicViewHandler.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ public partial class AcrylicViewHandler
1212
[nameof(IAcrylicView.EffectStyle)] = MapEffectStyle,
1313
[nameof(IAcrylicView.Content)] = MapContent,
1414
[nameof(IAcrylicView.BorderThickness)] = MapBorderThickness,
15-
[nameof(IAcrylicView.BorderColor)] = MapBorderColor
15+
[nameof(IAcrylicView.BorderColor)] = MapBorderColor,
16+
#if ANDROID
17+
[nameof(IAcrylicView.AndroidPerfect)] = MapAndroidPerfect
18+
#endif
1619
};
1720

1821

AcrylicView/Controls/IAcrylicView.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ public interface IAcrylicView : IView, IContentView
1212
EffectStyle EffectStyle { get; set; }
1313

1414
Thickness BorderThickness { get; set; }
15+
16+
/// <summary>
17+
/// Warning!!!|注意啦!
18+
/// OnlyAndroid/仅安卓系统可用
19+
/// Enabling this option will affect system performance/启用此项会完美显示,不会泛光,同时将会影响系统性能,因为会不停地对区域进行监听绘制
20+
/// </summary>
21+
bool AndroidPerfect { get;set; }
22+
23+
24+
1525
}
1626

1727
public enum EffectStyle

AcrylicView/Platforms/Android/AcrylicViewHandler.cs

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ protected override FrameLayout CreatePlatformView()
3030
{
3131
colorBlendLayer = new View(Context);
3232

33-
realtimeBlurView = new RealtimeBlurView(Context);
33+
realtimeBlurView = new RealtimeBlurView(Context, SetContentVisibel);
3434
realtimeBlurView.SetBlurRadius(100);
3535
realtimeBlurView.SetOverlayColor(Colors.Transparent.ToAndroid());
3636
realtimeBlurView.SetDownsampleFactor(2);
@@ -50,25 +50,41 @@ protected override FrameLayout CreatePlatformView()
5050
return frame;
5151
}
5252

53+
private static void MapAndroidPerfect(AcrylicViewHandler handler, IAcrylicView view)
54+
{
55+
handler.androidPerfect = view.AndroidPerfect;
56+
}
57+
58+
private bool androidPerfect = false;
59+
60+
/// <summary>
61+
/// 控制获取视图层时顶层视图的透明图
62+
/// </summary>
63+
/// <param name="isVisibel"></param>
64+
private void SetContentVisibel(bool isVisibel)
65+
{
66+
if (borderViewGroup == null || !androidPerfect) return;
67+
borderViewGroup.Alpha = isVisibel ? 1f : 0f;
68+
}
69+
5370
private static void MapTintColor(AcrylicViewHandler handler, IAcrylicView view)
5471
{
55-
if (view.EffectStyle != EffectStyle.Custom)
56-
return;
72+
if (view.EffectStyle != EffectStyle.Custom) return;
73+
5774
var nativView = handler?.PlatformView;
75+
5876
if (nativView == null) return;
5977

6078
handler.UpdateColorblendLayer(view);
6179
}
6280

6381
private static void MapTintOpacity(AcrylicViewHandler handler, IAcrylicView view)
6482
{
65-
if (view.EffectStyle != EffectStyle.Custom)
66-
return;
83+
if (view.EffectStyle != EffectStyle.Custom) return;
6784

68-
if (view.TintColor == null || view.TintColor == Colors.Transparent)
69-
{
70-
return;
71-
}
85+
86+
if (view.TintColor == null || view.TintColor == Colors.Transparent) return;
87+
7288
handler.colorBlendLayerAlpha = (float)view.TintOpacity;
7389
handler.colorBlendLayer.Alpha = handler.colorBlendLayerAlpha;
7490
}
@@ -105,7 +121,7 @@ private void UpdateEffectStyle(IAcrylicView view, Color color, float tintOpacity
105121
colorBlendLayer.SetBackgroundDrawable(colorGradientDrawable);
106122

107123
colorBlendLayerAlpha = tintOpacity;
108-
colorBlendLayer.Alpha = colorBlendLayerAlpha;
124+
colorBlendLayer.Alpha = colorBlendLayerAlpha;
109125
}
110126

111127
private static void MapContent(AcrylicViewHandler handler, IAcrylicView view)
@@ -114,19 +130,19 @@ private static void MapContent(AcrylicViewHandler handler, IAcrylicView view)
114130
if (nativView == null) return;
115131

116132
handler.borderViewGroup.RemoveAllViews();
117-
118133
if (view.Content is IView content && view.Handler != null)
119134
{
120135
var view3 = ElementExtensions.ToPlatform(content, view.Handler.MauiContext);
121136
handler.borderViewGroup.AddView(view3);
137+
System.Diagnostics.Debug.WriteLine("内容改变");
122138
}
123139
}
124140

125141
private static void MapBorderThickness(AcrylicViewHandler handler, IAcrylicView view)
126142
{
127143
var nativView = handler?.PlatformView;
128144
if (nativView == null) return;
129-
145+
handler.realtimeBlurView.SetBorderThickness(view.BorderThickness);
130146
PropertyChanged(handler, view);
131147
}
132148

@@ -154,7 +170,7 @@ private static void PropertyChanged(AcrylicViewHandler handler, IAcrylicView vie
154170
{
155171
var nativView = handler?.PlatformView;
156172
if (nativView == null) return;
157-
handler.borderViewGroup.BorderDrawable = new BorderDrawable(nativView.Context, view);
173+
handler.borderViewGroup.BorderDrawable = new BorderDrawable(nativView.Context, view);
158174
}
159175

160176
private void UpdateColorblendLayer(IAcrylicView view)

0 commit comments

Comments
 (0)