【问题标题】:React native Scrollview not scrolling at all反应原生 Scrollview 根本不滚动
【发布时间】:2021-10-20 16:39:59
【问题描述】:

我正在构建一个 react native 应用程序,我对某些内容使用滚动视图,但它没有滚动,我不知道为什么。 我尝试了很多东西,到处添加flex: 1,但这些都不起作用。

提前感谢您的帮助。

<KeyboardAwareScrollView contentContainerStyle={authStyles.container}>
          <Layout isBackArrow={true}>
              <BottomLayout>
                  <Header fontSize={20}>
                      <Text>Nous sommes</Text> {'\n'}
                      <Text style={authStyles.headerBold}>
                          Ravis de te revoir!
                      </Text>
                      {'\n'}
                      <Caption>Je me connecte via:</Caption>
                  </Header>
                  <View style={authStyles.socialIconView}>
                      <SocialIcon type="facebook" onPress={onFacebookLogin} />
                      <SocialIcon type="google" />
                      <SocialIcon
                          type="apple"
                          onPress={onAppleButtonPress}
                          style={{ backgroundColor: COLORS.BLACK }}
                      />
                  </View>
                  <View style={authStyles.orView}>
                      <Header fontSize={15}>
                          <Text style={authStyles.headerBold}>Ou</Text>
                          {'\n'}
                          <Caption>
                              Je saisis mon email et mot de passe
                          </Caption>
                      </Header>
                  </View>
                  <View style={authStyles.inputView}>
                      <CustomInput
                          label="Email"
                          icon
                          iconName="envelope"
                          iconFamily="font-awesome"
                          onChange={text => setEmail(text)}
                      />
                      <CustomInput
                          label="Mot de passe"
                          icon
                          iconName="lock"
                          iconFamily="entypo"
                          onChange={text => setPassword(text)}
                          password
                      />
                      <CustomButton
                          title="Mot de passe oublié ?"
                          clear
                          onPress={open}
                      />
                  </View>
              </BottomLayout>
          </Layout>
      </KeyboardAwareScrollView>

布局组件:

<View style={layoutStyles.background}>
            {isBackArrow && <BackArrow onPress={onBackArrowPress} />}
            <ScrollView
                style={{ flex: 1 }}
                contentContainerStyle={{
                    flex: 1,
                }}
            >
                {children}
            </ScrollView>
        </View>

布局风格:

background: {
        backgroundColor: COLORS.BRAND_ORANGE_OPACITY_2,
        width: '100%',
        height: '100%',
        flex: 1,
    },

底部布局组件:

<View style={layoutStyles.bottomLayout}>{children}</View>;

底部布局样式:

bottomLayout: {
        backgroundColor: COLORS.BRAND_ORANGE,
        position: 'absolute',
        bottom: 0,
        height: '75%',
        width: '100%',
        borderTopLeftRadius: 70,
        borderTopRightRadius: 70,
        paddingTop: 60,
        flex: 1,
    },

keyboardAwareScrollView contentContainerStyle:

container: {
       justifyContent: 'center',
       alignItems: 'center',
       flex: 1,
   },

提前致谢。

【问题讨论】:

    标签: android react-native react-native-scrollview


    【解决方案1】:

    KeyboardAwareScrollView 已经为您提供了一个 ScrollView,您无需在其中添加另一个。 从 Layout 中移除 ScrollView 或移除 KeyboardAwareScrollView。

    React Native Nested ScrollView Can`t Scroll on Android Device

    也不要在contentContainerStyle 中使用flex: 1,如果您希望它是全屏的,即使其中没​​有足够的内容,也要使用minHeight: '100%' (why?)。

    【讨论】:

    • 非常感谢 Ugur 的回复,确实当我删除 Scrollview 并设置 minHeight: '100%' 我的 KeyboardAwareScroll 工作正常,然后专注于输入,但我想要的也是在溢出时滚动屏幕,即使输入没有重点。不知道你明白我的意思吗?
    • 对不起,我没听懂。如果可见屏幕下有内容,您应该可以滚动。
    • 我编辑了我的帖子,请您检查一下,我不知道为什么不点击 inputText 就无法向下滚动。
    • 似乎问题出在底部布局样式中。它不能滚动,因为你给了绝对位置,绝对定位的视图不会影响容器。尝试删除 position: 'absolute'height: '75%'
    • 好的,非常感谢。你拯救了我的夜晚:)
    猜你喜欢
    • 1970-01-01
    • 2013-01-26
    • 2018-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-06
    • 1970-01-01
    • 2019-08-14
    相关资源
    最近更新 更多