{"action":"created","issue":{"url":"https://api.github.com/repos/NativeScript/NativeScript/issues/2820","repository_url":"https://api.github.com/repos/NativeScript/NativeScript","labels_url":"https://api.github.com/repos/NativeScript/NativeScript/issues/2820/labels{/name}","comments_url":"https://api.github.com/repos/NativeScript/NativeScript/issues/2820/comments","events_url":"https://api.github.com/repos/NativeScript/NativeScript/issues/2820/events","html_url":"https://github.com/NativeScript/NativeScript/issues/2820","id":180035991,"number":2820,"title":"ListView item template selector","user":{"login":"hamorphis","id":1201857,"avatar_url":"https://avatars.githubusercontent.com/u/1201857?v=3","gravatar_id":"","url":"https://api.github.com/users/hamorphis","html_url":"https://github.com/hamorphis","followers_url":"https://api.github.com/users/hamorphis/followers","following_url":"https://api.github.com/users/hamorphis/following{/other_user}","gists_url":"https://api.github.com/users/hamorphis/gists{/gist_id}","starred_url":"https://api.github.com/users/hamorphis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hamorphis/subscriptions","organizations_url":"https://api.github.com/users/hamorphis/orgs","repos_url":"https://api.github.com/users/hamorphis/repos","events_url":"https://api.github.com/users/hamorphis/events{/privacy}","received_events_url":"https://api.github.com/users/hamorphis/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":10,"created_at":"2016-09-29T12:30:57Z","updated_at":"2016-09-29T13:25:38Z","closed_at":null,"body":"To give more context (based on the slack chat we had):\r\nWe need to be able to display sets of data with different \"designs\" in a ListView without the need of using collapsed views (like a huge template which will be impossible to maintain and cost CPU cycles) or logic inside the view-model for `ContentView` which would have performance penalties.\r\n\r\nA good  scenario could be a news app, that needs to display the news with different designs based on the importance of the article: ![](http://razorianfly.com/wp-content/uploads/2015/01/Screen-Shot-2015-01-23-at-17.13.55.png)\r\n\r\nThank you 😄 "},"comment":{"url":"https://api.github.com/repos/NativeScript/NativeScript/issues/comments/250465017","html_url":"https://github.com/NativeScript/NativeScript/issues/2820#issuecomment-250465017","issue_url":"https://api.github.com/repos/NativeScript/NativeScript/issues/2820","id":250465017,"user":{"login":"ginev","id":5871176,"avatar_url":"https://avatars.githubusercontent.com/u/5871176?v=3","gravatar_id":"","url":"https://api.github.com/users/ginev","html_url":"https://github.com/ginev","followers_url":"https://api.github.com/users/ginev/followers","following_url":"https://api.github.com/users/ginev/following{/other_user}","gists_url":"https://api.github.com/users/ginev/gists{/gist_id}","starred_url":"https://api.github.com/users/ginev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ginev/subscriptions","organizations_url":"https://api.github.com/users/ginev/orgs","repos_url":"https://api.github.com/users/ginev/repos","events_url":"https://api.github.com/users/ginev/events{/privacy}","received_events_url":"https://api.github.com/users/ginev/received_events","type":"User","site_admin":false},"created_at":"2016-09-29T13:25:38Z","updated_at":"2016-09-29T13:25:38Z","body":"@hdeshev RadListView suffers from the same illness regarding Angular 2.0 templates. We had to rewrite the logic that parses standard NS templates and binds them. Now, there is a callback that simply returns a ready `View` for an item. This is something similar to the suggestion done by @hamorphis above but without passing an index or data item as an argument:\r\n\r\n```\r\n  this._listView.itemViewLoader = (viewType) => {\r\n            switch (viewType) {\r\n                case ListViewViewTypes.ItemView:\r\n                    if (component._itemTemplate && this.loader) {\r\n                        var nativeItem = this.loader.createEmbeddedView(component._itemTemplate, new ListItemContext(), 0);\r\n                        var typedView = getSingleViewFromViewRef(nativeItem);\r\n                        typedView[\"ng_view\"] = nativeItem;\r\n                        return typedView;\r\n                    }\r\n                    break;\r\n                case ListViewViewTypes.ItemSwipeView:\r\n                    if (component._itemSwipeTemplate && this.loader) {\r\n                        var nativeItem = this.loader.createEmbeddedView(component._itemSwipeTemplate, new ListItemContext(), 0);\r\n                        var typedView = getSingleViewFromViewRef(nativeItem);\r\n                        typedView[\"ng_view\"] = nativeItem;\r\n                        return typedView;\r\n                    }\r\n                    break;\r\n                case ListViewViewTypes.LoadOnDemandView:\r\n                    if (component._loadOnDemandTemplate && this.loader) {\r\n                        var viewRef = this.loader.createEmbeddedView(component._loadOnDemandTemplate, new ListItemContext(), 0);\r\n                        var nativeView = getSingleViewFromViewRef(viewRef);\r\n                        nativeView[\"ng_view\"] = viewRef;\r\n                        return nativeView;\r\n                    }\r\n                    break;\r\n                case ListViewViewTypes.HeaderView:\r\n                    if (component._headerTemplate && this.loader) {\r\n                        var viewRef = this.loader.createEmbeddedView(component._headerTemplate, new ListItemContext(), 0);\r\n                        var nativeView = getSingleViewFromViewRef(viewRef);\r\n                        nativeView[\"ng_view\"] = viewRef;\r\n                        return nativeView;\r\n                    }\r\n                    break;\r\n                case ListViewViewTypes.FooterView:\r\n                    if (component._footerTemplate && this.loader) {\r\n                        var viewRef = this.loader.createEmbeddedView(component._footerTemplate, new ListItemContext(), 0);\r\n                        var nativeView = getSingleViewFromViewRef(viewRef);\r\n                        nativeView[\"ng_view\"] = viewRef;\r\n                        return nativeView;\r\n                    }\r\n                    break;\r\n            }\r\n        };\r\n```\r\n\r\nWe can build on-top of that to implement the Template Selector functionality."}}
{"actor":{"display_login":"ginev"}}