我有 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>
)
}
}
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>
)
}
}
我希望在 ChooseMachine 组件上渲染 DraggableCard
我猜你在 Android 上看到过这个?
尝试下面的方法。
https://github.com/react-native-community/react-native-maps/issues/1901 https://github.com/react-native-community/react-native-maps/issues/1901
基本上,从以下位置删除子元素<MapView>
而是绝对定位它。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)