-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e19bcd7
commit e9d231f
Showing
12 changed files
with
213 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
Zebble/Android/Controls/Containers/AndroidBlurredContainer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using Android.Graphics; | ||
using Android.Runtime; | ||
using System; | ||
|
||
namespace Zebble.AndroidOS | ||
{ | ||
public class AndroidBlurredContainer : AndroidBaseContainer<Stack> | ||
{ | ||
RenderEffect BlurEffect; | ||
|
||
public AndroidBlurredContainer(Stack view) : base(view) | ||
{ | ||
view.BlurredChanged.HandleOnUI(MaintainBlur); | ||
CreateBlur(); | ||
MaintainBlur(); | ||
} | ||
|
||
[Preserve] | ||
protected AndroidBlurredContainer(IntPtr handle, JniHandleOwnership transfer) : base(handle, transfer) { } | ||
|
||
void CreateBlur() => BlurEffect = RenderEffect.CreateBlurEffect(10, 10, Shader.TileMode.Clamp); | ||
|
||
void MaintainBlur() | ||
{ | ||
if (IsDead(out var view)) return; | ||
SetRenderEffect(view.Blurred ? BlurEffect : null); | ||
} | ||
|
||
bool IsDead(out Stack result) | ||
{ | ||
result = View; | ||
if (result is null || result.IsDisposing) return true; | ||
return result.IsDisposing; | ||
} | ||
|
||
protected override void Dispose(bool disposing) | ||
{ | ||
if (disposing && !IsDisposed) | ||
{ | ||
View?.BlurredChanged.RemoveActionHandler(MaintainBlur); | ||
BlurEffect.Dispose(); | ||
BlurEffect = null; | ||
} | ||
|
||
base.Dispose(disposing); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
namespace Zebble.UWP | ||
{ | ||
public class UWPStack : UWPCanvasBase<Stack> | ||
{ | ||
public UWPStack(Renderer renderer, Stack view) : base(renderer, view) | ||
{ | ||
view.BlurredChanged.Handle(MaintainBlur); | ||
CreateBlur(); | ||
MaintainBlur(); | ||
} | ||
|
||
void CreateBlur() { } | ||
|
||
void MaintainBlur() | ||
{ | ||
if (IsDead(out var view)) return; | ||
// TODO | ||
// View.BackgroundColor(view.Blurred ? Colors.Black.WithAlpha(100) : null); | ||
} | ||
|
||
bool IsDead(out Stack result) | ||
{ | ||
result = View; | ||
if (result is null || result.IsDisposing) return true; | ||
return result.IsDisposing; | ||
} | ||
|
||
public override void Dispose() | ||
{ | ||
if (!IsDisposed) | ||
View?.BlurredChanged.RemoveActionHandler(MaintainBlur); | ||
|
||
base.Dispose(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
namespace Zebble.IOS | ||
{ | ||
using System; | ||
using UIKit; | ||
|
||
public class IosBlurredContainer : IosContainerBase<Stack> | ||
{ | ||
UIVisualEffectView BlurSubview; | ||
bool IsSubviewAdded; | ||
|
||
public IosBlurredContainer(Stack view) : base(view) | ||
{ | ||
View.BlurredChanged.HandleOnUI(MaintainBlur); | ||
CreateBlur(); | ||
MaintainBlur(); | ||
} | ||
|
||
void CreateBlur() => BlurSubview = new UIVisualEffectView | ||
{ | ||
Alpha = .975f, | ||
Effect = UIBlurEffect.FromStyle(UIBlurEffectStyle.Regular) | ||
}; | ||
|
||
public void OnBoundsChanged() => BlurSubview.Set(x => x.Frame = Bounds); | ||
|
||
void MaintainBlur() | ||
{ | ||
if (IsDead(out var view)) return; | ||
if (view.Blurred) | ||
{ | ||
if (IsSubviewAdded) return; | ||
AddSubview(BlurSubview); | ||
IsSubviewAdded = true; | ||
} | ||
else | ||
{ | ||
if (IsSubviewAdded == false) return; | ||
BlurSubview.RemoveFromSuperview(); | ||
IsSubviewAdded = false; | ||
} | ||
} | ||
|
||
public override void SubviewAdded(UIView uiview) | ||
{ | ||
base.SubviewAdded(uiview); | ||
if (IsSubviewAdded == false) return; | ||
if (uiview == BlurSubview) return; | ||
BringSubviewToFront(BlurSubview); | ||
} | ||
|
||
bool IsDead(out Stack result) | ||
{ | ||
result = View; | ||
if (result is null || result.IsDisposing) return true; | ||
return result.IsDisposing; | ||
} | ||
|
||
protected override void Dispose(bool disposing) | ||
{ | ||
if (disposing && !IsDisposed) | ||
{ | ||
View?.BlurredChanged.RemoveActionHandler(MaintainBlur); | ||
BlurSubview?.RemoveFromSuperview(); | ||
BlurSubview?.Dispose(); | ||
BlurSubview = null; | ||
} | ||
|
||
base.Dispose(disposing); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters