nativescript-segment-view
Version:
Make same style of segmentbar in android and ios, and have more attributes
140 lines • 6.42 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
var platform_1 = require("tns-core-modules/platform");
var utils_1 = require("tns-core-modules/utils/utils");
var n_s_segment_view_common_1 = require("./n-s-segment-view.common");
var NSSegmentViewItem = (function (_super) {
__extends(NSSegmentViewItem, _super);
function NSSegmentViewItem() {
return _super !== null && _super.apply(this, arguments) || this;
}
NSSegmentViewItem.prototype._update = function () {
var parent = this.parent;
if (parent) {
var tabIndex = parent.items.indexOf(this);
var title = this.title;
title = (title === null || title === undefined) ? "" : title;
parent.nativeView.itemArray[tabIndex].setTitleForState(title, 0);
}
};
return NSSegmentViewItem;
}(n_s_segment_view_common_1.NSSegmentViewItemBase));
exports.NSSegmentViewItem = NSSegmentViewItem;
var NSSegmentView = (function (_super) {
__extends(NSSegmentView, _super);
function NSSegmentView() {
var _this = _super.call(this) || this;
_this.delegate = SelectionHandlerImpl.initWithOwner(new WeakRef(_this));
console.log("NSSegmentView constructor");
var width = platform_1.screen.mainScreen.widthDIPs - 20;
_this.nativeView = SegmentView.initSegment();
var nsArray = NSMutableArray.new();
nsArray.addObject("1111");
nsArray.addObject("test2");
_this.nativeView.delegate = _this.delegate;
_this.nativeView.addItemsFrameInView(nsArray, CGRectMake(0, 0, width, 0), null);
return _this;
}
Object.defineProperty(NSSegmentView.prototype, "ios", {
get: function () {
return this.nativeView;
},
enumerable: true,
configurable: true
});
NSSegmentView.prototype[n_s_segment_view_common_1.selectedIndexProperty.getDefault] = function () {
return -1;
};
NSSegmentView.prototype[n_s_segment_view_common_1.selectedIndexProperty.setNative] = function (value) {
this.nativeView.selectIndex(value);
};
NSSegmentView.prototype[n_s_segment_view_common_1.itemsProperty.getDefault] = function () {
return null;
};
NSSegmentView.prototype[n_s_segment_view_common_1.itemsProperty.setNative] = function (value) {
var segmentedControl = this.nativeView;
var newItems = value;
if (newItems && newItems.length) {
var nsArray = NSMutableArray.new();
for (var _i = 0, newItems_1 = newItems; _i < newItems_1.length; _i++) {
var one = newItems_1[_i];
nsArray.addObject(one.title);
}
segmentedControl.replaceItems(nsArray);
}
};
NSSegmentView.prototype[n_s_segment_view_common_1.selectedBackgroundColorProperty.getDefault] = function () {
return this.nativeView.selectedBackgroundColor;
};
NSSegmentView.prototype[n_s_segment_view_common_1.selectedBackgroundColorProperty.setNative] = function (value) {
var color = value instanceof n_s_segment_view_common_1.Color ? value.ios : value;
this.nativeView.selectedBackgroundColor = color;
};
NSSegmentView.prototype[n_s_segment_view_common_1.backgroundProperty.getDefault] = function () {
return this.nativeView.segmentBackgroundColor;
};
NSSegmentView.prototype[n_s_segment_view_common_1.backgroundProperty.setNative] = function (value) {
var color = value instanceof n_s_segment_view_common_1.Color ? value.ios : value;
this.nativeView.segmentBackgroundColor = color;
};
NSSegmentView.prototype[n_s_segment_view_common_1.titleColorProperty.getDefault] = function () {
return null;
};
NSSegmentView.prototype[n_s_segment_view_common_1.titleColorProperty.setNative] = function (value) {
var color = value instanceof n_s_segment_view_common_1.Color ? value.ios : value;
this.nativeView.titleColor = color;
};
NSSegmentView.prototype[n_s_segment_view_common_1.selectedColorProperty.getDefault] = function () {
return null;
};
NSSegmentView.prototype[n_s_segment_view_common_1.selectedColorProperty.setNative] = function (value) {
var color = value instanceof n_s_segment_view_common_1.Color ? value.ios : value;
this.nativeView.selectColor = color;
};
NSSegmentView.prototype[n_s_segment_view_common_1.lineColorProperty.getDefault] = function () {
return null;
};
NSSegmentView.prototype[n_s_segment_view_common_1.lineColorProperty.setNative] = function (value) {
var color = value instanceof n_s_segment_view_common_1.Color ? value.ios : value;
this.nativeView.lineColor = color;
};
NSSegmentView.prototype[n_s_segment_view_common_1.fontInternalProperty.getDefault] = function () {
return null;
};
NSSegmentView.prototype[n_s_segment_view_common_1.fontInternalProperty.setNative] = function (value) {
var font = value ? value.getUIFont(UIFont.systemFontOfSize(utils_1.ios.getter(UIFont, UIFont.labelFontSize))) : null;
this.nativeView.titleFont = font;
};
return NSSegmentView;
}(n_s_segment_view_common_1.NSSegmentViewBase));
exports.NSSegmentView = NSSegmentView;
var SelectionHandlerImpl = (function (_super) {
__extends(SelectionHandlerImpl, _super);
function SelectionHandlerImpl() {
return _super !== null && _super.apply(this, arguments) || this;
}
SelectionHandlerImpl.initWithOwner = function (owner) {
var handler = SelectionHandlerImpl.new();
handler._owner = owner;
return handler;
};
SelectionHandlerImpl.prototype.didSelectSegmentAtIndex = function (index) {
var owner = this._owner.get();
if (owner) {
owner.selectedIndex = index;
}
};
return SelectionHandlerImpl;
}(NSObject));
SelectionHandlerImpl.ObjCProtocols = [SegmentViewControlDelegate];
var DelegateClass = (function (_super) {
__extends(DelegateClass, _super);
function DelegateClass() {
return _super !== null && _super.apply(this, arguments) || this;
}
DelegateClass.prototype.didSelectSegmentAtIndex = function (index) {
};
return DelegateClass;
}(NSObject));
DelegateClass.ObjCProtocols = [SegmentViewControlDelegate];
//# sourceMappingURL=n-s-segment-view.ios.js.map
;