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

TextInput has performance issue in ^0.55 #18916

Closed
3 tasks done
armenbadalyan opened this issue Apr 18, 2018 · 19 comments
Closed
3 tasks done

TextInput has performance issue in ^0.55 #18916

armenbadalyan opened this issue Apr 18, 2018 · 19 comments
Labels
Component: TextInput Related to the TextInput component. Resolution: Locked This issue was locked by the bot.

Comments

@armenbadalyan
Copy link

armenbadalyan commented Apr 18, 2018

Environment

Environment:
OS: macOS High Sierra 10.13.3
Node: 8.8.0
Yarn: 1.3.2
npm: 5.4.2
Watchman: 4.7.0
Xcode: Xcode 9.2 Build version 9C40b
Android Studio: Not Found

Packages: (wanted => installed)
react: ^16.0.0 => 16.3.2
react-native: ^0.55.0 => 0.55.3

Steps to Reproduce

  1. Create a new project with react-native init
  2. Replace App.js content with the following code:
import React, { Component } from 'react';
import {    
    TextInput,    
    View
} from 'react-native';

type Props = {};
export default class App extends Component<Props> {
    state = {
        text: ''
    }

    onChangeText = (event) => {
        const { text } = event.nativeEvent
        this.setState({ text })
    }

    render() {
        return (<View>
            <TextInput value={this.state.text} onChange={this.onChangeText} />
        </View>);
    }
}
  1. Run the app on Android device with react-native run-android
  2. Type and clear some text into the TextInput several times

Expected Behavior

Input should perform the same after several type/clear cycles.

Actual Behavior

Input becomes laggy after a couple of type/clear cycles.

@react-native-bot react-native-bot added the Component: TextInput Related to the TextInput component. label Apr 18, 2018
@ilonashub
Copy link

Having the same issue exactly... no need to clear the text even - if I type 3-4 lines it starts to become very laggy.

@wuyunqiang
Copy link

may be you can try like that:

class Input extends Component{
    constructor(){
        super();
        this.amount=0;
    }
    componentWillReceiveProps(nextProps) {
        if(this.props.amount!=nextProps.amount){
            this._textInput&&this._textInput.setNativeProps({text: nextProps.amount});//重点
        }
    }
    setAmout = (text)=>{
        this.amount = text;
    };

    getAmout = ()=>{
        this.props.getAmout&&this.props.getAmout(this.amount);
    };

    render(){
        return (<View style={styles.inputStyle}>
          <TextInput
                    ref={component => this._textInput = component}
                    numberOfLines={1}
                    underlineColorAndroid={'transparent'}
                    style={{padding:0,backgroundColor:'white',width:SCALE(400)}}
                    maxLength={10}
                    keyboardType = {'numeric'}
                    onChangeText={this.setAmout}
                    onEndEditing={this.getAmout}
                />
        </View>)
    }
}
   <Input
                    getAmout = {this.getAmount}
                    amount = {this.state.amount}/>

wuyunqiang/ReactNativeUtil#50

@armenbadalyan
Copy link
Author

@wuyunqiang Thanks for the suggestion. In my case I can't use uncontrolled TextInput (ref + setNativeProps) and I think the majority of developers are using the recommended way of setting text via value prop.

@Waltari10
Copy link

Waltari10 commented May 23, 2018

I think this is happening with defaultValue as well. If someone could confirm that would be great.

@Waltari10
Copy link

Waltari10 commented May 23, 2018

You can also set the initial textInput value like this, but this also seems to have the same performance issue:

<TextInput onChange={this.onChangeText}>{this.state.text}</TextInput>

@ilonashub
Copy link

@Waltari10 when I added the text as a child inside TextInput it made things much worst. Putting that as value attribute did better for me

@Waltari10
Copy link

@ilonashub Yep. I think setNativeProps is probably the best option at this point, just like in your example.

@shafy
Copy link

shafy commented May 23, 2018

Have the same issue with setting the value props... Is this related to #18874?

@aspidvip
Copy link

aspidvip commented May 29, 2018

#19464

@stueynet
Copy link

It would seem this is a pretty significant regression as it causes any react native app using text inputs to be laggy on android. What would be a good way to escalate this?

@shafy
Copy link

shafy commented May 31, 2018

I don't know @stueynet but we should definitely bump this up somehow...

@aspidvip
Copy link

aspidvip commented Jun 1, 2018

@shafy
Copy link

shafy commented Jun 14, 2018

I'm looking through the 0.56 pre-release bug fixes (https://github.com/react-native-community/react-native-releases/blob/master/CHANGELOG.md#056) and can't see this issue mentioned. Is this not an issue everyone has?

@stueynet
Copy link

Everyone who has a text field has this issue on Android. I am not sure the next steps other than Tweeting.

@davidpaulsson
Copy link

Any update on this issue? It's quite a severe regression :/ Fingers crossed it will get resolved quickly.

@shafy
Copy link

shafy commented Jun 20, 2018

Do we know the root cause of this? I understand that the RN team is busy with other, also important things, but maybe we could work on something?

@fhadsheikh
Copy link

There's an open PR to revert the changes that caused this regression. #19645

@shafy
Copy link

shafy commented Jun 21, 2018

I now manually added the patch from here: #19126 and it does fix the issue. Hopefully we can have it in the next release.

@kelset
Copy link
Contributor

kelset commented Jun 21, 2018

Hey folks, as @shafy there is a PR and I'll try to ensure it will get merged ASAP and added to 0.56 since it's pretty massive. That said, since this & #19126 are duplicate and that the author of the PR is moving the conv forward in the other issue I'll close this to reduce redundancy.

@kelset kelset closed this as completed Jun 21, 2018
@facebook facebook locked as resolved and limited conversation to collaborators Jun 21, 2019
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jun 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Component: TextInput Related to the TextInput component. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests