搜索输入框由RN的textInput组件实现,拍摄输入后点击搜索,搜索结果依然是输入前的文本。
import React, { useState } from 'react';
import { View, TextInput, Button } from 'react-native';
export default function App() {
const [input1Value, setInput1Value] = useState('');
const [input2Value, setInput2Value] = useState('');
return (
<View style={{paddingTop:100}}>
<TextInput
value={input1Value}
onChangeText={text => setInput1Value(text)}
/>
<Button
title="传递值"
onPress={() => setInput2Value(input1Value)}
/>
<TextInput
value={input2Value}
onChangeText={text => setInput2Value(text)}
/>
</View>
);
}
302版本上,拍摄输入时RNOH的TextInputComponentInstance::onChange方法中没有正确回调,新版本RNOH没有问题,需要使用规避方案规避。
在@rnoh/react-native-openharmony/src/main/cpp/RNOHCorePackage/ComponentInstances/TextInputComponentInstance.cpp文件中TextInputComponentInstance::onChange方法内加入onChange事件回调,如下代码所示: