Skip to content

Commit

Permalink
[NUI] Add VisibilityChanged event to Layer
Browse files Browse the repository at this point in the history
To notice the visibility changes of Layer, VisibilityChanged event is
added to Layer.
  • Loading branch information
Jaehyun-Cho committed Jul 18, 2023
1 parent 437208d commit 319adb2
Showing 1 changed file with 94 additions and 0 deletions.
94 changes: 94 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 @@ public class Layer : Container
{
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 @@ -609,6 +614,78 @@ public void SetHoverConsumed(bool consume)
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;
Interop.ActorSignal.VisibilityChangedConnect(SwigCPtr, visibilityChangedEventCallback.ToHandleRef(this));
NDalicPINVOKE.ThrowExceptionIfExists();
}
visibilityChangedEventHandler += value;
}

remove
{
visibilityChangedEventHandler -= value;
if (visibilityChangedEventHandler == null && visibilityChangedEventCallback != null)
{
Interop.ActorSignal.VisibilityChangedDisconnect(SwigCPtr, visibilityChangedEventCallback.ToHandleRef(this));
NDalicPINVOKE.ThrowExceptionIfExists();
visibilityChangedEventCallback = null;
}
}
}

/// <summary>
/// Event arguments of visibility changed.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public class VisibilityChangedEventArgs : EventArgs
{
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;
}
}
}

internal uint GetDepth()
{
var parentChildren = window?.LayersChildren;
Expand Down Expand Up @@ -797,5 +874,22 @@ internal class Property
{
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);
}
}
}
}

0 comments on commit 319adb2

Please sign in to comment.