I have a app on an Android Scanner which can accept scanned input as if it were user typed. No keyboard required. We're wanting to be able to listen for that input without a TextInput similar to how React Web would work with onKeyDown functionality. Is such a thing possible in Reach Native?
Closest thing I've found but it seems to be no longer maintained and brittle, so I'm hesitant to put this in and hack it to get it working.
I have a app on an Android Scanner which can accept scanned input as if it were user typed. No keyboard required. We're wanting to be able to listen for that input without a TextInput similar to how React Web would work with onKeyDown functionality. Is such a thing possible in Reach Native?
Closest thing I've found https://www.npmjs.com/package/react-native-keyevent but it seems to be no longer maintained and brittle, so I'm hesitant to put this in and hack it to get it working.
Example:
javascript
import React, { useRef } from 'react'; import { WebView } from 'react-native-webview';
const App = () => { const webViewRef = useRef(null);
const handleMessage = (event) => {
const data = event.nativeEvent.data;
console.log('Captured input:', data); };
return (
<WebView
ref={webViewRef}
source={{ html: '<input type="text" id="inputField" />' }}
onMessage={handleMessage}
injectedJavaScript={`
document.getElementById('inputField').addEventListener('input', (e) => {
window.ReactNativeWebView.postMessage(e.target.value);
});
`}
/> ); };
export default App;
Example:
import React, { useState } from 'react';
import { View, Text, Button } from 'react-native';
const App = () => {
const [input, setInput] = useState('');
const handleButtonPress = (value) => {
setInput((prev) => prev + value);
};
return (
<View>
<Text>Input: {input}</Text>
<View>
<Button title="1" onPress={() => handleButtonPress('1')} />
<Button title="2" onPress={() => handleButtonPress('2')} />
<Button title="3" onPress={() => handleButtonPress('3')} />
</View>
</View>
);
};
export default App;
javascript
import React, { useState } from 'react';
import { View, Text, Button, Clipboard } from 'react-native';
const App = () => {
const [input, setInput] = useState('');
const handlePaste = async () => {
const text = await Clipboard.getString();
setInput(text);
};
return (
<View>
<Text>Input: {input}</Text>
<Button title="Paste from Clipboard" onPress={handlePaste} />
</View>
);
};
export default App;