SearchMapScreen.jsx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import * as WebBrowser from 'expo-web-browser';
  2. import * as React from 'react';
  3. import { StatusBar } from 'expo-status-bar';
  4. import { Div } from 'react-native-magnus';
  5. import { Appbar } from 'react-native-paper';
  6. import { WebView } from 'react-native-webview';
  7. import { useRoute } from '@react-navigation/native';
  8. import useModel from 'flooks';
  9. import MapModel from './model';
  10. export default function MapScreen({ navigation }) {
  11. const { locationInfo, changeChooseInfo } = useModel(MapModel, [
  12. 'locationInfo',
  13. ]);
  14. const { location } = locationInfo;
  15. const [pageType, setpageType] = React.useState('homeSearch');
  16. const route = useRoute();
  17. React.useEffect(() => {
  18. const { params } = route;
  19. const { type } = params || {};
  20. if (type) {
  21. setpageType('addAddress');
  22. }
  23. }, [route]);
  24. return (
  25. <>
  26. <StatusBar backgroundColor="#fff" style="dark" translucent />
  27. <Appbar.Header
  28. theme={{ colors: { primary: '#fff' } }}
  29. style={{
  30. elevation: 0,
  31. shadowOffset: {
  32. width: 0,
  33. height: 0,
  34. },
  35. shadowOpacity: 0,
  36. zIndex: 2,
  37. }}
  38. >
  39. <Appbar.BackAction onPress={navigation.goBack} />
  40. <Appbar.Content
  41. title="选择收货地址"
  42. titleStyle={{ textAlign: 'center', fontSize: 16 }}
  43. />
  44. <Div w={56} h={56} />
  45. </Appbar.Header>
  46. <WebView
  47. source={{
  48. uri: `http://dingdong.izouma.com/map/chooseLocation?location=${location.lat},${location.lng}`,
  49. }}
  50. style={{ flexGrow: 1, width: '100%' }}
  51. onMessage={({ nativeEvent }) => {
  52. const info = JSON.parse(nativeEvent.data);
  53. if (pageType === 'homeSearch') {
  54. changeChooseInfo({
  55. addressName: info.poiname,
  56. location: info.latlng,
  57. });
  58. navigation.navigate('Home');
  59. } else {
  60. navigation.navigate('EditAddress', {
  61. locationInfo: info,
  62. });
  63. }
  64. }}
  65. />
  66. </>
  67. );
  68. }