我试图在iOS和andriod上使用react-native-maps
,但我也希望我的代码在Web上工作。我想在Web上禁用此功能,但使其在iOS和andriod上工作。有没有办法做到这一点?
我试过这个
if (Platform.OS === 'android' || Platform.OS === 'ios') {
Promise.all([
import('react-native-maps').then((module) => module.default),
import('react-native-maps').then((module) => module.Marker),
]).then(([MapView, Marker]) => {
setMapView(MapView);
setMarker(Marker);
});
}
在一个useEffect
没有任何运气
1条答案
按热度按时间iqih9akk1#
我认为你应该看看文档的“平台特定代码”部分,特别是文件扩展名部分。
https://reactnative.dev/docs/platform-specific-code#platform-specific-extensions
也许在你的情况下,你可以有一个BaseComponent.js与Component.js为Web和Component.native.js为移动的?