import React, { useCallback } from "react"; import { View, Text, TouchableOpacity, Linking, ViewStyle, Platform } from "react-native"; import { Icon, List, ActionSheet } from "."; import { $Theme } from "./style"; type AddressProps = { address: string; phone: string; title: string; onClick?: (meta: AddressDataMeta) => void; location: { latitude: number; longitude: number; }; style?: ViewStyle; OptionalComponent?: React.ComponentType | React.ReactElement | null; }; type AddressDataMeta = { coordinate: [number, number]; title: string; }; /** * * @param * OptionalComponent: could be any button like component, for example, copy * * @returns */ const Address: React.FC = ({ address, title, phone, style, location, onClick, OptionalComponent }) => { const Dial = (phone: string) => { if (Platform.OS === "ios") { return Linking.openURL(`tel:${phone}`).then((r) => {}); } ActionSheet.showActionSheetWithOptions( { options: [`拨打 ${phone}`, "Cancel"], cancelButtonIndex: 1, }, (buttonIndex: any) => { if (buttonIndex === 0) { Linking.openURL(`tel:${phone}`).then((r) => {}); } } ); }; const onViewMap = useCallback(() => { onClick && onClick({ coordinate: [location.longitude, location.latitude], title, }); }, [location, title]); return ( 地址:{address} {OptionalComponent} Dial(phone)}> ); }; export default Address;