MapScreen.jsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import * as WebBrowser from 'expo-web-browser';
  2. import * as React from 'react';
  3. import { Dimensions, View } from 'react-native';
  4. import { WebView } from 'react-native-webview';
  5. import { useCreation } from '@umijs/hooks';
  6. export default function MapScreen({ orderInfo }) {
  7. // console.log(orderInfo);
  8. const webRef = React.useRef();
  9. const { location, merLocation, ridLocation } = orderInfo;
  10. const merchantLocation = useCreation(() => {
  11. if (merLocation) {
  12. return {
  13. lat: merLocation.split(',')[1],
  14. lng: merLocation.split(',')[0],
  15. };
  16. } else {
  17. return null;
  18. }
  19. }, [merLocation]);
  20. const userLocation = useCreation(() => {
  21. if (location) {
  22. return {
  23. lat: location.split(',')[1],
  24. lng: location.split(',')[0],
  25. };
  26. } else {
  27. return null;
  28. }
  29. }, [location]);
  30. const riderLocation = useCreation(() => {
  31. if (ridLocation) {
  32. return {
  33. lat: ridLocation.split(',')[1],
  34. lng: ridLocation.split(',')[0],
  35. };
  36. } else {
  37. return null;
  38. }
  39. }, [ridLocation]);
  40. return (
  41. <WebView
  42. ref={webRef}
  43. source={{
  44. uri: `http://dingdong.izouma.com/map/home`,
  45. }}
  46. onLoad={() => {
  47. webRef.current.injectJavaScript(
  48. `window.setLocation(${JSON.stringify(orderInfo)},${JSON.stringify(
  49. userLocation
  50. )},${JSON.stringify(merchantLocation)},${JSON.stringify(
  51. ridLocation
  52. )})`
  53. );
  54. }}
  55. />
  56. );
  57. }