0

我确定store更新(我正在使用 redux),因为我可以在 中获取更新的值componentWillReceiveProps,但在我动态创建的组件中props不会更新(在创建组件时维护 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更新时,它在动态创建的组件中的引用不会更新。已经尝试将道具传递给本地状态,也没有工作。

4

0 回答 0