首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将搜索结果固定在容器顶部

将搜索结果固定在容器顶部
EN

Stack Overflow用户
提问于 2020-07-09 22:36:05
回答 1查看 45关注 0票数 0

我有一个屏幕,看起来像这样:

代码语言:javascript
复制
return (
    <SafeAreaView>
      <View style={styles.container}>
        <View style={styles.topContainer}>
          <View style={styles.searchFieldContainer}>
            <FavoritePointInput
              textChangeHandler={textChangeHandler}
            />
          </View>
          <LocationsFound
            addressesFound={locations.favAddressesFoundList}
          />
          {/* <View style={styles.fixed}> */}
          <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>
      {/* </View> */}
    </SafeAreaView>
  );

其Stlyes是这样的:

代码语言:javascript
复制
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',
  },
  fixed: {
    position: 'absolute',
  }
});

当我在第一个输入字段中编写内容时,我会通过LocationsFound组件获得搜索结果。这会扰乱整个样式,并将第二个输入字段向下推。我希望它只是简单地重叠并出现在第二个字段的顶部,直到它们中的一个被选中。这有可能吗?

编辑:

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-07-09 22:55:25

从代码中看,<LocationsFound>是您的下拉列表。您需要设置此组件的样式并为其提供绝对位置,以便将其从UI的正常定位流中移除。请注意,您将绝对作品定位为相对于其最近定位的祖先,因此您还需要相对定位其父级。

在你的标记中。

代码语言:javascript
复制
<LocationsFound
  styles={styles.dropdown}
  addressesFound={locations.favAddressesFoundList}
/>

在你的风格中

代码语言:javascript
复制
searchFieldContainer {
  position: relative,
  // other attributes
}

dropdown {
  position: absolute,
  // adjust top and left according to your situation e.g. 10px
  top: 0;
  left: 0;
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62817333

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档