首页 文章

React Native Web中Modal的替代方案

提问于
浏览
3

React Native Web中缺少Modal驱使我构建一个覆盖在当前视图之上的弹出组件 .

我尝试过'绝对'的位置,顶部:0和左:0黑客 . 这很有效但如果在子组件中使用它将无法正常工作,因为组件的顺序是auto zIndex . 下图说明了此问题(请参阅蓝色按钮阻止下拉列表弹出):

enter image description here

最后我发现React可以直接在根处渲染一个组件(在这个link找到更多),这意味着该组件将呈现在其他组件之上,但这是React而不是React Native .

我想知道React Native中是否有类似的东西 .

1 回答

  • 0

    尝试将组件放在最后的层次结构中 . 然后使用位置'absolute',top:0和left:0 hack . 它应该工作 .

    例如 .

    <View>
      {renderComponent1()}
      {renderComponent2()}
      {renderComponentWithAbsoluteStyling()} //Your component
    </View>
    

    在RN中,较低的组件在渲染时获得较高的优先级 . 所以你的组件应该覆盖component1和component2 .

相关问题