nativescript-community / ui-pager

Pager / Carousel component that allows the user to swipe left and right through pages of data.
https://nativescript-community.github.io/ui-pager/
Apache License 2.0
19 stars 10 forks source link

Custom itemTemplateSelector on working with Vue since 14.1.9 #52

Closed BozzaDaniel closed 9 months ago

BozzaDaniel commented 10 months ago

Since version 14.1.9 setting a custom itemTemplateSelector no longer works.

The following works in 14.1.8, but not in 14.1.9 or later:

<template>
    <Pager for="item in items" :itemTemplateSelector="templateSelector">
        <v-template name="template-1">
            <GridLayout>
                <Label text="template 1" />
            </GridLayout>
        </v-template>
        <v-template name="template-2">
            <GridLayout>
                <Label text="template 2" />
            </GridLayout>
        </v-template>
    </Pager>
</template>
<script lang="ts">
import Vue from 'vue'

export default Vue.extend({
    data() {
        return {
            items: ['template-1', 'template-2']
        }
    },
    methods: {
        templateSelector(item) {
            return item
        }
    }
})
</script>

The error logged in the console is the following:

  System.err: Calling js method onCreateViewHolder failed
  System.err: Error: Expecting a valid View instance.
  System.err:
  System.err: StackTrace:
  System.err: _addView(file: app/webpack:/app/node_modules/@nativescript/core/ui/core/view-base/index.js:531:0)
  System.err:   at PagerRecyclerAdapterImpl.onCreateViewHolder(file: app/webpack:/app/node_modules/@nativescript-community/ui-pager/index.android.js:674:0)

There is a workaround to get a custom itemTemplateSelector working, by changing type to always be 0. The correct template is still selected. https://github.com/nativescript-community/ui-pager/blob/056199593f4cac453370acf3ba6b2c7503a4f0e8/src/ui-pager/index.android.ts#L752

liamcharmer commented 9 months ago

Anything @BozzaDaniel ? @farfromrefug

farfromrefug commented 9 months ago

@BozzaDaniel @liamcharmer should be fixed in 14.1.18

liamcharmer commented 9 months ago

@farfromrefug works perfect!!!!