react-native-navigation
Version:
React Native Navigation - truly native navigation for iOS and Android
130 lines (129 loc) • 3.65 kB
JavaScript
"use strict";
import { LayoutType } from "./LayoutType.js";
export class LayoutTreeParser {
constructor(uniqueIdProvider) {
this.uniqueIdProvider = uniqueIdProvider;
this.parse = this.parse.bind(this);
}
parse(api) {
if (api.topTabs) {
return this.topTabs(api.topTabs);
} else if (api.sideMenu) {
return this.sideMenu(api.sideMenu);
} else if (api.bottomTabs) {
return this.bottomTabs(api.bottomTabs);
} else if (api.stack) {
return this.stack(api.stack);
} else if (api.component) {
return this.component(api.component);
} else if (api.externalComponent) {
return this.externalComponent(api.externalComponent);
} else if (api.splitView) {
return this.splitView(api.splitView);
}
throw new Error(`unknown LayoutType "${Object.keys(api)}"`);
}
topTabs(api) {
return {
id: api.id || this.uniqueIdProvider.generate(LayoutType.TopTabs),
type: LayoutType.TopTabs,
data: {
options: api.options
},
children: api.children ? api.children.map(this.parse) : []
};
}
sideMenu(api) {
return {
id: api.id || this.uniqueIdProvider.generate(LayoutType.SideMenuRoot),
type: LayoutType.SideMenuRoot,
data: {
options: api.options
},
children: this.sideMenuChildren(api)
};
}
sideMenuChildren(api) {
const children = [];
if (api.left) {
children.push({
id: this.uniqueIdProvider.generate(LayoutType.SideMenuLeft),
type: LayoutType.SideMenuLeft,
data: {},
children: [this.parse(api.left)]
});
}
children.push({
id: this.uniqueIdProvider.generate(LayoutType.SideMenuCenter),
type: LayoutType.SideMenuCenter,
data: {},
children: [this.parse(api.center)]
});
if (api.right) {
children.push({
id: this.uniqueIdProvider.generate(LayoutType.SideMenuRight),
type: LayoutType.SideMenuRight,
data: {},
children: [this.parse(api.right)]
});
}
return children;
}
bottomTabs(api) {
return {
id: api.id || this.uniqueIdProvider.generate(LayoutType.BottomTabs),
type: LayoutType.BottomTabs,
data: {
options: api.options
},
children: api.children ? api.children.map(this.parse) : []
};
}
stack(api) {
return {
id: api.id || this.uniqueIdProvider.generate(LayoutType.Stack),
type: LayoutType.Stack,
data: {
options: api.options
},
children: api.children ? api.children.map(this.parse) : []
};
}
component(api) {
return {
id: api.id || this.uniqueIdProvider.generate(LayoutType.Component),
type: LayoutType.Component,
data: {
name: api.name.toString(),
options: api.options,
passProps: api.passProps
},
children: []
};
}
externalComponent(api) {
return {
id: api.id || this.uniqueIdProvider.generate(LayoutType.ExternalComponent),
type: LayoutType.ExternalComponent,
data: {
name: api.name.toString(),
options: api.options,
passProps: api.passProps
},
children: []
};
}
splitView(api) {
const master = api.master ? this.parse(api.master) : undefined;
const detail = api.detail ? this.parse(api.detail) : undefined;
return {
id: api.id || this.uniqueIdProvider.generate(LayoutType.SplitView),
type: LayoutType.SplitView,
data: {
options: api.options
},
children: master && detail ? [master, detail] : []
};
}
}
//# sourceMappingURL=LayoutTreeParser.js.map