0

I'm having trouble initializing a RadListView from data that works with a regular ListView. i have an observable array that should output items in the listview, and when using regular old ListView, it works fine. Id like to take advantage of the out of the box swiping functions in RadListView, but Im getting a verbose error just trying to initialize with the same data I was using in regular ListView.

// THIS DOES NOT WORK.                
<lv:RadListView items="{{ addedParents }}" >

    <lv:RadListView.listViewLayout>
        <lv:ListViewLinearLayout scrollDirection="Vertical"/>
    </lv:RadListView.listViewLayout>
    <lv:RadListView.itemTemplate>
        <StackLayout orientation="vertical">
            <Label fontSize="20" text="{{ first_name }}"/>

            <Label fontSize="14" text="{{ email }}"/>

        </StackLayout>
    </lv:RadListView.itemTemplate>
</lv:RadListView>   




// THIS WORKS.
<ListView items="{{ addedParents }}" id="added_parents">
    <ListView.itemTemplate>
        <GridLayout columns="*, auto" rows="*, 1">
            <Label text="{{ first_name + ' ' + last_name + ' (' + email + ')'}}"/>
        </GridLayout>
    </ListView.itemTemplate>
</ListView>

The error I get is:

CONSOLE WARN file:///app/tns_modules/nativescript-telerik-ui/listview/listview.js:358:14: The TypeScript constructor "TKListViewDataSourceImpl" will not be executed.
CONSOLE WARN file:///app/tns_modules/nativescript-telerik-ui/listview/listview.js:499:14: The TypeScript constructor "ExtendedListViewCell" will not be executed.
*** Assertion failure in -[TKCollectionView _endItemAnimationsWithInvalidationContext:tentativelyForReordering:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3512.60.7/UICollectionView.m:4625
*** JavaScript call stack:
        (
            0   insertItemsAtIndexPaths@[native code]
            1   onSourceCollectionChanged@file:///app/tns_modules/nativescript-telerik-ui/listview/listview.js:881:45
            2   onSourceCollectionChangedInternal@file:///app/tns_modules/nativescript-telerik-ui/listview/listview-common.js:619:43
            3   handler@file:///app/tns_modules/ui/core/weak-event-listener.js:30:38
            4   notify@file:///app/tns_modules/data/observable/observable.js:155:31
            5   push@file:///app/tns_modules/data/observable-array/observable-array.js:99:20
            6   onShownModally@file:///app/views/modals/manageparents/manageparents.js:42:30
            7   notify@file:///app/tns_modules/data/observable/observable.js:155:31
            8   _raiseShowingModallyEvent@file:///app/tns_modules/ui/page/page-common.js:259:20
            9   _showNativeModalView@file:///app/tns_modules/ui/page/page.js:302:56
            10  showModal@file:///app/tns_modules/ui/page/page-common.js:202:38
            11  manageParents@file:///app/views/parent/kid/kid.js:156:19
            12  notify@file:///app/tns_modules/data/observable/observable.js:155:31
            13  _emit@file:///app/tns_modules/data/observable/observable.js:174:24
            14  tap@file:///app/tns_modules/ui/button/button.js:19:24
            15  UIApplicationMain@[native code]
            16  start@file:///app/tns_modules/application/application.js:233:26
            17  anonymous@file:///app/app.js:3:24
            18  evaluate@[native code]
            19  moduleEvaluation@:1:11
            20  @:8:48
            21  promiseReactionJob@:1:11
        )
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of items in section 0.  The number of items contained in an existing section after the update (1) must be equal to the number of items contained in that section before the update (1), plus or minus the number of items inserted or deleted from that section (1 inserted, 0 deleted) and plus or minus the number of items moved into or out of that section (0 moved in, 0 moved out).'
        *** First throw call stack:
        (
            0   CoreFoundation                      0x03d16494 __exceptionPreprocess + 180
            1   libobjc.A.dylib                     0x037d0e02 objc_exception_throw + 50
            2   CoreFoundation                      0x03d1632a +[NSException raise:format:arguments:] + 138
            3   Foundation                          0x01296322 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 118
            4   UIKit                               0x01fe2a6e -[UICollectionView _endItemAnimationsWithInvalidationContext:tentativelyForReordering:] + 17081
            5   UIKit                               0x01fde7b0 -[UICollectionView _endItemAnimationsWithInvalidationContext:] + 48
            6   UIKit                               0x01fde54c -[UICollectionView _updateRowsAtIndexPaths:updateAction:] + 400
            7   UIKit                               0x01fde5af -[UICollectionView insertItemsAtIndexPaths:] + 48
            8   TelerikUI                           0x036db9fb -[TKCollectionView insertItemsAtIndexPaths:] + 171
            9   TelerikUI                           0x03543bc1 __38-[TKListView insertItemsAtIndexPaths:]_block_invoke + 97
            10  UIKit                               0x017050c9 +[UIView(UIViewAnimationWithBlocks) _setupAnimationWithDuration:delay:view:options:factory:animations:start:animationStateGenerator:completion:] + 608
            11  UIKit                               0x01705679 +[UIView(UIViewAnimationWithBlocks) animateWithDuration:animations:] + 115
            12  TelerikUI                           0x03543aa2 -[TKListView insertItemsAtIndexPaths:] + 386
            13  NativeScript                        0x00c43ee8 ffi_call_i386 + 24
        )
com.apple.CoreSimulator.SimDevice.57D7D435-74D2-4D36-8ECE-D1ABA70AE4CF.launchd_sim[662] (UIKitApplication:com.cubbynotes.pocketnanny[0xdcbf][3806]): Service exited due to signal: Abort trap: 6

UPDATE: So, I was initializing the data in the showingModally handler. Moving the code where I update the array to the loaded handler doesnt crash my app, but the list view does not display. Here is my initialization code:

var addedParents = new ObservableArray();
var parentsArray = [];

var pageData = new Observable({
    addedParents: addedParents,
    kid_id: false,
    loading: false
});

var context;
var closeCallback;
function onShownModally(args) {
    page = args.object;
    parentsArray = args.context.parents;
    pageData.set('kid_id', args.context.id);
    closeCallback = args.closeCallback;
}
exports.onShownModally = onShownModally;

exports.loaded = function(args) {
    page = args.object;
    while (addedParents.length) addedParents.pop();
    if (parentsArray && parentsArray.length) {
        for (var i = 0; parentsArray.length > i; i++) {
            addedParents.push(parentsArray[i]);
        }
    }
    page.bindingContext = pageData;
}

Here is the symptom: screenshot

That is generated by this xml:

<Label text="I am a radlistview" />
<lv:RadListView items="{{ addedParents }}" id="added_parents">

    <lv:RadListView.listViewLayout>
        <lv:ListViewLinearLayout scrollDirection="Vertical"/>
    </lv:RadListView.listViewLayout>
    <lv:RadListView.itemTemplate>
        <StackLayout orientation="vertical">
            <Label fontSize="20" text="{{ first_name }}"/>

            <Label fontSize="14" text="{{ email }}"/>

        </StackLayout>
    </lv:RadListView.itemTemplate>
</lv:RadListView> 

<Label text="I am a regular old list view." />                

<ListView items="{{ addedParents }}" id="added_parents" separatorColor="#ffffff">
    <ListView.itemTemplate>
        <GridLayout columns="*, auto" rows="*, 1">
            <Label text="{{ first_name + ' ' + last_name + ' (' + email + ')'}}"/>
        </GridLayout>
    </ListView.itemTemplate>
</ListView>
Vladimir Amiorkov
  • 2,652
  • 3
  • 17
  • 35
davecoffin
  • 509
  • 1
  • 3
  • 11
  • I have used a dummy data ( https://github.com/NickIliev/NativeScript-issues/tree/master/stack/radList/app ) for items and it seems to work on my side .. i guess you are passing the data via some service and you should re-asure the data is received before the initialization of the list-view. – Nick Iliev Sep 14 '16 at 06:17
  • @davecoffin can you paste the code that is responsible for filling the ObservableArray you are using? – WorldIntruder Sep 14 '16 at 08:43
  • @WorldIntruder I just posted an update and my initialization code. If I am using an observable array why would it need the data before the list view is initialized? shouldnt it "observe" the fact that I added items to the array and display them in the list? Either way, I am setting the binding context after I have added the objects to the observable array. – davecoffin Sep 15 '16 at 13:06
  • 1
    @davecoffin Can you paste the whole Page XML? Are you putting the Label, RadListView and ListVIew instances in a StackLayout? If so, can you try using a Grid? There are several examples of binding RadListView to an ObservableArray here: github.com/telerik/nativescript-ui-samples. You may find a solution to the case there. These might be helpful. – WorldIntruder Sep 15 '16 at 14:41
  • As @WorldIntruder hinted this looks like an issue where the parent container of the RadListView is measuring its children with infinity. Such containers are not supported by the RadListView and you should replace it with for example GridLayout – Vladimir Amiorkov Dec 02 '16 at 12:26

0 Answers0