Getting notification on NavigationView go back?
ccc last edited by
Can my app get Alerted when the user clicks
backin a NavView?
dgelessus last edited by
I haven't tested this, but perhaps you could check when the topmost view goes off screen (using the
on_screenproperty or the
wait_modalmethod). This would of course require some custom code when pushing each view onto the navigation view.
There's probably a better way to do this with
objc_utiland the native UIKit APIs, but I know almost nothing about UIKit.
enceladus last edited by
May be you can implement your own navigation view which may not be difficult. Here is an example implementation. The program simple_navigation_view.py builds a navigation view from a sequence of pyui files. The program custom_simple_navigation_view builds the same directly. Note that the second program does not have much additional code and you can customize the pop to your need.
ccc last edited by ccc
@omz Would it be possible for you to add a callback mechanism so that the root_view of a ui.NavigationView() receives a
go_back()method call when the user clicks on back (
<in the upper left of the nav view)?
ui.View.go_back() could operate like ui.View.layout() -- if the method is present then it gets called at the appropriate time.
import ui about = '''Press "Tap me" and then back ("<" in the upper left) numerous times. Desired behavior: Colors remain constant (white, red, white, red) Actual behavior: Colors cycle forward (white, red, white, green)''' colors = 'white red green blue grey'.split() class ColorView(ui.View): def __init__(self): self.index = 0 self.name = 'white' self.add_subview(self.make_button()) frame = (0, -220, *(ui.get_screen_size())) self.add_subview(ui.Label(text=about, frame=frame, number_of_lines=0)) def button_tapped(self, sender): sender.navigation_view.push_view(self.make_button()) def go_back(self): # this NEVER gets called :-( self.index -= 1 def layout(self): self.subviews.frame = self.bounds def make_button(self): color = colors[self.index % len(colors)] self.index += 1 return ui.Button(title='Tap me', action=self.button_tapped, bg_color=color, name=color) def will_close(self): # this NEVER gets called :-( self.index -= 1 ui.NavigationView(ColorView()).present()
ccc last edited by ccc
Thanks @dgelessus Your
view.on_screenchecking idea worked well at https://github.com/cclauss/f1_hack/blob/master/discover_view.py#L24. This is a ui for walking the hierarchy of any json data. It would still be much easier if views displayed in ui.NavigationViews received a
go_back()callback when the user presses
omz last edited by
@ccc I'll think about it.