【问题标题】:drop down menu hiding behind content隐藏在内容后面的下拉菜单
【发布时间】:2020-11-02 02:51:31
【问题描述】:

我的屏幕如下所示:

return (
    <SafeAreaView>
      <View style={styles.container}>
        <View style={styles.topContainer}>
          <View style={styles.searchFieldContainer}>
            <FavoritePointInput
              textChangeHandler={textChangeHandler}
            />
          </View>
          <View style={styles.dropdown}>
          <LocationsFound
            addressesFound={locations.favAddressesFoundList}
          />
          </View>
          <View style={styles.fieldDescription}>
            <Text>Set Location's Name:</Text>
          </View>
          <View style={styles.searchFieldContainer}>
            <Item style={styles.searchField}>
              <Input
                placeholder="Library"
                onChangeText={(text) => setLocationName(text)}
                style={styles.searchText}
              />
            </Item>
          </View> 
          <View style={styles.buttonContainer}>
            <Button style={styles.button}>
              <Text>Save Location</Text>
            </Button>
          </View>
          </View>
        </View>
    </SafeAreaView>
  );

它的风格是这样的:

export const styles = StyleSheet.create({
  container: {
    height: '100%',
    width: '100%',
  },
  topContainer: {
    height: moderateScale(750),
  },
  topTextContainer: {
    flexDirection: 'row',
    justifyContent: 'space-between',
    marginVertical: moderateScale(15),
    height: moderateScale(30),
    paddingLeft: moderateScale(30),
    paddingRight: moderateScale(30),
  },
  topMiddleContainer: {
    alignItems: 'center',
  },
  topMiddleText: {
    justifyContent: 'center',
    paddingBottom: 40,
  },
  searchFieldContainer: {
    alignItems: 'center',
    height: moderateScale(120),
  },
  button: {
    width: moderateScale(120),
    borderRadius: moderateScale(20),
    alignItems: 'center',
    alignContent: 'center',
  },
  buttonContainer: {
    flexDirection: 'row',
    justifyContent: 'center',
  },
  searchField: {
    width: moderateScale(300, 0.3),
    height: verticalScale(40),
    marginVertical: moderateScale(3),
    borderRadius: verticalScale(10),
  },
  fieldDescription: {
    alignItems: 'center',
  },
    dropdown:{
    position: 'absolute',
    top: 200,
  }
});

当我在第一个输入字段中写入内容时,我会通过LocationsFound 组件获得搜索结果。但是,搜索结果开始隐藏在第二个输入字段后面。我希望它简单地重叠并位于第二个字段的顶部,直到其中一个被选中。这可能吗?

【问题讨论】:

    标签: javascript css reactjs typescript react-native


    【解决方案1】:

    你试过zIndex吗?

    dropdown:{
      position: 'absolute',
      top: 200,
      zIndex: 10,
      backgroundColor: '#fff'
    }
    

    【讨论】:

      【解决方案2】:

      您可以尝试的第一件事是更改 DOM 对象的顺序,并确保将结果添加为最后一项:

      return (
          <SafeAreaView>
            <View style={styles.container}>
              <View style={styles.topContainer}>
                <View style={styles.searchFieldContainer}>
                  <FavoritePointInput
                    textChangeHandler={textChangeHandler}
                  />
                </View>
                <View style={styles.fieldDescription}>
                  <Text>Set Location's Name:</Text>
                </View>
                <View style={styles.searchFieldContainer}>
                  <Item style={styles.searchField}>
                    <Input
                      placeholder="Library"
                      onChangeText={(text) => setLocationName(text)}
                      style={styles.searchText}
                    />
                  </Item>
                </View> 
                <View style={styles.buttonContainer}>
                  <Button style={styles.button}>
                    <Text>Save Location</Text>
                  </Button>
                </View>
                <View style={styles.dropdown}>
                <LocationsFound
                  addressesFound={locations.favAddressesFoundList}
                />
                </View>
                </View>
              </View>
          </SafeAreaView>
        );
      

      另一种解决方案可能是将 z-index 添加到您的下拉列表中:

          fieldDescription: {
              alignItems: 'center',
            },
              dropdown:{
              position: 'absolute',
              top: 200,
              zIndex: 1 // ... or more  
      }
      

      【讨论】:

        猜你喜欢
        • 2016-11-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-08-03
        • 2018-01-04
        相关资源
        最近更新 更多