SearchMapScreen.tsx 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /* eslint-disable react/style-prop-object */
  2. import * as WebBrowser from "expo-web-browser";
  3. import * as React from "react";
  4. import { WebView } from "react-native-webview";
  5. import { useMount } from "ahooks";
  6. import { useModel } from "flooks";
  7. import { getLocation } from "../Utils/MapUtils.ts";
  8. export default function SearchMapScreen({ navigation }) {
  9. const [location, setLocation] = React.useState<any>();
  10. const { saveLocation } = useModel("userModel");
  11. const [show, setshow] = React.useState<boolean>(false);
  12. useMount(() => {
  13. getLocation().then(res => {
  14. setLocation(res.location);
  15. setTimeout(() => {
  16. setshow(true);
  17. }, 500);
  18. });
  19. });
  20. return (
  21. <>
  22. {show && (
  23. <WebView
  24. source={{
  25. uri: `http://dingdong.izouma.com/map/chooseLocation?location=${location.lat},${location.lng}`,
  26. }}
  27. style={{ flexGrow: 1, width: "100%" }}
  28. onMessage={({ nativeEvent }) => {
  29. const info = JSON.parse(nativeEvent.data);
  30. console.log(info);
  31. saveLocation(
  32. info.poiaddress + info.poiname,
  33. info.latlng.lat,
  34. info.latlng.lng
  35. );
  36. navigation.goBack();
  37. }}
  38. />
  39. )}
  40. </>
  41. );
  42. }