Skip to content

Commit

Permalink
navigation manager (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
ianharrigan committed Mar 5, 2024
1 parent db07b55 commit f8ed421
Show file tree
Hide file tree
Showing 5 changed files with 568 additions and 0 deletions.
5 changes: 5 additions & 0 deletions haxe/ui/events/NavigationEvent.hx
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");
}
79 changes: 79 additions & 0 deletions haxe/ui/macros/NavigationMacros.hx
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
}
6 changes: 6 additions & 0 deletions haxe/ui/navigation/INavigatableView.hx
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;
}
Loading

0 comments on commit f8ed421

Please sign in to comment.