This commit is contained in:
Don Syme 2018-07-03 22:19:21 +01:00
Родитель f00f70e023
Коммит 2557d1d7be
8 изменённых файлов: 139 добавлений и 29 удалений

Просмотреть файл

@ -0,0 +1,17 @@
// Auto-Generated by FAKE; do not edit
namespace System
open System.Reflection
[<assembly: AssemblyTitleAttribute("Elmish.XamarinForms.SkiaSharp")>]
[<assembly: AssemblyProductAttribute("Elmish.XamarinForms.SkiaSharp")>]
[<assembly: AssemblyDescriptionAttribute("Elmish.XamarinForms bindings for SkiaSharp")>]
[<assembly: AssemblyVersionAttribute("0.10.0")>]
[<assembly: AssemblyFileVersionAttribute("0.10.0")>]
do ()
module internal AssemblyVersionInformation =
let [<Literal>] AssemblyTitle = "Elmish.XamarinForms.SkiaSharp"
let [<Literal>] AssemblyProduct = "Elmish.XamarinForms.SkiaSharp"
let [<Literal>] AssemblyDescription = "Elmish.XamarinForms bindings for SkiaSharp"
let [<Literal>] AssemblyVersion = "0.10.0"
let [<Literal>] AssemblyFileVersion = "0.10.0"

Просмотреть файл

@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<OtherFlags>/warnon:1182</OtherFlags>
</PropertyGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.fs" />
<Compile Include="SkiaSharp.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="FSharp.Core" Version="4.5.0" />
<PackageReference Include="Xamarin.Forms" Version="3.0.0.482510" />
<PackageReference Include="SkiaSharp" Version="1.60.2" />
<PackageReference Include="SkiaSharp.Views.Forms" Version="1.60.2" />
<ProjectReference Include="..\Elmish.XamarinForms\Elmish.XamarinForms.fsproj" />
</ItemGroup>
</Project>

Просмотреть файл

@ -0,0 +1,51 @@
namespace Elmish.XamarinForms.DynamicViews
[<AutoOpen>]
module MapsExtension =
open Elmish.XamarinForms
open Elmish.XamarinForms.DynamicViews
open Xamarin.Forms
open SkiaSharp
open SkiaSharp.Views.Forms
let CanvasEnableTouchEventsAttribKey = AttributeKey<_> "SKCanvas_EnableTouchEvents"
let IgnorePixelScalingAttribKey = AttributeKey<_> "SKCanvas_IgnorePixelScaling"
let OnPaintSurfaceAttribKey = AttributeKey<_> "SKCanvas_PaintSurface"
let OnTouchAttribKey = AttributeKey<_> "SKCanvas_Touch"
type Xaml with
/// Describes a Map in the view
static member SKCanvasView(?onPaintSurface: (SKPaintSurfaceEventArgs -> unit), ?onTouch: (SKTouchEventArgs -> unit), ?enableTouchEvents: bool, ?ignorePixelScaling: bool, ?horizontalOptions: Xamarin.Forms.LayoutOptions, ?verticalOptions: Xamarin.Forms.LayoutOptions, ?margin: obj, ?gestureRecognizers: ViewElement list, ?anchorX: double, ?anchorY: double, ?backgroundColor: Xamarin.Forms.Color, ?heightRequest: double, ?inputTransparent: bool, ?isEnabled: bool, ?isVisible: bool, ?minimumHeightRequest: double, ?minimumWidthRequest: double, ?opacity: double, ?rotation: double, ?rotationX: double, ?rotationY: double, ?scale: double, ?style: Xamarin.Forms.Style, ?translationX: double, ?translationY: double, ?widthRequest: double, ?resources: (string * obj) list, ?styles: Xamarin.Forms.Style list, ?styleSheets: Xamarin.Forms.StyleSheets.StyleSheet list, ?classId: string, ?styleId: string) =
// Count the number of additional attributes
let attribCount = 0
let attribCount = match enableTouchEvents with Some _ -> attribCount + 1 | None -> attribCount
let attribCount = match ignorePixelScaling with Some _ -> attribCount + 1 | None -> attribCount
let attribCount = match onPaintSurface with Some _ -> attribCount + 1 | None -> attribCount
let attribCount = match onTouch with Some _ -> attribCount + 1 | None -> attribCount
// Populate the attributes of the base element
let attribs = Xaml._BuildView(attribCount, ?horizontalOptions=horizontalOptions, ?verticalOptions=verticalOptions, ?margin=margin, ?gestureRecognizers=gestureRecognizers, ?anchorX=anchorX, ?anchorY=anchorY, ?backgroundColor=backgroundColor, ?heightRequest=heightRequest, ?inputTransparent=inputTransparent, ?isEnabled=isEnabled, ?isVisible=isVisible, ?minimumHeightRequest=minimumHeightRequest, ?minimumWidthRequest=minimumWidthRequest, ?opacity=opacity, ?rotation=rotation, ?rotationX=rotationX, ?rotationY=rotationY, ?scale=scale, ?style=style, ?translationX=translationX, ?translationY=translationY, ?widthRequest=widthRequest, ?resources=resources, ?styles=styles, ?styleSheets=styleSheets, ?classId=classId, ?styleId=styleId)
// Add our own attributes. They must have unique names which must match the names below.
match enableTouchEvents with None -> () | Some v -> attribs.Add(CanvasEnableTouchEventsAttribKey, v)
match ignorePixelScaling with None -> () | Some v -> attribs.Add(IgnorePixelScalingAttribKey, v)
match onPaintSurface with None -> () | Some v -> attribs.Add(OnPaintSurfaceAttribKey, System.EventHandler<_>(fun _sender args -> v args))
match onTouch with None -> () | Some v -> attribs.Add(OnTouchAttribKey, System.EventHandler<_>(fun _sender args -> v args))
// The create method
let create () = new SkiaSharp.Views.Forms.SKCanvasView()
// The update method
let update (prevOpt: ViewElement voption) (source: ViewElement) (target: SKCanvasView) =
Xaml._UpdateView prevOpt source (target :> View)
source.UpdatePrimitive(prevOpt, target, CanvasEnableTouchEventsAttribKey, (fun target v -> target.EnableTouchEvents <- v))
source.UpdatePrimitive(prevOpt, target, IgnorePixelScalingAttribKey, (fun target v -> target.IgnorePixelScaling <- v))
source.UpdateEvent(prevOpt, OnPaintSurfaceAttribKey, target.PaintSurface)
source.UpdateEvent(prevOpt, OnTouchAttribKey, target.Touch)
// The element
ViewElement.Create(create, update, attribs)

Просмотреть файл

@ -0,0 +1,15 @@
type file
id Elmish.XamarinForms.Maps
version 0.0
authors Elmish.XamarinForms Contributors
description
Elmish.XamarinForms bindings for Xamarin.Forms.Maps
tags
Xamarin.Forms F# Elmish Elm
projectUrl
https://github.com/fsprojects/Elmish.XamarinForms
licenseUrl
https://github.com/fsprojects/Elmish.XamarinForms/blob/master/LICENSE.md
requireLicenseAcceptance false
files
../build_output/Elmish.XamarinForms.Maps.dll ==> lib/netstandard2.0

Просмотреть файл

@ -3868,7 +3868,7 @@ type Xaml() =
(fun _ _ _ -> ())
canReuseChild
updateChild
(fun _ _ target -> Xamarin.Forms.PlatformConfiguration.iOSSpecific.Page.SetUseSafeArea(target.On<Xamarin.Forms.PlatformConfiguration.iOS>(), true) |> ignore) prevUseSafeAreaOpt currUseSafeAreaOpt target
(fun _ _ target -> Xamarin.Forms.PlatformConfiguration.iOSSpecific.Page.SetUseSafeArea((target : Xamarin.Forms.Page).On<Xamarin.Forms.PlatformConfiguration.iOS>(), true) |> ignore) prevUseSafeAreaOpt currUseSafeAreaOpt target
match prevPage_AppearingOpt, currPage_AppearingOpt with
| ValueSome prevValue, ValueSome currValue when identical prevValue currValue -> ()
| ValueSome prevValue, ValueSome currValue -> target.Appearing.RemoveHandler(prevValue); target.Appearing.AddHandler(currValue)

Просмотреть файл

@ -1212,7 +1212,7 @@
"name": "UseSafeArea",
"inputType": "bool",
"modelType": "bool",
"updateCode": "(fun _ _ target -> Xamarin.Forms.PlatformConfiguration.iOSSpecific.Page.SetUseSafeArea(target.On<Xamarin.Forms.PlatformConfiguration.iOS>(), true) |> ignore)"
"updateCode": "(fun _ _ target -> Xamarin.Forms.PlatformConfiguration.iOSSpecific.Page.SetUseSafeArea((target : Xamarin.Forms.Page).On<Xamarin.Forms.PlatformConfiguration.iOS>(), true) |> ignore)"
},
{
"name": "Appearing",

Просмотреть файл

@ -105,7 +105,7 @@ Target "TestTemplatesNuGet" (fun _ ->
let slash = if isUnix then "\\" else ""
for c in ["Debug"; "Release"] do
for p in ["AnyCPU"; "iPhoneSimulator"] do
for p in ["Any CPU"; "iPhoneSimulator"] do
exec "msbuild" (sprintf "%s/%s.sln /p:Platform=\"%s\" /p:Configuration=%s /p:PackageSources=%s\"https://api.nuget.org/v3/index.json%s;%s%s\"" testAppName testAppName p c slash slash pkgs slash)
(* Manual steps without building nupkg

Просмотреть файл

@ -99,10 +99,6 @@ The sample implements the extension for the types [Map](https://docs.microsoft.c
module Maps =
open Xamarin.Forms.Maps
type Xaml with
/// Describes a Map in the view
static member Map(?pins: seq<ViewElement>, ?isShowingUser: bool, ?mapType: bool, ?hasScrollEnabled: bool, ?hasZoomEnabled: bool, ?requestedRegion: bool) =
let MapHasScrollEnabledAttribKey = AttributeKey "Map_HasScrollEnabled"
let MapIsShowingUserAttribKey = AttributeKey "Map_IsShowingUser"
let MapPinsAttribKey = AttributeKey "Map_Pins"
@ -115,9 +111,17 @@ module Maps =
let PinTypeAttribKey = AttributeKey "Pin_PinType"
let PinAddressAttribKey = AttributeKey "Pin_Address"
type Xaml with
/// Describes a Map in the view
static member Map(?pins: seq<ViewElement>, ?isShowingUser: bool, ?mapType: bool, ?hasScrollEnabled: bool, ?hasZoomEnabled: bool, ?requestedRegion: bool) =
static member inline Map
(?pins: seq<ViewElement>, ?isShowingUser: bool, ?mapType: MapType, ?hasScrollEnabled: bool, ?hasZoomEnabled: bool, ?requestedRegion: MapSpan,
//inherited properties
?horizontalOptions: Xamarin.Forms.LayoutOptions, ?verticalOptions: Xamarin.Forms.LayoutOptions, ?margin: obj,
?gestureRecognizers: ViewElement list, ?anchorX: double, ?anchorY: double, ?backgroundColor: Xamarin.Forms.Color,
?heightRequest: double, ?inputTransparent: bool, ?isEnabled: bool, ?isVisible: bool, ?minimumHeightRequest: double,
?minimumWidthRequest: double, ?opacity: double, ?rotation: double, ?rotationX: double, ?rotationY: double,
?scale: double, ?style: Xamarin.Forms.Style, ?translationX: double, ?translationY: double, ?widthRequest: double,
?resources: (string * obj) list, ?styles: Xamarin.Forms.Style list, ?styleSheets: Xamarin.Forms.StyleSheets.StyleSheet list,
?classId: string, ?styleId: string) =
// Count the number of additional attributes
let attribCount = 0
@ -129,32 +133,38 @@ module Maps =
let attribCount = match requestedRegion with Some _ -> attribCount + 1 | None -> attribCount
// Populate the attributes of the base element
let attribs = Xaml._BuildView(attribCount)
let attribs =
Xaml._BuildView(attribCount, ?horizontalOptions=horizontalOptions, ?verticalOptions=verticalOptions, ?margin=margin,
?gestureRecognizers=gestureRecognizers, ?anchorX=anchorX, ?anchorY=anchorY, ?backgroundColor=backgroundColor,
?heightRequest=heightRequest, ?inputTransparent=inputTransparent, ?isEnabled=isEnabled, ?isVisible=isVisible,
?minimumHeightRequest=minimumHeightRequest, ?minimumWidthRequest=minimumWidthRequest, ?opacity=opacity,
?rotation=rotation, ?rotationX=rotationX, ?rotationY=rotationY, ?scale=scale, ?style=style,
?translationX=translationX, ?translationY=translationY, ?widthRequest=widthRequest, ?resources=resources,
?styles=styles, ?styleSheets=styleSheets, ?classId=classId, ?styleId=styleId)
// Add our own attributes. They must have unique names which must match the names below.
match pins with None -> () | Some v -> attribs.Add(MapPinsAttributeKey, box v)
match hasScrollEnabled with None -> () | Some v -> attribs.Add(MapHasScrollEnabledAttributeKey, box v)
match isShowingUser with None -> () | Some v -> attribs.Add(MapIsShowingUserAttributeKey, box v)
match mapType with None -> () | Some v -> attribs.Add(MapTypeAttributeKey, box v)
match hasZoomEnabled with None -> () | Some v -> attribs.Add(MapHasZoomEnabledAttributeKey, box v)
match requestedRegion with None -> () | Some v -> attribs.Add(MapRequestingRegionAttributeKey, box v)
match pins with None -> () | Some v -> attribs.Add(MapPinsAttribKey, v)
match hasScrollEnabled with None -> () | Some v -> attribs.Add(MapHasScrollEnabledAttribKey, v)
match isShowingUser with None -> () | Some v -> attribs.Add(MapIsShowingUserAttribKey, v)
match mapType with None -> () | Some v -> attribs.Add(MapTypeAttribKey, v)
match hasZoomEnabled with None -> () | Some v -> attribs.Add(MapHasZoomEnabledAttribKey, v)
match requestedRegion with None -> () | Some v -> attribs.Add(MapRequestingRegionAttribKey, v)
// The create method
let create () = box (new Xamarin.Forms.Maps.Map())
let create () = new Xamarin.Forms.Maps.Map()
// The update method
let update (prevOpt: ViewElement voption) (source: ViewElement) (targetObj:obj) =
Xaml._UpdateView prevOpt source targetObj
let target = (targetObj :?> Xamarin.Forms.Maps.Map)
source.UpdatePrimitive(prevOpt, target, MapHasScrollEnabledAttributeKey, (fun target v -> target.HasScrollEnabled <- v))
source.UpdatePrimitive(prevOpt, target, MapHasZoomEnabledAttributeKey, (fun target v -> target.HasZoomEnabled <- v))
let update (prevOpt: ViewElement voption) (source: ViewElement) (target: Map) =
Xaml._UpdateView prevOpt source (target :> View)
source.UpdatePrimitive(prevOpt, target, MapHasScrollEnabledAttribKey, (fun target v -> target.HasScrollEnabled <- v))
source.UpdatePrimitive(prevOpt, target, MapHasZoomEnabledAttribKey, (fun target v -> target.HasZoomEnabled <- v))
source.UpdatePrimitive(prevOpt, target, MapIsShowingUserAttribKey, (fun target v -> target.IsShowingUser <- v))
source.UpdatePrimitive(prevOpt, target, MapTypeAttribKey, (fun target v -> target.MapType <- v))
source.UpdateElementCollection(prevOpt, MapPinsAttribKey, target.Pins)
source.UpdatePrimitive(prevOpt, target, MapRequestingRegionAttribKey, (fun target v -> target.MoveToRegion(v)))
// The element
new ViewElement(typeof<Xamarin.Forms.Maps.Map>, create, update, attribs)
ViewElement.Create<Xamarin.Forms.Maps.Map>(create, update, attribs)
/// Describes a Pin in the view
static member Pin(?position: Position, ?label: string, ?pinType: PinType, ?address: string) =
@ -169,10 +179,10 @@ module Maps =
let attribs = AttributesBuilder(attribCount)
// Add our own attributes. They must have unique names which must match the names below.
match position with None -> () | Some v -> attribs.Add(PinPositionAttribKey, box v)
match label with None -> () | Some v -> attribs.Add(PinLabelAttribKey, box v)
match pinType with None -> () | Some v -> attribs.Add(PinTypeAttribKey, box v)
match address with None -> () | Some v -> attribs.Add(PinAddressAttribKey, box v)
match position with None -> () | Some v -> attribs.Add(PinPositionAttribKey, v)
match label with None -> () | Some v -> attribs.Add(PinLabelAttribKey, v)
match pinType with None -> () | Some v -> attribs.Add(PinTypeAttribKey, v)
match address with None -> () | Some v -> attribs.Add(PinAddressAttribKey, v)
// The create method
let create () = box (new Xamarin.Forms.Maps.Pin())
@ -196,8 +206,8 @@ Pins can be added using:
```fsharp
Xaml.Map(pins = [ Xaml.Pin(...); Xaml.Pin(...) ])
```
In the above example, no inherited properties from `View` (such as `margin` or `horizontalOptions`) have been included in the facade for `Map`. These properties
can be added, or you can set them on elements using the helper `With`, usable for all `View` properties:
In the above example, inherited properties from `View` (such as `margin` or `horizontalOptions`) have been included in the facade for `Map`. These properties
need not be added, you can set them on elements using the helper `With`, usable for all `View` properties:
```fsharp
Xaml.Map(hasZoomEnabled = true, hasScrollEnabled = true).With(horizontalOptions = LayoutOptions.FillAndExpand)
```