我确定store
更新(我正在使用redux),因为我可以在componentWillReceiveProps
中获取更新的值,但是在我动态创建的组件中,props
赢得了不会更新(在创建组件时保留道具的值)。
我如何创建组件:
_getFetchDataDevice(...) {
[...]
coordinatesObjectsAR.forEach((tempObject, i) => {
objectsComponenets.push(
<ViroFlexView width={10} key={"viro_flex_"+i} transformBehaviors={["billboard"]} scale={[0.7*(distanceFromObjectsAR[i]/60),0.68*(distanceFromObjectsAR[i]/60),0.9*(distanceFromObjectsAR[i]/60)]} position={[coordinatesObjectsAR[i].x,0,coordinatesObjectsAR[i].z]} height={16} backgroundColor={'pink'} style={{ flexDirection: 'column' }} >
<ViroFlexView key={"viro_flex_inside_"+i} backgroundColor={'white'} style={{ flex: 1, flexDirection: 'column' }} >
<ViroText
key={"distance_"+i}
backgroundColor={'pink'}
style={{ flex: 1, color: 'purple', marginLeft:.2 }}
text={ this.props.distanceBetweenUserLocationAndPoints[i].toFixed(2).toString() + "m\n"}
fontSize={162} />
<ViroText
key={"xy_"+i}
backgroundColor={'pink'}
style={{ flex: 1, color: 'purple', marginLeft:.2 }}
text={"x:"+coordinatesObjectsAR[i].x.toFixed(2).toString()+",y:"+coordinatesObjectsAR[i].z.toFixed(2).toString()}
fontSize={162} />
<ViroText
key={"title_"+i}
backgroundColor={'pink'}
style={{ flex: 1, color: 'purple', marginLeft:.2 }}
text={jsonObjects[i].title}
fontSize={162} />
<ViroImage onClick={() => {this._startNavigationToLocal(i)}}
height={8}
width={6.75}
key={"button_"+i}
source={require("../resource/image/navigation.png")}
/>
</ViroFlexView>
</ViroFlexView>
);
});
this.setState({objects: objectsComponenets});
[...]
}
我需要获取更新值的道具是 this.props.distanceBetweenUserLocationAndPoints 。
状态objects
中存储的动态创建的组件的呈现为:
return (
<ViroARScene onTrackingUpdated={this._onTrackingUpdated} onAnchorFound={this._foundAnchor}>
<ViroText text={"Compass: "+compassDegree} transformBehaviors={["billboard"]} scale={[.5, .5, .5]} position={[0,0,-1]} style={styles.helloWorldTextStyle} />
{this.state.objects}
<ViroBox position={[0,0,-1]} scale={[.3, .3, .1]}/>
<ViroAmbientLight color={"#aaaaaa"} influenceBitMask={1} />
</ViroARScene>
);
在生命周期方法中调用_getFetchDataDevice(...)。
this.state.objects
可以工作并呈现我想要的正确视图,但是当 this.props.distanceBetweenUserLocationAndPoints 更新时,动态创建的组件中对它的引用不会更新。已经尝试将道具传递给当地政府,也没有用。