瀏覽代碼

perf: 相机扫码支付节流

zengkunsen 4 月之前
父節點
當前提交
9900187c6a
共有 2 個文件被更改,包括 10 次插入11 次删除
  1. 2 2
      app/(auth)/(tabs)/(home)/scanQrPage.tsx
  2. 8 9
      component/searchPage/searchResultComponent.tsx

+ 2 - 2
app/(auth)/(tabs)/(home)/scanQrPage.tsx

@@ -24,7 +24,7 @@ import { walletService } from '../../../../service/walletService';
 import useUserInfoStore from '../../../../providers/userinfo_store';
 import Modal from 'react-native-modal';
 import NormalButton from '../../../../component/global/normal_button';
-import { ceil } from 'lodash';
+import { ceil, throttle } from 'lodash';
 import AsyncStorage from '@react-native-async-storage/async-storage';
 import { useChargingStore } from '../../../../providers/scan_qr_payload_store';
 
@@ -497,7 +497,7 @@ const ScanQrPage = () => {
                         barcodeScannerSettings={{
                             barcodeTypes: ['qr']
                         }}
-                        onBarcodeScanned={scanned ? undefined : handleBarCodeScanned}
+                        onBarcodeScanned={scanned ? undefined : throttle(handleBarCodeScanned, 400)}
                         responsiveOrientationWhenOrientationLocked={true}
                     ></CameraView>
                     <View style={styles.overlay}>

+ 8 - 9
component/searchPage/searchResultComponent.tsx

@@ -22,15 +22,17 @@ import { PROVIDER_GOOGLE } from 'react-native-maps';
 import { calculateDistance } from '../global/distanceCalculator';
 
 interface TabItem {
-    imgURL: ImageSourcePropType;
+    imgURL?: ImageSourcePropType | undefined;
     date: string;
     time: string;
     chargeStationName: string;
     chargeStationAddress: string;
     distance: string;
-    stationID: string;
-    lat: number;
-    lng: number;
+    stationID?: string;
+    longitude?: number;
+    latitude?: number;
+    lat?: number;
+    lng?: number;
 }
 
 const dummyTabItems: TabItem[] = [
@@ -182,10 +184,7 @@ const SearchResultComponent = () => {
                         lat: station.StationLat,
                         date: '今天',
                         stationID: station.StationID,
-
-                        // imgURL: stationImages[station.StationID] || require('../../assets/dummyStationPicture.png'),
                         imgURL: station.image
-                        // distance: distance !== null ? formatDistance(distance) : 'N/A'
                     };
                 })
             );
@@ -333,7 +332,7 @@ const SearchResultComponent = () => {
                                                         router.push({
                                                             pathname: '/resultDetailPage',
                                                             params: {
-                                                                imageSource: item.imgURL,
+                                                                imageSource: item.imgURL as string,
                                                                 chargeStationAddress: item.chargeStationAddress,
                                                                 chargeStationID: item.stationID,
                                                                 chargeStationName: item.chargeStationName,
@@ -350,7 +349,7 @@ const SearchResultComponent = () => {
                                                     ]}
                                                 >
                                                     <View style={styles.rowContainer}>
-                                                        <Image style={styles.image} source={{ uri: item.imgURL }} />
+                                                        <Image style={styles.image} source={{ uri: item.imgURL } as ImageSourcePropType} />
                                                         <View style={styles.textContainer}>
                                                             <Text
                                                                 style={{