mirror of
https://github.com/Rapptz/discord.py.git
synced 2026-09-21 03:27:42 +00:00
Fix nested UI item parent state
This commit is contained in:
@@ -203,6 +203,9 @@ class ActionRow(Item[V]):
|
||||
def _swap_item(self, base: Item, new: DynamicItem, custom_id: str) -> None:
|
||||
child_index = self._children.index(base)
|
||||
self._children[child_index] = new # type: ignore
|
||||
base._detach_view()
|
||||
new._update_view(self.view)
|
||||
new._parent = self
|
||||
|
||||
@property
|
||||
def width(self):
|
||||
@@ -299,6 +302,7 @@ class ActionRow(Item[V]):
|
||||
if self._view:
|
||||
self._view._add_count(-1)
|
||||
self._weight -= item.width
|
||||
item._detach_view()
|
||||
|
||||
return self
|
||||
|
||||
@@ -330,6 +334,8 @@ class ActionRow(Item[V]):
|
||||
"""
|
||||
if self._view:
|
||||
self._view._add_count(-len(self._children))
|
||||
for item in self._children:
|
||||
item._detach_view()
|
||||
self._children.clear()
|
||||
self._weight = 0
|
||||
return self
|
||||
|
||||
@@ -197,6 +197,9 @@ class Container(Item[V]):
|
||||
def _swap_item(self, base: Item, new: DynamicItem, custom_id: str) -> None:
|
||||
child_index = self._children.index(base)
|
||||
self._children[child_index] = new # type: ignore
|
||||
base._detach_view()
|
||||
new._update_view(self.view)
|
||||
new._parent = self
|
||||
|
||||
@property
|
||||
def children(self) -> List[Item[V]]:
|
||||
@@ -336,6 +339,7 @@ class Container(Item[V]):
|
||||
else:
|
||||
if self._view:
|
||||
self._view._add_count(-item._total_count)
|
||||
item._detach_view()
|
||||
return self
|
||||
|
||||
def find_item(self, id: int, /) -> Optional[Item[V]]:
|
||||
@@ -367,5 +371,7 @@ class Container(Item[V]):
|
||||
|
||||
if self._view:
|
||||
self._view._add_count(-len(tuple(self.walk_children())))
|
||||
for item in self._children:
|
||||
item._detach_view()
|
||||
self._children.clear()
|
||||
return self
|
||||
|
||||
@@ -206,6 +206,10 @@ class Item(Generic[V]):
|
||||
def _update_view(self, view) -> None:
|
||||
self._view = view
|
||||
|
||||
def _detach_view(self) -> None:
|
||||
self._update_view(None)
|
||||
self._parent = None
|
||||
|
||||
def copy(self) -> Self:
|
||||
return copy.deepcopy(self)
|
||||
|
||||
|
||||
@@ -212,6 +212,7 @@ class Section(Item[V]):
|
||||
else:
|
||||
if self._view:
|
||||
self._view._add_count(-1)
|
||||
item._detach_view()
|
||||
|
||||
return self
|
||||
|
||||
@@ -244,6 +245,8 @@ class Section(Item[V]):
|
||||
if self._view:
|
||||
self._view._add_count(-len(self._children)) # we don't count the accessory because it is required
|
||||
|
||||
for item in self._children:
|
||||
item._detach_view()
|
||||
self._children.clear()
|
||||
return self
|
||||
|
||||
|
||||
Reference in New Issue
Block a user