简体   繁体   English

使用React Native Animated.View和PanResponder将可拖动项置于所有其他项之上

[英]Make draggable item above all others with React Native Animated.View and PanResponder

I have a render method with these components: 我有这些组件的render方法:

<View style={styles.root}>
    {p.parts.map((part, index) =>
        <Animated.View
            key={`part${index}`}
            style={[
                this.draggables[index].pan.getLayout()
            ]}
            {...this.draggables[index].panResponder.panHandlers}
        >
            <SphereView part={part} />
        </Animated.View>
    )}
</View>

And this style: 而这种风格:

const styles = StyleSheet.create({
    root: {
        flexDirection: 'row'
    }
});

Drag and drop is working, but the problem is that when I drag the second element, it is shown above only the first and below all others. 拖放有效,但是问题是,当我拖动第二个元素时,它仅在第一个元素上方显示,而在所有其他元素下方显示。 I want the component being dragged to be above all others. 我希望将组件拖动到所有其他组件之上。

I've tried various combinations with zIndex and none worked. 我已经尝试过使用zIndex进行各种组合,但均无效果。

How to do it? 怎么做?

Edit: I've now just achieved with with the "elevation" style in Android. 编辑:我现在刚刚在Android中以“高程”样式实现了。 Is it the correct approach (even for iOS)? 这是正确的方法(甚至对于iOS)吗?

It's a shame that most of the PanResponder questions on SO (or at least the ones Ive seen) have no answer. 可惜的是,大多数关于SO的PanResponder问题(或者至少是我见过的问题)都没有答案。 You can use zIndex. 您可以使用zIndex。 Just set the zIndex to 999 or something during the drag, and then on release, set it to the original zIndex+1, so that it STAYS above the other images. 只需在拖动过程中将zIndex设置为999或类似的值,然后在释放时将其设置为原始zIndex + 1,使其停留在其他图像上方。 If you kept all of the dragged elements at 999, they would no longer overlap after one drag. 如果将所有拖动的元素都保留为999,则一次拖动后它们将不再重叠。

Elevation only works on android, but zIndex works on both, and will not create a shadow/3D effect 高程仅适用于android,但zIndex两者均可,并且不会创建阴影/ 3D效果

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM