tidev / titanium-sdk

🚀 Native iOS and Android Apps with JavaScript
https://titaniumsdk.com/
Other
2.76k stars 1.21k forks source link

feat(android): parity for Tab.popToRootWindow() #13976

Open m1ga opened 10 months ago

m1ga commented 10 months ago

An iOS TabGroup opens Windows inside of it and you can use Tab.popToRootWindow() to close all those tabs. Since Android is opening new windows we don't have that stack and can close them.

The idea is to emulate that behavior by looking at the first activity and check if it is a TabGroup. If so loop through all activity above it and close them. Works with style: Titanium.UI.Android.TABS_STYLE_BOTTOM_NAVIGATION too.

Test:

var win = Ti.UI.createWindow();
var btn = Ti.UI.createButton({
    title: "open"
})
win.add(btn);

btn.addEventListener("click", function() {
    createWindow();
})

function createWindow() {
    let newWin = Ti.UI.createWindow({});
    newWin.addEventListener("close", function(e){
        console.log("closing window");
    })
    newWin.open();
    let newButton = Ti.UI.createButton({
        title: "close",
        bottom: 0
    })
    let newButton2 = Ti.UI.createButton({
        title: "new"
    })
    newWin.add([newButton, newButton2]);
    newButton.addEventListener("click", function() {
        tab1.popToRootWindow();
    });
    newButton2.addEventListener("click", function() {
        createWindow()
    });
}

var tab1 = Ti.UI.createTab({
        window: win,
        title: 'a'
    }),
    tab2 = Ti.UI.createTab({
        window: Ti.UI.createWindow(),
        title: 'b'
    }),
    tabGroup = Ti.UI.createTabGroup({
        tabs: [tab1, tab2]
    });
tabGroup.open();

Todo:

https://github.com/tidev/titanium-sdk/assets/4334997/1cbb4282-be46-4bc4-ab0d-2808d8320623

hansemannn commented 2 days ago

@m1ga Can you give me an update on a few of your Draft PR's? Many of them are super interesting and I wonder if you just missed to change the state after finishing work on them.

m1ga commented 2 days ago

I just don't use this in any app so I don't have many test data to verify it doesn't have side effects. It's only still a draft as I don't have any infos besides this one demo that it is working :smile: It was requested on Slack from time to time so I've added this but no one tested it.

I'll change it to ready for review so we can get some more people to test it