Skip to content

Commit d9492ee

Browse files
authored
Merge branch 'master' into master
2 parents 005cf38 + ae944c7 commit d9492ee

File tree

9 files changed

+111
-88
lines changed

9 files changed

+111
-88
lines changed

AcrylicView.Samples/MainPage.xaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616

1717

18+
1819
<Grid
1920
Padding="20"
2021
RowDefinitions="120,170,120,120,120,*"
@@ -26,6 +27,16 @@
2627
CornerRadius="20"
2728
EffectStyle="Light">
2829
<Grid Padding="20,0" ColumnDefinitions="*,*,*,*">
30+
31+
32+
33+
34+
35+
<Grid RowDefinitions="120,170,120,120,120,*" Padding="20" RowSpacing="30">
36+
37+
<ui:AcrylicView EffectStyle="Light" BorderColor="White" BorderThickness="0" CornerRadius="20" >
38+
<Grid ColumnDefinitions="*,*,*,*" Padding="20,0">
39+
2940
<VerticalStackLayout HorizontalOptions="Center" VerticalOptions="Center">
3041
<Label
3142
FontFamily="XF"

AcrylicView/Controls/AcrylicView.cs

Lines changed: 33 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,66 @@
1-
using System.Diagnostics;
2-
using Xe.AcrylicView.Controls;
1+
using Xe.AcrylicView.Controls;
32

43
namespace Xe.AcrylicView
54
{
65
public partial class AcrylicView : ContentView, IAcrylicView
76
{
7+
public static readonly BindableProperty BorderColorProperty = BindableProperty.Create(nameof(BorderColor), typeof(Color), typeof(AcrylicView), Colors.Transparent);
88

9-
//protected override void OnSizeAllocated(double width, double height)
10-
//{
11-
// Debug.WriteLine($"*******************{width}*{height}*****************************************");
12-
// base.OnSizeAllocated(width, height);
13-
//}
14-
15-
16-
public static readonly BindableProperty TintColorProperty = BindableProperty.Create(
17-
nameof(TintColor),
18-
typeof(Color),
19-
typeof(AcrylicView), DeviceInfo.Current.Platform == DevicePlatform.Android ? Colors.LightGray : Colors.Transparent);
20-
21-
public Color TintColor
22-
{
23-
get => (Color)GetValue(TintColorProperty);
24-
set => SetValue(TintColorProperty, value);
25-
}
9+
public static readonly BindableProperty BorderThicknessProperty = BindableProperty.Create(nameof(BorderThickness), typeof(Thickness), typeof(AcrylicView), new Thickness(1.0));
2610

2711
public static readonly BindableProperty CornerRadiusProperty = BindableProperty.Create(
2812
nameof(CornerRadius),
2913
typeof(Thickness),
30-
typeof(AcrylicView),new Thickness(5.0));
14+
typeof(AcrylicView), new Thickness(5.0));
3115

32-
public Thickness CornerRadius
33-
{
34-
get => (Thickness)GetValue(CornerRadiusProperty);
35-
set => SetValue(CornerRadiusProperty, value);
36-
}
16+
public static readonly BindableProperty EffectStyleProperty = BindableProperty.Create(
17+
nameof(EffectStyle),
18+
typeof(EffectStyle),
19+
typeof(AcrylicView), EffectStyle.Custom);
20+
21+
public static readonly BindableProperty TintColorProperty = BindableProperty.Create(
22+
nameof(TintColor),
23+
typeof(Color),
24+
typeof(AcrylicView), DeviceInfo.Current.Platform == DevicePlatform.Android ? Colors.LightGray : Colors.Transparent);
3725

3826
public static readonly BindableProperty TintOpacityProperty = BindableProperty.Create(
3927
nameof(TintOpacity),
4028
typeof(double),
4129
typeof(AcrylicView), 0.0);
4230

43-
public double TintOpacity
31+
public Color BorderColor
4432
{
45-
get => (double)GetValue(TintOpacityProperty);
46-
set => SetValue(TintOpacityProperty, value);
33+
get => (Color)GetValue(BorderColorProperty);
34+
set => SetValue(BorderColorProperty, value);
4735
}
4836

37+
public Thickness BorderThickness
38+
{
39+
get => (Thickness)GetValue(BorderThicknessProperty);
40+
set => SetValue(BorderThicknessProperty, value);
41+
}
4942

50-
51-
public static readonly BindableProperty EffectStyleProperty = BindableProperty.Create(
52-
nameof(EffectStyle),
53-
typeof(EffectStyle),
54-
typeof(AcrylicView), EffectStyle.Custom);
43+
public Thickness CornerRadius
44+
{
45+
get => (Thickness)GetValue(CornerRadiusProperty);
46+
set => SetValue(CornerRadiusProperty, value);
47+
}
5548

5649
public EffectStyle EffectStyle
5750
{
5851
get => (EffectStyle)GetValue(EffectStyleProperty);
5952
set => SetValue(EffectStyleProperty, value);
6053
}
6154

62-
63-
64-
public static readonly BindableProperty BorderThicknessProperty = BindableProperty.Create(nameof(BorderThickness), typeof(Thickness), typeof(AcrylicView), new Thickness(1.0));
65-
66-
public Thickness BorderThickness
55+
public Color TintColor
6756
{
68-
get => (Thickness)GetValue(BorderThicknessProperty);
69-
set => SetValue(BorderThicknessProperty, value);
57+
get => (Color)GetValue(TintColorProperty);
58+
set => SetValue(TintColorProperty, value);
7059
}
71-
72-
73-
74-
public static readonly BindableProperty BorderColorProperty = BindableProperty.Create(nameof(BorderColor), typeof(Color), typeof(AcrylicView), Colors.Transparent);
75-
76-
public Color BorderColor
60+
public double TintOpacity
7761
{
78-
get => (Color)GetValue(BorderColorProperty);
79-
set => SetValue(BorderColorProperty, value);
62+
get => (double)GetValue(TintOpacityProperty);
63+
set => SetValue(TintOpacityProperty, value);
8064
}
81-
82-
83-
84-
8565
}
86-
}
66+
}

AcrylicView/Controls/IAcrylicView.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-

2-
namespace Xe.AcrylicView.Controls
1+
namespace Xe.AcrylicView.Controls
32
{
4-
public interface IAcrylicView : IView,IContentView
3+
public interface IAcrylicView : IView, IContentView
54
{
65
Thickness CornerRadius { get; set; }
76

@@ -15,14 +14,12 @@ public interface IAcrylicView : IView,IContentView
1514
Thickness BorderThickness { get; set; }
1615
}
1716

18-
1917
public enum EffectStyle
2018
{
2119
ExtraLight = 0,
2220
Light = 1,
2321
Dark = 2,
2422
ExtraDark = 3,
25-
Custom=4
26-
23+
Custom = 4
2724
}
28-
}
25+
}

AcrylicView/Platforms/Android/AcrylicViewHandler.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,7 @@ private void UpdateEffectStyle(IAcrylicView view, Color color, float tintOpacity
105105
colorBlendLayer.SetBackgroundDrawable(colorGradientDrawable);
106106

107107
colorBlendLayerAlpha = tintOpacity;
108-
colorBlendLayer.Alpha = colorBlendLayerAlpha;
109-
110-
108+
colorBlendLayer.Alpha = colorBlendLayerAlpha;
111109
}
112110

113111
private static void MapContent(AcrylicViewHandler handler, IAcrylicView view)

AcrylicView/Platforms/Android/AndroidStockBlurImpl.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ public bool Prepare(Context context, Bitmap buffer, float radius)
3232
// In release mode, just ignore
3333
Release();
3434
return false;
35-
3635
}
3736
}
3837

AcrylicView/Platforms/Android/RealtimeBlurView.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,8 @@ public void SetCornerRadius(float topLeft, float topRight, float bottomRight, fl
594594
protected override void OnSizeChanged(int w, int h, int oldw, int oldh)
595595
{
596596
base.OnSizeChanged(w, h, oldw, oldh);
597+
598+
if (w>0 && h>0)
597599
preDrawListener.OnPreDraw();
598600
}
599601

AcrylicView/Platforms/MacCatalyst/AcrylicViewHandler.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,14 @@ private static void MapEffectStyle(AcrylicViewHandler handler, IAcrylicView view
9595
return;
9696

9797
var ver = UIDevice.CurrentDevice.SystemVersion;
98-
if (!float.TryParse(ver, out float version))
99-
return;
98+
10099

101100
var style = view.EffectStyle switch
102101
{
103102
EffectStyle.Light => UIBlurEffectStyle.Light,
104103
EffectStyle.Dark => UIBlurEffectStyle.Dark,
105104
EffectStyle.ExtraLight => UIBlurEffectStyle.ExtraLight,
106-
EffectStyle.ExtraDark => version >= 14.2 ? UIBlurEffectStyle.ExtraDark : UIBlurEffectStyle.Dark,
105+
EffectStyle.ExtraDark =>UIBlurEffectStyle.Dark,
107106
_ => UIBlurEffectStyle.Light
108107
};
109108
handler.acrylicEffectView.Effect = UIBlurEffect.FromStyle(style);

AcrylicView/Platforms/iOS/AcrylicViewHandler.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ private static void MapEffectStyle(AcrylicViewHandler handler, IAcrylicView view
9595
return;
9696

9797
var ver = UIDevice.CurrentDevice.SystemVersion;
98+
9899
//if (!float.TryParse(ver, out float version))
99100
// return;
100101

@@ -104,7 +105,7 @@ private static void MapEffectStyle(AcrylicViewHandler handler, IAcrylicView view
104105
EffectStyle.Light => UIBlurEffectStyle.Light,
105106
EffectStyle.Dark => UIBlurEffectStyle.Dark,
106107
EffectStyle.ExtraLight => UIBlurEffectStyle.ExtraLight,
107-
EffectStyle.ExtraDark => UIBlurEffectStyle.ExtraDark,
108+
EffectStyle.ExtraDark => UIBlurEffectStyle.Dark, //ExtraDark仅支持tvos
108109
_ => UIBlurEffectStyle.Light
109110
};
110111
handler.acrylicEffectView.Effect = UIBlurEffect.FromStyle(style);

AcrylicView/README.md

Lines changed: 56 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,67 @@
1-
using Xe.AcrylicView;
21

3-
public static class MauiProgram { public static MauiApp CreateMauiApp() { var builder = MauiApp.CreateBuilder(); builder .UseMauiApp<App>()
2+
| Supported platforms |
3+
|----------------------------|
4+
| :heavy_check_mark: Android |
5+
| :heavy_check_mark: iOS |
6+
| :heavy_check_mark: macOS |
7+
| :heavy_check_mark: Windows |
8+
9+
10+
MauiProgram.cs
11+
12+
```csharp
13+
14+
using Xe.AcrylicView;
415

5-
.UseAcrylicView() //
6-
7-
8-
.ConfigureFonts(fonts =>
16+
public static class MauiProgram
17+
{
18+
public static MauiApp CreateMauiApp()
919
{
10-
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
11-
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
12-
});
13-
return builder.Build();
20+
var builder = MauiApp.CreateBuilder();
21+
builder
22+
.UseMauiApp<App>()
23+
24+
.UseAcrylicView() //********* Use
25+
26+
27+
.ConfigureFonts(fonts =>
28+
{
29+
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
30+
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
31+
});
32+
return builder.Build();
33+
}
34+
}
1435
}
15-
} }
36+
```
37+
38+
39+
40+
41+
```xml
42+
xmlns:ui="clr-namespace:Xe.AcrylicView;assembly=Xe.AcrylicView"
43+
44+
<ui:AcrylicView VerticalOptions="Center"
45+
HeightRequest="100"
46+
EffectStyle="Custom"
47+
Margin="10"
48+
TintColor="OrangeRed"
49+
TintOpacity=".15 "
50+
BorderColor="OrangeRed"
51+
BorderThickness="1,2"
52+
CornerRadius="50,10,30,20" >
53+
<Grid>
54+
<Label Text="Hello Word" FontSize="25" HorizontalOptions="Center" VerticalOptions="Center" TextColor="OrangeRed"/>
55+
</Grid>
56+
</ui:AcrylicView>
57+
```
1658

1759

1860

19-
xmlns:ui="clr-namespace:Xe.AcrylicView;assembly=Xe.AcrylicView"
2061

62+
Android平台的实现方式是从这个仓库获取,从Xamarin.Forms简单移植过来的,请支持原作者:
63+
https://github.com/roubachof/Sharpnado.MaterialFrame
2164

22-
<ui:AcrylicView VerticalOptions="Center" HeightRequest="100" EffectStyle="Custom" Margin="10" TintColor="OrangeRed" TintOpacity=".15 " BorderColor="OrangeRed" BorderThickness="2" CornerRadius="50,10,30,20" >
23-
<Grid>
24-
<Label Text="Hello Word" FontSize="25" HorizontalOptions="Center" VerticalOptions="Center" TextColor="OrangeRed"/>
25-
<Label/>
26-
</Grid>
27-
</ui:AcrylicView>
2865

29-
iOS、Mac平台不支持颜色混合
3066

31-
Android平台的实现方式是从这个仓库获取,从Xamarin.Forms简单移植过来的,请支持原作者: https://github.com/roubachof/Sharpnado.MaterialFrame
67+
![02](https://user-images.githubusercontent.com/39110708/231667033-e99ed65b-d74a-4e70-9e89-0958afdc5e45.png)

0 commit comments

Comments
 (0)