1

Expo SDK v27.0.0 based on React-Native 0.55

I have a value I want numeric values only so I filter the input using onChangeText. On Android you see the non-numeric value but it is then erased but on IOS all characters are displayed until another digit is pressed. The code is as follows:-

state = {
    appCode: ""
};

render() {
    console.log(this.state.appCode);
    return (
        <View style={styles.container}>
            <TextInput
                label={"App Code"}
                placeholder={"App Code"}
                keyboardType="phone-pad"
                maxLength={6}
                onChangeText={text => {
                    this.setState({ appCode: text.replace(/\D/g, "") });
                }}
                value={this.state.appCode}
            />
        </View>
    );
}

I can see on the console that the appCode value is being updated correctly but the value on the IOS screen doesn't follow the variable. If I enter

1*#+

that is displayed on the IOS screen (the console shows this.state.appCode is 1 for each keypress) but then pressing, for example, 7 and the value displayed on the screen is updated to

17

All the documentation shows this is the correct way to filter the input, and on Android it works but not on IOS

2 Answers 2

3

This is a known bug - only fix for now seems to revert to pre-Jan 2018 React Native:

https://github.com/facebook/react-native/issues/18874

(answering as SO won't let me just comment)

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks @dan674, I've been searching for an answer but didn't find that issue
0

A work around can be - before setting the state on onChangeText, first check that the changed text does not contain any non-numeric value and if does then simply do not update the state. In this way, it should work on both iOS and android and also you will not see the non numeric entries in TextInput.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.