mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
feat: Scoped Packages (#7911)
* chore: move tns-core-modules to nativescript-core * chore: preparing compat generate script * chore: add missing definitions * chore: no need for http-request to be private * chore: packages chore * test: generate tests for tns-core-modules * chore: add anroid module for consistency * chore: add .npmignore * chore: added privateModulesWhitelist * chore(webpack): added bundle-entry-points * chore: scripts * chore: tests changed to use @ns/core * test: add scoped-packages test project * test: fix types * test: update test project * chore: build scripts * chore: update build script * chore: npm scripts cleanup * chore: make the compat pgk work with old wp config * test: generate diff friendly tests * chore: create barrel exports * chore: move files after rebase * chore: typedoc config * chore: compat mode * chore: review of barrels * chore: remove tns-core-modules import after rebase * chore: dev workflow setup * chore: update developer-workflow * docs: experiment with API extractor * chore: api-extractor and barrel exports * chore: api-extractor configs * chore: generate d.ts rollup with api-extractor * refactor: move methods inside Frame * chore: fic tests to use Frame static methods * refactor: create Builder class * refactor: use Builder class in tests * refactor: include Style in ui barrel * chore: separate compat build script * chore: fix tslint errors * chore: update NATIVESCRIPT_CORE_ARGS * chore: fix compat pack * chore: fix ui-test-app build with linked modules * chore: Application, ApplicationSettings, Connectivity and Http * chore: export Trace, Profiling and Utils * refactor: Static create methods for ImageSource * chore: fix deprecated usages of ImageSource * chore: move Span and FormattedString to ui * chore: add events-args and ImageSource to index files * chore: check for CLI >= 6.2 when building for IOS * chore: update travis build * chore: copy Pod file to compat package * chore: update error msg ui-tests-app * refactor: Apply suggestions from code review Co-Authored-By: Martin Yankov <m.i.yankov@gmail.com> * chore: typings and refs * chore: add missing d.ts files for public API * chore: adress code review FB * chore: update api-report * chore: dev-workflow for other apps * chore: api update * chore: update api-report
This commit is contained in:
committed by
GitHub
parent
6c7139477e
commit
cc97a16800
5
nativescript-core/ui/text-field/package.json
Normal file
5
nativescript-core/ui/text-field/package.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "text-field",
|
||||
"main": "text-field",
|
||||
"types": "text-field.d.ts"
|
||||
}
|
||||
15
nativescript-core/ui/text-field/text-field-common.ts
Normal file
15
nativescript-core/ui/text-field/text-field-common.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { TextField as TextFieldDefinition } from ".";
|
||||
import { EditableTextBase, Property, booleanConverter, CSSType } from "../editable-text-base";
|
||||
|
||||
export * from "../editable-text-base";
|
||||
|
||||
@CSSType("TextField")
|
||||
export class TextFieldBase extends EditableTextBase implements TextFieldDefinition {
|
||||
public static returnPressEvent = "returnPress";
|
||||
public secure: boolean;
|
||||
}
|
||||
|
||||
TextFieldBase.prototype.recycleNativeView = "auto";
|
||||
|
||||
export const secureProperty = new Property<TextFieldBase, boolean>({ name: "secure", defaultValue: false, valueConverter: booleanConverter });
|
||||
secureProperty.register(TextFieldBase);
|
||||
96
nativescript-core/ui/text-field/text-field.android.ts
Normal file
96
nativescript-core/ui/text-field/text-field.android.ts
Normal file
@@ -0,0 +1,96 @@
|
||||
import { TextFieldBase, secureProperty, whiteSpaceProperty, WhiteSpace, keyboardTypeProperty } from "./text-field-common";
|
||||
|
||||
export * from "./text-field-common";
|
||||
|
||||
export class TextField extends TextFieldBase {
|
||||
public _configureEditText(editText: android.widget.EditText) {
|
||||
editText.setInputType(android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_NORMAL | android.text.InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | android.text.InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
|
||||
editText.setLines(1);
|
||||
editText.setMaxLines(1);
|
||||
editText.setHorizontallyScrolling(true);
|
||||
}
|
||||
|
||||
public _onReturnPress() {
|
||||
this.notify({ eventName: TextField.returnPressEvent, object: this });
|
||||
}
|
||||
|
||||
[secureProperty.setNative]() {
|
||||
this.setSecureAndKeyboardType();
|
||||
}
|
||||
|
||||
[keyboardTypeProperty.setNative]() {
|
||||
this.setSecureAndKeyboardType();
|
||||
}
|
||||
|
||||
setSecureAndKeyboardType(): void {
|
||||
|
||||
let inputType: number;
|
||||
|
||||
// Password variations are supported only for Text and Number classes.
|
||||
if (this.secure) {
|
||||
if (this.keyboardType === "number") {
|
||||
inputType = android.text.InputType.TYPE_CLASS_NUMBER | android.text.InputType.TYPE_NUMBER_VARIATION_PASSWORD;
|
||||
} else {
|
||||
inputType = android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_PASSWORD;
|
||||
}
|
||||
} else {
|
||||
// default
|
||||
inputType = android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_NORMAL;
|
||||
|
||||
// add autocorrect flags
|
||||
if (this.autocorrect) {
|
||||
inputType = inputType | android.text.InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE;
|
||||
inputType = inputType | android.text.InputType.TYPE_TEXT_FLAG_AUTO_CORRECT;
|
||||
inputType = inputType & ~android.text.InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS;
|
||||
}
|
||||
|
||||
// add autocapitalization type
|
||||
switch (this.autocapitalizationType) {
|
||||
case "words":
|
||||
inputType = inputType | android.text.InputType.TYPE_TEXT_FLAG_CAP_WORDS; //8192 (0x00020000) 14th bit
|
||||
break;
|
||||
case "sentences":
|
||||
inputType = inputType | android.text.InputType.TYPE_TEXT_FLAG_CAP_SENTENCES; //16384(0x00040000) 15th bit
|
||||
break;
|
||||
case "allcharacters":
|
||||
inputType = inputType | android.text.InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS; //4096 (0x00010000) 13th bit
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// add keyboardType flags.
|
||||
// They override previous if set.
|
||||
switch (this.keyboardType) {
|
||||
case "datetime":
|
||||
inputType = android.text.InputType.TYPE_CLASS_DATETIME | android.text.InputType.TYPE_DATETIME_VARIATION_NORMAL;
|
||||
break;
|
||||
case "phone":
|
||||
inputType = android.text.InputType.TYPE_CLASS_PHONE;
|
||||
break;
|
||||
case "number":
|
||||
inputType = android.text.InputType.TYPE_CLASS_NUMBER | android.text.InputType.TYPE_NUMBER_VARIATION_NORMAL | android.text.InputType.TYPE_NUMBER_FLAG_SIGNED | android.text.InputType.TYPE_NUMBER_FLAG_DECIMAL;
|
||||
break;
|
||||
case "url":
|
||||
inputType = android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_URI;
|
||||
break;
|
||||
case "email":
|
||||
inputType = android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
this._setInputType(inputType);
|
||||
}
|
||||
|
||||
[whiteSpaceProperty.getDefault](): WhiteSpace {
|
||||
return "nowrap";
|
||||
}
|
||||
[whiteSpaceProperty.setNative](value: WhiteSpace) {
|
||||
// Don't change it otherwise TextField will go to multiline mode.
|
||||
}
|
||||
}
|
||||
|
||||
TextField.prototype._isSingleLine = true;
|
||||
30
nativescript-core/ui/text-field/text-field.d.ts
vendored
Normal file
30
nativescript-core/ui/text-field/text-field.d.ts
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* Contains the TextField class, which represents an editable single-line box.
|
||||
* @module "ui/text-field"
|
||||
*/ /** */
|
||||
|
||||
import { EditableTextBase, Property } from "../editable-text-base";
|
||||
|
||||
export const secureProperty: Property<TextField, boolean>;
|
||||
|
||||
/**
|
||||
* Represents an editable text field.
|
||||
*/
|
||||
export class TextField extends EditableTextBase {
|
||||
public static returnPressEvent: string;
|
||||
|
||||
/**
|
||||
* Gets the native [android widget](http://developer.android.com/reference/android/widget/EditText.html) that represents the user interface for this component. Valid only when running on Android OS.
|
||||
*/
|
||||
android: any /* android.widget.EditText */;
|
||||
|
||||
/**
|
||||
* Gets the native iOS [UITextField](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextField_Class/) that represents the user interface for this component. Valid only when running on iOS.
|
||||
*/
|
||||
ios: any /* UITextField */;
|
||||
|
||||
/**
|
||||
* Gets or sets if a text field is for password entry.
|
||||
*/
|
||||
secure: boolean;
|
||||
}
|
||||
264
nativescript-core/ui/text-field/text-field.ios.ts
Normal file
264
nativescript-core/ui/text-field/text-field.ios.ts
Normal file
@@ -0,0 +1,264 @@
|
||||
import {
|
||||
TextFieldBase, secureProperty, textProperty, hintProperty, colorProperty, placeholderColorProperty,
|
||||
Length, paddingTopProperty, paddingRightProperty, paddingBottomProperty, paddingLeftProperty, _updateCharactersInRangeReplacementString, Color, layout
|
||||
} from "./text-field-common";
|
||||
import { profile } from "../../profiling";
|
||||
|
||||
export * from "./text-field-common";
|
||||
|
||||
const zeroLength: Length = {
|
||||
value: 0,
|
||||
unit: "px"
|
||||
};
|
||||
|
||||
class UITextFieldDelegateImpl extends NSObject implements UITextFieldDelegate {
|
||||
public static ObjCProtocols = [UITextFieldDelegate];
|
||||
|
||||
private _owner: WeakRef<TextField>;
|
||||
private firstEdit: boolean;
|
||||
|
||||
public static initWithOwner(owner: WeakRef<TextField>): UITextFieldDelegateImpl {
|
||||
const delegate = <UITextFieldDelegateImpl>UITextFieldDelegateImpl.new();
|
||||
delegate._owner = owner;
|
||||
|
||||
return delegate;
|
||||
}
|
||||
|
||||
public textFieldShouldBeginEditing(textField: UITextField): boolean {
|
||||
this.firstEdit = true;
|
||||
const owner = this._owner.get();
|
||||
if (owner) {
|
||||
return owner.editable;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public textFieldDidBeginEditing(textField: UITextField): void {
|
||||
const owner = this._owner.get();
|
||||
if (owner) {
|
||||
owner.notify({ eventName: TextField.focusEvent, object: owner });
|
||||
}
|
||||
}
|
||||
|
||||
public textFieldDidEndEditing(textField: UITextField) {
|
||||
const owner = this._owner.get();
|
||||
if (owner) {
|
||||
if (owner.updateTextTrigger === "focusLost") {
|
||||
textProperty.nativeValueChange(owner, textField.text);
|
||||
}
|
||||
|
||||
owner.dismissSoftInput();
|
||||
}
|
||||
}
|
||||
|
||||
public textFieldShouldClear(textField: UITextField) {
|
||||
this.firstEdit = false;
|
||||
const owner = this._owner.get();
|
||||
if (owner) {
|
||||
textProperty.nativeValueChange(owner, "");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public textFieldShouldReturn(textField: UITextField): boolean {
|
||||
// Called when the user presses the return button.
|
||||
const owner = this._owner.get();
|
||||
if (owner) {
|
||||
owner.dismissSoftInput();
|
||||
owner.notify({ eventName: TextField.returnPressEvent, object: owner });
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public textFieldShouldChangeCharactersInRangeReplacementString(textField: UITextField, range: NSRange, replacementString: string): boolean {
|
||||
const owner = this._owner.get();
|
||||
if (owner) {
|
||||
const delta = replacementString.length - range.length;
|
||||
if (delta > 0) {
|
||||
if (textField.text.length + delta > owner.maxLength) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (owner.updateTextTrigger === "textChanged") {
|
||||
if (textField.secureTextEntry && this.firstEdit) {
|
||||
textProperty.nativeValueChange(owner, replacementString);
|
||||
}
|
||||
else {
|
||||
if (range.location <= textField.text.length) {
|
||||
const newText = NSString.stringWithString(textField.text).stringByReplacingCharactersInRangeWithString(range, replacementString);
|
||||
textProperty.nativeValueChange(owner, newText);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (owner.formattedText) {
|
||||
_updateCharactersInRangeReplacementString(owner.formattedText, range.location, range.length, replacementString);
|
||||
}
|
||||
}
|
||||
|
||||
this.firstEdit = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
class UITextFieldImpl extends UITextField {
|
||||
|
||||
private _owner: WeakRef<TextField>;
|
||||
|
||||
public static initWithOwner(owner: WeakRef<TextField>): UITextFieldImpl {
|
||||
const handler = <UITextFieldImpl>UITextFieldImpl.new();
|
||||
handler._owner = owner;
|
||||
|
||||
return handler;
|
||||
}
|
||||
|
||||
private _getTextRectForBounds(bounds: CGRect): CGRect {
|
||||
const owner = this._owner ? this._owner.get() : null;
|
||||
|
||||
if (!owner) {
|
||||
return bounds;
|
||||
}
|
||||
|
||||
const size = bounds.size;
|
||||
|
||||
const x = layout.toDeviceIndependentPixels(owner.effectiveBorderLeftWidth + owner.effectivePaddingLeft);
|
||||
const y = layout.toDeviceIndependentPixels(owner.effectiveBorderTopWidth + owner.effectivePaddingTop);
|
||||
const width = layout.toDeviceIndependentPixels(layout.toDevicePixels(size.width) - (owner.effectiveBorderLeftWidth + owner.effectivePaddingLeft + owner.effectivePaddingRight + owner.effectiveBorderRightWidth));
|
||||
const height = layout.toDeviceIndependentPixels(layout.toDevicePixels(size.height) - (owner.effectiveBorderTopWidth + owner.effectivePaddingTop + owner.effectivePaddingBottom + owner.effectiveBorderBottomWidth));
|
||||
|
||||
return CGRectMake(x, y, width, height);
|
||||
}
|
||||
|
||||
public textRectForBounds(bounds: CGRect): CGRect {
|
||||
return this._getTextRectForBounds(bounds);
|
||||
}
|
||||
|
||||
public editingRectForBounds(bounds: CGRect): CGRect {
|
||||
return this._getTextRectForBounds(bounds);
|
||||
}
|
||||
}
|
||||
|
||||
export class TextField extends TextFieldBase {
|
||||
nativeViewProtected: UITextField;
|
||||
private _delegate: UITextFieldDelegateImpl;
|
||||
|
||||
createNativeView() {
|
||||
return UITextFieldImpl.initWithOwner(new WeakRef(this));
|
||||
}
|
||||
|
||||
initNativeView() {
|
||||
super.initNativeView();
|
||||
this._delegate = UITextFieldDelegateImpl.initWithOwner(new WeakRef(this));
|
||||
}
|
||||
|
||||
disposeNativeView() {
|
||||
this._delegate = null;
|
||||
super.disposeNativeView();
|
||||
}
|
||||
|
||||
@profile
|
||||
public onLoaded() {
|
||||
super.onLoaded();
|
||||
this.ios.delegate = this._delegate;
|
||||
}
|
||||
|
||||
public onUnloaded() {
|
||||
this.ios.delegate = null;
|
||||
super.onUnloaded();
|
||||
}
|
||||
|
||||
get ios(): UITextField {
|
||||
return this.nativeViewProtected;
|
||||
}
|
||||
|
||||
[hintProperty.getDefault](): string {
|
||||
return this.nativeTextViewProtected.placeholder;
|
||||
}
|
||||
[hintProperty.setNative](value: string) {
|
||||
this._updateAttributedPlaceholder();
|
||||
}
|
||||
|
||||
[secureProperty.getDefault](): boolean {
|
||||
return this.nativeTextViewProtected.secureTextEntry;
|
||||
}
|
||||
[secureProperty.setNative](value: boolean) {
|
||||
this.nativeTextViewProtected.secureTextEntry = value;
|
||||
}
|
||||
|
||||
[colorProperty.getDefault](): { textColor: UIColor, tintColor: UIColor } {
|
||||
return {
|
||||
textColor: this.nativeTextViewProtected.textColor,
|
||||
tintColor: this.nativeTextViewProtected.tintColor
|
||||
};
|
||||
}
|
||||
[colorProperty.setNative](value: Color | { textColor: UIColor, tintColor: UIColor }) {
|
||||
if (value instanceof Color) {
|
||||
let color = value instanceof Color ? value.ios : value;
|
||||
this.nativeTextViewProtected.textColor = color;
|
||||
this.nativeTextViewProtected.tintColor = color;
|
||||
} else {
|
||||
this.nativeTextViewProtected.textColor = value.textColor;
|
||||
this.nativeTextViewProtected.tintColor = value.tintColor;
|
||||
}
|
||||
}
|
||||
|
||||
[placeholderColorProperty.getDefault](): UIColor {
|
||||
return null;
|
||||
}
|
||||
[placeholderColorProperty.setNative](value: UIColor | Color) {
|
||||
this._updateAttributedPlaceholder();
|
||||
}
|
||||
|
||||
_updateAttributedPlaceholder(): void {
|
||||
let stringValue = this.hint;
|
||||
if (stringValue === null || stringValue === void 0) {
|
||||
stringValue = "";
|
||||
} else {
|
||||
stringValue = stringValue + "";
|
||||
}
|
||||
if (stringValue === "") {
|
||||
// we do not use empty string since initWithStringAttributes does not return proper value and
|
||||
// nativeView.attributedPlaceholder will be null
|
||||
stringValue = " ";
|
||||
}
|
||||
const attributes: any = {};
|
||||
if (this.style.placeholderColor) {
|
||||
attributes[NSForegroundColorAttributeName] = this.style.placeholderColor.ios;
|
||||
}
|
||||
const attributedPlaceholder = NSAttributedString.alloc().initWithStringAttributes(stringValue, attributes);
|
||||
this.nativeTextViewProtected.attributedPlaceholder = attributedPlaceholder;
|
||||
}
|
||||
|
||||
[paddingTopProperty.getDefault](): Length {
|
||||
return zeroLength;
|
||||
}
|
||||
[paddingTopProperty.setNative](value: Length) {
|
||||
// Padding is realized via UITextFieldImpl.textRectForBounds method
|
||||
}
|
||||
|
||||
[paddingRightProperty.getDefault](): Length {
|
||||
return zeroLength;
|
||||
}
|
||||
[paddingRightProperty.setNative](value: Length) {
|
||||
// Padding is realized via UITextFieldImpl.textRectForBounds method
|
||||
}
|
||||
|
||||
[paddingBottomProperty.getDefault](): Length {
|
||||
return zeroLength;
|
||||
}
|
||||
[paddingBottomProperty.setNative](value: Length) {
|
||||
// Padding is realized via UITextFieldImpl.textRectForBounds method
|
||||
}
|
||||
|
||||
[paddingLeftProperty.getDefault](): Length {
|
||||
return zeroLength;
|
||||
}
|
||||
[paddingLeftProperty.setNative](value: Length) {
|
||||
// Padding is realized via UITextFieldImpl.textRectForBounds method
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user