react-native-masked-text icon indicating copy to clipboard operation
react-native-masked-text copied to clipboard

beforeMaskApply

Open diegorodriguesvieira opened this issue 8 years ago • 8 comments

Hello, how to avoid this behavior? unnamed

diegorodriguesvieira avatar Feb 16 '17 22:02 diegorodriguesvieira

Hi =)

Sorry, unfortunately, this is a bug of a text-input component of the react-native.

It don't block the controlled input before the state is applied.

bug_input_react_native mov

I will open an issue to react-native's repository and keep this issue opened for feature fix.

Thanks for report.

bhrott avatar Feb 17 '17 22:02 bhrott

Thanks for help! =)

diegorodriguesvieira avatar Feb 20 '17 11:02 diegorodriguesvieira

You can prevent this by wrapping the masked text input with a custom component. Pass a "type" prop to the wrapper component, then at the shouldComponentUpdate lifecycle function return false if the "type" prop equals "masked".

viniciusfonseca avatar May 06 '17 13:05 viniciusfonseca

@viniciusfonseca, do you mind elaborating more on the workaround you mentioned? I can't seem to get it working correctly

agarcia17 avatar Jun 27 '17 03:06 agarcia17

@agarcia17

class FormField extends React.Component { // wrapper component
    maskedInputRef = null
    
    static get TYPE() {
        return {
            DATE: 'date',
            MASKED: 'masked'
        }
    }

    shouldComponentUpdate() {
        return this.props.type !== FormField.TYPE.MASKED // return false if type prop equals masked
    }

    render() {
        switch (this.props.type) {
            case FormField.TYPE.MASKED:
                return <TextInputMask onBlur={this.props.onChange} /> // render TextInputMask here
        }
    }
}

viniciusfonseca avatar Jun 27 '17 13:06 viniciusfonseca

@viniciusfonseca will try that out! thanks a bunch!

agarcia17 avatar Jun 28 '17 04:06 agarcia17

@agarcia17

class FormField extends React.Component { // wrapper component
    maskedInputRef = null
    
    static get TYPE() {
        return {
            DATE: 'date',
            MASKED: 'masked'
        }
    }

    shouldComponentUpdate() {
        return this.props.type !== FormField.TYPE.MASKED // return false if type prop equals masked
    }

    render() {
        switch (this.props.type) {
            case FormField.TYPE.MASKED:
                return <TextInputMask onBlur={this.props.onChange} /> // render TextInputMask here
        }
    }
}

Tested and still getting the ugly effect, @viniciusfonseca do you have any reproducible code without the flicker? 🙏

Thanks

frangeris avatar Mar 19 '19 15:03 frangeris

Same for me!

Benzer1406 avatar Apr 02 '19 10:04 Benzer1406