【问题标题】:Why does ScrollView make the screen go up?为什么 ScrollView 会让屏幕向上?
【发布时间】:2021-12-11 16:47:21
【问题描述】:

当我使用ScrollView 时,屏幕会上升,甚至滚动,但不起作用。当我使用KeyboardAvoidingView 时,它也有同样的问题。有什么问题?

export default function AuthLayout({ children }) {
  const dismissKeyboard = () => {
    Keyboard.dismiss();
  };

  return (
    <ScrollView style={{ flexGrow: 1 }}>
      <TouchableWithoutFeedback
        style={{ flex: 1 }}
        onPress={dismissKeyboard}
        disabled={Platform.OS === "web"}
      >
        <SAuthLayout>{children}</SAuthLayout>
      </TouchableWithoutFeedback>
    </ScrollView>
  );
}

我的应用程序的屏幕截图和下面的灰色部分是具有ScrollView的空间:

【问题讨论】:

    标签: react-native scrollview


    【解决方案1】:

    根据内存,您应该用Viewflex 封装您的ScrollView

    export default function AuthLayout({ children }) {
      const dismissKeyboard = () => {
        Keyboard.dismiss();
      };
    
      return (
        <View style={{ flex: 1 }}>
        <ScrollView>
          <TouchableWithoutFeedback
            style={{ flex: 1 }}
            onPress={dismissKeyboard}
            disabled={Platform.OS === "web"}
          >
            <SAuthLayout>{children}</SAuthLayout>
          </TouchableWithoutFeedback>
        </ScrollView>
        </View>
      );
    }
    

    【讨论】:

    • 我试过了。但它显示相同的屏幕。
    • 让我检查一下我的笔记我想说这是有原因的以及为什么我使用FlatList
    • 如果我使用 FlatList,它只会显示一个白屏。
    • 是的,我遇到了一个特定的过程。在移动设备上,但当我回来时,我会检查我的反应原生笔记的回购。如果您使用示例数据编辑您的问题,我可以构建一个更好的示例
    • 你能帮我吗?或者只是给我一些线索?
    猜你喜欢
    • 2022-11-01
    • 1970-01-01
    • 2019-03-26
    • 1970-01-01
    • 1970-01-01
    • 2020-02-01
    • 2016-05-10
    • 1970-01-01
    • 2016-10-05
    相关资源
    最近更新 更多