react-native-google-places-autocomplete 无法解析模块 `path/custom/left-icon`

标签 react-native

我无法使用 react native autocomplete npm 包,我收到了这个错误“react-native-google-places-autocomplete unable to resolve module path/custom/left-icon” 我正在使用 React Native V0.44.0 我做错了什么?

simulator error

import React from 'react';
import { View, Image } from 'react-native';
import { GooglePlacesAutocomplete } from 'react-native-google-places-autocomplete';

const homePlace = { description: 'Home', geometry: { location: { lat: 48.8152937, lng: 2.4597668 } }};
const workPlace = { description: 'Work', geometry: { location: { lat: 48.8496818, lng: 2.2940881 } }};

const GooglePlacesInput = () => {
  return (
    <GooglePlacesAutocomplete
      placeholder='Search'
      minLength={2} 
      autoFocus={false}
      returnKeyType={'search'}
      listViewDisplayed='auto'    
      fetchDetails={true}
      renderDescription={(row) => row.description} 
      onPress={(data, details = null) => { 
        console.log(data);
        console.log(details);
      }}
      getDefaultValue={() => {
        return ''; 
      }}
      query={{

        key: 'YOUR API KEY',
        language: 'en', 
        types: '(cities)' 
      }}
      styles={{
        description: {
          fontWeight: 'bold'
        },
        predefinedPlacesDescription: {
          color: '#1faadb'
        }
      }}

      currentLocation={true} 
      currentLocationLabel="Current location"
      nearbyPlacesAPI='GooglePlacesSearch' 
      GoogleReverseGeocodingQuery={{

      }}
      GooglePlacesSearchQuery={{

        rankby: 'distance',
        types: 'food'
      }}

      filterReverseGeocodingByTypes={['locality', 'administrative_area_level_3']} 
      predefinedPlaces={[homePlace, workPlace]}

      debounce={200} 
      renderLeftButton={() => <Image source={require('path/custom/left-icon')} />}
      renderRightButton={() => <Text>Custom text after the inputg</Text>}
    />
  );
}

最佳答案

把线拿出来

 renderLeftButton={() => <Image source={require('path/custom/left-icon')} />}

或将其替换为文本或您自己的图像。您应该将该路径替换为您自己的文本或图像,或者如果您不需要它,您应该将其完全删除。

例如试试这个:

renderLeftButton={() => <Text> Left Button or Left Icon </Text>}

关于react-native-google-places-autocomplete 无法解析模块 `path/custom/left-icon`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48255203/

相关文章:

react-native - 如何在 React-Native 上设置第一个初始页面

javascript - React Native TextInput 多行数字键盘类型?

react-native - npm 安装时遇到代码 EWORKSPACESCONFIG 问题

android - 在 React Native 上设置 Android BroadcastReceiver

ios - 如何从 JavaScript 向 JavaScript 发送 React Native 事件

iOS React Native 应用程序不会从 CodePush 服务器更新

react-native - React Native 中的垂直居中不起作用

react-native - 呈现 UI 但除非触摸,否则不会绘制屏幕

android - React Native 刷新控件是否适用于 Android?

javascript - React Native NetInfo 'connectionChange' 事件未触发