|
1 | 1 | import { ItemEventData, ItemsSource } from '.'; |
2 | 2 | import { ListViewBase, separatorColorProperty, itemTemplatesProperty } from './list-view-common'; |
3 | 3 | import { View, KeyedTemplate } from '../core/view'; |
| 4 | +import { PercentLength } from '../styling/length-shared'; |
4 | 5 | import { unsetValue } from '../core/properties/property-shared'; |
5 | 6 | import { CoreTypes } from '../../core-types'; |
6 | 7 | import { Color } from '../../color'; |
@@ -404,11 +405,28 @@ function ensureListViewAdapterClass() { |
404 | 405 |
|
405 | 406 | this.owner._prepareItem(args.view, index); |
406 | 407 | if (!args.view.parent) { |
407 | | - // Proxy containers should not get treated as layouts. |
408 | | - // Wrap them in a real layout as well. |
| 408 | + // Ensure margins defined on the template root are honored on Android ListView. |
| 409 | + // ListView's children don't support layout margins, so we insert an outer wrapper |
| 410 | + // and keep the original view (with its margins) inside. This mirrors iOS spacing. |
| 411 | + |
| 412 | + // If the view is already a LayoutBase (typical for templates like GridLayout), |
| 413 | + // we wrap it so its margins take effect. For non-layout roots (labels, etc.) |
| 414 | + // we already wrap below with a StackLayout. |
409 | 415 | if (args.view instanceof LayoutBase && !(args.view instanceof ProxyViewContainer)) { |
410 | | - this.owner._addView(args.view); |
411 | | - convertView = args.view.nativeViewProtected; |
| 416 | + const mt = PercentLength.toDevicePixels(args.view.marginTop, 0, Number.NaN); |
| 417 | + const mb = PercentLength.toDevicePixels(args.view.marginBottom, 0, Number.NaN); |
| 418 | + const ml = PercentLength.toDevicePixels(args.view.marginLeft, 0, Number.NaN); |
| 419 | + const mr = PercentLength.toDevicePixels(args.view.marginRight, 0, Number.NaN); |
| 420 | + const hasMargins = mt > 0 || mb > 0 || ml > 0 || mr > 0; |
| 421 | + if (hasMargins) { |
| 422 | + const outer = new StackLayout(); |
| 423 | + outer.addChild(args.view); |
| 424 | + this.owner._addView(outer); |
| 425 | + convertView = outer.nativeViewProtected; |
| 426 | + } else { |
| 427 | + this.owner._addView(args.view); |
| 428 | + convertView = args.view.nativeViewProtected; |
| 429 | + } |
412 | 430 | } else { |
413 | 431 | const sp = new StackLayout(); |
414 | 432 | sp.addChild(args.view); |
|
0 commit comments