Mobile App - Changing behaviour of 'Back' button

Mobile App - Changing behaviour of 'Back' button

by Conn Warwicker -
Number of replies: 0
Picture of Core developers Picture of Plugin developers

Hi,


I am currently working on a request for a client's mobile moodle app.


At the bottom of each course they have an 'FAQ' link to a Page module somewhere else on the site, with some key FAQ information.


When a user clicks this, they are taken to said Page module. However, when they then click Back, instead of returning to the course they came from, they are taken to the site home. I noticed that when clicking the FAQ link, the page briefly changes to Site Home, before loading the Page module.


Client wants this to be changed so that when clicking back from the Page module, users are returned to the course they clicked it from, instead of Site Home.


I am totally new to all mobile development and have never looked at the moodle app before, so I am currently trying to work out how this all works...



When clicking the link to the module, these seems to go through:


- /src/core/contentlinks/classes/module-index-handler.ts 


The getActions() method is called, passing in the 'url' of the module to go to. Though the 'courseId' argument is undefined here.


This then calls: 'this.courseHelper.navigateToModule()''


Which leads to:


- /src/core/course/providers/helper.ts


Which eventually ends up going into this if statement:


if (courseId == site.getSiteHomeId()) {

        // Check if site home is available.

        return this.siteHomeProvider.isAvailable().then(() => {

            this.loginHelper.redirect('CoreSiteHomeIndexPage', params, siteId);

        });

    } 


Both of those 'courseId' and 'site.getSiteHomeId()' return 'undefined' in the debugging window, I am not sure if that is expected or not, but that's why it goes into that statement.


So then it calls: 'this.loginHelper.redirect()''


- /src/core/login/providers/helper.ts


Which in turn ends up calling: 'this.loadPageInMainMenu(page, params);'


Where the page parameter is: 'CoreSiteHomeIndexPage'

And the params parameter contains the 'url' of the module to go to.



So it seems like it is just default behaviour to first load the site home, then load whatever module page is being asked for. I would assume that is why when you press back, it goes back to the Site Home.



So first question, is there a way to override that behaviour so that it skips the loading of Site Home first? Will that have any negative effects on anything?


If not, if I were to pass through in the params object somewhere the URL of the original course, could the behaviour on the Back button itself be changed to return to that URL instead? If so, any ideas whereabouts would I need to put that?



Thanks.

Average of ratings: -