Skip to content

Keyboard focus() not working in Android platform after using RN image picker #26038

Closed
@sumudu-dewasurendra

Description

@sumudu-dewasurendra

React Native version:

"react-native": "0.57.8"
"react-native-image-picker": "^0.28.0"

React Native Environment Info:
System:
OS: Windows 10
CPU: (6) x64 Intel(R) Core(TM) i5-8500 CPU @ 3.00GHz
Memory: 1.71 GB / 7.85 GB
Binaries:
Yarn: 1.9.2 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
npm: 6.4.1 - C:\Program Files\nodejs\npm.CMD
IDEs:
Android Studio: Version 3.1.0.0 AI-173.4819257

Steps To Reproduce

  1. Type something on text input
  2. While focus on that using image picker to take photo or video
  3. Press select button to choose video or photo
  4. Keyboard is getting hide in android when coming back to the page

Describe what you expected to happen:

Keyboard should open in android platform when coming to the same page after using image picker

Snack, code example, screenshot, or link to a repository:

`renderView() {

    return(
      <View>
        <TouchableOpacity style={{marginLeft:28}} onPress={()=>{this.selectPhotoTapped()}}></TouchableOpacity>
        <TextInput
            style={{ maxHeight: Math.min(this.state.height+20,250),
                            height: Math.min(this.state.height+20,250)}}
            placeholderTextColor="#aaaaaa"
            autoGrow={true}
            autoFocus={false}
            multiline= {true}
            ref={ref => (this.ref = ref)}
            onChangeText={( postText) => this.setState({ postText})}
        />
      </View>                               
    )
    
  }`

`selectPhotoTapped() {

    const options = {
        quality: 1.0,
        maxWidth: 500,
        maxHeight: 500,
        storageOptions: {
            skipBackup: true
        }       
    };
  
    ImagePicker.showImagePicker(options, (response) => { 
    console.log('Response = ', response);

    if (response.didCancel) {

        console.log('User cancelled photo picker');
    }
    else if (response.error) {

        console.log('ImagePicker Error: ', response.error);
    }
    else if (response.customButton) {

        console.log('User tapped custom button: ', response.customButton);
    }
    else {
        let mediaType = response.type

        this.setState({
        mediaAttached: true,
        attachedMediaType: 2,
        mediaPath:response.uri,
        uploadMediaType:mediaType,           
        });
        this.UploadSelectedImageForGT()

    }

    });   
  
}`

`UploadSelectedImageForGT (){

      this.setState({ visiblePostsomething:false, mediaUploading: true})
      this.ref.focus(); 
        const uuidv4 = require('uuid/v4');
        if(this.state.mediaPath!= ''){
          try{
            const storage = firebase.storage();
            this.setState({fireBaseMediaPath: 'Appsurvey/Image/user1/'+uuidv4()+'img.jpg'})
              const mRef = storage.ref('portal1').child(this.state.fireBaseMediaPath);
              mRef.putFile(this.state.mediaPath, { contentType: this.state.uploadMediaType })
              .on('state_changed', snapshot => {
                                    }, err => {
                                    }, uploadedFile => {
                                      console.log('uploadedFile.downloadURL: ', uploadedFile.downloadURL);                                
                                      this.setState({PostMediaURL: uploadedFile.downloadURL, uploadSuccess: true, mediaUploading: false}) 
                                  });
            }catch(error){
                Alert.alert(error)
            }
        }      
    }`

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions