在这里,我正在尝试做非常基本的事情。首先,我专注于TextInput,同时专注于我正在使用imagepicker拍照。在我拿走它并回来之后我的键盘变得隐藏起来。保存图像后,我使用了 focus() 方法。在 iOS 中,它得到了关注。但是在android中它不起作用。我需要再次触摸 textinput 才能打开它。是android平台的问题还是我错了请告诉我。示例代码如下。谢谢你。
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)
}
}
}