最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - React-Native TextInput with focus but without keyboard showing - Stack Overflow

programmeradmin3浏览0评论

I'm developing an inventory system for my father's pany and on of its requisites is to be able to use an external Barcode/QR Code scanner.

I've developed everything using the camera as well, but I really need to use the scanner whithout showing the keyboard.

Do any of you guys know if it's possible? if not, can it be done in any other way?

I'm developing an inventory system for my father's pany and on of its requisites is to be able to use an external Barcode/QR Code scanner.

I've developed everything using the camera as well, but I really need to use the scanner whithout showing the keyboard.

Do any of you guys know if it's possible? if not, can it be done in any other way?

Share Improve this question edited Jan 8, 2020 at 4:41 Tharindu Ketipearachchi 1,0661 gold badge9 silver badges26 bronze badges asked Jan 8, 2020 at 3:30 Gustavo Martins do SantosGustavo Martins do Santos 311 silver badge2 bronze badges 7
  • I have made a little search about this and seen that there is still not a solution for this on react native side. So I think you might need to right some native code to achieve that. – Bora Sumer Commented Jan 8, 2020 at 5:01
  • This may be what you are after: stackoverflow./questions/49199745/… – CampbellMG Commented Jan 8, 2020 at 5:35
  • what is the purpose of using the TextInput here? – Gautam Shrivastav Commented Jan 8, 2020 at 5:49
  • I don't find any requrement of using TextInput if not at all you need user interaction. – Ravi Commented Jan 8, 2020 at 12:11
  • 1 @Ravi The scanner works as an axternal keyboard, it writes the content and presses enter, thats why i nees a TextInput, so i can register the data – Gustavo Martins do Santos Commented Jan 8, 2020 at 14:45
 |  Show 2 more ments

2 Answers 2

Reset to default 3

There is a property called showSoftInputOnFocus in newer react-native versions. Setting this to false keeps the keyboard hidden.

<TextInput showSoftInputOnFocus={false} autoFocus={true}..../>

Working for me on v0.60.0

Wrap TouchableOpacity with ScrollView without any props which enables tapto open keyboard work. This Works both on ios and android now!

const [openKeyboard, setOpenKeyboard] = useState(autoFocus);

const onPressInput = useCallback(() => {
    inputRef.current.focus();
    setOpenKeyboard(true)
}, [inputRef]);

  <ScrollView
    >
        <TouchableOpacity
            activeOpacity={1}
            style={[styles.container, style]}
            onPress={onPressInput}

        >
            {renderInputBox()}
            <View style={{ width: 0, height: 0 }}>
                <TextInput
                    keyboardType="numeric"
                    returnKeyType="done"
                    autoFocus={openKeyboard}
                    maxLength={codeLength}
                    ref={inputRef}
                />
            </View>
        </TouchableOpacity>
    </ScrollView>
发布评论

评论列表(0)

  1. 暂无评论