Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Cannot paste magic code on mWeb iOS #23254

Merged
12 changes: 5 additions & 7 deletions src/components/MagicCodeInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,7 @@ 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.
marcaaron marked this conversation as resolved.
Show resolved Hide resolved
const isMobileSafari = Browser.isMobileSafari();
const isBrowser = Boolean(Browser.getBrowser());

return (
<>
Expand All @@ -323,7 +320,7 @@ function MagicCodeInput(props) {
>
<Text style={[styles.magicCodeInput, styles.textAlignCenter]}>{decomposeString(props.value, props.maxLength)[index] || ''}</Text>
</View>
<View style={[StyleSheet.absoluteFillObject, styles.w100, isMobileSafari ? styles.bgTransparent : styles.opacity0]}>
<View style={[StyleSheet.absoluteFillObject, styles.w100, styles.bgTransparent]}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we always passing styles.bgTransparent here? Can you add some comment in the code above this to explain what purpose that serves?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tienifr bump!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading the comment made me wonder why would we need this now in the first place, what does it do?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is that we're basically doing a "hidden input" trick here.

Copy link
Collaborator

@Santhosh-Sellavel Santhosh-Sellavel Aug 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just curious. Because now we do the trick with styles and props on the TextInput itself. So I don't understand why would need this, let me know if am missing anything thanks!

<TextInput
ref={(ref) => (inputRefs.current[index] = ref)}
autoFocus={index === 0 && props.autoFocus && !props.shouldDelayFocus}
Expand All @@ -348,8 +345,9 @@ function MagicCodeInput(props) {
onKeyPress={onKeyPress}
onPress={(event) => onPress(event, index)}
onFocus={onFocus}
caretHidden={isMobileSafari}
inputStyle={[isMobileSafari ? styles.magicCodeInputTransparent : undefined]}
selectionColor="transparent"
marcaaron marked this conversation as resolved.
Show resolved Hide resolved
textInputContainerStyles={[styles.borderNone]}
tienifr marked this conversation as resolved.
Show resolved Hide resolved
inputStyle={[styles.magicCodeInputTransparent, isBrowser ? styles.magicCodeInputTransparentWebKit : undefined]}
Copy link
Contributor Author

@tienifr tienifr Jul 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The isBrowser check is to prevent warning since WebkitTextFillColor prop is only available on Web platforms.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move the isBrowser check into the styles.js code?

accessibilityRole={CONST.ACCESSIBILITY_ROLE.TEXT}
/>
</View>
Expand Down
3 changes: 3 additions & 0 deletions src/styles/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -2535,6 +2535,9 @@ const styles = {

magicCodeInputTransparent: {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separating magicCodeInputTransparent and magicCodeTransparentWebkit since color: transparent is required on all platforms while the rest are for Web & mWeb only. Without color: transparent we may get this:

image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok so my suggestion, is to take the isBrowser check and put it in styles and make this name more generic

inputTransparent: {
    color: 'transparent',
    ...(Browser.getBrowser() ? {
        caretColor: 'transparent',
        ...etc
    } : {}),
},

Can we do something like this?

color: 'transparent',
},

magicCodeInputTransparentWebKit: {
caretColor: 'transparent',
WebkitTextFillColor: 'transparent',
// After setting the input text color to transparent, it acquires the background-color.
Expand Down
Loading