SearchMapScreen.jsx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. export default function MapScreen({ navigation }) {
  13. const { t } = useTranslation();
  14. const { locationInfo, changeChooseInfo } = useModel(MapModel, [
  15. 'locationInfo',
  16. ]);
  17. const { location } = locationInfo;
  18. const webRef = React.useRef();
  19. const [pageType, setpageType] = React.useState('homeSearch');
  20. const route = useRoute();
  21. React.useEffect(() => {
  22. const { params } = route;
  23. const { type } = params || {};
  24. if (type) {
  25. setpageType('addAddress');
  26. }
  27. }, [route]);
  28. return (
  29. <>
  30. <StatusBar backgroundColor="#fff" style="dark" translucent />
  31. <Appbar.Header
  32. theme={{ colors: { primary: '#fff' } }}
  33. style={{
  34. elevation: 0,
  35. shadowOffset: {
  36. width: 0,
  37. height: 0,
  38. },
  39. shadowOpacity: 0,
  40. zIndex: 2,
  41. }}
  42. >
  43. <Appbar.BackAction onPress={navigation.goBack} />
  44. <Appbar.Content
  45. title={t('xuan-ze-shou-huo-di-zhi')}
  46. titleStyle={{ textAlign: 'center', fontSize: 16 }}
  47. />
  48. <Div w={56} h={56} />
  49. </Appbar.Header>
  50. <WebView
  51. ref={webRef}
  52. source={{
  53. uri: `http://dingdong.izouma.com/map/chooseLocation`,
  54. }}
  55. style={{ flexGrow: 1, width: '100%' }}
  56. onMessage={({ nativeEvent }) => {
  57. const info = JSON.parse(nativeEvent.data);
  58. if (pageType === 'homeSearch') {
  59. changeChooseInfo({
  60. addressName: info.poiname,
  61. location: info.latlng,
  62. });
  63. navigation.navigate('Home');
  64. } else {
  65. navigation.navigate('EditAddress', {
  66. locationInfo: info,
  67. });
  68. }
  69. }}
  70. onLoad={() => {
  71. webRef.current.injectJavaScript(
  72. `window.setLocation('${
  73. location ? `${location.lat},${location.lng}` : ''
  74. }')`
  75. );
  76. }}
  77. />
  78. </>
  79. );
  80. }