Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 动画不适用于重新激活的API_Reactjs_React Native - Fatal编程技术网

Reactjs 动画不适用于重新激活的API

Reactjs 动画不适用于重新激活的API,reactjs,react-native,Reactjs,React Native,在那些日子里,我一直试图将React Native Reanimated集成到我自己的应用程序中,但我对动画的很多方面一无所知。运行一些复活的GitHub文档示例时,我发现其中一些示例并不适合我。我已经解决了在状态下保存动画值的示例 但我有一个疑问,因为评估示例和一些来自internet的代码示例时,我发现使用类组件不需要更新状态上的值,否则直接在“value”对象上更新值将触发动画(我想是重新渲染)。但它不适用于我,我没有其他工作方式,只有当我将值对象保存在状态上,然后在我想要更改动画值时更新

在那些日子里,我一直试图将React Native Reanimated集成到我自己的应用程序中,但我对动画的很多方面一无所知。运行一些复活的GitHub文档示例时,我发现其中一些示例并不适合我。我已经解决了在状态下保存动画值的示例

但我有一个疑问,因为评估示例和一些来自internet的代码示例时,我发现使用类组件不需要更新状态上的值,否则直接在“value”对象上更新值将触发动画(我想是重新渲染)。但它不适用于我,我没有其他工作方式,只有当我将值对象保存在状态上,然后在我想要更改动画值时更新状态时,它才适用于我

可能是我做错了什么吗

class ListAddressComponent extends React.Component {
  state = {
    modalVisible: false,
  }

  value = new Animated.Value(1);

  animate = (clock, value, dest) => {
    const state = {
      time: new Value(0),
      finished: new Value(0),
      velocity: new Value(0),
      position: new Value(0),
    };

    const config = {
      toValue: new Value(0),
      damping: 50,
      mass: 1,
      stiffness: 100,
      overshootClamping: false,
      restSpeedThreshold: 0.001,
      restDisplacementThreshold: 0.001,
    };

    return block([
      cond(clockRunning(clock), 0, [
        set(state.finished, 0),
        set(state.time, 0),
        set(state.position, value),
        set(state.velocity, 500),
        set(config.toValue, dest),
        startClock(clock),
      ]),
      spring(clock, state, config),
      cond(state.finished, stopClock(clock)),
      // state.position
      set(this.value, state.position)
    ]);
  }

  componentDidUpdate(prevProps) {
    // update the modal visible state on props change
    if (prevProps.visible !== this.props.visible) {
      this.setState({
        modalVisible: this.props.visible,
      }, () => {
        const clock = new Clock();
        this.animate(clock, 1, 300);
      });
    }
  }

  onCloseModal = () => {
    const clock = new Clock();
    this.animate(clock, 300, 1);
    setTimeout(() => {
      this.setState({ modalVisible: false });
      this.props.onClose && this.props.onClose('LIST');
    }, 500);
  }

  render() {
    return <Modal
      transparent
      animationType="fade"
      visible={this.state.modalVisible}
      onRequestClose={this.onCloseModal}
    >
      <TouchableOpacity
        activeOpacity={1}
        onPress={this.onCloseModal}
        style={{ backgroundColor: 'rgba(0, 0, 0, 0.4)', flex: 1, justifyContent: 'flex-end' }}
      >
        <Animated.View
          activeOpacity={1}
          style={[Style.backdrop, { height: this.value }]}
        >
          <View>
            { this.renderTitle() }
            <View style={{ marginBottom: scale(20) }}>
              { this.renderActualAddress() }
              { this.renderAddress() }
            </View>
            { this.renderAddNewAddress() }
          </View>
        </Animated.View>
      </TouchableOpacity>
    </Modal>
  }
}
类ListAddressComponent扩展了React.Component{
状态={
modalVisible:错误,
}
值=新动画。值(1);
动画=(时钟、值、目标)=>{
常量状态={
时间:新值(0),
已完成:新值(0),
速度:新值(0),
位置:新值(0),
};
常量配置={
toValue:新值(0),
阻尼:50,
质量:1,,
刚度:100,
超调幅度:错误,
restSpeedThreshold:0.001,
再位移阈值:0.001,
};
返回块([
康德(时钟运行),0[
设置(state.finished,0),
设置(state.time,0),
设置(状态、位置、值),
设置(state.velocity,500),
设置(config.toValue,dest),
StartLock(时钟),
]),
弹簧(时钟、状态、配置),
cond(状态完成,停止时钟(时钟)),
//状态
设置(this.value,state.position)
]);
}
componentDidUpdate(prevProps){
//更新道具更改时的模态可见状态
if(prevProps.visible!==此.props.visible){
这是我的国家({
modalVisible:this.props.visible,
}, () => {
常数时钟=新时钟();
这个。动画(时钟,1300);
});
}
}
onCloseModal=()=>{
常数时钟=新时钟();
这个。动画(时钟,300,1);
设置超时(()=>{
this.setState({modalVisible:false});
this.props.onClose&&this.props.onClose('LIST');
}, 500);
}
render(){
返回
{this.renderTitle()}
{this.renderActualAddress()}
{this.renderAddress()}
{this.renderAddNewAddress()}
}
}