Skip to content

Commit

Permalink
Control.parent property (#2906)
Browse files Browse the repository at this point in the history
* initial commit

* remove parent when unmounting

* update parent typing

* set parent when adding/replacing

---------

Co-authored-by: Feodor Fitsner <feodor@appveyor.com>
  • Loading branch information
ndonkoHenri and FeodorFitsner authored Apr 3, 2024
1 parent d21c512 commit 3409085
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions sdk/python/packages/flet-core/src/flet_core/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def __init__(
self.__data: Any = None
self.data = data
self.__event_handlers = {}
self.parent: Optional[Control] = None
if ref:
ref.current = self

Expand Down Expand Up @@ -418,6 +419,7 @@ def build_update_commands(
index=index, added_controls=added_controls
)
assert self.__uid is not None
ctrl.parent = self # set as parent
commands.append(
Command(
indent=0,
Expand Down Expand Up @@ -447,6 +449,7 @@ def build_update_commands(
index=index, added_controls=added_controls
)
assert self.__uid is not None
ctrl.parent = self # set as parent
commands.append(
Command(
indent=0,
Expand Down Expand Up @@ -515,6 +518,7 @@ def _build_add_commands(self, indent=0, index=None, added_controls=None):
indent=indent + 2, index=index, added_controls=added_controls
)
commands.extend(childCmd)
control.parent = self # set as parent

self.__previous_children.clear()
self.__previous_children.extend(children)
Expand Down
1 change: 1 addition & 0 deletions sdk/python/packages/flet-core/src/flet_core/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ def __update_control_ids(self, added_controls, results):
def __handle_mount_unmount(self, added_controls, removed_controls):
for ctrl in removed_controls:
ctrl.will_unmount()
ctrl.parent = None # remove parent reference
ctrl.page = None
for ctrl in added_controls:
ctrl.did_mount()
Expand Down

0 comments on commit 3409085

Please sign in to comment.