question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Change detection issue in ListView

See original GitHub issue

Conditional styling in ListView templates don’t get consistently applied. Most times they require the item to go off screen and back in, in order for the new status to be reflected.

Gif repro

Here is a sample to reproduce:

Component:

import {Component} from "@angular/core";
@Component({
    selector: "my-app",
    templateUrl: "app.component.html",
})
export class AppComponent {
    public options: string[] = ["Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", "District of Columbia", "Florida", "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey", "New Mexico", "New York", "North Carolina", "North Dakota", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", "Vermont", "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming"];

    public selectedOption: string = "";

    public onItemTap(args) {
        this.selectedOption = this.options[args.index];
    }
}

Markup:

<StackLayout>
<ListView #listview [items]="options" separatorColor="white" (itemTap)="onItemTap($event)">
    <template let-item="item" let-i="index" let-odd="odd" let-even="even">
        <GridLayout columns="44, *" height="48">
            <StackLayout colSpan="2" verticalAlignment="bottom" class="line"></StackLayout>      
            <Label col="1" [text]="item" style="font-size:20" [class.active]="selectedOption == item"></Label>
        </GridLayout>
    </template>
</ListView>
</StackLayout>

CSS

.active {
    color:red;
}

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:6
  • Comments:31 (4 by maintainers)

github_iconTop GitHub Comments

7reactions
erkanarslancommented, Dec 22, 2017

This happens only on iOS, works correctly on Android.

7reactions
eduardoturconicommented, Jan 26, 2017

After trying some modifications to my code, I could solve this issue by doing:

...
this.items[i].is_list = true;
this.items = this.items.slice();

That way, when reassigning to this.items it’s own array, the UI got updated.

Read more comments on GitHub >

github_iconTop Results From Across the Web

android - How to detect change in listview from mainactivity
I noticed that it is possible to add an observer using registerDataSetObserver() that will be notified when notifyDataSetChanged() is called.
Read more >
List View - NativeScript Docs
NativeScript for Angular Documentation - Using ListView. ... counts on Angular's change detection mechanism for notification that something has changed.
Read more >
ListView - .NET MAUI | Microsoft Learn
ListView defines an ItemSelected event that's raised when the SelectedItem property changes, either due to the user selecting an item from the ...
Read more >
List View | Mendix Documentation
With this property you can change the number of items that will be shown next to each other in one row. If you...
Read more >
Help to detect any change in row selection for listview
Ok so I have used GUIEvent to detect double clicks, but row selection may change using cursor keys etc. I simply want to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found