-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Memo support for Any* + itemsLayout for CollectionView
- Loading branch information
1 parent
90fe2e7
commit 3cd1735
Showing
13 changed files
with
313 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/Fabulous.XamarinForms/Views/Collections/GridItemsLayout.fs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
namespace Fabulous.XamarinForms | ||
|
||
open System.Runtime.CompilerServices | ||
open Fabulous | ||
open Fabulous.ScalarAttributeDefinitions | ||
open Xamarin.Forms | ||
|
||
type IGridItemsLayout = inherit Fabulous.XamarinForms.IItemsLayout | ||
|
||
module GridItemsLayout = | ||
let Span = Attributes.defineBindableInt GridItemsLayout.SpanProperty | ||
|
||
let WidgetKey = Widgets.registerWithFactory(fun widget -> | ||
let span = | ||
match widget.ScalarAttributes with | ||
| ValueNone -> ValueNone | ||
| ValueSome attrs -> | ||
match Array.tryFind (fun (attr: ScalarAttribute) -> attr.Key = Span.Key) attrs with | ||
| None -> ValueNone | ||
| Some attr -> ValueSome (SmallScalars.Int.decode attr.NumericValue) | ||
|
||
let orientation = | ||
match widget.ScalarAttributes with | ||
| ValueNone -> failwith "GridItemsLayout must have an orientation attribute" | ||
| ValueSome attrs -> | ||
match Array.tryFind (fun (attr: ScalarAttribute) -> attr.Key = ItemsLayout.Orientation.Key) attrs with | ||
| None -> failwith "GridItemsLayout must have an orientation attribute" | ||
| Some attr -> SmallScalars.IntEnum.decode<ItemsLayoutOrientation> attr.NumericValue | ||
|
||
match span with | ||
| ValueNone -> GridItemsLayout(orientation) | ||
| ValueSome span -> GridItemsLayout(span, orientation) | ||
) | ||
|
||
let HorizontalItemSpacing = Attributes.defineBindableFloat GridItemsLayout.HorizontalItemSpacingProperty | ||
let VerticalItemSpacing = Attributes.defineBindableFloat GridItemsLayout.VerticalItemSpacingProperty | ||
|
||
[<AutoOpen>] | ||
module GridItemsBuilders = | ||
type Fabulous.XamarinForms.View with | ||
static member inline GridItemsLayout(orientation: ItemsLayoutOrientation) = | ||
WidgetBuilder<'msg, IGridItemsLayout>( | ||
GridItemsLayout.WidgetKey, | ||
ItemsLayout.Orientation.WithValue(orientation) | ||
) | ||
|
||
[<Extension>] | ||
type GridItemsLayoutExtensions = | ||
[<Extension>] | ||
static member inline horizontalItemSpacing(this: WidgetBuilder<'msg, #IGridItemsLayout>, value: float) = | ||
this.AddScalar(GridItemsLayout.HorizontalItemSpacing.WithValue(value)) | ||
|
||
[<Extension>] | ||
static member inline span(this: WidgetBuilder<'msg, #IGridItemsLayout>, value: int) = | ||
this.AddScalar(GridItemsLayout.Span.WithValue(value)) | ||
|
||
[<Extension>] | ||
static member inline verticalItemSpacing(this: WidgetBuilder<'msg, #IGridItemsLayout>, value: float) = | ||
this.AddScalar(GridItemsLayout.VerticalItemSpacing.WithValue(value)) | ||
|
||
/// <summary>Link a ViewRef to access the direct GridItemsLayout control instance</summary> | ||
[<Extension>] | ||
static member inline reference(this: WidgetBuilder<'msg, IListView>, value: ViewRef<GridItemsLayout>) = | ||
this.AddScalar(ViewRefAttributes.ViewRef.WithValue(value.Unbox)) |
42 changes: 42 additions & 0 deletions
42
src/Fabulous.XamarinForms/Views/Collections/LinearItemsLayout.fs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
namespace Fabulous.XamarinForms | ||
|
||
open System.Runtime.CompilerServices | ||
open Fabulous | ||
open Xamarin.Forms | ||
|
||
type ILinearItemsLayout = inherit Fabulous.XamarinForms.IItemsLayout | ||
|
||
module LinearItemsLayout = | ||
let WidgetKey = Widgets.registerWithFactory(fun widget -> | ||
let orientation = | ||
match widget.ScalarAttributes with | ||
| ValueNone -> failwith "LinearItemsLayout must have an orientation attribute" | ||
| ValueSome attrs -> | ||
match Array.tryFind (fun (attr: ScalarAttribute) -> attr.Key = ItemsLayout.Orientation.Key) attrs with | ||
| None -> failwith "LinearItemsLayout must have an orientation attribute" | ||
| Some attr -> SmallScalars.IntEnum.decode<ItemsLayoutOrientation> attr.NumericValue | ||
|
||
LinearItemsLayout(orientation) | ||
) | ||
|
||
let ItemSpacing = Attributes.defineBindableWithEquality<float> LinearItemsLayout.ItemSpacingProperty | ||
|
||
[<AutoOpen>] | ||
module LinearItemsBuilders = | ||
type Fabulous.XamarinForms.View with | ||
static member inline LinearItemsLayout(orientation: ItemsLayoutOrientation) = | ||
WidgetBuilder<'msg, ILinearItemsLayout>( | ||
LinearItemsLayout.WidgetKey, | ||
ItemsLayout.Orientation.WithValue(orientation) | ||
) | ||
|
||
[<Extension>] | ||
type LinearItemsLayoutExtensions = | ||
[<Extension>] | ||
static member inline itemSpacing(this: WidgetBuilder<'msg, #ILinearItemsLayout>, value: float) = | ||
this.AddScalar(LinearItemsLayout.ItemSpacing.WithValue(value)) | ||
|
||
/// <summary>Link a ViewRef to access the direct LinearItemsLayout control instance</summary> | ||
[<Extension>] | ||
static member inline reference(this: WidgetBuilder<'msg, IListView>, value: ViewRef<LinearItemsLayout>) = | ||
this.AddScalar(ViewRefAttributes.ViewRef.WithValue(value.Unbox)) |
38 changes: 38 additions & 0 deletions
38
src/Fabulous.XamarinForms/Views/Collections/_GroupableItemsView.fs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
namespace Fabulous.XamarinForms | ||
|
||
open Fabulous | ||
open Fabulous.XamarinForms | ||
open Xamarin.Forms | ||
|
||
type IGroupableItemsView = inherit ISelectableItemsView | ||
|
||
module GroupableItemsView = | ||
let GroupedItemsSource = | ||
Attributes.defineSimpleScalar<GroupedWidgetItems> | ||
"CollectionView_GroupedItemsSource" | ||
(fun a b -> ScalarAttributeComparers.equalityCompare a.OriginalItems b.OriginalItems) | ||
(fun _ newValueOpt node -> | ||
let collectionView = node.Target :?> GroupableItemsView | ||
|
||
match newValueOpt with | ||
| ValueNone -> | ||
collectionView.IsGrouped <- false | ||
collectionView.ClearValue(CollectionView.ItemsSourceProperty) | ||
collectionView.ClearValue(CollectionView.GroupHeaderTemplateProperty) | ||
collectionView.ClearValue(CollectionView.GroupFooterTemplateProperty) | ||
collectionView.ClearValue(CollectionView.ItemTemplateProperty) | ||
|
||
| ValueSome value -> | ||
collectionView.IsGrouped <- true | ||
|
||
collectionView.SetValue(CollectionView.ItemTemplateProperty, WidgetDataTemplateSelector(node, unbox >> value.ItemTemplate)) | ||
|
||
collectionView.SetValue(CollectionView.GroupHeaderTemplateProperty, WidgetDataTemplateSelector(node, unbox >> value.HeaderTemplate)) | ||
|
||
if value.FooterTemplate.IsSome then | ||
collectionView.SetValue( | ||
CollectionView.GroupFooterTemplateProperty, | ||
WidgetDataTemplateSelector(node, unbox >> value.FooterTemplate.Value) | ||
) | ||
|
||
collectionView.SetValue(CollectionView.ItemsSourceProperty, value.OriginalItems)) |
Oops, something went wrong.