Search code examples
ioslistviewnativescriptangular2-nativescript

Remove ListView item highlight on tap Nativescript Angular iOS


I would like to remove default behaviour on the ListView on iOS - highlight items on tap. I tried with setting the background color. And it didn't work out. I found this issue on github https://github.com/NativeScript/NativeScript/issues/455 however I don't know how to achieve this in Angular nativescript


Solution

  • Set the itemLoading event on the list view like this:

    <ListView [items]="items" (itemLoading)="onItemLoading($event)">
    

    Then in your typescript, define your onItemLoading event like this:

    import { isIOS } from 'tns-core-modules/platform';
    declare var UITableViewCellSelectionStyle;
    // ...
    onItemLoading(args: ItemEventData) {
      if (isIOS) {
        const iosCell = args.ios;
        iosCell.selectionStyle = UITableViewCellSelectionStyle.None;
      }
    }
    

    FYI - I tested this on nativescript-angular version 3.1.0 and tns-core-modules version 3.3