2025-01-21 14:33:59 +08:00
|
|
|
|
import {
|
|
|
|
|
View,
|
|
|
|
|
Image as NativeImage,
|
|
|
|
|
Text,
|
|
|
|
|
Animated,
|
|
|
|
|
Easing,
|
|
|
|
|
TouchableOpacity,
|
|
|
|
|
Alert,
|
|
|
|
|
} from "react-native";
|
|
|
|
|
import React, { useState, useEffect } from "react";
|
|
|
|
|
import { useTailwind } from "tailwind-rn";
|
|
|
|
|
import * as Linking from "expo-linking";
|
|
|
|
|
|
|
|
|
|
export default function ScrollNotice({
|
|
|
|
|
navigation,
|
|
|
|
|
length,
|
|
|
|
|
content,
|
|
|
|
|
url,
|
|
|
|
|
action,
|
|
|
|
|
}) {
|
|
|
|
|
const tailwind = useTailwind();
|
2025-01-23 17:32:48 +08:00
|
|
|
|
const [fadeAnim] = useState(new Animated.Value(length * 75 + 4));
|
2025-01-21 14:33:59 +08:00
|
|
|
|
let animation = Animated.timing(fadeAnim, {
|
2025-01-23 17:32:48 +08:00
|
|
|
|
toValue: -(length * 75),
|
|
|
|
|
duration: 15000,
|
|
|
|
|
delay: 0,
|
2025-01-21 14:33:59 +08:00
|
|
|
|
easing: Easing.linear,
|
2025-01-23 17:32:48 +08:00
|
|
|
|
useNativeDriver: true,
|
2025-01-21 14:33:59 +08:00
|
|
|
|
useNativeDriverForTransform: true, // 如果动画涉及transform属性,则需要此设置
|
|
|
|
|
});
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
return () => {
|
|
|
|
|
animation && animation.stop();
|
|
|
|
|
animation = null;
|
|
|
|
|
};
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
const runAnimation = () => {
|
|
|
|
|
animation &&
|
|
|
|
|
animation.start(() => {
|
|
|
|
|
// 动画完成时的回调,重置动画值并再次运行动画以实现循环
|
2025-01-23 17:32:48 +08:00
|
|
|
|
fadeAnim.setValue(length * 75); // 重置动画值(如果需要)
|
2025-01-21 14:33:59 +08:00
|
|
|
|
runAnimation(); // 再次运行动画
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
2025-01-23 17:32:48 +08:00
|
|
|
|
content.length > 10 && runAnimation(); // 组件挂载时开始动画
|
2025-01-21 14:33:59 +08:00
|
|
|
|
// 注意:这里没有清理函数,因为动画是无限循环的。
|
|
|
|
|
// 如果你需要在组件卸载时停止动画,你需要实现一个机制来跟踪组件的状态,并在适当时调用`stopAnimation`。
|
|
|
|
|
}, [fadeAnim]);
|
|
|
|
|
return (
|
|
|
|
|
<View
|
|
|
|
|
style={{
|
|
|
|
|
...tailwind("bg-[#301024] border-2 px-4 py-3 rounded-xl flex-row"),
|
|
|
|
|
borderColor: "#FF518F26",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<View
|
|
|
|
|
style={{
|
2025-01-23 17:32:48 +08:00
|
|
|
|
...tailwind("mr-2 "),
|
2025-01-21 14:33:59 +08:00
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<NativeImage
|
|
|
|
|
source={require("../../../../assets/icon/others/notice.png")}
|
|
|
|
|
/>
|
|
|
|
|
</View>
|
|
|
|
|
<TouchableOpacity
|
|
|
|
|
onPress={() => {
|
|
|
|
|
if (typeof url === "string") {
|
2025-01-23 17:32:48 +08:00
|
|
|
|
if (
|
|
|
|
|
action === "webViewHeaderInward" ||
|
|
|
|
|
action === "webViewHeaderOutward"
|
|
|
|
|
) {
|
2025-01-21 14:33:59 +08:00
|
|
|
|
navigation.navigate("WebWithHeader", {
|
|
|
|
|
title: "",
|
|
|
|
|
uri: url,
|
|
|
|
|
});
|
|
|
|
|
return;
|
2025-01-23 17:32:48 +08:00
|
|
|
|
} else if (
|
|
|
|
|
action === "webViewWithOutHeaderInward" ||
|
|
|
|
|
action === "webViewWithOutHeaderOutward"
|
|
|
|
|
) {
|
2025-01-21 14:33:59 +08:00
|
|
|
|
navigation.navigate("WebWithoutHeader", {
|
|
|
|
|
title: "",
|
|
|
|
|
uri: url,
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
// 尝试启动微信客户端
|
|
|
|
|
Linking.openURL(url).catch(() => {
|
|
|
|
|
// 启动微信客户端失败,弹出提示安装对话框
|
|
|
|
|
Alert.alert(
|
|
|
|
|
"错误提醒",
|
|
|
|
|
"打开链接失败,请返回重试或者联系在线客服",
|
|
|
|
|
[{ text: "确认", style: "cancel" }],
|
|
|
|
|
{ cancelable: false }
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
} catch (error) {
|
|
|
|
|
// 启动微信客户端失败,继续加载URL
|
|
|
|
|
console.error(error);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
navigation.navigate(...url);
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
style={{
|
|
|
|
|
...tailwind("flex-1"),
|
|
|
|
|
overflow: "hidden",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Animated.View
|
|
|
|
|
style={{
|
2025-01-23 17:32:48 +08:00
|
|
|
|
width: length * 75,
|
2025-01-21 14:33:59 +08:00
|
|
|
|
// opacity: fadeAnim,
|
|
|
|
|
transform: [
|
|
|
|
|
{
|
2025-01-23 17:32:48 +08:00
|
|
|
|
translateX: content.length > 10 ? fadeAnim : 0,
|
2025-01-21 14:33:59 +08:00
|
|
|
|
},
|
|
|
|
|
],
|
2025-01-23 17:32:48 +08:00
|
|
|
|
// transform: [
|
|
|
|
|
// {
|
|
|
|
|
// translateX: -(length * 75),
|
|
|
|
|
// },
|
|
|
|
|
// ],
|
|
|
|
|
// paddingBottom: 5,
|
2025-01-21 14:33:59 +08:00
|
|
|
|
}}
|
|
|
|
|
>
|
2025-01-23 17:32:48 +08:00
|
|
|
|
<Text
|
|
|
|
|
numberOfLines={1}
|
|
|
|
|
style={{
|
|
|
|
|
...tailwind("text-white text-[#FF669E]"),
|
|
|
|
|
}}
|
|
|
|
|
>
|
2025-01-21 14:33:59 +08:00
|
|
|
|
{content}
|
|
|
|
|
</Text>
|
|
|
|
|
</Animated.View>
|
|
|
|
|
</TouchableOpacity>
|
|
|
|
|
</View>
|
|
|
|
|
);
|
|
|
|
|
}
|