OnPress后,背景颜色变为黑色,显示在FlatList的顶部

MCM*_*tan 15 listview ios react-native react-native-flatlist

非常奇怪的行为,我正在使用它FlatList,并且在它上面有2个浮动按钮(TouchableOpacity)(绝对位置),当它们被按下时,它们的背景颜色变成黑色.这只发生在IOS上.

在此输入图像描述 在此输入图像描述

码:

给予

let content = (
  <CollapsableNavList
    onListScroll={this.showOrHideFilterButtons}
    showFilterButtonsOnScroll={this.showOrHideFilterButtons}
    style={styles.list}
    isHorizontal={false}
    dataModel={this.props.isFetching ? this.props.whileFetchingDisplayedResults : this.props.dataModel}
    isFetching={false}
    onRowSelect={this._onRowSelect}
    didScrollWithOffset={this.didScrollWithOffset}
    renderRowContent={this.renderRowContent}
    keyExtractor={(item) => {
      if (this.props.isFetching) {
        return item
      }
      const property = item
      return property.propertyId
    }}
  >
    {header}
  </CollapsableNavList>
)

return (
  <View style={[styles.container, styles.relative]}>
    <View style={styles.filterBtnBlock}>
      <AdditionalSearchParamsButton

        title='Map'
        iconName='map'
        onPress={this.onMapPress}
      />
    </View>
    {content}
  </View>
)


export default class AdditionalSearchParamsButton extends Component {
  // Prop type warnings
  static propTypes = {
    iconName: PropTypes.string.isRequired,
    title: PropTypes.string.isRequired,
    onPress: PropTypes.func.isRequired
  }

  render () {
    const { iconName, title, onPress } = this.props
    return (
      <View>
        <TouchableHighlight onPress={onPress} underlayColor={Colors.clear}>
          <View style={styles.innerContainer}>
            <McIcon
              name={iconName}
              style={styles.additionalPropsIcon}
          />
            <Text style={styles.additionalPropsText}>{title}</Text>
          </View>
        </TouchableHighlight>
      </View>
    )
  }
}

export default StyleSheet.create({
  container: {
    height: 50,
    width: 150,
    alignItems: 'center',
    justifyContent: 'center'
  },
  innerContainer: {
    height: 36,
    width: 126,
    flexDirection: 'row',
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: Colors.snow,
    borderRadius: 18,
    elevation: 2,
    shadowOffset: {width: 0, height: 2},
    shadowColor: 'black',
    shadowOpacity: 0.3,
    marginBottom: 5,
  },
  additionalPropsBtn: {
    height: 36,
    flexDirection: 'row',
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: Colors.snow
  },
  additionalPropsText: {
    ...Fonts.style.bigTitle,
    color: Colors.blue,
    paddingLeft: 10
  },
  additionalPropsIcon: {
    fontSize: 22,
    color: Colors.blue
  }
})
Run Code Online (Sandbox Code Playgroud)

我尝试过的:

- 设置底色以清除颜色,但没有成功.

- 添加不同的层,没有成功.

- 这只会在列表中显示时发生,ListView也会发生.

Nis*_*kar 19

请使用TouchableOpacity 而不是TouchableHighlight

TouchableHighlight 单击时突出显示背景


Sad*_*ass 9

在您的TouchableOpacity道具中尝试一下

underlayColor="#ffffff00"
Run Code Online (Sandbox Code Playgroud)


Isr*_*aro 7

尝试添加这个 <TouchableHighlight underlayColor='none' />

  • @JenniferGoncalves 我认为它不需要是一个“过于冗长”的描述 (3认同)

Ali*_*war 6

我已经使用带有背景颜色的 activeOpacity 解决了这个问题

<TouchableOpacity activeOpacity={1} backgroundColor="#FFF"></TouchableOpacity>
Run Code Online (Sandbox Code Playgroud)

您可以使用自己的背景颜色