React native 如何用一个反应元件触发两个功能?

React native 如何用一个反应元件触发两个功能?,react-native,React Native,我为公共按钮创建了一个带有动画的类组件: import React, { Component } from 'react'; import { Text, TouchableOpacity, StyleSheet, Animated, Easing, View } from 'react-native'; class AnimatedPrimaryButton extends Component { constructor(props) { super(props); t

我为公共按钮创建了一个带有动画的类组件:

import React, { Component } from 'react';
import { Text, TouchableOpacity, StyleSheet, Animated, Easing, View } from 'react-native';

class AnimatedPrimaryButton extends Component {
  constructor(props) {
    super(props);

    this.state = {
      toggle: false,
      animated: new Animated.Value(0)
    }
  }

  animatedButton = (toggle) => {
    this.state.animated.setValue(toggle ? 1 : 0);

    Animated.timing(this.state.animated, {
      toValue: toggle ? 0 : 1,
      duration: 250,
      easing: Easing.bounce
    }).start();

    this.setState({ toggle: !toggle });
  }

  render() {
    const { toggle, animated } = this.state;
    const { onPress, disabled, width, height } = this.props;

    return (
      <TouchableOpacity
        disabled={disabled} 
        onPress={onPress} 
        style={[styles.buttonStyle, { width, height }]}
      >
        <Animated.View style={{ 
            // other styles
            transform: [{ scale: animated.interpolate({ inputRange: [0, 1], outputRange: [0, 1]})
              }
            ]
        }}>
        </Animated.View>
        <Text style={[styles.textStyle, { fontSize }]}>
          {children}
        </Text>
      </TouchableOpacity>
    );
  }; 
}

const styles = StyleSheet.create({
  // some styles
});

export default AnimatedPrimaryButton;
看起来在箭头下使用道具
onPress
功能不起作用

如何在类组件上使用
doSomething
animatedButton
函数
AnimatedPrimaryButton


任何帮助都将不胜感激。

AnimatedPrimaryButton
组件中,您可以使用onPress功能

onPress(){
  this.props.onPress();
  this. animatedButton();
}

在其他屏幕上调用
AnimatedPrimaryButton
时,在onPress上正确发送doSomething()函数。

AnimatedPrimaryButton
组件中,可以创建onPress函数

onPress(){
  this.props.onPress();
  this. animatedButton();
}

在其他屏幕上调用
AnimatedPrimaryButton
时,按on时正确发送doSomething()函数。

动画完成后,调用
doSomething()
。您可以通过在两个函数调用之间提供延迟来实现,但是my
doSomething()
animatedButton()
是分开的,如何设置动画后的延迟?动画完成后调用您的
doSomething()
。您可以通过在两个函数调用之间提供延迟来实现它,但是我的
doSomething()
animatedButton()
是分开的,动画后如何设置延迟?谢谢您的回复,我稍后会尝试。非常感谢!这就是解决方案。很高兴能帮忙!:)快乐编码!谢谢你的回复,我稍后会试试。非常感谢!这就是解决方案。很高兴能帮忙!:)快乐编码!
onPress(){
  this.props.onPress();
  this. animatedButton();
}