NativeScript Angular textfield-更改';安全';属性从true到false(iOS)

NativeScript Angular textfield-更改';安全';属性从true到false(iOS),nativescript,angular2-nativescript,nativescript-angular,Nativescript,Angular2 Nativescript,Nativescript Angular,-点击显示/隐藏按钮查看问题时,确保光标位于文本字段中 我有一个简单的文本字段供用户在我的NS+Angular应用程序中输入密码。我正在尝试实现显示/隐藏功能。以下是我尝试过的: <GridLayout rows="auto, auto" class="field" row="0"> <Label text="Password" class="field-label" *ngIf="focused" textWrap="true" row="0">

-点击显示/隐藏按钮查看问题时,确保光标位于文本字段中

我有一个简单的文本字段供用户在我的NS+Angular应用程序中输入密码。我正在尝试实现显示/隐藏功能。以下是我尝试过的:

    <GridLayout rows="auto, auto" class="field" row="0">
        <Label text="Password" class="field-label" *ngIf="focused" textWrap="true" row="0"></Label>
        <TextField hint="Password" [ngClass]="{'field-text': true, 'inactive': !focused}" [secure]="pwdSecure" 
            formControlName="password" [(ngModel)]="password" 
            (ngModelChange)="focused = password.length ? true : false" 
            (blur)="focused = password.length ? true : false" returnKeyType="next" (returnPress)="focusConfirmPwd()" row="1">
        </TextField>
        <Label *ngIf="focused" [text]="pwdSecure ? 'show' : 'hide'" (tap)="pwdSecure = !pwdSecure" class="secure pull-right" textWrap="true" row="1"></Label>
    </GridLayout>
当我点击“隐藏”按钮时,密码掩码显示得很好。但当我点击“show”时,密码文本会显示出来,但文本和光标之间的空间太大。当有遮罩时,光标将保持在它应该位于的位置

你知道我需要做什么来解决这个问题吗


谢谢

我已经在android上测试了你的案例,它看起来像是个bug,在ios上运行良好。 所以,问题的解决方案是,每当用户点击隐藏/显示标签时,将光标设置在文本的末尾

  • 为textfield添加一个焦点事件,并将textfield分配给一个变量以供进一步使用

  • 如果你想进一步澄清,请看一下,它在两种平台上都可以正常工作。

    我已经在android上测试了你的案例,看起来它是个bug,在ios上也可以正常工作。 所以,问题的解决方案是,每当用户点击隐藏/显示标签时,将光标设置在文本的末尾

  • 为textfield添加一个焦点事件,并将textfield分配给一个变量以供进一步使用

  • 如果你想进一步澄清,请看一看,它在两个平台上都运行良好。

    这是特定于iOS的吗?@Manoj我只在iOS上测试过它。这是特定于iOS的吗?@Manoj我只在iOS上测试过它。我实际上在iOS上体验过这一点,没有在Android上测试过。我正在使用自定义字体和字体大小,我不知道这是否相关。我想尝试实现你对iOS的建议——你知道它的语法是什么吗?谢谢你的帮助!可能是这样的:
    this.pwdield.nativeElement.position(从:this.pwdield.nativeElement.selectedRange.start到:this.pwdield.nativeElement.selectedRange.start)但是“from”和“to”在NS中导致错误…?如果是ios,请访问本机属性this.textfield.ios.endofdocument谢谢-我收到以下错误:
    控制台错误[本机代码]:错误类型错误:this.textfield.ios.textRange不是函数。(在'this.textfield.ios.textRange(newPosition,newPosition)'中,'this.textfield.ios.textRange'未定义)
    我在ios上实际遇到过这种情况,没有在Android上测试。我正在使用自定义字体和字体大小,我不知道这是否相关。我想尝试实现你对iOS的建议——你知道它的语法是什么吗?谢谢你的帮助!可能是这样的:
    this.pwdield.nativeElement.position(从:this.pwdield.nativeElement.selectedRange.start到:this.pwdield.nativeElement.selectedRange.start)但是“from”和“to”在NS中导致错误…?如果是ios,请访问本机属性this.textfield.ios.endofdocument谢谢-我收到以下错误:
    控制台错误[本机代码]:错误类型错误:this.textfield.ios.textRange不是函数。(在“this.textfield.ios.textRange(newPosition,newPosition)”中,“this.textfield.ios.textRange”未定义)
        pwdSecure = true;
        confirmPwdSecure = true;
    
      <TextField [ngClass]="{'field-text': true, 'inactive': !focused}" (focus)="onFocus($event)" hint="Password" [secure]="pwdSecure" [(ngModel)]="textFieldValue" (ngModelChange)="focused = password.length ? true : false"
                row="1" (blur)="focused = password.length ? true : false"></TextField>
    
        <Label *ngIf="focused" [text]="pwdSecure ? 'show' : 'hide'" (tap)="chandPwdtype()" class="secure pull-right" textWrap="true" row="1"></Label>
    
    chandPwdtype() {
        this.pwdSecure = !this.pwdSecure
        if (isAndroid) {
            setTimeout(() => {
                alert(this.textfield);
                this.textfield.android.setSelection(this.textFieldValue.length);
            }, 0);
        }else{
            let newPosition = this.textfield.ios.endOfDocument;
            //alert(this.textfield.ios.beginningOfDocument);
            //alert(this.textfield.ios.endOfDocument);
            this.textfield.ios.selectedTextRange = 
            this.textfield.ios.textRangeFromPositionToPosition(newPosition, newPosition);
    }