working on cleaner navigation

This commit is contained in:
Dante Ruiz 2017-05-01 21:23:38 +01:00
parent 9f33af479d
commit c205bf0980

View file

@ -23,6 +23,7 @@ Item {
property bool keyboardRaised: false property bool keyboardRaised: false
property bool punctuationMode: false property bool punctuationMode: false
property bool isDesktop: false property bool isDesktop: false
property string initialPage: ""
property bool startingUp: true property bool startingUp: true
property bool removingPage: false property bool removingPage: false
property alias webView: webview property alias webView: webview
@ -32,6 +33,7 @@ Item {
property bool loadingStarted: false property bool loadingStarted: false
property bool loadingFinished: false property bool loadingFinished: false
property var urlList: [] property var urlList: []
property var forwardList: []
property int currentPage: -1 // used as a model for repeater property int currentPage: -1 // used as a model for repeater
@ -103,15 +105,15 @@ Item {
} }
function goBack() { function goBack() {
if (webview.canGoBack && !isUrlLoaded(webview.url)) { if (webview.canGoBack) {
if (currentPage > 0) { forwardList.push(webview.url);
removingPage = true;
pagesModel.remove(currentPage);
}
webview.goBack(); webview.goBack();
} else if (currentPage > 0) { } else if (web.urlList.length > 0) {
removingPage = true; removingPage = true;
pagesModel.remove(currentPage); var url = web.urlList.pop();
loadUrl(url);
} else if (fowardList.length == 1) {
console.log("--------------> going foward <---------------");
} }
} }
@ -147,53 +149,43 @@ Item {
view.setActiveFocusOnPress(true); view.setActiveFocusOnPress(true);
view.setEnabled(true); view.setEnabled(true);
} }
function shouldLoadUrl(url) { function loadUrl(url) {
switch (url) { webview.url = url
case "https://twitter.com/intent/sessions": web.url = webview.url;
return true; web.address = webview.url;
}
return false;
} }
function onInitialPage(url) {
return (url === webview.url);
}
function urlAppend(url) { function urlAppend(url) {
console.log(url);
if (removingPage || shouldLoadUrl(url)) {
removingPage = false;
return;
}
var lurl = decodeURIComponent(url) var lurl = decodeURIComponent(url)
if (lurl[lurl.length - 1] !== "/") { if (lurl[lurl.length - 1] !== "/") {
lurl = lurl + "/" lurl = lurl + "/"
} }
console.log("-------> trying to append url <------------"); web.urlList.push(url);
console.log(currentPage); setBackButtonStatus();
console.log(pagesModel.get(currentPage).webUrl !== lurl);
if (currentPage === -1 || (pagesModel.get(currentPage).webUrl !== lurl)) {
timer.start();
console.log("---------> appending url <-------------");
pagesModel.append({webUrl: lurl});
};
} }
onCurrentPageChanged: { function setBackButtonStatus() {
if (currentPage >= 0 && currentPage < pagesModel.count && removingPage) { if (web.urlList.length > 0 || webview.canGoBack) {
timer.start(); back.enabledColor = hifi.colors.darkGray;
webview.url = pagesModel.get(currentPage).webUrl; back.enabled = true;
web.url = webview.url; } else {
web.address = webview.url; back.enabledColor = hifi.colors.baseGray;
removingPage = false; back.enabled = false;
} else if (startingUp) {
webview.url = pagesModel.get(currentPage).webUrl;
web.url = webview.url;
web.address = webview.url;
startingUp = false;
} }
} }
onUrlChanged: { onUrlChanged: {
gotoPage(url) loadUrl(url);
if (startingUp) {
web.initialPage = webview.url;
startingUp = false;
}
} }
QtObject { QtObject {
@ -201,18 +193,7 @@ Item {
WebChannel.id: "eventBridgeWrapper" WebChannel.id: "eventBridgeWrapper"
property var eventBridge; property var eventBridge;
} }
Timer {
id: timer
interval: 200
running: false
repeat: false
onTriggered: timer.stop();
}
WebEngineView { WebEngineView {
id: webview id: webview
objectName: "webEngineView" objectName: "webEngineView"
@ -280,9 +261,6 @@ Item {
// Required to support clicking on "hifi://" links // Required to support clicking on "hifi://" links
if (WebEngineView.LoadStartedStatus == loadRequest.status) { if (WebEngineView.LoadStartedStatus == loadRequest.status) {
var url = loadRequest.url.toString(); var url = loadRequest.url.toString();
web.urlList.push(url);
//urlAppend(url);
web.loadingStarted = true;
if (urlHandler.canHandleUrl(url)) { if (urlHandler.canHandleUrl(url)) {
if (urlHandler.handleUrl(url)) { if (urlHandler.handleUrl(url)) {
root.stop(); root.stop();
@ -295,19 +273,16 @@ Item {
} }
if (WebEngineView.LoadSucceededStatus == loadRequest.status) { if (WebEngineView.LoadSucceededStatus == loadRequest.status) {
console.log web.address = webview.url;
urlList = []; if (startingUp) {
web.initialPage = webview.url;
startingUp = false;
}
} }
} }
onWindowCloseRequested: {
console.log("---------->requested to closeWindow <--------------");
}
onNewViewRequested: { onNewViewRequested: {
console.log("-----------> newViewRequested <--------------");
var currentUrl = webview.url; var currentUrl = webview.url;
console.log(currentUrl);
urlAppend(currentUrl); urlAppend(currentUrl);
request.openIn(webview); request.openIn(webview);
} }