react-native-leaflet icon indicating copy to clipboard operation
react-native-leaflet copied to clipboard

Issue with web simulation under expo

Open AF-Hub opened this issue 3 years ago • 5 comments

Hello,

I'm trying a simple example under expo.

The leaflet shows up fine when running iOS simulation. However, when I launch the web simulation, I obtain the following error:

./node_modules/react-native-leaflet-view/lib/module/LeafletView/index.js:22:7 Module not found: Can't resolve '../../android/src/main/assets/leaflet.html' 20 | 21 | const LEAFLET_HTML_SOURCE = Platform.select({

22 | ios: require('../../android/src/main/assets/leaflet.html'), | ^ 23 | android: { uri: 'file:///android_asset/leaflet.html' }, 24 | });

The example:

import { StyleSheet, Text, View, SafeAreaView } from 'react-native'; import { LatLng, LeafletView } from 'react-native-leaflet-view';

const DEFAULT_COORDINATE: LatLng = { lat: 37.78825, lng: -122.4324, };

export default function App() { return ( <SafeAreaView style={styles.root}> <LeafletView mapMarkers={[ { position: DEFAULT_COORDINATE, icon: '📍', size: [32, 32], }, ]} mapCenterPosition={DEFAULT_COORDINATE} /> </SafeAreaView>); }

const styles = StyleSheet.create({ root: { flex: 1, justifyContent: 'center', alignItems: 'center', }, });

AF-Hub avatar Jan 06 '22 09:01 AF-Hub

I have the same issue with my react-native-web based project. My stack:

  • native-base 3.2.2
  • react-native-web 0.17.5
  • next 12.0.4
  • firefox 96.0.3
  • macos 12.1
  • macbook air 2019

Here is my investigation so far:

When react-native-leaflet is installed, android/src/main/assets/leaflet.html is installed to node_modules/react-native-leaflet-view/android/src/main/assets/leaflet.html

While src/LeafletView/index.tsx is installed to node_modules/react-native-leaflet-view/lib/module/LeafletView/index.js

Thus src/LeafletView/index.tsx should do ✅ require('../../../android/src/main/assets/leaflet.html')

Instead of ❌ require('../../android/src/main/assets/leaflet.html')

@pavel-corsaghin Do you have an idea how to fix this? I can help send a PR.

silgal avatar Feb 01 '22 06:02 silgal

Maybe an option for now would be to duplicate the index.html, so that expo does not do anything stupid on iOS 🤔

miallo avatar Feb 05 '22 08:02 miallo

Maybe an option for now would be to duplicate the index.html, so that expo does not do anything stupid on iOS 🤔

To clarify, my problem happens on macbook air, see above for my stack.

silgal avatar Feb 07 '22 01:02 silgal

Hi is there any solution or workaround to this issue?

It would be nice to be able to write an Expo app, having leaflet work on native devices and the web :-)

rallep avatar Nov 09 '22 14:11 rallep

Found a solution here: https://github.com/pavel-corsaghin/react-native-leaflet/issues/8#issuecomment-1435787897

lichtmetzger avatar Feb 18 '23 23:02 lichtmetzger