Skip to content

Commit

Permalink
añadido cambios y documentacion al README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
hicode committed Mar 5, 2023
1 parent f081a58 commit 7fb8b6e
Show file tree
Hide file tree
Showing 5 changed files with 212 additions and 241 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BSD 3-Clause License

Copyright (c) 2023, Nike
Copyright (c) 2023, hicode

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Expand Down
47 changes: 45 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,46 @@
# voir-native
# Voir Native

It is a framework to develop applications in a more controlled way with tabrisjs
It is a framework to develop android and ios applications in a more organized way with tabrisjs

## How To Use

```typescript

import addView, {CoordinatePage, CoordinatePageComponent, menuDrawer} from 'voir-native'
import {contentView} from "tabris"

contentView.append(CoordinatePage({
layoutData: 'stretch'
}))


menuDrawer(
{
one: {
text: "home",
id: "home",
image: "/images/home.png",
},
thwo: {
text: "favorite",
id: "favorite",
image: "/images/favorite.png",
},
three: {
text: "configure",
id: "config",
image: "/images/settings.png",
},
}
);

// or

contentView.append(
<CoordinatePageComponent stretch />
)

```
addView function adds views to the CoordinatePage or CoordinatePageComponent

> new features will be added little by little
43 changes: 19 additions & 24 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CoordinatePageComponent = exports.CoordinatePage = exports.menuDrawer = void 0;
var tabris_1 = require("tabris");
var navigation;
tabris_1.contentView.on("addChild", function (_a) {
var child = _a.child;
if (child instanceof tabris_1.NavigationView && !navigation) {
navigation = child;
}
});
function addView() {
var widgets = [];
for (var _i = 0; _i < arguments.length; _i++) {
widgets[_i] = arguments[_i];
}
return navigation.append.apply(navigation, widgets);
}
exports.default = addView;
var menu_1 = require("./navigation/menu");
Object.defineProperty(exports, "menuDrawer", { enumerable: true, get: function () { return menu_1.menuDrawer; } });
var coordinate_page_1 = require("./navigation/coordinate-page");
Object.defineProperty(exports, "CoordinatePage", { enumerable: true, get: function () { return coordinate_page_1.CoordinatePage; } });
Object.defineProperty(exports, "CoordinatePageComponent", { enumerable: true, get: function () { return coordinate_page_1.CoordinatePageComponent; } });
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CoordinatePageComponent = exports.CoordinatePage = exports.menuDrawer = void 0;
const tabris_1 = require("tabris");
let navigation;
tabris_1.contentView.on("addChild", ({ child }) => {
if (child instanceof tabris_1.NavigationView && !navigation) {
navigation = child;
}
});
function addView(...widgets) {
return navigation.append(...widgets);
}
exports.default = addView;
var menu_1 = require("./navigation/menu");
Object.defineProperty(exports, "menuDrawer", { enumerable: true, get: function () { return menu_1.menuDrawer; } });
var coordinate_page_1 = require("./navigation/coordinate-page");
Object.defineProperty(exports, "CoordinatePage", { enumerable: true, get: function () { return coordinate_page_1.CoordinatePage; } });
Object.defineProperty(exports, "CoordinatePageComponent", { enumerable: true, get: function () { return coordinate_page_1.CoordinatePageComponent; } });
246 changes: 98 additions & 148 deletions navigation/coordinate-page.js
Original file line number Diff line number Diff line change
@@ -1,148 +1,98 @@
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.CoordinatePageComponent = exports.CoordinatePage = void 0;
var tabris_1 = require("tabris");
/**
* guarda el contexto de pagina
*/
var ctxPages = new Map();
/**
* @description
* utilizar en JSX <CoordinatePageComponent></CoordinatePageComponent>
* encapsula la logica del menu de acciones del AppBar
* cuando se añade un Page con Action o SearchAction
* estas acciones desapareceran si la no es visible
* haciendo que la nueva pagina no tenga los menus anteriores
*/
var CoordinatePageComponent = /** @class */ (function (_super) {
__extends(CoordinatePageComponent, _super);
function CoordinatePageComponent(props) {
if (props === void 0) { props = {}; }
var _this = _super.call(this, props) || this;
_this.on("addChild", function (_a) {
var child = _a.child;
if (child instanceof tabris_1.Page) {
ctxPages.set(child, {
hidden: false,
actions: null,
isDisposed: false,
});
child.on("appear", function () {
var info = ctxPages.get(child);
if (typeof info === "object" && info.hidden) {
_this.append(info.actions);
info.hidden = false;
}
if (ctxPages.size === 1) {
setChangeEnabledDrawer(true);
}
});
child.on("disappear", function () {
var info = ctxPages.get(child);
setChangeEnabledDrawer(false);
if (!info.hidden) {
info.hidden = true;
info.actions.forEach(function (action) { return action.detach(); });
}
if (info.isDisposed)
ctxPages.delete(child);
});
child.on("dispose", function () {
ctxPages.get(child).isDisposed = true;
});
}
});
function setChangeEnabledDrawer(enable) {
if (props.drawerActionVisible)
tabris_1.drawer.enabled = enable;
}
return _this;
}
CoordinatePageComponent.prototype.append = function () {
var widgets = [];
for (var _i = 0; _i < arguments.length; _i++) {
widgets[_i] = arguments[_i];
}
var sup = _super.prototype.append.apply(this, widgets);
setTimeout(function () { return resolveParameter(widgets); }, 0);
return sup;
};
return CoordinatePageComponent;
}(tabris_1.NavigationView));
exports.CoordinatePageComponent = CoordinatePageComponent;
function navigationController(widgets) {
var page = widgets.find(function (widget) { return widget instanceof tabris_1.Page; });
var actions = widgets.filter(function (widget) {
return widget instanceof tabris_1.Action || widget instanceof tabris_1.SearchAction;
});
var info = ctxPages.get(page);
if (page && actions.length && info.actions === null) {
info.actions = actions;
}
}
function resolveParameter($widgets) {
var widgets = $widgets.length > 1
? $widgets
: Array.isArray($widgets[0])
? $widgets.shift()
: $widgets;
if (widgets.some(function (widget) { return Array.isArray(widget); }))
throw new Error("error parameter");
if (Array.isArray(widgets) && widgets.length > 0)
navigationController(widgets);
}
function ProxyCoordinatePage(props) {
if (props === void 0) { props = {}; }
return new CoordinatePageComponent(props);
}
/**
* @description
* encapsula en un proxy cuando se ejecute como funcion o instancia
*/
var CoordinatePage = new Proxy(ProxyCoordinatePage, {
construct: function ($ProxyCoordinatePage, args) {
return new Proxy($ProxyCoordinatePage(args[0]), {
get: function (coordinatePage, prop) {
if (prop === "append") {
return function () {
var widgets = [];
for (var _i = 0; _i < arguments.length; _i++) {
widgets[_i] = arguments[_i];
}
return (coordinatePage.append.apply(coordinatePage, widgets),
resolveParameter(widgets),
coordinatePage);
};
}
return typeof coordinatePage[prop] === "function"
? coordinatePage[prop].bind(coordinatePage)
: coordinatePage[prop];
},
set: function (coordinatePage, prop, value) {
//@ts-ignore
coordinatePage[prop] = value;
return true;
},
});
},
apply: function () {
//@ts-ignore
return new CoordinatePage(arguments[2][1]);
},
});
exports.CoordinatePage = CoordinatePage;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CoordinatePageComponent = exports.CoordinatePage = void 0;
const tabris_1 = require("tabris");
const ctxPages = new Map();
class CoordinatePageComponent extends tabris_1.NavigationView {
constructor(props = {}) {
super(props);
this.on("addChild", ({ child }) => {
if (child instanceof tabris_1.Page) {
ctxPages.set(child, {
hidden: false,
actions: null,
isDisposed: false,
});
child.on("appear", () => {
const info = ctxPages.get(child);
if (typeof info === "object" && info.hidden) {
this.append(info.actions);
info.hidden = false;
}
if (ctxPages.size === 1) {
setChangeEnabledDrawer(true);
}
});
child.on("disappear", () => {
const info = ctxPages.get(child);
setChangeEnabledDrawer(false);
if (!info.hidden) {
info.hidden = true;
info.actions.forEach((action) => action.detach());
}
if (info.isDisposed)
ctxPages.delete(child);
});
child.on("dispose", () => {
ctxPages.get(child).isDisposed = true;
});
}
});
function setChangeEnabledDrawer(enable) {
if (props.drawerActionVisible)
tabris_1.drawer.enabled = enable;
}
}
append(...widgets) {
const sup = super.append(...widgets);
setTimeout(() => resolveParameter(widgets), 0);
return sup;
}
}
exports.CoordinatePageComponent = CoordinatePageComponent;
function navigationController(widgets) {
const page = widgets.find((widget) => widget instanceof tabris_1.Page);
const actions = widgets.filter((widget) => widget instanceof tabris_1.Action || widget instanceof tabris_1.SearchAction);
const info = ctxPages.get(page);
if (page && actions.length && info.actions === null) {
info.actions = actions;
}
}
function resolveParameter($widgets) {
let widgets = $widgets.length > 1
? $widgets
: Array.isArray($widgets[0])
? $widgets.shift()
: $widgets;
if (widgets.some((widget) => Array.isArray(widget)))
throw new Error("error parameter");
if (Array.isArray(widgets) && widgets.length > 0)
navigationController(widgets);
}
function ProxyCoordinatePage(props = {}) {
return new CoordinatePageComponent(props);
}
const CoordinatePage = new Proxy(ProxyCoordinatePage, {
construct($ProxyCoordinatePage, args) {
return new Proxy($ProxyCoordinatePage(args[0]), {
get(coordinatePage, prop) {
if (prop === "append") {
return (...widgets) => (coordinatePage.append(...widgets),
resolveParameter(widgets),
coordinatePage);
}
return typeof coordinatePage[prop] === "function"
? coordinatePage[prop].bind(coordinatePage)
: coordinatePage[prop];
},
set(coordinatePage, prop, value) {
coordinatePage[prop] = value;
return true;
},
});
},
apply() {
return new CoordinatePage(arguments[2][1]);
},
});
exports.CoordinatePage = CoordinatePage;
Loading

0 comments on commit 7fb8b6e

Please sign in to comment.