NativeScript / plugins

@nativescript plugins to help with your developments.
https://docs.nativescript.org/plugins/index.html
Apache License 2.0
190 stars 107 forks source link

isListLikeIterable not found in @angular/core 15.2.2 #463

Closed jwrascoe closed 1 year ago

jwrascoe commented 1 year ago

Is it possible to adjust nativescript-ui-listview 14.2.4 to work with the latest version of @angular/core ?

NS fails to build with the following error if the list view package is use.

ERROR in ../../node_modules/nativescript-ui-listview/angular/fesm2015/nativescript-ui-listview-angular.mjs 181:24-43 export 'isListLikeIterable' (imported as 'isListLikeIterable') was not found in '@angular/core'

gabrielbiga commented 1 year ago

The method has been removed from the Angular head (https://github.com/angular/angular/pull/49297).

This patch seems to fix the problem palliatively:

diff --git a/node_modules/nativescript-ui-listview/angular/fesm2015/nativescript-ui-listview-angular.mjs b/node_modules/nativescript-ui-listview/angular/fesm2015/nativescript-ui-listview-angular.mjs
index 2a29a7e..0677c25 100644
--- a/node_modules/nativescript-ui-listview/angular/fesm2015/nativescript-ui-listview-angular.mjs
+++ b/node_modules/nativescript-ui-listview/angular/fesm2015/nativescript-ui-listview-angular.mjs
@@ -1,9 +1,20 @@
-import { ObservableArray, isIOS, LayoutBase } from '@nativescript/core';
 import * as i0 from '@angular/core';
-import { ElementRef, EventEmitter, ɵisListLikeIterable, IterableDiffers, NgZone, TemplateRef, ViewContainerRef, Component, ChangeDetectionStrategy, Inject, ViewChild, ContentChild, Output, Input, HostListener, Directive, Host, NgModule, NO_ERRORS_SCHEMA } from '@angular/core';
+import { ChangeDetectionStrategy, Component, ContentChild, Directive, ElementRef, EventEmitter, Host, HostListener, Inject, Input, IterableDiffers, NgModule, NgZone, NO_ERRORS_SCHEMA, Output, TemplateRef, ViewChild, ViewContainerRef } from '@angular/core';
 import * as i1 from '@nativescript/angular';
-import { DetachedLoader, NativeScriptRendererFactory, extractSingleViewRecursive, registerElement } from '@nativescript/angular';
-import { ListViewLinearLayout, ListViewViewType, NG_VIEW, RadListView, ListViewGridLayout, ListViewStaggeredLayout, ReorderHandle } from 'nativescript-ui-listview';
+import { DetachedLoader, extractSingleViewRecursive, NativeScriptRendererFactory, registerElement } from '@nativescript/angular';
+import { isIOS, LayoutBase, ObservableArray } from '@nativescript/core';
+import { ListViewGridLayout, ListViewLinearLayout, ListViewStaggeredLayout, ListViewViewType, NG_VIEW, RadListView, ReorderHandle } from 'nativescript-ui-listview';
+
+export function isJsObject(o) {
+    return o !== null && (typeof o === 'function' || typeof o === 'object');
+}
+
+export function isListLikeIterable(obj) {
+    if (!isJsObject(obj)) return false;
+    return Array.isArray(obj) ||
+        (!(obj instanceof Map) &&
+         Symbol.iterator in obj);
+}

 class ListItemContext extends ElementRef {
     constructor($implicit, item, index, even, odd, category) {
@@ -180,7 +191,7 @@ class RadListViewComponent {
             needDiffer = false;
         }
         if (!this._differ) {
-            if (needDiffer && ɵisListLikeIterable(value)) {
+            if (needDiffer && isListLikeIterable(value)) {
                 this._differ = this._iterableDiffers.find(this._items).create(this.trackBy || ((index, item) => item));
             }
             this._listView.items = this._items;
NathanWalker commented 1 year ago

We’re going to publish a 15.2.0 for ui-listview to meet their breaking change there by this evening.

jwrascoe commented 1 year ago

@NathanWalker @gabrielbiga Case closed, thanks for the fix. I tested the v15.2.0, works as advertised.

NathanWalker commented 1 year ago

Thanks for confirming @jwrascoe - for others coming across this, there's two options we would suggest:

  1. Use nativescript-ui-listview:^15.2.0
  2. Swap it out with @nstudio/ui-collectionview (this is more modern control and recommended these days - we began moving to this control last year and CollectionView is the likely successor to RadListView - I will be sharing a blog series on gaining all same rich features and more with it that you could do with RLV)
SeanKelly369 commented 1 year ago

With ui-collectionview, I ran into this problem when running on Angular 13.3.0.