JoshDSommer / nativescript-ngx-shadow

Angular directive to apply shadows to native elements according to the elevation level guidelines of material design specification
Apache License 2.0
9 stars 6 forks source link

Using shadow on RadListView list items causes errors #6

Closed BasyaLipman closed 5 years ago

BasyaLipman commented 6 years ago

Which platform(s) does your issue occur on?

Please, provide the following version numbers that your issue occurs with:

Please, tell us how to recreate the issue in as much detail as possible.

Describe the steps to reproduce it.

Adding the shadow to the list item, causes the following errors in console: CONSOLE ERROR [native code]: ERROR TypeError: undefined is not an object (evaluating'_v.context.item.alertDate')

Remove this: shadow [elevation]="5" from the code below, and all is well.

Is there any code involved?

<GridLayout *ngIf="!isBusy" rows="*">
    <RadListView class="list-background" [items]="items" pullToRefresh="true" (pullToRefreshInitiated)="onPullToRefreshInitiated($event)"
        loadOnDemandMode="Manual" (loadMoreDataRequested)="onLoadMoreItemsRequested($event)" [itemTemplateSelector]="templateSelector" (itemLoading)="onItemLoading($event)" row="0">

        <ng-template tkTemplateKey="pending" let-item="item">
            <GridLayout class="list-item pending" shadow [elevation]="5" rows="25, auto" columns="5*, 2*">
                <StackLayout class="list-item-heading" row="0" colSpan="2">
                    <Label class="date pull-right" [text]="item.alertDate | date:'mediumDate'" textWrap="true"></Label>                    
                </StackLayout>
                <Label class="alert-desc" [text]="getAlertType(item.alertType) + ': ' + item.message" textWrap="true" row="1" col="0"></Label>
                <Label class="amount" [text]="item.amount | centsToDollars | currency:'USD':'symbol-narrow'" textWrap="true" row="1" col="1"></Label>
            </GridLayout>
        </ng-template>

        ...

    </RadListView>

</GridLayout>

I saw this same error when using the shadow on text fields which were not included in a RadListView as well.

edusperoni commented 6 years ago

This is not an issue with this plugin, but with Nativescript. When you hook a "loaded" event, for some reason, nativescript sends "undefined" or "null" as the item in a ListView (or RadListView). See https://github.com/NativeScript/nativescript-angular/issues/1221 and the last comments in the thread. I haven't had the time to open an issue on https://github.com/telerik/nativescript-ui-feedback, but you can go ahead if you want and I'll add a comment to it.

As a workaround, use *ngIf="item on your shadowed component and add a Layout around it, like so:

<GridLayout *ngIf="!isBusy" rows="*">
    <RadListView class="list-background" [items]="items" pullToRefresh="true" (pullToRefreshInitiated)="onPullToRefreshInitiated($event)"
        loadOnDemandMode="Manual" (loadMoreDataRequested)="onLoadMoreItemsRequested($event)" [itemTemplateSelector]="templateSelector" (itemLoading)="onItemLoading($event)" row="0">

        <ng-template tkTemplateKey="pending" let-item="item">
           <StackLayout>
            <GridLayout *ngIf="item" class="list-item pending" shadow [elevation]="5" rows="25, auto" columns="5*, 2*">
                <StackLayout class="list-item-heading" row="0" colSpan="2">
                    <Label class="date pull-right" [text]="item.alertDate | date:'mediumDate'" textWrap="true"></Label>                    
                </StackLayout>
                <Label class="alert-desc" [text]="getAlertType(item.alertType) + ': ' + item.message" textWrap="true" row="1" col="0"></Label>
                <Label class="amount" [text]="item.amount | centsToDollars | currency:'USD':'symbol-narrow'" textWrap="true" row="1" col="1"></Label>
            </GridLayout>
           </StackLayout>
        </ng-template>

        ...

    </RadListView>

</GridLayout>