-
-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
db07b55
commit f8ed421
Showing
5 changed files
with
568 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package haxe.ui.events; | ||
|
||
class NavigationEvent extends UIEvent { | ||
public static final NAVIGATION_CHANGED:EventType<NavigationEvent> = EventType.name("navigationchanged"); | ||
} |
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,79 @@ | ||
package haxe.ui.macros; | ||
|
||
import haxe.macro.ExprTools; | ||
#if macro | ||
import haxe.macro.TypeTools; | ||
import haxe.macro.ComplexTypeTools; | ||
import haxe.macro.Context; | ||
import haxe.macro.Expr.Field; | ||
|
||
using StringTools; | ||
#end | ||
|
||
class NavigationMacros { | ||
#if macro | ||
public static macro function buildNavigatableView():Array<Field> { | ||
var localClass = Context.getLocalClass(); | ||
var localType = Context.getLocalType(); | ||
var localComplexType = TypeTools.toComplexType(localType); | ||
var localMeta = localClass.get().meta; | ||
|
||
var routeDetailsMeta = null; | ||
if (localMeta.has(":route")) { | ||
routeDetailsMeta = localMeta.extract(":route")[0]; | ||
} | ||
if (localMeta.has("route")) { | ||
routeDetailsMeta = localMeta.extract("route")[0]; | ||
} | ||
|
||
var navigationSubDomain = Context.getDefines().get("haxeui_navigation_sub_domain"); | ||
if (navigationSubDomain != null && navigationSubDomain.trim().length > 0) { | ||
BackendMacros.additionalExprs.push(macro haxe.ui.navigation.NavigationManager.instance.subDomain = $v{navigationSubDomain}); | ||
} | ||
|
||
if (routeDetailsMeta != null) { | ||
var routePathExpr = routeDetailsMeta.params[0]; | ||
var initialRoute = localMeta.has(":initialRoute") || localMeta.has("initialRoute"); | ||
var errorRoute = localMeta.has(":errorRoute") || localMeta.has("errorRoute"); | ||
var preserveView = localMeta.has(":preserveView") || localMeta.has("preserveView"); | ||
|
||
if (routePathExpr != null) { | ||
var parts = localClass.toString().split("."); | ||
parts.push("new"); | ||
BackendMacros.additionalExprs.push(macro haxe.ui.navigation.NavigationManager.instance.registerRoute($routePathExpr, { | ||
viewCtor: $p{parts}, | ||
initial: $v{initialRoute}, | ||
error: $v{errorRoute}, | ||
preserveView: $v{preserveView} | ||
})); | ||
} | ||
} | ||
|
||
var applyParamsField = null; | ||
var fields = Context.getBuildFields(); | ||
for (f in fields) { | ||
if (f.name == "applyParams") { | ||
applyParamsField = f; | ||
break; | ||
} | ||
} | ||
|
||
if (applyParamsField == null) { | ||
fields.push({ | ||
name: "applyParams", | ||
access: [APublic], | ||
kind: FFun({ | ||
args: [{name: "params", type: macro: Map<String, Any>}], | ||
expr: macro { | ||
} | ||
}), | ||
pos: Context.currentPos() | ||
}); | ||
} | ||
|
||
|
||
return fields; | ||
} | ||
|
||
#end | ||
} |
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,6 @@ | ||
package haxe.ui.navigation; | ||
|
||
@:autoBuild(haxe.ui.macros.NavigationMacros.buildNavigatableView()) | ||
interface INavigatableView { | ||
public function applyParams(params:Map<String, Any>):Void; | ||
} |
Oops, something went wrong.