@@ -5,7 +5,7 @@ import stackLayout = require("ui/layouts/stack-layout");
55import proxy = require( "ui/core/proxy" ) ;
66import dependencyObservable = require( "ui/core/dependency-observable" ) ;
77import definition = require( "ui/list-view" ) ;
8- import { ProxyViewContainer } from "ui/proxy-view-container" ;
8+ import { ProxyViewContainer } from "ui/proxy-view-container" ;
99import * as layoutBase from "ui/layouts/layout-base" ;
1010import * as colorModule from "color" ;
1111import { separatorColorProperty , registerHandler , Styler , StylePropertyChangedHandler } from "ui/styling/style" ;
@@ -43,7 +43,7 @@ function onSeparatorColorPropertyChanged(data: dependencyObservable.PropertyChan
4343export class ListView extends common . ListView {
4444 private _androidViewId : number = - 1 ;
4545 private _android : android . widget . ListView ;
46- public _realizedItems = new Map < android . view . View , viewModule . View > ( ) ;
46+ public _realizedItems = new Map < android . view . View , viewModule . View > ( ) ;
4747 public _realizedTemplates = new Map < string , Map < android . view . View , viewModule . View > > ( ) ;
4848
4949 public _createUI ( ) {
@@ -82,12 +82,12 @@ export class ListView extends common.ListView {
8282 }
8383
8484 // clear bindingContext when it is not observable because otherwise bindings to items won't reevaluate
85- this . _realizedItems . forEach ( ( view , nativeView , map ) => {
85+ this . _realizedItems . forEach ( ( view , nativeView , map ) => {
8686 if ( ! ( view . bindingContext instanceof observable . Observable ) ) {
8787 view . bindingContext = null ;
8888 }
8989 } ) ;
90-
90+
9191 ( < android . widget . BaseAdapter > this . android . getAdapter ( ) ) . notifyDataSetChanged ( ) ;
9292 }
9393
@@ -120,16 +120,16 @@ export class ListView extends common.ListView {
120120 } ) ;
121121 }
122122
123- public _dumpRealizedTemplates ( ) {
124- console . log ( `Realized Templates:` ) ;
123+ public _dumpRealizedTemplates ( ) {
124+ console . log ( `Realized Templates:` ) ;
125125 this . _realizedTemplates . forEach ( ( value , index , map ) => {
126126 console . log ( `\t${ index } :` ) ;
127127 value . forEach ( ( value , index , map ) => {
128128 console . log ( `\t\t${ index . hashCode ( ) } : ${ value } ` ) ;
129129 } ) ;
130130 } ) ;
131- console . log ( `Realized Items Size: ${ this . _realizedItems . size } ` ) ;
132- }
131+ console . log ( `Realized Items Size: ${ this . _realizedItems . size } ` ) ;
132+ }
133133
134134 private clearRealizedCells ( ) : void {
135135 // clear the cache
@@ -148,16 +148,16 @@ export class ListView extends common.ListView {
148148 }
149149
150150 public _onItemTemplatesPropertyChanged ( data : dependencyObservable . PropertyChangeData ) {
151- this . _itemTemplatesInternal = new Array < viewModule . KeyedTemplate > ( this . _defaultTemplate ) ;
152- if ( data . newValue ) {
151+ this . _itemTemplatesInternal = new Array < viewModule . KeyedTemplate > ( this . _defaultTemplate ) ;
152+ if ( data . newValue ) {
153153 this . _itemTemplatesInternal = this . _itemTemplatesInternal . concat ( data . newValue ) ;
154154 }
155-
156- if ( this . android ) {
155+
156+ if ( this . android ) {
157157 ensureListViewAdapterClass ( ) ;
158158 this . android . setAdapter ( new ListViewAdapterClass ( this ) ) ;
159159 }
160-
160+
161161 this . refresh ( ) ;
162162 }
163163}
@@ -200,18 +200,18 @@ function ensureListViewAdapterClass() {
200200 }
201201
202202 public getViewTypeCount ( ) {
203- return this . _listView . _itemTemplatesInternal . length ;
203+ return this . _listView . _itemTemplatesInternal . length ;
204204 }
205205
206206 public getItemViewType ( index : number ) {
207207 let template = this . _listView . _getItemTemplate ( index ) ;
208208 let itemViewType = this . _listView . _itemTemplatesInternal . indexOf ( template ) ;
209209 return itemViewType ;
210210 }
211-
211+
212212 public getView ( index : number , convertView : android . view . View , parent : android . view . ViewGroup ) : android . view . View {
213213 //this._listView._dumpRealizedTemplates();
214-
214+
215215 if ( ! this . _listView ) {
216216 return null ;
217217 }
@@ -224,9 +224,9 @@ function ensureListViewAdapterClass() {
224224 // Recycle an existing view or create a new one if needed.
225225 let template = this . _listView . _getItemTemplate ( index ) ;
226226 let view : viewModule . View ;
227- if ( convertView ) {
227+ if ( convertView ) {
228228 view = this . _listView . _realizedTemplates . get ( template . key ) . get ( convertView ) ;
229- if ( ! view ) {
229+ if ( ! view ) {
230230 throw new Error ( `There is no entry with key '${ convertView } ' in the realized views cache for template with key'${ template . key } '.` ) ;
231231 }
232232 }
@@ -273,10 +273,10 @@ function ensureListViewAdapterClass() {
273273
274274 // Cache the view for recycling
275275 let realizedItemsForTemplateKey = this . _listView . _realizedTemplates . get ( template . key ) ;
276- if ( ! realizedItemsForTemplateKey ) {
276+ if ( ! realizedItemsForTemplateKey ) {
277277 realizedItemsForTemplateKey = new Map < android . view . View , viewModule . View > ( ) ;
278278 this . _listView . _realizedTemplates . set ( template . key , realizedItemsForTemplateKey ) ;
279- }
279+ }
280280 realizedItemsForTemplateKey . set ( convertView , args . view ) ;
281281 this . _listView . _realizedItems . set ( convertView , args . view ) ;
282282 }
@@ -290,22 +290,37 @@ function ensureListViewAdapterClass() {
290290
291291export class ListViewStyler implements Styler {
292292 // separator-color
293+ private static getSeparatorColorProperty ( view : viewModule . View ) : any {
294+ let listView = < android . widget . ListView > view . _nativeView ;
295+ return listView . getDivider ( ) ;
296+ }
297+
293298 private static setSeparatorColorProperty ( view : viewModule . View , newValue : any ) {
294299 let listView = < android . widget . ListView > view . _nativeView ;
295- listView . setDivider ( new android . graphics . drawable . ColorDrawable ( newValue ) ) ;
300+
301+ if ( newValue instanceof android . graphics . drawable . Drawable ) {
302+ listView . setDivider ( newValue ) ;
303+ } else {
304+ listView . setDivider ( new android . graphics . drawable . ColorDrawable ( newValue ) ) ;
305+ }
296306 listView . setDividerHeight ( 1 ) ;
297307 }
298308
299309 private static resetSeparatorColorProperty ( view : viewModule . View , nativeValue : any ) {
300310 let listView = < android . widget . ListView > view . _nativeView ;
301- listView . setDivider ( new android . graphics . drawable . ColorDrawable ( nativeValue ) ) ;
302- listView . setDividerHeight ( 1 ) ;
311+
312+ if ( nativeValue instanceof android . graphics . drawable . Drawable ) {
313+ listView . setDivider ( nativeValue ) ;
314+ } else {
315+ listView . setDivider ( new android . graphics . drawable . ColorDrawable ( nativeValue ) ) ;
316+ }
303317 }
304318
305319 public static registerHandlers ( ) {
306320 registerHandler ( separatorColorProperty , new StylePropertyChangedHandler (
307321 ListViewStyler . setSeparatorColorProperty ,
308- ListViewStyler . resetSeparatorColorProperty ) , "ListView" ) ;
322+ ListViewStyler . resetSeparatorColorProperty ,
323+ ListViewStyler . getSeparatorColorProperty ) , "ListView" ) ;
309324 }
310325}
311326
0 commit comments