在将 TextInput Ref 传递给子组件时,我曾经在子组件中使用 forwardRef 捕获 ref。但是这里我没有在子组件中使用forwardRef,虽然我已经导入了。我正在使用最新的 React 和 React Native 包。
import React, {forwardRef} from "react";
export interface TextInput_Write_A_Comment_In_Comment_Props{
t_Width: number,
t_Height: number,
onChange__Comments:(some_input_string:string)=>void
comment_post:()=>void,
android_KeyBoard_Focused__onPressIn__testing_1:(nativeEvent: any)=>void,
TextInput_commentRef: React.RefObject<TextInput>,
}
const TextInput_Write_A_Comment_In_Comment: React.FC<TextInput_Write_A_Comment_In_Comment_Props> = (
props: TextInput_Write_A_Comment_In_Comment_Props,
)=> {
const Text_Input__Editing_comment_State: string = useAppSelector(editing__comment_string_for_Tagging);
return (
<View style={{
flexDirection: 'column',
height: props.t_Height/12,
width: props.t_Width,
}}>
<View style={{
// ----__-_-whatever----__-_-
}}>
<TextInput
style={{
...TextInput_Write_A_Comment_In_Comment_Styles.commentInput,
color: 'black',
}}
placeholder="Write a comment..."
autoFocus={false}
ref = {props.TextInput_commentRef}
onSubmitEditing= {Keyboard.dismiss}
autoCapitalize="none"
keyboardType="default"
onChangeText= {(feedTextInputValue: string) => props.onChange__Comments(feedTextInputValue)}
value= {Text_Input__Editing_comment_State}
onPressIn= {props.android_KeyBoard_Focused__onPressIn__testing_1}
maxLength={244} //250 ,244 otherwise may not invoke the alert message.
/>
<View style={{
// ----__-_-whatever----__-_-
}}
>
<TouchableOpacity
onPress={ () => Alert.alert('not implemented yet')}>
<Icon
size={40}
style= {TextInput_Write_A_Comment_In_Comment_Styles.selected_Items_Button_Text} name={'ios-attach'}/>
</TouchableOpacity>
</View>
<View style={{
// ----__-_-whatever----__-_-
}}
>
<TouchableOpacity
onPress={()=>props.comment_post()}
style={TextInput_Write_A_Comment_In_Comment_Styles.rounded_back_groud}
>
<MTI
size={45}
style={{
color: 'white',
textAlign: 'left',
alignSelf: 'stretch',
fontSize: 40
}}
name={'send-circle'}
/>
</TouchableOpacity>
</View>
</View>
</View>
);
};
const TextInput_Write_A_Comment_In_Comment_Styles = StyleSheet.create({
// ......
});
export default TextInput_Write_A_Comment_In_Comment;