diff --git a/src/components/MagicCodeInput.js b/src/components/MagicCodeInput.js index cea98cfd3747..a52cee04af8a 100644 --- a/src/components/MagicCodeInput.js +++ b/src/components/MagicCodeInput.js @@ -12,7 +12,6 @@ import FormHelpMessage from './FormHelpMessage'; import {withNetwork} from './OnyxProvider'; import networkPropTypes from './networkPropTypes'; import useNetwork from '../hooks/useNetwork'; -import * as Browser from '../libs/Browser'; const propTypes = { /** Information about the network */ @@ -264,11 +263,6 @@ function MagicCodeInput(props) { } }; - // We need to check the browser because, in iOS Safari, an input in a container with its opacity set to - // 0 (completely transparent) cannot handle user interaction, hence the Paste option is never shown. - // Alternate styling will be applied based on this condition. - const isMobileSafari = Browser.isMobileSafari(); - return ( <> @@ -287,7 +281,8 @@ function MagicCodeInput(props) { > {decomposeString(props.value, props.maxLength)[index] || ''} - + {/* Hide the input above the text. Cannot set opacity to 0 as it would break pasting on iOS Safari. */} + (inputRefs.current[index] = ref)} autoFocus={index === 0 && props.autoFocus && !props.shouldDelayFocus} @@ -311,8 +306,11 @@ function MagicCodeInput(props) { }} onKeyPress={onKeyPress} onFocus={(event) => onFocus(event, index)} - caretHidden={isMobileSafari} - inputStyle={[isMobileSafari ? styles.magicCodeInputTransparent : undefined]} + // Manually set selectionColor to make caret transparent. + // We cannot use caretHidden as it breaks the pasting function on Android. + selectionColor="transparent" + textInputContainerStyles={[styles.borderNone]} + inputStyle={[styles.inputTransparent]} accessibilityRole={CONST.ACCESSIBILITY_ROLE.TEXT} /> diff --git a/src/styles/styles.js b/src/styles/styles.js index 0fe77205e9ad..aa6c1fe360be 100644 --- a/src/styles/styles.js +++ b/src/styles/styles.js @@ -2538,14 +2538,21 @@ const styles = { lineHeight: variables.inputHeight, }, - magicCodeInputTransparent: { + // Manually style transparent, in iOS Safari, an input in a container with its opacity set to + // 0 (completely transparent) cannot handle user interaction, hence the Paste option is never shown + inputTransparent: { color: 'transparent', - caretColor: 'transparent', - WebkitTextFillColor: 'transparent', - // After setting the input text color to transparent, it acquires the background-color. - // However, it is not possible to override the background-color directly as explained in this resource: https://developer.mozilla.org/en-US/docs/Web/CSS/:autofill - // Therefore, the transition effect needs to be delayed. - transitionDelay: '99999s', + // These properties are available in browser only + ...(Browser.getBrowser() + ? { + caretColor: 'transparent', + WebkitTextFillColor: 'transparent', + // After setting the input text color to transparent, it acquires the background-color. + // However, it is not possible to override the background-color directly as explained in this resource: https://developer.mozilla.org/en-US/docs/Web/CSS/:autofill + // Therefore, the transition effect needs to be delayed. + transitionDelay: '99999s', + } + : {}), }, iouAmountText: {