Leon 1 rok temu
rodzic
commit
6fd4634d24
1 zmienionych plików z 39 dodań i 1 usunięć
  1. 39 1
      src/app/time_of_day/index_time.tsx

+ 39 - 1
src/app/time_of_day/index_time.tsx

@@ -13,7 +13,10 @@ import Taro from "@tarojs/taro";
 import { useTranslation } from "react-i18next";
 import 'dayjs/locale/zh-cn';
 import 'dayjs/locale/en';
+
 import { getTimezone, getTimezoneName } from "@/utils/tools";
+
+import { AppState } from "react-native";
 // import 'moment/locale/en';
 
 
@@ -41,12 +44,47 @@ export default function IndexTimePage() {
 
     useEffect(() => {
         getLanguage();
-        login()
+        AppState.addEventListener('change', handleAppStateChange);
+        // login()
         setInterval(() => {
             setCount(t => t + 1)
+            const now = new Date()
+            const seconds = now.getHours()*3600+now.getMinutes()*60+now.getSeconds()
+            if (current && current.time && current.time.timezone.use_dst){
+                if (current.time_changes && current.time_changes.length>1){
+                    const date = new Date(current.time_changes[1].timestamp)
+                    const seconds2 = date.getHours()*3600+date.getMinutes()*60+date.getSeconds()
+                    if (seconds == seconds2){
+                        refresh()
+                    }
+                }
+            }
+            
+            
         }, 1000)
     }, [])
 
+    const handleAppStateChange = (nextAppState) => {
+        console.log(nextAppState)
+        if (nextAppState != 'active') {
+            return
+        }
+        if (nextAppState == 'active') {
+            console.log('active')
+            refresh()
+        }
+
+    };
+
+    function refresh() {
+        if (current) {
+            chooseLocation({
+                lat: current.geo.lat,
+                lng: current.geo.lng
+            })
+        }
+    }
+
     async function getLanguage() {
         var strLocation = await getStorage('lastLocation')
         if (strLocation) {