Skip to content

Commit

Permalink
Block native callback if view is disposed or disposing
Browse files Browse the repository at this point in the history
Signed-off-by: Eunki, Hong <[email protected]>
  • Loading branch information
Eunki, Hong authored and jmmhappy committed Nov 20, 2024
1 parent a594a1f commit 401f7bb
Show file tree
Hide file tree
Showing 5 changed files with 246 additions and 0 deletions.
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

0 comments on commit 401f7bb

Please sign in to comment.