Skip to content

Instantly share code, notes, and snippets.

@mattpodwysocki
Created October 19, 2016 21:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattpodwysocki/ac8f05969f905327747b47285f911e6e to your computer and use it in GitHub Desktop.
Save mattpodwysocki/ac8f05969f905327747b47285f911e6e to your computer and use it in GitHub Desktop.
/// <summary>
/// Insert a child at the given index.
/// </summary>
/// <param name="child">The child.</param>
/// <param name="index">The index.</param>
public void AddChildAt(CSSNode child, int index)
{
Insert(index, child);
MarkUpdated();
var node = (ReactShadowNode)child;
if (!IsLeafNode)
{
var increase = node.IsLayoutOnly ? node._totalNativeChildren : 1;
_totalNativeChildren += increase;
UpdateNativeChildrenCountInParent(increase);
}
}
/// <summary>
/// Removes the child at the given index.
/// </summary>
/// <param name="index">The index.</param>
public ReactShadowNode RemoveChildAt(int index)
{
var removed = RemoveAndReturnChildAt(index);
MarkUpdated();
if (!IsLeafNode)
{
var decrease = removed.IsLayoutOnly ? removed._totalNativeChildren : 1;
_totalNativeChildren -= decrease;
UpdateNativeChildrenCountInParent(decrease * -1);
}
return removed;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment