Skip to content

[Android] Value resets when re-rendering styles #101

@akuul

Description

@akuul

Describe the bug
If I have dynamic styling, the MaskedTextInput resets itself. This doesn't seem to happen with a normal React Native TextInput. This can be testable side-by-side having both.

I have applied changes from 1.2.3 on getExportedCustomDirectEventTypeConstants, due to a Android build error. However, I have used 1.2.3 and I had the same results.

Code snippet

<...>
const [amount, setAmount] = useState('')

const amountExceeded = Number(amount) > 500

 <MaskedTextInput
              mask="[$99990].[09]"
              value={amount}
              keyboardType="numeric"
              allowedKeys="0123456789,."
              onChangeText={(val) => setAmount(val)}
              placeholder="0"
              customNotations={CUSTOM_NOTATION}
              placeholderTextColor={theme.color.blueJasmine}
              style={[styles.amount, amountExceeded && styles.amountExceeded]}
            />
            <TextInput
              value={amount}
              keyboardType="numeric"
              onChangeText={(val) => setAmount(val)}
              placeholder="1"
              placeholderTextColor={theme.color.blueJasmine}
              style={[styles.amount, amountExceeded && styles.amountExceeded]}
            />

const styles = StyleSheet.create({
  amount: { color: 'black' },
  amountExceeded: { color: 'blue' },
});

To Reproduce
Steps to reproduce the behavior:
Copy the snippet.

Change value of React Native TextInput to 600, you will see text of input become blue for both inputs.
Change value of MaskedTextInput and you will see the text of input becoming orange briefly and then resetting back to empty.

Expected behavior
Dynamically applying styles should not reset the MaskedTextInput. Removing amountExceeded && styles.amountExceeded works fine.

Smartphone (please complete the following information):

  • Desktop OS: macOS
  • Device: Pixel 7 Pro
  • OS: Android 14
  • RN version: 0.71.17
  • RN architecture: Old
  • JS engine: Hermes
  • Library version: 1.3.5

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions