【问题标题】:React Native shadow not displaying反应本机阴影不显示
【发布时间】:2019-08-09 21:06:26
【问题描述】:

我在很多视图和按钮上都使用了阴影,它们工作正常。但它不适用于这个自动完成列表元素,它是一个绝对定位的FlatList,带有一个 zIndex(我删除了 zIndex,还删除了位置“绝对”,阴影仍然不显示)。这是针对 iOS 的。我还没有在 Android 上尝试过。:

代码:

let PresentationalLocationView = (props: PresentationalLocationViewProps) => {
  return (
    <View>
      <Input
        isValid={props.isValid}
        label={'Shop / Restaurant'}
        value={props.value}
        onChangeText={(text) => props.onChangeText(text)}
        deleteText={() => {
          props.onChangeText('')
          props.updateLocationAutocompletePlace({})
        }}
        placeholder={props.placeholder}
      />
      <FlatList
        keyboardShouldPersistTaps={true}
        data={props.autocompleteResults.predictions}
        renderItem={(listItemValue) =>
          renderAutocompleteItem(props, listItemValue)
        }
        style={{
          ...autocompleteStyle.listView(props),
          ...Shadows.shadedSmall,
          backgroundColor: 'white'
        }}
      />
    </View>
  )
}

const renderAutocompleteItem = (
  props: PresentationalLocationViewProps,
  listItemValue: { item: { description: string, place_id: string } }
) => (
  <View style={{ ...Shadows.shadedSmall, backgroundColor: 'white' }}>
    <TouchableOpacity
      onPress={() => {
        props.onListItemSelect(listItemValue.item)
      }}
      style={{
        height: 40,
        display: 'flex',
        justifyContent: 'center',
        ...Shadows.shadedSmall,
        backgroundColor: 'white'
      }}>
      <Text style={styles.label} numberOfLines={1}>
        {listItemValue.item.description}
      </Text>
    </TouchableOpacity>
  </View>
)

export const shadedSmall = {
  elevation: 3,
  shadowColor: Colors.black,
  shadowOffset: {
    width: 0,
    height: 3
  },
  shadowRadius: 2,
  shadowOpacity: 0.2
}

如您所见,我只是试图将阴影应用于图像中该白色 FlatList 的每个容器。为什么它不能在我的其他按钮和视图上工作?

【问题讨论】:

    标签: css react-native react-native-ios shadow


    【解决方案1】:

    阴影在 FlatList 上不起作用。但它适用于 View。我将 FlatList 包装在样式视图中:

      <View
        style={{
          elevation: 3,
          shadowColor: Colors.black,
          shadowOffset: {
            width: 0,
            height: 3
          },
          shadowRadius: 2,
          shadowOpacity: 0.2,
          ...autocompleteStyle.listView(props)
        }}>
        <FlatList
          keyboardShouldPersistTaps={true}
          data={props.autocompleteResults.predictions}
          renderItem={(listItemValue) =>
            renderAutocompleteItem(props, listItemValue)
          }
        />
      </View>
    

    【讨论】:

    • 如果你使用 columnWrapperStyle,你可能不必使用视图。
    猜你喜欢
    • 2018-03-05
    • 2021-10-22
    • 1970-01-01
    • 1970-01-01
    • 2023-03-08
    • 2017-09-06
    • 2016-04-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多