Composer: Fix auto-capitalize feature on iOS (#1227)
This commit is contained in:
parent
02dd2044e8
commit
d41d87325d
@ -5,6 +5,7 @@ import { GlobalActions, GlobalState } from '../../global/types';
|
|||||||
|
|
||||||
import '../../modules/actions/initial';
|
import '../../modules/actions/initial';
|
||||||
import { pick } from '../../util/iteratees';
|
import { pick } from '../../util/iteratees';
|
||||||
|
import { PLATFORM_ENV } from '../../util/environment';
|
||||||
|
|
||||||
import UiLoader from '../common/UiLoader';
|
import UiLoader from '../common/UiLoader';
|
||||||
import AuthPhoneNumber from './AuthPhoneNumber';
|
import AuthPhoneNumber from './AuthPhoneNumber';
|
||||||
@ -14,7 +15,6 @@ import AuthRegister from './AuthRegister.async';
|
|||||||
import AuthQrCode from './AuthQrCode';
|
import AuthQrCode from './AuthQrCode';
|
||||||
|
|
||||||
import './Auth.scss';
|
import './Auth.scss';
|
||||||
import { PLATFORM_ENV } from '../../util/environment';
|
|
||||||
|
|
||||||
type StateProps = Pick<GlobalState, 'authState'>;
|
type StateProps = Pick<GlobalState, 'authState'>;
|
||||||
type DispatchProps = Pick<GlobalActions, 'reset' | 'initApi'>;
|
type DispatchProps = Pick<GlobalActions, 'reset' | 'initApi'>;
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { ChangeEvent } from 'react';
|
import { ChangeEvent } from 'react';
|
||||||
import React, {
|
import React, {
|
||||||
FC, useEffect, useRef, memo, useState, useCallback,
|
FC, useEffect, useRef, memo, useState, useCallback, useLayoutEffect,
|
||||||
} from '../../../lib/teact/teact';
|
} from '../../../lib/teact/teact';
|
||||||
import { withGlobal } from '../../../lib/teact/teactn';
|
import { withGlobal } from '../../../lib/teact/teactn';
|
||||||
|
|
||||||
@ -22,6 +22,7 @@ import useFlag from '../../../hooks/useFlag';
|
|||||||
import parseEmojiOnlyString from '../../common/helpers/parseEmojiOnlyString';
|
import parseEmojiOnlyString from '../../common/helpers/parseEmojiOnlyString';
|
||||||
import { isSelectionInsideInput } from './helpers/selection';
|
import { isSelectionInsideInput } from './helpers/selection';
|
||||||
import useLang from '../../../hooks/useLang';
|
import useLang from '../../../hooks/useLang';
|
||||||
|
import applyIosAutoCapitalizationFix from './helpers/applyIosAutoCapitalizationFix';
|
||||||
|
|
||||||
import TextFormatter from './TextFormatter';
|
import TextFormatter from './TextFormatter';
|
||||||
|
|
||||||
@ -104,6 +105,12 @@ const MessageInput: FC<OwnProps & StateProps & DispatchProps> = ({
|
|||||||
updateInputHeight(false);
|
updateInputHeight(false);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
useLayoutEffect(() => {
|
||||||
|
if (IS_IOS && !html && inputRef.current === document.activeElement) {
|
||||||
|
applyIosAutoCapitalizationFix(inputRef.current!);
|
||||||
|
}
|
||||||
|
}, [html]);
|
||||||
|
|
||||||
useLayoutEffectWithPrevDeps(([prevHtml]) => {
|
useLayoutEffectWithPrevDeps(([prevHtml]) => {
|
||||||
if (html !== inputRef.current!.innerHTML) {
|
if (html !== inputRef.current!.innerHTML) {
|
||||||
inputRef.current!.innerHTML = html;
|
inputRef.current!.innerHTML = html;
|
||||||
|
|||||||
@ -0,0 +1,15 @@
|
|||||||
|
import { IS_IOS } from '../../../../util/environment';
|
||||||
|
|
||||||
|
let resetInput: HTMLInputElement;
|
||||||
|
|
||||||
|
if (IS_IOS) {
|
||||||
|
resetInput = document.createElement('input');
|
||||||
|
resetInput.classList.add('for-ios-autocapitalization-fix');
|
||||||
|
document.body.appendChild(resetInput);
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://stackoverflow.com/a/55652503
|
||||||
|
export default function applyIosAutoCapitalizationFix(inputEl: HTMLElement) {
|
||||||
|
resetInput.focus();
|
||||||
|
inputEl.focus();
|
||||||
|
}
|
||||||
@ -189,6 +189,14 @@ div[role="button"] {
|
|||||||
color: var(--color-text-secondary) !important;
|
color: var(--color-text-secondary) !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.for-ios-autocapitalization-fix {
|
||||||
|
position: fixed;
|
||||||
|
font-size: 16px;
|
||||||
|
opacity: 0;
|
||||||
|
bottom: 1rem;
|
||||||
|
z-index: -1;
|
||||||
|
}
|
||||||
|
|
||||||
@keyframes grow-icon {
|
@keyframes grow-icon {
|
||||||
0% {
|
0% {
|
||||||
transform: scale(0.5);
|
transform: scale(0.5);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user