dev #14384 Правка ошибок отображения WPA КофеЛайк: fix sms enter code in safari

This commit is contained in:
nikolay 2023-06-21 10:06:11 +04:00
parent 26b2e8eb13
commit 15e9fe7ec4
4 changed files with 45 additions and 20 deletions

View File

@ -9,7 +9,9 @@ export class FocusNextInputDirective {
constructor(private renderer: Renderer2) { } constructor(private renderer: Renderer2) { }
ngOnInit() { ngOnInit() {
// TODO: don't need to listen all events // TODO:
// 1: don't need to listen all events
// 2: not working in safari
this.eventEmitter.subscribe(elementId => { this.eventEmitter.subscribe(elementId => {
try { try {
const element = this.renderer.selectRootElement(elementId) const element = this.renderer.selectRootElement(elementId)

View File

@ -15,7 +15,7 @@ export class SocialMediaButtonsComponent implements OnInit {
public links: ISocialMediaLink[] = [ public links: ISocialMediaLink[] = [
{ {
label: 'Инстаграм', label: 'Инстаграм',
url: 'https://www.instagram.com/', url: 'https://instagram.com/coffeelike_com?igshid=MzRlODBiNWFlZA==',
imgUrl: '/assets/social-media-icons/instagram.svg' imgUrl: '/assets/social-media-icons/instagram.svg'
}, },
{ {

View File

@ -55,7 +55,6 @@
type="tel" type="tel"
placeholder="•" placeholder="•"
#field #field
[appFocusNextInput]="inputFocusEmitter"
formControlName="code" formControlName="code"
maxlength="1" maxlength="1"
/></label> /></label>
@ -66,7 +65,6 @@
type="tel" type="tel"
placeholder="•" placeholder="•"
#field1 #field1
[appFocusNextInput]="inputFocusEmitter"
formControlName="code1" formControlName="code1"
maxlength="1" maxlength="1"
/></label> /></label>
@ -77,7 +75,6 @@
type="tel" type="tel"
placeholder="•" placeholder="•"
#field2 #field2
[appFocusNextInput]="inputFocusEmitter"
formControlName="code2" formControlName="code2"
maxlength="1" maxlength="1"
/></label> /></label>
@ -88,7 +85,6 @@
type="tel" type="tel"
placeholder="•" placeholder="•"
#field3 #field3
[appFocusNextInput]="inputFocusEmitter"
formControlName="code3" formControlName="code3"
maxlength="1" maxlength="1"
/></label> /></label>

View File

@ -1,9 +1,11 @@
import { import {
AfterViewInit, AfterViewInit,
Component, Component,
ElementRef,
EventEmitter, EventEmitter,
HostListener, HostListener,
OnInit, OnInit,
ViewChild,
} from '@angular/core'; } from '@angular/core';
import { FormControl, FormGroup, Validators } from '@angular/forms'; import { FormControl, FormGroup, Validators } from '@angular/forms';
import { MatSnackBar } from '@angular/material/snack-bar'; import { MatSnackBar } from '@angular/material/snack-bar';
@ -39,17 +41,17 @@ export class LoginComponent implements OnInit, AfterViewInit {
private messageService: MessageService, private messageService: MessageService,
private _snackBar: MatSnackBar, private _snackBar: MatSnackBar,
private jsonRpcService: JsonrpcService private jsonRpcService: JsonrpcService
) {} ) { }
ngOnInit(): void {} ngOnInit(): void { }
ngAfterViewInit() { ngAfterViewInit() {
setTimeout(() => {
this.inputFocusEmitter.emit(`#${this.inputIds[0]}`);
}, 1000);
} }
public inputFocusEmitter = new EventEmitter<string>(); @ViewChild('field', { static: false }) field!: ElementRef;
@ViewChild('field1', { static: false }) field1!: ElementRef;
@ViewChild('field2', { static: false }) field2!: ElementRef;
@ViewChild('field3', { static: false }) field3!: ElementRef;
@HostListener('window:keydown', ['$event']) @HostListener('window:keydown', ['$event'])
HandlKeyEvents(event: any) { HandlKeyEvents(event: any) {
@ -63,23 +65,48 @@ export class LoginComponent implements OnInit, AfterViewInit {
event.target.value = ''; event.target.value = '';
const prevInputIndex = this.inputIds.indexOf(elementId) - 1; const prevInputIndex = this.inputIds.indexOf(elementId) - 1;
if (prevInputIndex >= 0) { if (prevInputIndex >= 0) {
this.inputFocusEmitter.emit(`#${this.inputIds[prevInputIndex]}`); // this.inputFocusEmitter.emit(`#${this.inputIds[prevInputIndex]}`);
this.focusFieldByIndex(prevInputIndex);
} }
break; break;
default: default:
elementId = event.target.id; elementId = event.target.id;
const index = this.inputIds.indexOf(elementId); const index = this.inputIds.indexOf(elementId);
const nextInputIndex = index + 1; const nextInputIndex = index + 1;
event.target.value = event.key; event.target.value = key;
if (nextInputIndex > 0 && nextInputIndex <= this.inputIds.length) { if (nextInputIndex > 0 && nextInputIndex <= this.inputIds.length) {
this.inputFocusEmitter.emit(`#${this.inputIds[nextInputIndex]}`); // this.inputFocusEmitter.emit(`#${this.inputIds[nextInputIndex]}`);
this.focusFieldByIndex(nextInputIndex);
} }
if (nextInputIndex == this.inputIds.length) {
this.field3!.nativeElement.blur();
}
break; break;
} }
} }
focusFieldByIndex(i: number) {
setTimeout(() => {
switch (i) {
case 0:
this.field.nativeElement.focus();
break;
case 1:
this.field1.nativeElement.focus();
break;
case 2:
this.field2.nativeElement.focus();
break;
case 3:
this.field3.nativeElement.focus();
break;
}
}, 0);
}
submitNumber() { submitNumber() {
const data = this.phoneForm.value; const data = this.phoneForm.value;
this.isShowNumber = false; this.isShowNumber = false;
@ -123,7 +150,7 @@ export class LoginComponent implements OnInit, AfterViewInit {
}, },
}); });
setTimeout(() => { setTimeout(() => {
this.inputFocusEmitter.emit(`#${this.inputIds[0]}`); this.field.nativeElement.focus();
}, 0); }, 0);
} }
@ -164,7 +191,7 @@ export class LoginComponent implements OnInit, AfterViewInit {
}, },
error: (err) => { error: (err) => {
console.error(err); console.error(err);
} }
}) })
// this.phoneConfirmed.emit(null); // this.phoneConfirmed.emit(null);