react-qml
Version:
125 lines (94 loc) • 3.81 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _RQAttributePayload = require("./RQAttributePayload");
var _util = require("util");
var _UIManager = _interopRequireDefault(require("./UIManager"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function isNumber(x) {
return typeof x === 'number';
}
var globalTagCounter = 0;
var RQElementContainer =
/*#__PURE__*/
function () {
function RQElementContainer(element, metadata, parent) {
_classCallCheck(this, RQElementContainer);
_defineProperty(this, "element", void 0);
_defineProperty(this, "metadata", void 0);
_defineProperty(this, "viewTag", void 0);
_defineProperty(this, "parent", void 0);
_defineProperty(this, "children", void 0);
this.element = element;
this.metadata = metadata;
this.viewTag = ++globalTagCounter;
this.children = new Set();
this.parent = parent;
}
_createClass(RQElementContainer, [{
key: "setNativeProps",
value: function setNativeProps(props) {
this.updateNativeProps({}, props);
}
}, {
key: "updateNativeProps",
value: function updateNativeProps(prevProps, nextProps) {
var element = this.element;
if (!element) {
return;
} // generate update payload
var updatePayload = (0, _RQAttributePayload.diffProps)(prevProps, nextProps);
if (updatePayload != null) {
(0, _RQAttributePayload.updateProps)(this, updatePayload);
}
}
}, {
key: "measure",
value: function measure(callback) {
var element = this.element;
if (!element) {
return;
}
callback(isNumber(element.x) ? element.x : 0, isNumber(element.y) ? element.y : 0, isNumber(element.width) ? element.width : 0, isNumber(element.height) ? element.height : 0, isNumber(element.x) ? element.x : 0, isNumber(element.y) ? element.y : 0);
}
}, {
key: "getViewTag",
value: function getViewTag() {
return this.viewTag;
}
}, {
key: "appendChild",
value: function appendChild(child) {
// on Container level
this.children.add(child);
child.parent = this; // on Element level
_UIManager.default.appendChild(this, child);
}
}, {
key: "removeChild",
value: function removeChild(child) {
// remove children recursively
child.removeAllChildren(); // then remove child
child.parent = undefined;
this.children.delete(child);
_UIManager.default.removeChild(this, child);
}
}, {
key: "removeAllChildren",
value: function removeAllChildren() {
var _this = this;
this.children.forEach(function (child) {
_this.removeChild(child);
});
}
}]);
return RQElementContainer;
}();
var _default = RQElementContainer;
exports.default = _default;