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

react native - Why does Keyboard.dismiss not work in App.js? - Stack Overflow

programmeradmin3浏览0评论

I created the following component in react-native:

import { TouchableWithoutFeedback, Keyboard } from "react-native";

export default function DismissKeyboard({ children }) {
  return (
    <TouchableWithoutFeedback onPress={Keyboard.dismiss}>
      {children}
    </TouchableWithoutFeedback>
  );
}

It works fine if I use it in a screen rendered by App.js, like this:

export default function StartGameScreen(props) {
  return (
    <DismissKeyboard>
      <View style={styles.container}>
        <Text style={styles.text}>Guess my Number</Text>
        <NumberInput onSet={(number) => props.onSet(number)} />
      </View>
    </DismissKeyboard>
  );
}

But it doesn't work if I use it directly in App.js, like this:

export default function App() {
  
  [...]

  return (
    <DismissKeyboard>
      <>
        <StatusBar style="auto" />
        {screen}
      </>
    </DismissKeyboard>
  );
}

Any idea of why it doesn't work in App.js?

发布评论

评论列表(0)

  1. 暂无评论