triniwiz / nativescript-plugins

Apache License 2.0
80 stars 50 forks source link

[Accordion][IOS] Plugin doesn't work #183

Open kefahB opened 1 year ago

kefahB commented 1 year ago

Hi @triniwiz,

The plugin show this:

The problem come from this line at the init time itemHeaderTemplate is undefined and for that the plugin set the json data to the view instead of the template for that we see [object object]

I tried setTimeOut on the constructor but it doesn't solve it but if I did that it work for the header and need to be set for all templates! :

this._defaultItemHeaderTemplate = {
            key: 'default',
            createView: () => {

                return Builder.parse(`<StackLayout id="headerTemplate" backgroundColor="green" >
                <Label text="{{headerText}}"/>
            </StackLayout>`, this);
            }
        };

What can we do on this scenario ?

my code is same as the doc, here it:

<accordion:Accordion height="100%" items="{{items}}" allowMultiple="false" selectedIndexes="{{selectedIndexes}}">

                <accordion:Accordion.headerTemplate>
                    <StackLayout id="headerTemplate" backgroundColor="green" >
                        <Label text="{{headerText}}"/>
                    </StackLayout>
                </accordion:Accordion.headerTemplate>

                <accordion:Accordion.itemHeaderTemplate>
                    <GridLayout backgroundColor="blue">
                    <Label height="100%" text="{{title}}"/>
                    </GridLayout>
                </accordion:Accordion.itemHeaderTemplate>

                <accordion:Accordion.itemContentTemplate>
                    <StackLayout backgroundColor="orange">
                    <Image height="200" decodeWidth="200" decodeHeight="200"  src="{{image}}"/>
                    <Label text="{{text}}"/>
                    </StackLayout>
                </accordion:Accordion.itemContentTemplate>

                <accordion:Accordion.footerTemplate>
                    <StackLayout backgroundColor="yellow">
                    <Label text="{{footerText}}"/>
                    </StackLayout>
                </accordion:Accordion.footerTemplate>
            </accordion:Accordion>
export class HowToViewModel extends Observable {

    selectedIndexes = [0]
    items: ObservableArray<any>

    constructor() {
        super();
        this.items = new ObservableArray([
            {
              title: '1',
              footer: '10',
              headerText: 'First',
              footerText: '4',
              image: 'http://placehold.it/120x120&text=First',
              items: [
                {image: '~/images/a9ff17db85f8136619feb0d5a200c0e4.png', text: 'Stop'},
                {
                  text: 'Drop',
                  image: '~/images/shazam.jpg'
                }]
            },
            {
              title: '2',
              footer: '20',
              headerText: 'Second',
              footerText: '5',
              image: 'http://placehold.it/120x120&text=Second',
              items: [{
                text: 'Drop',
                image: '~/images/batman.jpg'
              }, {text: 'Drop', image: '~/images/f29.png'}]
            },
            {
              title: '3',
              footer: '30',
              headerText: 'Third',
              footerText: '6',
              image: 'http://placehold.it/120x120&text=Third',
              items: [{text: 'Drop', image: '~/images/strider.png'}, {
                text: 'Drop',
                image: '~/images/f29.png'
              }]
            }
          ]);
    }

}
triniwiz commented 1 year ago

I’ll do some testing to verify if something changed along the way, as for code test test with you can check out the demo in the older package