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): fire selected event again when clicking the same Tab again #14094

Merged
merged 6 commits into from
Aug 21, 2024

Conversation

m1ga
Copy link
Contributor

@m1ga m1ga commented Aug 8, 2024

If you reclick a tab it won't fire the event again. This PR will fire the selected event again if you click the tab again

Can be used to reset/reload content in the tab if you click it again.

const tab1 = Ti.UI.createTab({
	window: Ti.UI.createWindow(),
	title: 'Tab 1'
});
const tab2 = Ti.UI.createTab({
	window: Ti.UI.createWindow(),
	title: 'Tab 2'
});

tab1.addEventListener("selected", function(opts) {
	console.log("selected", opts.index)
})
tab2.addEventListener("selected", function(opts) {
	console.log("selected", opts.index)
})

const tabGroup = Ti.UI.createTabGroup({
	tabs: [tab1, tab2]
});

tabGroup.open();

I didn't check yes how iOS selected behaves. Is that a one time event when you reclick the same tab?

@m1ga m1ga changed the title feat(android): new 'reselected' event on a Tab feat(android): new reselected event on a Tab Aug 8, 2024
@cb1kenobi
Copy link
Contributor

This new event feels like bloat. I would think a "click" event with a current tab that you can check would suffice.

@m1ga
Copy link
Contributor Author

m1ga commented Aug 9, 2024

This would work too (I would reuse the selected event that is there) but then apps that currently use that event will get multiple events now. Even if I add a parameter reselected: true in the KrollDict the user has to use that in an existing app.

That was my only concern to move it to a different event. I'm more than happy with having only the selected. In my case I wanted to reset a filter when clicking on the tab again and was surprised that the event didn't fire again

@cb1kenobi
Copy link
Contributor

Still not sure on this one. Feels unnessary. I don't get why we have a "selected" and "unselected" events either. On the web, we would have "click" and "change". It feels like there's too many events.

@hansemannn
Copy link
Collaborator

I kind of agree, although the code itself is fine. What was the reason for adding this new API? Was someone unable to achieve this behavior with the current events?

@m1ga
Copy link
Contributor Author

m1ga commented Aug 20, 2024

What was the reason for adding this new API? Was someone unable to achieve this behavior with the current events?

yes, I wanted to reset the data to the original state in my tab when I click the icon again and the was no event. We only have events when we change tabs. Clicking on the same doesn't trigger the selected again (which I thought it would).

My only concern was that it is a behavior change for existing apps if I just use selected again, that's why I've added a new event. If we are fine with just triggering selected again I would go with that and remove the reselected

Edit: I don't know if iOS triggers selected again if you click the same tab twice. Didn't test it

@cb1kenobi
Copy link
Contributor

I would be fine with firing selected when a tab is selected twice.

I would have to see how the UX is, but I could see how fat fingering a tab and reseting the state may be a bad UX pattern. I would think a "reset" button would be best, but I understand each app is different.

@m1ga
Copy link
Contributor Author

m1ga commented Aug 20, 2024

e.g. in Slack, Whatsapp or Instagram it will scroll up to the first item if you click the Tab icon again which is a very handy use case.
Maybe I could add a property to selected so the user knows if it is a first click or if you reselected it. On the other hand you can do that already by tracking the current selected index if you'll need that and compare it in the event

@m1ga
Copy link
Contributor Author

m1ga commented Aug 20, 2024

updated the example and code so it will just simply fire the selected event again 👍

@m1ga m1ga changed the title feat(android): new reselected event on a Tab feat(android): fire selected event again when clicking the same Tab again Aug 20, 2024
@hansemannn hansemannn merged commit dfb1b5c into master Aug 21, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants