Guys, I'm trying to code my navigation bar so that it has a back/forward function. I did what's below but It's not working. Can anybody help me?
#Event on View (Script onStartup)
def runAction(self):
Petrobras.navigation.update_history(self)
# 'next', 'previous', 'up', 'down', 'back', 'forward'
def runAction(self, event):
system.perspective.sendMessage('mainNavigation', {'command': 'previous'})
#Code inside my views
def onMessageReceived(self, payload):
Petrobras.navigation.default_navigation(self.view, payload)
#Global Script
def default_navigation(view, payload):
# Get the custom property from the message
index = view.session.custom.navigation.index
history = view.session.custom.navigation.history
system.perspective.print(index)
system.perspective.print(history)
command = payload.get('command')
# Check if the custom property is not None and not blank
if command is not None and command.strip():
# Perform a "Switch-case" and navigate to the corresponding URL for one of the variables
if command in ['next', 'previous', 'up', 'down']:
system.perspective.navigate(view=view.custom.navigation[command])
elif command == 'forward':
system.perspective.print("Forward function")
index += 1
next_page = view.session.custom.navigation.history[index]
system.perspective.navigate(view=next_page)
session.custom.navigation.index = index
elif command == 'back':
if index == 0:
index = 9
previous_page = view.session.custom.navigation.history[index]
system.perspective.navigate(view=previous_page)
session.custom.navigation.index = index
else:
index -= 1
previous_page = view.session.custom.navigation.history[index]
system.perspective.navigate(view=previous_page)
session.custom.navigation.index = index
def update_history(view_current):
history = view_current.session.custom.navigation.history
index = view_current.session.custom.navigation.index
if len(history) == 0:
index = 0
history.append(view_current.page.props.primaryView)
index += 1
else:
history.append(view_current.page.props.primaryView)
index += 1
history = history[-10:]
index = len(history) - 1
view_current.session.custom.navigation.history = history
view_current.session.custom.navigation.index = index