SearchMapScreen.tsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 { locationInfo, changeChooseInfo, getNowLocation } = useModel(
  23. MapModel,
  24. ['locationInfo']
  25. );
  26. const { setLocation } = useModel(Login, []);
  27. const { location } = locationInfo;
  28. const [show, setshow] = React.useState<boolean>(false);
  29. useMount(() => {
  30. toastShow();
  31. getNowLocation().then(() => {
  32. setTimeout(() => {
  33. setshow(true);
  34. setTimeout(() => {
  35. toastHide();
  36. }, 1000);
  37. }, 300);
  38. });
  39. });
  40. return (
  41. <>
  42. {show && (
  43. <WebView
  44. source={{
  45. uri: `http://dingdong.izouma.com/map/chooseLocation?location=${location.lat},${location.lng}`,
  46. }}
  47. style={{ flexGrow: 1, width: '100%' }}
  48. onMessage={({ nativeEvent }) => {
  49. const info = JSON.parse(nativeEvent.data);
  50. console.log(info);
  51. setLocation(
  52. info.poiaddress + info.poiname,
  53. info.latlng.lat,
  54. info.latlng.lng
  55. );
  56. navigation.goBack();
  57. }}
  58. />
  59. )}
  60. </>
  61. );
  62. }