Reanimated 的每个文档都在使用类组件设置为 Opacity.setvalue(0) 它可以工作,但我需要设置为以便将时钟用于其他动画,请提供任何帮助。
import React, { useState } from "react";
import { View, Text, StyleSheet, Image, Dimensions } from "react-native";
import Animated, { Easing } from "react-native-reanimated";
import { TapGestureHandler, State } from "react-native-gesture-handler";
function MusicApp() {
const {
Value,
Clock,
startClock,
stopClock,
debug,
timing,
clockRunning,
block,
cond,
set,
eq
} = Animated;
const { width, height } = Dimensions.get("window");
const [buttonOpacity, setbuttonOpacity] = useState(1);
const Opacity = new Value(1);
function onStateChange() {
Animated.event([
{
nativeEvent: ({state}) =>
Animated.block([cond(eq(state, State.END),set(Opacity,0) )
])
}
]);
}
return (
<View style={{ backgroundColor: "black", justifyContent: "flex-end" }}>
<View
style={{ position: "absolute", top: 0, bottom: 0, left: 0, right: 0 }}
>
<Image
source={require("../assets/bg.jpg")}
style={{ height: height, width: width }}
/>
</View>
<View style={{ height: height / 3, justifyContent: "center" }}>
<TapGestureHandler
onHandlerStateChange={() => {
onStateChange();
}}
>
<Animated.View style={{ ...styles.button, opacity: Opacity}}>
<Text style={{ fontSize: 20 }}>SIGN IN</Text>
</Animated.View>
</TapGestureHandler>
</View>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff",
alignItems: "center",
justifyContent: "center"
},
button: {
backgroundColor: "red",
height: 70,
marginHorizontal: 20,
borderRadius: 35,
alignItems: "center",
justifyContent: "center"
},
button2: {
backgroundColor: "blue",
height: 70,
marginHorizontal: 20,
borderRadius: 35,
alignItems: "center",
justifyContent: "center"
}
});
export default MusicApp;