Skip to content

Controlled TextInput broken for Chinese (and other languages) in v0.54 on iOS #18403

Closed

Description

@danielsuo

Controlled TextInput breaks the Chinese pinyin keyboard's autocomplete feature. A similar issue was raised a year and a half ago (#8265) and fixed by #7496. However, it appears that others are having the same problem (#12599, #18260, #18379), but re-filing the issue with the template filled out and an example to reproduce.

Note that this works correctly in v0.53. This may have something to do with the big Text, TextInput refactor that dropped with v0.54 (Thanks, btw, @shergin and @hovox!).

I've included both a working (v0.53) and broken (v0.54) example below.

Environment

Environment:
OS: macOS High Sierra 10.13
Node: 9.3.0
Yarn: 1.3.2
npm: 5.6.0
Watchman: 4.9.0
Xcode: Xcode 9.2 Build version 9C40b
Android Studio: Not Found

Packages: (wanted => installed)
react: 16.2.0 => 16.2.0
react-native: 0.54.0 => 0.54.0

Expected Behavior

Typing on a US keyboard would bring up Chinese characters corresponding to letters typed.

Actual Behavior

Each new letter typed is considered individually, instead of along with the previous untranslated characters.

Shamelessly stealing an image from @Foru who did a nice job of showing the issue:

image

Steps to Reproduce

Unfortunately, expo hasn't updated to the latest version of React Native. I've prepared a small project that demonstrates the issue here. There is a working version on a branch here; same project, just using RN v0.53 instead of v0.54.

Activity

  1. changed the title [-]Controlled TextInput broken for Chinese (and other languages) in v0.54[/-] [+]Controlled TextInput broken for Chinese (and other languages) in v0.54 on iOS[/+] on Mar 16, 2018
  2. added
    Platform: iOS
    Ran Commands
    on Mar 16, 2018
  3. added
    Issue: Author Provided Repro
    Impact: Regression
    on Mar 16, 2018
  4. hramos commented on Mar 16, 2018

    @hramos
    Contributor

    Great bug report! Thanks for organizing all of the reports.

  5. added
    Component: TextInput
    on Mar 16, 2018
  6. added
    Missing Test Plan
    on Mar 16, 2018
  7. removed
    Missing Test Plan
    on Mar 16, 2018
  8. magicien commented on Mar 20, 2018

    @magicien
    Contributor

    @danielsuo I created a PR #18456 to fix this issue.
    I made sure that it works for Japanese, but I'm not sure about Chinese.
    I forked your test app and applied this change.
    Can you (or anyone who can speak Chinese) try this app to check if it's fixed?

  9. phalera commented on Mar 20, 2018

    @phalera

    if it has prop value or defaultvalue,you can't input Chinese

  10. magicien commented on Mar 20, 2018

    @magicien
    Contributor

    Thank you @booyeu! It might need to include #18278.
    Let me update the PR.

  11. magicien commented on Mar 20, 2018

    @magicien
    Contributor

    I updated the pull request and the sample app.
    And I tried one of Chinese keyboards. I hope it's expected behavior.
    screenshot

  12. phalera commented on Mar 20, 2018

    @phalera

    I changed and tried again , but it doesn't work . Do you have the prop "defaultValue" like defaultValue=this.props.value ? I found it ok that using defaultValue="test"

  13. 33 remaining items

  14. mmmulani commented on Jul 30, 2018

    @mmmulani
    Contributor

    I just landed a fix for this on iOS. Please try it out and let me know if it doesn't work for this problem.

  15. added
    Resolution: Fixed
    on Jul 30, 2018
  16. added a commit that references this issue on Aug 2, 2018
    ac707b3
  17. added a commit that references this issue on Aug 7, 2018
  18. Taphood commented on Aug 8, 2018

    @Taphood

    Which official release is going to have this bug fix? In RN0.56 I'm still seeing this issue

  19. krizpoon commented on Aug 9, 2018

    @krizpoon

    Based on @tsangwailam 's solution, I came up with the following component. It works as a drop-in replacement (almost, except for the ref prop). It would work with external changes to the text value too.

    import React, { PureComponent } from 'react';
    import { TextInput, Platform } from 'react-native';
    import ReactNativeVersion from 'react-native/Libraries/Core/ReactNativeVersion';
    
    export function fixComposeInput(Component) {
        return class MyTextInput extends PureComponent {
            state = { diffKey: 0, value: '', display: '' };
    
            static getDerivedStateFromProps(props, state) {
    
                if (!state || !state.props || props.value !== state.props.value) {
    
                    const value = props.value || '';
                    const display = state && state.display || '';
                    if (value !== display) {
                        const diffKey = ((state && state.diffKey) >>> 0) + 1;
                        return { props, value, display: value, diffKey };
                    }
                }
    
                return { props };
            }
    
            handleChange = text => {
                // keep track of the display value
                this.setState({ display: text }, () => {
                    const { onChangeText } = this.props;
                    onChangeText && onChangeText(text);
                });
            };
    
            render() {
                const { refInput, value: valueProp, onChangeText, ...inputProps } = this.props;
                const { value, diffKey } = this.state;
    
                return <Component
                    { ...inputProps }
                    key={ `TextInput${diffKey}` }
                    ref={ refInput }
                    value={ value }
                    onChangeText={ this.handleChange }
                />;
            }
        };
    }
    
    const rnVer = ReactNativeVersion.version.minor;
    
    export default (Platform.OS === 'ios' && rnVer >= 54 && rnVer <= 56 ? fixComposeInput(TextInput) : TextInput);
    
  20. added a commit that references this issue on Aug 21, 2018
    bb1c488
  21. added a commit that references this issue on Aug 31, 2018
    2b8be32
  22. added a commit that references this issue on Sep 6, 2018
    142c71c
  23. locked as resolved and limited conversation to collaborators on Jul 30, 2019
  24. added
    Resolution: Locked
    on Jul 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Component: TextInputImpact: RegressionIssue: Author Provided ReproPlatform: iOSRan CommandsResolution: FixedResolution: Locked

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions