【问题标题】:zIndex in React NativeReact Native 中的 zIndex
【发布时间】:2016-11-17 11:50:51
【问题描述】:

zIndex如何处理?

我试图从滚动视图中指定最大的数字,但它仍然在底部(

没有 ScrollView 它看起来像这样,但我需要向上滚动到图像。

谢谢

【问题讨论】:

  • zIndex 在 react-native 中不受支持,您放置元素的顺序决定了它的布局顺序。您可以尝试使滚动视图的溢出可见。
  • 我相信最新版本的 react native 仅支持 iOS 的 zIndex。也许在这里查看示例:github.com/facebook/react-native/commit/…
  • 我不认为这是 z-index 的问题,而是头像视图被裁剪到其父滚动视图的边界。看看你是否可以通过在滚动视图中设置样式来解决这个问题:<ScrollView style={{overflow =visible}} >
  • @Abhishek zIndex 现已推出。查看版本 0.29 的发行说明github.com/facebook/react-native/releases/tag/v0.29.0
  • @brien.crean 也适用于 Android,但仅限于 0.30 版 github.com/facebook/react-native/commit/…

标签: ios node.js reactjs react-native


【解决方案1】:

这已在 iOS 0.30(参见 commit changes)和 android 0.31(changes)中实现

我制作了一个简单的示例组件来说明我是如何使用它的:

'use-strict';

import React, { Component } from 'react';
const { View, StyleSheet } = require('react-native');

const styles = StyleSheet.create({
    wrapper: {
        flex:1,
    },
    back: {
        width: 100,
        height: 100,
        backgroundColor: 'blue',
        zIndex: 0
    },
    front: {
        position: 'absolute',
        top:25,
        left:25,
        width: 50,
        height:50,
        backgroundColor: 'red',
        zIndex: 1
    }
});

class Layers extends Component {
    constructor(props) {
        super(props);
    }

    render() {
        return (
            <View style={styles.wrapper}>
                <View style={styles.back}></View>
                <View style={styles.front}></View>
            </View>
        );
    }
}

module.exports = Layers;

【讨论】:

  • 因此,在您的示例中,如果您颠倒加载“后”和“前”元素的顺序,zIndex 是否还能正常播放?我只问,因为现在你让它们重新加载到前面,所以不管zIndex如何它都可以工作,对吧?
  • 您说得对,如果您颠倒顺序,它们仍将位于预期的 z-index 中。您可能会认为出现的顺序可能会改变分层,但 View 的工作方式与 html Div 非常相似,因为它们不是作为图层在屏幕上绘制,而是最终从上到下堆叠
  • 注意:这仅适用于iOS,当元素为siblings时。
  • 我面临的主要问题是我使用直接按钮或任何图像上的位置...这就是为什么我没有得到正确的结果...谢谢伙计...这对我有帮助很多...
猜你喜欢
  • 2018-01-06
  • 2019-07-03
  • 2017-06-16
  • 1970-01-01
  • 1970-01-01
  • 2017-11-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多