SearchMapScreen.jsx 2.2 KB

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