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

fix(android): touchEnabled for ListView #13951

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

m1ga
Copy link
Contributor

@m1ga m1ga commented Dec 6, 2023

Currently a ListView on Android doesn't reflect the touchEnabled state. If you set it to false it will still fire the itemclick event.

This PR checks touchEnabled before it fires the itemclick event. You can set it for an item, section and the whole listview.

var win = Ti.UI.createWindow();
var listView = Ti.UI.createListView();
var btn = Ti.UI.createButton({bottom:0, title:"disable all"});
var sections = [];

var fruitDataSet = [
    {properties: { title: 'Apple (no touch)', touchEnabled:false}},
    {properties: { title: 'Banana'}},
];
var fruitSection = Ti.UI.createListSection({ headerTitle: 'Fruits', items: fruitDataSet});
sections.push(fruitSection);

var vegDataSet = [
    {properties: { title: 'Carrots'}},
    {properties: { title: 'Potatoes (no touch)', touchEnabled:false}},
];
var vegSection = Ti.UI.createListSection({ headerTitle: 'Vegetables (no touch)', items: vegDataSet, touchEnabled: false});
sections.push(vegSection);

listView.sections = sections;
win.add([listView, btn]);
win.open();

var fishDataSet = [
    {properties: { title: 'Cod'}},
    {properties: { title: 'Haddock'}},
];
var fishSection = Ti.UI.createListSection({ headerTitle: 'Fish', items: fishDataSet});
listView.appendSection(fishSection);
listView.addEventListener("itemclick", function(){
  console.log("click")
})

var isEnabled = true;
btn.addEventListener("click", function(){
  if (isEnabled) {
    listView.touchEnabled = false;
    btn.title = "enable"
  } else {
    listView.touchEnabled = true;
    btn.title = "disable all"
  }
  isEnabled = !isEnabled;
})

Test:

  • run the app above.
  • 12.2.1.GA will show "click" for all items, even after clicking the bottom button
  • with this PR it won't show a click event for the items with no touch, for the whole no touch section and when you click the button it won't show it for all items

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.

1 participant