React Native:指定的孩子已经有一个父母

时间:2019-06-04 17:32:28

标签: 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.

我不知道被两次调用的子组件是什么。

我尝试删除作为道具传递给DraggableCard的Some Text,它可以解决该错误,但是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>
    )
  }
}

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>
    )
  }
}

我希望在DragMachine组件上渲染DraggableCard

1 个答案:

答案 0 :(得分:0)

我想您在Android上看到了吗? 请尝试以下方法; https://github.com/react-native-community/react-native-maps/issues/1901