React Native:指定的子级已经有父级

Ern*_*nni 6 android react-native

我有 2 个组件,DraggableCard 和 ChooseMachine(ChooseMachine 使用 DraggableCard)。当我到达 ChooseMachine 组件时,它返回错误:The specified child already has a parent. You must call removeView() on the child's parent first.

我不知道哪个子组件被调用了两次。

我尝试删除Some Text作为道具传递给 DraggableCard 的 ,这解决了错误,但 DraggableCard 没有显示,这不完全是我需要的。它应该显示 DraggableCard 和传递的文本。我已经尝试过绕过Some Text标签,但问题仍然存在。

import React, {Component} from 'react'
import {View} from 'react-native'
import MapView from 'react-native-maps'

import styles from './style'
import DraggableCard from '../../components/DraggableCard'

export default class ChooseMachine extends Component{

  render(){
    return(
      <View style={styles.body}>
        <MapView
          style={styles.map}>

          <DraggableCard>
            Some Text
          </DraggableCard>

        </MapView>

      </View>
    )
  }
}
Run Code Online (Sandbox Code Playgroud)

DraggableCard 组件

import React, {Component} from 'react'
import { View, Text } from 'react-native'

export default class DraggableCard extends Component {

  render(){

    return(
      <View
        style={styles.containerStyle}>
        <View style={styles.smallHyphen}/>
        <Text>
          {this.props.children}
        </Text>
      </View>
    )
  }
}
Run Code Online (Sandbox Code Playgroud)

我希望在 ChooseMachine 组件上渲染 DraggableCard

SHG*_*G21 11

我猜你在 Android 上看到过这个?尝试下面的方法。

https://github.com/react-native-community/react-native-maps/issues/1901

基本上,从中删除子元素<MapView>并将其绝对定位。