Skip to content

[Android] Some devices TextInput .focus() does not work when editable is false  #30597

Closed

Description

@vuongkien

Environment
react: 16.11.0
react-native: 0.62.2

const inputAddPoints = useRef(null);
const inputAddName = useRef(null);

const onAddName = () => {
    if (name.length > 0) {
      setNameAdded(true);
      inputAddPoints.current.focus();
    }
  };

 const onEditAddName = () => {
    setNameAdded(!nameAdded);
    if (!nameAdded) {
      inputAddName.current.focus();
    }
  };

 <View style={styles.viewInput}>
            <TextInput
              ref={inputAddName}
              placeholder="Enter Driver's Name"
              shadowed={false}
              style={renderStyleAddNameInput()}
              value={name}
              onChangeText={setName}
              editable={!nameAdded}
              onFocus={_onFocusInput(ADD_NAME)}
              onSubmitEditing={_onSubmitAddName}
              selectTextOnFocus
            />
            {nameAdded && (
              <View style={styles.iconCheck}>
                <Ionicons
                  size={30}
                  color={Colors.button}
                  name="md-checkmark-circle"
                />
              </View>
            )}
          </View>
          <View style={styles.type}>
            <Text style={styles.textType}>Name</Text>
          </View>
          <View style={styles.bgButton}>
            <TouchableOpacity
              onPress={!nameAdded ? onAddName : onEditAddName}
              disabled={disableAddNameButton()}
              style={[styles.verifyButton, renderStyleAddNameButton()]}>
              <Text style={styles.txtBtn}>{!nameAdded ? 'ADD' : 'EDIT'}</Text>
            </TouchableOpacity>
          </View>
        </View>

Hi guys, there is my code, when I press onAddName function I can focus inputAddPoints input. But when I click onEditAddName I cannot focus inputAddName, Please help me any solution, Thanks!

Activity

  1. added
    Component: TextInput
    Platform: Android
    Needs: Environment Info
    and removed on Dec 16, 2020
  2. github-actions commented on Dec 16, 2020

    @github-actions
    ⚠️ Missing Environment Information
    ℹ️ Your issue may be missing information about your development environment. You can obtain the missing information by running react-native info in a console.
  3. github-actions commented on Dec 17, 2021

    @github-actions

    This issue is stale because it has been open 365 days with no activity. Remove stale label or comment or this will be closed in 7 days.

  4. added
    Stale
    on Dec 17, 2021
  5. locked as resolved and limited conversation to collaborators on Dec 30, 2021
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: TextInputNeeds: Author FeedbackNeeds: Environment InfoPlatform: AndroidStale

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions