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] Block native callback if view is disposed or disposing #6456

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions src/Tizen.NUI/src/public/BaseComponents/ImageView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2007,6 +2007,12 @@ protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef
// Callback for View ResourceReady signal
private void OnResourceReady(IntPtr data)
{
if (Disposed || IsDisposeQueued)
{
// Ignore native callback if the view is disposed or queued for disposal.
return;
}

if (!CheckResourceReady())
{
return;
Expand Down Expand Up @@ -2381,6 +2387,12 @@ protected override bool CheckResourceReady()

private void OnResourceLoaded(IntPtr view)
{
if (Disposed || IsDisposeQueued)
{
// Ignore native callback if the view is disposed or queued for disposal.
return;
}

if (!CheckResourceReady())
{
return;
Expand Down
54 changes: 54 additions & 0 deletions src/Tizen.NUI/src/public/BaseComponents/TextEditorEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,12 @@ internal TextEditorSignal InputFilteredSignal()

private void OnTextChanged(IntPtr textEditor)
{
if (Disposed || IsDisposeQueued)
{
// Ignore native callback if the view is disposed or queued for disposal.
return;
}

if (textEditorTextChangedEventHandler != null && invokeTextChanged)
{
TextChangedEventArgs e = new TextChangedEventArgs();
Expand All @@ -408,18 +414,36 @@ private void OnTextChanged(IntPtr textEditor)

private void OnSelectionStarted(IntPtr textEditor)
{
if (Disposed || IsDisposeQueued)
{
// Ignore native callback if the view is disposed or queued for disposal.
return;
}

//no data to be sent to the user
textEditorSelectionStartedEventHandler?.Invoke(this, EventArgs.Empty);
}

private void OnSelectionCleared(IntPtr textEditor)
{
if (Disposed || IsDisposeQueued)
{
// Ignore native callback if the view is disposed or queued for disposal.
return;
}

//no data to be sent to the user
textEditorSelectionClearedEventHandler?.Invoke(this, EventArgs.Empty);
}

private void OnScrollStateChanged(IntPtr textEditor, ScrollState state)
{
if (Disposed || IsDisposeQueued)
{
// Ignore native callback if the view is disposed or queued for disposal.
return;
}

if (textEditorScrollStateChangedEventHandler != null)
{
ScrollStateChangedEventArgs e = new ScrollStateChangedEventArgs();
Expand All @@ -437,12 +461,24 @@ private void OnScrollStateChanged(IntPtr textEditor, ScrollState state)

private void OnCursorPositionChanged(IntPtr textEditor, uint oldPosition)
{
if (Disposed || IsDisposeQueued)
{
// Ignore native callback if the view is disposed or queued for disposal.
return;
}

// no data to be sent to the user, as in NUI there is no event provide old values.
textEditorCursorPositionChangedEventHandler?.Invoke(this, EventArgs.Empty);
}

private void OnMaxLengthReached(IntPtr textEditor)
{
if (Disposed || IsDisposeQueued)
{
// Ignore native callback if the view is disposed or queued for disposal.
return;
}

if (textEditorMaxLengthReachedEventHandler != null)
{
MaxLengthReachedEventArgs e = new MaxLengthReachedEventArgs();
Expand All @@ -456,6 +492,12 @@ private void OnMaxLengthReached(IntPtr textEditor)

private void OnAnchorClicked(IntPtr textEditor, IntPtr href, uint hrefLength)
{
if (Disposed || IsDisposeQueued)
{
// Ignore native callback if the view is disposed or queued for disposal.
return;
}

// Note: hrefLength is useful for get the length of a const char* (href) in dali-toolkit.
// But NUI can get the length of string (href), so hrefLength is not necessary in NUI.
AnchorClickedEventArgs e = new AnchorClickedEventArgs();
Expand All @@ -468,12 +510,24 @@ private void OnAnchorClicked(IntPtr textEditor, IntPtr href, uint hrefLength)

private void OnSelectionChanged(IntPtr textEditor, uint oldStart, uint oldEnd)
{
if (Disposed || IsDisposeQueued)
{
// Ignore native callback if the view is disposed or queued for disposal.
return;
}

// no data to be sent to the user, as in NUI there is no event provide old values.
textEditorSelectionChangedEventHandler?.Invoke(this, EventArgs.Empty);
}

private void OnInputFiltered(IntPtr textEditor, InputFilterType type)
{
if (Disposed || IsDisposeQueued)
{
// Ignore native callback if the view is disposed or queued for disposal.
return;
}

InputFilteredEventArgs e = new InputFilteredEventArgs();

// Populate all members of "e" (InputFilteredEventArgs) with real data
Expand Down
48 changes: 48 additions & 0 deletions src/Tizen.NUI/src/public/BaseComponents/TextFieldEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -350,18 +350,36 @@ internal TextFieldSignal InputFilteredSignal()

private void OnSelectionStarted(IntPtr textField)
{
if (Disposed || IsDisposeQueued)
{
// Ignore native callback if the view is disposed or queued for disposal.
return;
}

//no data to be sent to the user
textFieldSelectionStartedEventHandler?.Invoke(this, EventArgs.Empty);
}

private void OnSelectionCleared(IntPtr textField)
{
if (Disposed || IsDisposeQueued)
{
// Ignore native callback if the view is disposed or queued for disposal.
return;
}

//no data to be sent to the user
textFieldSelectionClearedEventHandler?.Invoke(this, EventArgs.Empty);
}

private void OnTextChanged(IntPtr textField)
{
if (Disposed || IsDisposeQueued)
{
// Ignore native callback if the view is disposed or queued for disposal.
return;
}

if (textFieldTextChangedEventHandler != null && invokeTextChanged)
{
TextChangedEventArgs e = new TextChangedEventArgs();
Expand All @@ -375,12 +393,24 @@ private void OnTextChanged(IntPtr textField)

private void OnCursorPositionChanged(IntPtr textField, uint oldPosition)
{
if (Disposed || IsDisposeQueued)
{
// Ignore native callback if the view is disposed or queued for disposal.
return;
}

// no data to be sent to the user, as in NUI there is no event provide old values.
textFieldCursorPositionChangedEventHandler?.Invoke(this, EventArgs.Empty);
}

private void OnMaxLengthReached(IntPtr textField)
{
if (Disposed || IsDisposeQueued)
{
// Ignore native callback if the view is disposed or queued for disposal.
return;
}

if (textFieldMaxLengthReachedEventHandler != null)
{
MaxLengthReachedEventArgs e = new MaxLengthReachedEventArgs();
Expand All @@ -394,6 +424,12 @@ private void OnMaxLengthReached(IntPtr textField)

private void OnAnchorClicked(IntPtr textField, IntPtr href, uint hrefLength)
{
if (Disposed || IsDisposeQueued)
{
// Ignore native callback if the view is disposed or queued for disposal.
return;
}

// Note: hrefLength is useful for get the length of a const char* (href) in dali-toolkit.
// But NUI can get the length of string (href), so hrefLength is not necessary in NUI.
AnchorClickedEventArgs e = new AnchorClickedEventArgs();
Expand All @@ -406,12 +442,24 @@ private void OnAnchorClicked(IntPtr textField, IntPtr href, uint hrefLength)

private void OnSelectionChanged(IntPtr textField, uint oldStart, uint oldEnd)
{
if (Disposed || IsDisposeQueued)
{
// Ignore native callback if the view is disposed or queued for disposal.
return;
}

// no data to be sent to the user, as in NUI there is no event provide old values.
textFieldSelectionChangedEventHandler?.Invoke(this, EventArgs.Empty);
}

private void OnInputFiltered(IntPtr textField, InputFilterType type)
{
if (Disposed || IsDisposeQueued)
{
// Ignore native callback if the view is disposed or queued for disposal.
return;
}

InputFilteredEventArgs e = new InputFilteredEventArgs();

// Populate all members of "e" (InputFilteredEventArgs) with real data
Expand Down
30 changes: 30 additions & 0 deletions src/Tizen.NUI/src/public/BaseComponents/TextLabelEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ public event EventHandler<AsyncTextSizeComputedEventArgs> AsyncHeightForWidthCom

private void OnAsyncHeightForWidthComputed(IntPtr textLabel, float width, float height)
{
if (Disposed || IsDisposeQueued)
{
// Ignore native callback if the view is disposed or queued for disposal.
return;
}

AsyncTextSizeComputedEventArgs e = new AsyncTextSizeComputedEventArgs(width, height);

if (textLabelAsyncHeightForWidthComputedEventHandler != null)
Expand Down Expand Up @@ -128,6 +134,12 @@ public event EventHandler<AsyncTextSizeComputedEventArgs> AsyncNaturalSizeComput

private void OnAsyncNaturalSizeComputed(IntPtr textLabel, float width, float height)
{
if (Disposed || IsDisposeQueued)
{
// Ignore native callback if the view is disposed or queued for disposal.
return;
}

AsyncTextSizeComputedEventArgs e = new AsyncTextSizeComputedEventArgs(width, height);

if (textLabelAsyncNaturalSizeComputedEventHandler != null)
Expand Down Expand Up @@ -166,6 +178,12 @@ public event EventHandler<AsyncTextRenderedEventArgs> AsyncTextRendered

private void OnAsyncTextRendered(IntPtr textLabel, float width, float height)
{
if (Disposed || IsDisposeQueued)
{
// Ignore native callback if the view is disposed or queued for disposal.
return;
}

AsyncTextRenderedEventArgs e = new AsyncTextRenderedEventArgs(width, height);

if (textLabelAsyncTextRenderedEventHandler != null)
Expand Down Expand Up @@ -208,6 +226,12 @@ internal TextLabelSignal AnchorClickedSignal()

private void OnAnchorClicked(IntPtr textLabel, IntPtr href, uint hrefLength)
{
if (Disposed || IsDisposeQueued)
{
// Ignore native callback if the view is disposed or queued for disposal.
return;
}

// Note: hrefLength is useful for get the length of a const char* (href) in dali-toolkit.
// But NUI can get the length of string (href), so hrefLength is not necessary in NUI.
AnchorClickedEventArgs e = new AnchorClickedEventArgs();
Expand Down Expand Up @@ -253,6 +277,12 @@ internal TextLabelSignal TextFitChangedSignal()

private void OnTextFitChanged(IntPtr textLabel)
{
if (Disposed || IsDisposeQueued)
{
// Ignore native callback if the view is disposed or queued for disposal.
return;
}

// no data to be sent to the user, as in NUI there is no event provide old values.
textLabelTextFitChangedEventHandler?.Invoke(this, EventArgs.Empty);
}
Expand Down
Loading
Loading