Provided nested tree of VC/View/Subview ready for generation

Xam.Mac currently only supports VC gen
This commit is contained in:
Dave Thomas 2017-06-27 17:42:35 +01:00
Родитель 581c77f32c
Коммит 3944f63123
4 изменённых файлов: 55 добавлений и 39 удалений

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

@ -6,24 +6,37 @@ open ExtCore.Control
open MonoTouch.Design
module IOS =
let outletMap (vc:ProxiedViewController) (o:Outlet) =
let vcOutletMap (vc:ProxiedViewController) (o:Outlet) =
maybe {
let! destination = vc.FindById(o.Destination) |> Option.ofObj
return {Property=o.Property; ElementName= destination.Element.Name.LocalName }}
let vOutletMap (v:ProxiedView) (o:Outlet) =
maybe {
let! destination = v.FindById(o.Destination) |> Option.ofObj
return {Property=o.Property; ElementName= destination.Element.Name.LocalName }}
let actionMap (vc:ProxiedViewController) (ac:ActionConnection) =
maybe {
let! destination = vc.FindById(ac.Destination) |> Option.ofObj
return {Selector=ac.Selector;ElementName= destination.Element.Name.LocalName}}
let rec createView (view:ProxiedView) =
maybe {
let! view = view |> Option.ofObj
if not (String.IsNullOrWhiteSpace(view.CustomClass))
then
return { View.CustomClass = view.CustomClass
XmlType = view.Element.Name.LocalName
Outlets = view.Outlets |> Seq.choose (vOutletMap view) |> Seq.toList
SubViews = view.Subviews
|> Seq.map createView
|> Seq.choose id
|> Seq.toList }
else return! None}
let createScene (scene : MonoTouch.Design.Scene) =
let vc = scene.ViewController
let outlets = vc.Outlets
let newOutlets =
outlets
|> Seq.choose (outletMap vc)
|> Seq.toList
let actions = maybe {
let! view = vc.View |> Option.ofObj
@ -33,16 +46,16 @@ module IOS =
|> Seq.distinct
|> Seq.choose (actionMap vc)
|> Seq.toList } |> Option.fill List.empty
let view = createView vc.View
let newVc = {ViewController.XmlType = vc.Element.Name.LocalName
CustomClass = vc.CustomClass
Outlets = newOutlets
Actions = actions}
Outlets = vc.Outlets |> Seq.choose (vcOutletMap vc) |> Seq.toList
Actions = actions
View = view}
let view = Unchecked.defaultof<_>
let scene = {ViewController = newVc
View = view }
let scene = {ViewController = newVc }
scene
let scenesFromXDoc (xdoc:XDocument) =
@ -55,6 +68,6 @@ module IOS =
| _ -> failwith "Could not parse file, no supported files were found"
scenes
|> Seq.choose (fun scene ->
if String.IsNullOrWhiteSpace scene.CustomClass
then None
else Some (createScene scene))
//if String.IsNullOrWhiteSpace scene.CustomClass
//then None
Some (createScene scene))

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

@ -62,7 +62,8 @@ module Mac =
return {XmlType = vc.Name.LocalName
CustomClass = customClass.Value
Outlets = outlets
Actions = actions} }
Actions = actions
View = None } }
let scenesFromXDoc (xdoc:XDocument) =
let tryLookup = createIdLookup xdoc
@ -70,8 +71,7 @@ module Mac =
|> Seq.collect (fun scene -> let vcElement = scene.Descendants(xn "viewController")
vcElement
|> Seq.choose (viewControllerMapping tryLookup)
|> Seq.map (fun vc -> {ViewController=vc
View=[]}))
|> Seq.map (fun vc -> {ViewController=vc}))
let scenesFromStoryBoardFileName (sb:string) =
let xdoc = XDocument.Load(new StreamReader(sb, true))

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

@ -11,18 +11,19 @@ type Outlet = {
type Action = {
Selector:string
ElementName: string }
type ViewController = {
XmlType: string
CustomClass : string
Outlets: Outlet List
Actions: Action List}
type View = {
XmlType: string
CustomClass : string
Outlets: Outlet List}
Outlets: Outlet list
SubViews : View list}
type ViewController = {
XmlType: string
CustomClass : string
Outlets: Outlet list
Actions: Action list
View : View option}
type Scene = {
ViewController : ViewController
View : View }
ViewController : ViewController }

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

@ -47,24 +47,26 @@ type iOSDesignerProvider(config: TypeProviderConfig) as this =
let groupedViewControllers =
query {for scene in scenes do
groupValBy scene.ViewController scene.ViewController.CustomClass}
groupValBy scene.ViewController scene.ViewController.CustomClass }
let groupedViews =
query {for scene in scenes do
groupValBy scene.View scene.View.CustomClass}
let rec proc (v:View) =
[ yield v
yield! v.SubViews |> Seq.collect proc ]
[ for scene in scenes do
match scene.ViewController.View with
| Some view -> yield! proc view
| None -> () ]
|> List.groupBy (fun v -> v.CustomClass )
let dd = groupedViews |> List.toArray
//generate storyboard container
let container = ProvidedTypeDefinition(asm, ns, typeName, Some(typeof<obj>), IsErased=false)
let generatedTypes =
[ for sc in groupedViewControllers do
let viewControllers = sc.AsEnumerable()
yield TypeBuilder.buildController runtimeBinding viewControllers isAbstract addUnitCtor register config
for v in groupedViews do
let views = v.AsEnumerable()
() ]
yield TypeBuilder.buildController runtimeBinding viewControllers isAbstract addUnitCtor register config ]
//Add the types to the container
container.AddMembers generatedTypes