SearchMapScreen.tsx 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* eslint-disable react/style-prop-object */
  2. import * as WebBrowser from 'expo-web-browser';
  3. import * as React from 'react';
  4. import { StatusBar } from 'expo-status-bar';
  5. import { Div } from 'react-native-magnus';
  6. import { Appbar } from 'react-native-paper';
  7. import { WebView } from 'react-native-webview';
  8. import { useTranslation } from 'react-i18next';
  9. import { useRoute } from '@react-navigation/native';
  10. import useModel from 'flooks';
  11. import MapModel from './model';
  12. import Login from '../login/model';
  13. import { useMount } from 'ahooks';
  14. import {
  15. toastShow,
  16. toastHide,
  17. toastInfo,
  18. toastSuccess,
  19. } from '../utils/SystemUtils';
  20. export default function SearchMapScreen({ navigation }) {
  21. const { t } = useTranslation();
  22. const { getNowLocation } = useModel(MapModel, []);
  23. const webRef = React.useRef();
  24. const { setLocation } = useModel(Login, []);
  25. const [show, setshow] = React.useState<boolean>(false);
  26. useMount(() => {
  27. toastShow();
  28. getNowLocation().then((res) => {
  29. let location = '';
  30. if (res.addressName !== '定位失败') {
  31. location = `${res.location.lat},${res.location.lng}`;
  32. }
  33. webRef.current.injectJavaScript(`window.setLocation('${location}')`);
  34. toastHide();
  35. });
  36. });
  37. return (
  38. <>
  39. <WebView
  40. ref={webRef}
  41. source={{
  42. uri: `http://dingdong.izouma.com/map/chooseLocation`,
  43. }}
  44. style={{ flexGrow: 1, width: '100%' }}
  45. onMessage={({ nativeEvent }) => {
  46. const info = JSON.parse(nativeEvent.data);
  47. console.log(info);
  48. setLocation(
  49. info.poiaddress + info.poiname,
  50. info.latlng.lat,
  51. info.latlng.lng
  52. );
  53. navigation.goBack();
  54. }}
  55. />
  56. </>
  57. );
  58. }