Provided nested tree of VC/View/Subview ready for generation
Xam.Mac currently only supports VC gen
This commit is contained in:
Родитель
581c77f32c
Коммит
3944f63123
|
@ -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
|
||||
|
@ -34,15 +47,15 @@ module IOS =
|
|||
|> 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}
|
||||
|
||||
let view = Unchecked.defaultof<_>
|
||||
|
||||
let scene = {ViewController = newVc
|
||||
Outlets = vc.Outlets |> Seq.choose (vcOutletMap vc) |> Seq.toList
|
||||
Actions = actions
|
||||
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))
|
||||
|
|
|
@ -12,17 +12,18 @@ 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 }
|
|
@ -50,21 +50,23 @@ type iOSDesignerProvider(config: TypeProviderConfig) as this =
|
|||
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
|
||||
|
|
Загрузка…
Ссылка в новой задаче