bottom-tabs.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import { HapticTab } from "@/components/haptic-tab";
  2. import { ThemedView } from '@/components/themed-view';
  3. import { useThemeColor } from '@/hooks/use-theme-color';
  4. import { RefObject } from "react";
  5. import { StyleSheet, Text, View } from "react-native";
  6. import { WebView } from "react-native-webview";
  7. import { UNA_URL } from "../constants/settings";
  8. import { Bars, Bell, Chat, Plus, Search, User } from "./icons";
  9. type Props = {
  10. webViewRef: RefObject<WebView>;
  11. data: any;
  12. };
  13. export default function BottomTabs({ webViewRef, data }: Props) {
  14. const iconColor = useThemeColor({}, 'icon');
  15. const runFuncJS = (js: string) => {
  16. webViewRef.current?.injectJavaScript(`
  17. if (window.${js}) {
  18. ${js}();
  19. }
  20. true;
  21. `);
  22. };
  23. const runJS = (js: string) => {
  24. webViewRef.current?.injectJavaScript(`
  25. ${js};
  26. true;
  27. `);
  28. };
  29. const renderBadge = (number: number) => {
  30. if (number <= 0) return null;
  31. return (
  32. <View style={styles.badge}>
  33. <Text style={styles.badgeText}>{number}</Text>
  34. </View>
  35. );
  36. };
  37. return (
  38. <ThemedView style={styles.container}>
  39. <HapticTab onPress={() => runFuncJS("bx_mobile_apps_show_main_menu")}>
  40. <Bars size={24} color={iconColor} />
  41. </HapticTab>
  42. <HapticTab onPress={() => runJS(`document.location = "${UNA_URL}/page.php?i=notifications-view"`)}>
  43. <Bell size={24} color={iconColor} />
  44. {renderBadge(data.bubbles?.['notifications-preview'] ?? 0)}
  45. </HapticTab>
  46. <HapticTab onPress={() => runFuncJS("bx_mobile_apps_show_add_menu")}>
  47. <Plus size={24} color={iconColor} />
  48. </HapticTab>
  49. <HapticTab onPress={() => runFuncJS("bx_mobile_apps_show_messenger_menu")}>
  50. <Chat size={24} color={iconColor} />
  51. {renderBadge(data.bubbles?.['notifications-messenger'] ?? 0)}
  52. </HapticTab>
  53. <HapticTab onPress={() => runJS(`document.location = "${UNA_URL}/searchKeyword.php"`)}>
  54. <Search size={24} color={iconColor} />
  55. </HapticTab>
  56. <HapticTab onPress={() => runFuncJS("bx_mobile_apps_show_profile_menu")}>
  57. <User size={24} color={iconColor} />
  58. {renderBadge(data.bubbles?.account ?? 0)}
  59. </HapticTab>
  60. </ThemedView>
  61. );
  62. }
  63. const styles = StyleSheet.create({
  64. container: {
  65. height: 56,
  66. flexDirection: "row",
  67. justifyContent: "space-around",
  68. alignItems: "center",
  69. borderTopWidth: 1,
  70. },
  71. tab: {
  72. justifyContent: "center",
  73. alignItems: "center",
  74. position: "relative",
  75. },
  76. badge: {
  77. position: "absolute",
  78. top: -6,
  79. right: -10,
  80. backgroundColor: "red",
  81. borderRadius: 8,
  82. minWidth: 16,
  83. height: 16,
  84. justifyContent: "center",
  85. alignItems: "center",
  86. paddingHorizontal: 3,
  87. },
  88. badgeText: {
  89. color: "#fff",
  90. fontSize: 10,
  91. fontWeight: "bold",
  92. },
  93. });