Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

m1ga
Copy link
Contributor

@m1ga m1ga commented Jan 29, 2024

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();
  • start the app.
  • open some windows and then press close
  • you should go back to the TabGroup again

Todo:

  • Test it 😄 Draft for now as I only tested it with the small demo above
simplescreenrecorder-2024-01-29_21.14.34.mp4

@m1ga m1ga added the feature label May 23, 2024
@hansemannn
Copy link
Collaborator

@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
Copy link
Contributor Author

m1ga commented Nov 23, 2024

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 😄 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

@m1ga m1ga marked this pull request as ready for review November 23, 2024 15:39
Copy link
Collaborator

@hansemannn hansemannn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few comments to make it less error-prone

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants