【问题标题】:react native bottom sheet bottom transparent反应原生底片底部透明
【发布时间】:2022-01-02 07:38:40
【问题描述】:
import React, { useState } from "react";
import { View, Text, StyleSheet, TouchableOpacity } from "react-native";
import { BottomSheet } from "react-native-btr";

export default function BottomSheetDemo() {
  const [visible, setVisible] = useState(false);

  function toggle() {
    setVisible((visible) => !visible);
  }

  return (
    <View style={styles.container}>
      <TouchableOpacity onPress={toggle}>
        <View style={styles.button}>
          <Text>Toggle BottomSheet</Text>
        </View>
      </TouchableOpacity>
      <BottomSheet
        visible={visible}
        onBackButtonPress={toggle}
        onBackdropPress={toggle}
      >
        <View style={styles.card}>
          <Text>Place your custom view inside BottomSheet</Text>
        </View>
      </BottomSheet>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: "center",
    alignItems: "center",
  },
  button: {
    backgroundColor: "#fff",
    borderWidth: 2,
    borderRadius: 50,
    padding: 16,
  },
  card: {
    backgroundColor: "#fff",
    height: 250,
    justifyContent: "center",
    alignItems: "center",
  },
});

我正在使用上面的代码。所以我的问题是我得到了预期的底部表。我希望它比底部高 100 像素。这也很好。但问题是我得到了底部和顶部模糊黑色背景。但我想在底部边缘 - 底部 100。它不会显示黑色地面。我将从 marginbottom:100 开始。但底部背景将是透明的,我可以点击底部的项目。

【问题讨论】:

  • 所以你不想显示黑色背景,margindBottom 是 100。我说的对吗?
  • @MRPMOHIBURRAHMAN 我想从底部显示 100px。但我不想在底部显示背景阴影。
  • 因此,如果您不想显示背景阴影,它会减少底布顶部和底部的阴影。
  • 如果你想要这个,请告诉我。
  • 好的,让我试试。如果我找到任何东西,我会告诉你的。

标签: react-native bottom-sheet


【解决方案1】:

TLDR:工作源code。请注意,此解决方案可能会得到 乱七八糟的。

如果我们看到react-native-btr 的源code,那么我们将看到BottomSheet 组件实际上是来自react-native-modalModal 组件,将4 个基本道具传递给react-native-modal,如下所示

<Modal
  isVisible={visible}
  onBackButtonPress={onBackButtonPress}
  onBackdropPress={onBackdropPress}
  style={{ justifyContent: "flex-end", margin: 0 }}
>
  {children}
</Modal>

所以,我所做的是,从只有五个文件的react-native-modal 中提取所有源代码code 并修改此源代码。我为react-native-modal 添加了一个名为bottomSpacing 的新道具,以便用户可以更改底部间距。

回到 app.js 代码是这样的

  <Modal
    testID={"modal"}
    isVisible={isModalVisible}
    style={{ justifyContent: "flex-end", margin: 0 }} // this line was using in react-native-btr source
    bottomSpacing={BOTTOM_SPACING}>
    <View style={styles.card}>
      <Text>Place your custom view inside BottomSheet</Text>
    </View>
  </Modal>

这里,BOTTOM_SPACING 用于bottomSpacing 道具和styles.card,如下所示

  card: {
    marginBottom: BOTTOM_SPACING,
    ...
  }

奖励:现在您可以使用react-native-modal 的所有features,例如更改阴影的颜色和阴影的不透明度等。

【讨论】:

  • @Rambler,如果它解决了您的问题,请接受答案。
  • 所以我必须在我的代码文件夹中制作这段代码。
  • 如果您想查看,我还添加了更多问题。我也会喜欢你的投票。
  • @Rambler,别担心,我现在正在检查。
  • @Rambler,我希望有办法在这里发送直接消息。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-10-13
  • 2020-12-10
  • 1970-01-01
  • 2021-09-01
  • 2019-04-06
  • 2021-02-12
  • 2021-12-27
相关资源
最近更新 更多