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
120 lines (119 loc) • 4.7 kB
JavaScript
"use strict";
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 UIScrollView_exports = {};
__export(UIScrollView_exports, {
UIScrollView: () => UIScrollView
});
module.exports = __toCommonJS(UIScrollView_exports);
var import_UIObject = require("./UIObject");
var import_UIPoint = require("./UIPoint");
var import_UIView = require("./UIView");
class UIScrollView extends import_UIView.UIView {
constructor(elementID, viewHTMLElement) {
super(elementID, viewHTMLElement);
this._contentOffset = new import_UIPoint.UIPoint(0, 0);
this._contentScale = 1;
this._scrollEnabled = import_UIObject.YES;
this._previousClientPoint = import_UIObject.nil;
this.containerView = new import_UIView.UIView(elementID + "ContainerView");
super.addSubview(this.containerView);
this.style.overflow = "hidden";
this.pausesPointerEvents = import_UIObject.NO;
this.addTargetForControlEvent(import_UIView.UIView.controlEvent.PointerDown, () => this._pointerDown = import_UIObject.YES);
this.addTargetForControlEvent(import_UIView.UIView.controlEvent.PointerUp, () => {
this._pointerDown = import_UIObject.NO;
this._previousClientPoint = import_UIObject.nil;
scrollStopped();
});
function scrollStopped() {
}
this.addTargetForControlEvent(import_UIView.UIView.controlEvent.PointerMove, (sender, event) => {
if (!(this._pointerDown && this._scrollEnabled && this._enabled)) {
return;
}
const currentClientPoint = new import_UIPoint.UIPoint(import_UIObject.nil, import_UIObject.nil);
if (window.MouseEvent && event instanceof MouseEvent) {
currentClientPoint.x = event.clientX;
currentClientPoint.y = event.clientY;
}
if (window.TouchEvent && event instanceof TouchEvent) {
const touchEvent = event;
if (touchEvent.touches.length != 1) {
this._pointerDown = import_UIObject.NO;
this._previousClientPoint = import_UIObject.nil;
scrollStopped();
return;
}
currentClientPoint.x = touchEvent.touches[0].clientX;
currentClientPoint.y = touchEvent.touches[0].clientY;
}
if ((0, import_UIObject.IS_NOT)(this._previousClientPoint)) {
this._previousClientPoint = currentClientPoint;
return;
}
const changePoint = currentClientPoint.copy().subtract(this._previousClientPoint);
if (this.containerView.bounds.width <= this.bounds.width) {
changePoint.x = 0;
}
if (0 < this.contentOffset.x + changePoint.x) {
changePoint.x = -this.contentOffset.x;
}
if (this.contentOffset.x + changePoint.x < -this.bounds.width) {
changePoint.x = -this.bounds.width - this.contentOffset.x;
}
if (this.containerView.bounds.height <= this.bounds.height) {
changePoint.y = 0;
}
if (0 < this.contentOffset.y + changePoint.y) {
changePoint.y = -this.contentOffset.y;
}
if (this.contentOffset.y + changePoint.y < -this.bounds.height) {
changePoint.y = -this.bounds.height - this.contentOffset.y;
}
this.contentOffset = this.contentOffset.add(changePoint);
this._previousClientPoint = currentClientPoint;
});
}
invalidateIntrinsicContentFrame() {
this._intrinsicContentFrame = void 0;
}
get contentOffset() {
return this._contentOffset;
}
set contentOffset(offset) {
this._contentOffset = offset;
this.setNeedsLayout();
}
layoutSubviews() {
super.layoutSubviews();
this.containerView.frame = this.containerView.bounds.offsetByPoint(this.contentOffset);
}
hasSubview(view) {
return this.containerView.hasSubview(view);
}
addSubview(view) {
this.containerView.addSubview(view);
this.invalidateIntrinsicContentFrame();
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
UIScrollView
});
//# sourceMappingURL=UIScrollView.js.map