sửa lỗi polygon không bị xóa ở map

This commit is contained in:
Tran Anh Tuan
2025-11-03 10:33:30 +07:00
parent 67a80c1498
commit efe9749a8e
9 changed files with 468 additions and 425 deletions

View File

@@ -2,7 +2,7 @@ import {
calculateTotalDistance,
getMiddlePointOfPolyline,
} from "@/utils/polyline";
import React, { memo } from "react";
import React from "react";
import { StyleSheet, Text, View } from "react-native";
import { Marker, Polyline } from "react-native-maps";
@@ -21,7 +21,7 @@ export interface PolylineWithLabelProps {
/**
* Component render Polyline kèm Label/Text ở giữa
*/
const PolylineWithLabelComponent: React.FC<PolylineWithLabelProps> = ({
export const PolylineWithLabel: React.FC<PolylineWithLabelProps> = ({
coordinates,
label,
strokeColor = "#FF5733",
@@ -103,22 +103,3 @@ const styles = StyleSheet.create({
textAlign: "center",
},
});
// Export memoized component để tránh re-render không cần thiết
export const PolylineWithLabel = memo(
PolylineWithLabelComponent,
(prev, next) => {
// Custom comparison: chỉ re-render khi coordinates, label hoặc showDistance thay đổi
return (
prev.coordinates.length === next.coordinates.length &&
prev.coordinates.every(
(coord, index) =>
coord.latitude === next.coordinates[index]?.latitude &&
coord.longitude === next.coordinates[index]?.longitude
) &&
prev.label === next.label &&
prev.showDistance === next.showDistance &&
prev.strokeColor === next.strokeColor
);
}
);