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

[NUI] Add VisibilityChanged event to Layer #5398

Merged
Merged
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
111 changes: 111 additions & 0 deletions src/Tizen.NUI/src/public/Common/Layer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using System;
using Tizen.NUI.BaseComponents;
using System.ComponentModel;
using System.Runtime.InteropServices;

namespace Tizen.NUI
{
Expand All @@ -28,6 +29,10 @@
{
private Window window;
private int layoutCount = 0;
private EventHandler<VisibilityChangedEventArgs> visibilityChangedEventHandler;
private VisibilityChangedEventCallbackType visibilityChangedEventCallback;
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
private delegate void VisibilityChangedEventCallbackType(IntPtr data, bool visibility, VisibilityChangeType type);

/// <summary>
/// Creates a Layer object.
Expand Down Expand Up @@ -55,6 +60,12 @@
return;
}

if (visibilityChangedEventCallback != null)
{
VisibilityChangedSignal(this).Disconnect(visibilityChangedEventCallback);

Check warning on line 65 in src/Tizen.NUI/src/public/Common/Layer.cs

View workflow job for this annotation

GitHub Actions / build

Call System.IDisposable.Dispose on object created by 'VisibilityChangedSignal(this)' before all references to it are out of scope.
visibilityChangedEventCallback = null;
}

LayoutCount = 0;

base.Dispose(type);
Expand Down Expand Up @@ -611,6 +622,89 @@
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}

/// <summary>
/// An event for visibility change which can be used to subscribe or unsubscribe the event handler.<br />
/// This signal is emitted when the visible property of this or a parent view is changed.<br />
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public event EventHandler<VisibilityChangedEventArgs> VisibilityChanged
{
add
{
if (visibilityChangedEventHandler == null)
{
visibilityChangedEventCallback = OnVisibilityChanged;
VisibilityChangedSignal(this).Connect(visibilityChangedEventCallback);

Check warning on line 637 in src/Tizen.NUI/src/public/Common/Layer.cs

View workflow job for this annotation

GitHub Actions / build

Call System.IDisposable.Dispose on object created by 'VisibilityChangedSignal(this)' before all references to it are out of scope.
}

visibilityChangedEventHandler += value;
}

remove
{
visibilityChangedEventHandler -= value;

if (visibilityChangedEventHandler == null && VisibilityChangedSignal(this).Empty() == false)

Check warning on line 647 in src/Tizen.NUI/src/public/Common/Layer.cs

View workflow job for this annotation

GitHub Actions / build

Call System.IDisposable.Dispose on object created by 'VisibilityChangedSignal(this)' before all references to it are out of scope.
{
VisibilityChangedSignal(this).Disconnect(visibilityChangedEventCallback);

Check warning on line 649 in src/Tizen.NUI/src/public/Common/Layer.cs

View workflow job for this annotation

GitHub Actions / build

Call System.IDisposable.Dispose on object created by 'VisibilityChangedSignal(this)' before all references to it are out of scope.
if (VisibilityChangedSignal(this).Empty() == true)

Check warning on line 650 in src/Tizen.NUI/src/public/Common/Layer.cs

View workflow job for this annotation

GitHub Actions / build

Call System.IDisposable.Dispose on object created by 'VisibilityChangedSignal(this)' before all references to it are out of scope.
{
visibilityChangedEventCallback = null;
}
}
}
}

/// <summary>
/// Event arguments of visibility changed.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public class VisibilityChangedEventArgs : EventArgs

Check warning on line 662 in src/Tizen.NUI/src/public/Common/Layer.cs

View workflow job for this annotation

GitHub Actions / build

Do not nest type VisibilityChangedEventArgs. Alternatively, change its accessibility so that it is not externally visible.
{
private Layer layer;
private bool visibility;

/// <summary>
/// The layer whose visibility has changed.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public Layer Layer
{
get
{
return layer;
}
set
{
layer = value;
}
}

/// <summary>
/// Whether the layer is now visible or not.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public bool Visibility
{
get
{
return visibility;
}
set
{
visibility = value;
}
}
}

// Since ViewVisibilityChangedSignal uses Actor's visibility, Layer uses it as well.
internal ViewVisibilityChangedSignal VisibilityChangedSignal(Layer layer)
{
ViewVisibilityChangedSignal ret = new ViewVisibilityChangedSignal(Interop.NDalic.VisibilityChangedSignal(Layer.getCPtr(layer)), false);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}

internal uint GetDepth()
{
var parentChildren = window?.LayersChildren;
Expand Down Expand Up @@ -799,5 +893,22 @@
{
internal static readonly int BEHAVIOR = Interop.Layer.BehaviorGet();
}

// Callback for View visibility change signal
// type is not used because layer does not have parent so layer's visibility cannot be changed by its parent.
private void OnVisibilityChanged(IntPtr data, bool visibility, VisibilityChangeType type)
{
VisibilityChangedEventArgs e = new VisibilityChangedEventArgs();
if (data != null)
{
e.Layer = Registry.GetManagedBaseHandleFromNativePtr(data) as Layer;
}
e.Visibility = visibility;

if (visibilityChangedEventHandler != null)
{
visibilityChangedEventHandler(this, e);
}
}
}
}
Loading