uicore-ts
Version:
UICore is a library to build native-like user interfaces using pure Typescript. No HTML is needed at all. Components are described as TS classes and all user interactions are handled explicitly. This library is strongly inspired by the UIKit framework tha
182 lines (181 loc) • 6.06 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var __async = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
};
var rejected = (value) => {
try {
step(generator.throw(value));
} catch (e) {
reject(e);
}
};
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
step((generator = generator.apply(__this, __arguments)).next());
});
};
var UIViewController_exports = {};
__export(UIViewController_exports, {
UIViewController: () => UIViewController
});
module.exports = __toCommonJS(UIViewController_exports);
var import_UIObject = require("./UIObject");
var import_UIRoute = require("./UIRoute");
class UIViewController extends import_UIObject.UIObject {
constructor(view) {
super();
this.view = view;
this.childViewControllers = [];
this.view.viewController = this;
}
get routeComponent() {
return import_UIRoute.UIRoute.currentRoute.componentWithViewController(this.class);
}
handleRouteRecursively(route) {
this.handleRoute(route);
this.childViewControllers.forEach((controller) => {
controller.handleRouteRecursively(route);
});
}
handleRoute(route) {
return __async(this, null, function* () {
});
}
viewWillAppear() {
return __async(this, null, function* () {
});
}
viewDidAppear() {
return __async(this, null, function* () {
});
}
viewWillDisappear() {
return __async(this, null, function* () {
});
}
viewDidDisappear() {
return __async(this, null, function* () {
});
}
updateViewConstraints() {
}
updateViewStyles() {
}
layoutViewSubviews() {
}
_triggerLayoutViewSubviews() {
if (this.view.needsLayout) {
this.view.layoutSubviews();
this.viewDidLayoutSubviews();
}
}
viewWillLayoutSubviews() {
this.updateViewConstraints();
this.updateViewStyles();
}
viewDidLayoutSubviews() {
}
viewDidReceiveBroadcastEvent(event) {
}
get core() {
return this.view.core;
}
hasChildViewController(viewController) {
if (!(0, import_UIObject.IS)(viewController)) {
return import_UIObject.NO;
}
for (let i = 0; i < this.childViewControllers.length; i++) {
const childViewController = this.childViewControllers[i];
if (childViewController == viewController) {
return import_UIObject.YES;
}
}
return import_UIObject.NO;
}
addChildViewController(viewController) {
if (!this.hasChildViewController(viewController)) {
viewController.willMoveToParentViewController(this);
this.childViewControllers.push(viewController);
this.view.addSubview(viewController.view);
viewController.didMoveToParentViewController(this);
}
}
removeFromParentViewController() {
var _a;
(_a = this.parentViewController) == null ? void 0 : _a.removeChildViewController(this);
}
willMoveToParentViewController(parentViewController) {
}
didMoveToParentViewController(parentViewController) {
this.parentViewController = parentViewController;
}
removeChildViewController(controller) {
var _a, _b, _c;
controller = (0, import_UIObject.FIRST_OR_NIL)(controller);
controller.viewWillDisappear();
if ((0, import_UIObject.IS)(controller.parentViewController)) {
const index = (_b = (_a = this.parentViewController) == null ? void 0 : _a.childViewControllers.indexOf(this)) != null ? _b : -1;
if (index > -1) {
(_c = this.parentViewController) == null ? void 0 : _c.childViewControllers.splice(index, 1);
this.view.removeFromSuperview();
this.parentViewController = void 0;
}
}
if ((0, import_UIObject.IS)(controller.view)) {
controller.view.removeFromSuperview();
}
controller.viewDidDisappear();
}
addChildViewControllerInContainer(controller, containerView) {
controller = (0, import_UIObject.FIRST_OR_NIL)(controller);
containerView = (0, import_UIObject.FIRST_OR_NIL)(containerView);
controller.viewWillAppear();
this.addChildViewController(controller);
containerView.addSubview(controller.view);
controller.handleRouteRecursively(import_UIRoute.UIRoute.currentRoute);
controller.didMoveToParentViewController(this);
controller.viewDidAppear();
}
addChildViewControllerInDialogView(controller, dialogView) {
controller = (0, import_UIObject.FIRST_OR_NIL)(controller);
dialogView = (0, import_UIObject.FIRST_OR_NIL)(dialogView);
controller.viewWillAppear();
this.addChildViewController(controller);
dialogView.view = controller.view;
const originalDismissFunction = dialogView.dismiss.bind(dialogView);
dialogView.dismiss = (animated) => {
originalDismissFunction(animated);
this.removeChildViewController(controller);
};
controller.handleRouteRecursively(import_UIRoute.UIRoute.currentRoute);
controller.didMoveToParentViewController(this);
controller.viewDidAppear();
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
UIViewController
});
//# sourceMappingURL=UIViewController.js.map