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

Fix "Child already has a owner" Assert #242

Merged
merged 5 commits into from
Jan 11, 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
16 changes: 10 additions & 6 deletions Sources/Swift/FlexLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,12 @@ public final class Flex {
//

/**
This method adds a flex item (UIView) to a flex container. Internally the methods adds the UIView has subviews and enables flexbox.
Adds a flex item (`UIView`) to the receiver and returns the item's flex interface.

This method internally creates a new `UIView` instance corresponding to the flex item,
and is useful for adding a flex item/container when you don't need to refer to it later.

- Returns: The added view flex interface
- Returns: The flex interface corresponding to the added view.
*/
@discardableResult
public func addItem() -> Flex {
Expand All @@ -69,11 +72,12 @@ public final class Flex {
}

/**
This method is similar to `addItem(: UIView)` except that it also creates the flex item's UIView. Internally the method creates an
UIView, adds it has subviews and enables flexbox. This is useful to add a flex item/container easily when you don't need to refer to it later.
Adds a flex item (`UIView`) to the receiver and returns the item's flex interface.

This method enables flexbox for `view` and adds it as a subview of the receiver's associated host view.

- Parameter view: view to add to the flex container
- Returns: The added view flex interface
- Parameter view: The view to be added.
- Returns: The flex interface corresponding to the added view.
*/
@discardableResult
public func addItem(_ view: UIView) -> Flex {
Expand Down
7 changes: 6 additions & 1 deletion Sources/YogaKit/YGLayout.mm
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,12 @@ static void YGAttachNodesFromViewHierachy(UIView* const view) {
if (!YGNodeHasExactSameChildren(node, subviewsToInclude)) {
YGRemoveAllChildren(node);
for (int i = 0; i < subviewsToInclude.count; i++) {
YGNodeInsertChild(node, subviewsToInclude[i].yoga.node, i);
YGNodeRef child = subviewsToInclude[i].yoga.node;
YGNodeRef parent = YGNodeGetParent(child);
if (parent != NULL) {
YGNodeRemoveChild(parent, child);
}
YGNodeInsertChild(node, child, i);
}
}

Expand Down
Loading