UNPKG

nativescript-autocomplete-x

Version:
148 lines 5.96 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var autocomplete_x_common_1 = require("./autocomplete-x.common"); var AutocompleteX = (function (_super) { __extends(AutocompleteX, _super); function AutocompleteX() { return _super !== null && _super.apply(this, arguments) || this; } AutocompleteX.prototype[autocomplete_x_common_1.editableProperty.setNative] = function (value) { this.editable = value; }; AutocompleteX.prototype[autocomplete_x_common_1.textProperty.getDefault] = function () { return ''; }; AutocompleteX.prototype[autocomplete_x_common_1.textProperty.setNative] = function (value) { this.nativeView.text = value; }; AutocompleteX.prototype[autocomplete_x_common_1.currentTextInResultsPrefixProperty.getDefault] = function () { return ''; }; AutocompleteX.prototype[autocomplete_x_common_1.currentTextInResultsPrefixProperty.setNative] = function (value) { this._ios.currentTextOnResultsListPrefix = value; }; AutocompleteX.prototype[autocomplete_x_common_1.hintProperty.getDefault] = function () { return ''; }; AutocompleteX.prototype[autocomplete_x_common_1.hintProperty.setNative] = function (value) { this.nativeView.placeholder = value; }; AutocompleteX.prototype[autocomplete_x_common_1.itemsProperty.getDefault] = function () { return []; }; AutocompleteX.prototype[autocomplete_x_common_1.itemsProperty.setNative] = function (value) { this._ios.filterStrings(value); }; Object.defineProperty(AutocompleteX.prototype, "ios", { get: function () { return this.nativeView; }, enumerable: true, configurable: true }); AutocompleteX.prototype.createNativeView = function () { this._ios = SearchTextField.alloc().init(); return this._ios; }; AutocompleteX.prototype.initNativeView = function () { _super.prototype.initNativeView.call(this); this._delegate = AutoCompleteXDelegateImpl.initWithOwner(new WeakRef(this)); }; AutocompleteX.prototype.onLoaded = function () { _super.prototype.onLoaded.call(this); this._ios.delegate = this._delegate; this._ios.startVisible = true; var fontSize = 18; var theme = SearchTextFieldTheme.lightTheme(); theme.font = UIFont.systemFontOfSize(fontSize); theme.cellHeight = 2 * fontSize; theme.bgColor = new UIColor({ red: 1, green: 1, blue: 1, alpha: 0.9 }); this._ios.theme = theme; this._ios.clearButtonMode = 3; this._ios.itemSelectionTextHandler = this._emitSelected.bind(this); this._ios.filterStrings(this.items); }; AutocompleteX.prototype._emitSelected = function (selectedItemTitle) { this.notify({ eventName: AutocompleteX.selectedEvent, object: this, text: selectedItemTitle }); }; AutocompleteX.prototype.emitOpened = function () { this.notify({ eventName: AutocompleteX.openedEvent, object: this, }); }; AutocompleteX.prototype.emitClosed = function () { this.notify({ eventName: AutocompleteX.closedEvent, object: this, }); }; AutocompleteX.prototype.emitTextChanged = function (str) { this.notify({ eventName: AutocompleteX.textChangedEvent, object: this, text: str }); }; return AutocompleteX; }(autocomplete_x_common_1.AutocompleteXBase)); exports.AutocompleteX = AutocompleteX; var AutoCompleteXDelegateImpl = (function (_super) { __extends(AutoCompleteXDelegateImpl, _super); function AutoCompleteXDelegateImpl() { return _super !== null && _super.apply(this, arguments) || this; } AutoCompleteXDelegateImpl_1 = AutoCompleteXDelegateImpl; AutoCompleteXDelegateImpl.initWithOwner = function (owner) { var delegate = AutoCompleteXDelegateImpl_1.new(); delegate._owner = owner; return delegate; }; AutoCompleteXDelegateImpl.prototype.textFieldShouldBeginEditing = function (textField) { this.firstEdit = true; var owner = this._owner.get(); if (owner) { return owner.editable; } return true; }; AutoCompleteXDelegateImpl.prototype.textFieldDidBeginEditing = function (textField) { var owner = this._owner.get(); if (owner) { } }; AutoCompleteXDelegateImpl.prototype.textFieldShouldChangeCharactersInRangeReplacementString = function (textField, range, replacementString) { var owner = this._owner.get(); if (owner) { var delta = replacementString.length - range.length; if (delta > 0) { if (textField.text.length + delta > owner.maxLength) { return false; } } if (true) { if (textField.secureTextEntry && this.firstEdit) { autocomplete_x_common_1.textProperty.nativeValueChange(owner, replacementString); } else { if (range.location <= textField.text.length) { var newText = NSString.stringWithString(textField.text).stringByReplacingCharactersInRangeWithString(range, replacementString); autocomplete_x_common_1.textProperty.nativeValueChange(owner, newText); } } } } this.firstEdit = false; return true; }; var AutoCompleteXDelegateImpl_1; AutoCompleteXDelegateImpl = AutoCompleteXDelegateImpl_1 = __decorate([ ObjCClass(UITextFieldDelegate) ], AutoCompleteXDelegateImpl); return AutoCompleteXDelegateImpl; }(NSObject)); //# sourceMappingURL=autocomplete-x.ios.js.map