Skip to content

Commit

Permalink
Update control itself when isolated (#31)
Browse files Browse the repository at this point in the history
Re-implement control.build()
  • Loading branch information
FeodorFitsner authored Jun 17, 2022
1 parent 90ddef6 commit 3eed963
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
15 changes: 12 additions & 3 deletions sdk/python/flet/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ def __init__(
def _is_isolated(self):
return False

def _build(self):
pass

def did_mount(self):
pass

Expand Down Expand Up @@ -270,13 +273,16 @@ def clean(self):
self._remove_control_recursively(self.__page.index, child)
return self.__page._send_command("clean", [self.uid])

def build_update_commands(self, index, added_controls, commands):
def build_update_commands(self, index, added_controls, commands, isolated=False):
update_cmd = self._get_cmd_attrs(update=True)

if len(update_cmd.attrs) > 0:
update_cmd.name = "set"
commands.append(update_cmd)

if isolated:
return

# go through children
previous_children = self.__previous_children
current_children = self._get_children()
Expand Down Expand Up @@ -312,8 +318,9 @@ def build_update_commands(self, index, added_controls, commands):
# unchanged control
for h in previous_ints[a1:a2]:
ctrl = hashes[h]
if not ctrl._is_isolated():
ctrl.build_update_commands(index, added_controls, commands)
ctrl.build_update_commands(
index, added_controls, commands, isolated=ctrl._is_isolated()
)
n += 1
elif tag == "replace":
ids = []
Expand All @@ -326,6 +333,7 @@ def build_update_commands(self, index, added_controls, commands):
for h in current_ints[b1:b2]:
# add
ctrl = hashes[h]
ctrl._build()
innerCmds = ctrl.get_cmd_str(
index=index, added_controls=added_controls
)
Expand All @@ -343,6 +351,7 @@ def build_update_commands(self, index, added_controls, commands):
# add
for h in current_ints[b1:b2]:
ctrl = hashes[h]
ctrl._build()
innerCmds = ctrl.get_cmd_str(
index=index, added_controls=added_controls
)
Expand Down
9 changes: 4 additions & 5 deletions sdk/python/flet/user_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@


class UserControl(Stack):
def __init__(self):
super().__init__()
def build(self):
pass

def _build(self):
content = self.build()
if isinstance(content, Control):
self.controls = [content]
Expand All @@ -19,8 +21,5 @@ def __init__(self):
f"{self.__class__.__name__}.build() method must be implemented and returning either Control or List[Control]."
)

def build(self):
pass

def _is_isolated(self):
return True

0 comments on commit 3eed963

Please sign in to comment.