Skip to content

Commit

Permalink
allow pasting magic codes in iOS Safari
Browse files Browse the repository at this point in the history
  • Loading branch information
akinwale committed May 11, 2023
1 parent 1d951e6 commit 7a7d3d6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/components/MagicCodeInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import CONST from '../CONST';
import Text from './Text';
import TextInput from './TextInput';
import FormHelpMessage from './FormHelpMessage';
import * as Browser from '../libs/Browser';

const propTypes = {
/** Name attribute for the input */
Expand Down Expand Up @@ -84,6 +85,10 @@ function MagicCodeInput(props) {
const [focusedIndex, setFocusedIndex] = useState(0);
const [editIndex, setEditIndex] = useState(0);

// For Safari on iOS, a transparent background will be used instead of opacity: 0, so that magic code pasting can work.
// Alternate styling will be applied based on this condition.
const isMobileSafari = Browser.isMobileSafari();

useImperativeHandle(props.innerRef, () => ({
focus() {
setFocusedIndex(0);
Expand Down Expand Up @@ -266,7 +271,7 @@ function MagicCodeInput(props) {
<View style={[styles.textInputContainer, focusedIndex === index ? styles.borderColorFocus : {}]}>
<Text style={[styles.magicCodeInput, styles.textAlignCenter]}>{decomposeString(props.value)[index] || ''}</Text>
</View>
<View style={[StyleSheet.absoluteFillObject, styles.w100, styles.opacity0]}>
<View style={[StyleSheet.absoluteFillObject, styles.w100, isMobileSafari ? styles.bgTransparent : styles.opacity0]}>
<TextInput
ref={(ref) => (inputRefs.current[index] = ref)}
autoFocus={index === 0 && props.autoFocus}
Expand All @@ -291,6 +296,8 @@ function MagicCodeInput(props) {
onKeyPress={onKeyPress}
onPress={(event) => onPress(event, index)}
onFocus={onFocus}
caretHidden={isMobileSafari}
inputStyle={[isMobileSafari ? styles.magicCodeInputTransparent : undefined]}
/>
</View>
</View>
Expand Down
4 changes: 4 additions & 0 deletions src/styles/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -2332,6 +2332,10 @@ const styles = {
lineHeight: variables.inputHeight,
},

magicCodeInputTransparent: {
color: 'transparent',
},

iouAmountText: {
...headlineFont,
fontSize: variables.iouAmountTextSize,
Expand Down

0 comments on commit 7a7d3d6

Please sign in to comment.