【发布时间】:2020-05-15 22:13:24
【问题描述】:
我在将 Animated.timing 与 setState 结合使用时遇到问题。
export default function Main() {
const [stateMenu, setStateMenu] = useState(false);
const translateY = new Animated.Value(0);
const {width, height} = Dimensions.get('window');
function Descer() {
Animated.timing(translateY, {
toValue: 800,
duration: 2000,
useNativeDriver: false
}).start();
}
//(1) - With the "Teste" function, this works perfectly.
function teste()
{
Descer();
//setStateMenu(!stateMenu);
}
//(2) - In this way nothing happens.
function teste()
{
Descer();
setStateMenu(!stateMenu);
}
return (
<Container>
<Header onPress={() => teste()} state={stateMenu}/>
<Scene>
<Menu/>
<ScenePage style={[{flex:1, position:'absolute', top:0, left:0, zIndex:15, width:'100%', height:height }, {top:translateY}]}>
<Routes />
</ScenePage>
</Scene>
</Container>
)
};
我没有两个“Teste”函数,我放了两个只是为了解释会发生什么。
我需要使用第二种方式,为什么它不起作用?
【问题讨论】:
标签: react-native react-hooks react-animated