1

尝试获取图标时出现错误,请使用 react-native-vector-icons 库。我阅读了有关图书馆的所有文档并尝试了他们的示例,但没有。

class AuthScreen extends Component {
   constructor(props){
      super(props);
      this.state = {
          userIcon: "",
          lockIcon: ""
     }
  };
  render () {
     return (        
             <View style={styles.container}>
              <TextInput
                 placeholder="Usuario"
                 style={styles.InputContainer}
                 placeholderTextColor="#EEE"
                 inlineImageLeft={this.state.userIcon}
             />
               <TextInput
                 placeholder="Contraseña"
                 secureTextEntry={true}
                 style={styles.InputContainer}
                 placeholderTextColor="#EEE"
                 inlineImageLeft='search_icon'
                 inlineImageLeft={this.state.lockIcon}
              />             
              </View>
        ); 
    }
} 
Promise.all([
    Icon.getImageSource("md-person", 30),
    Icon.getImageSource("md-lock", 30)
]).then( sources => 
    this.setState({ 
        userIcon: sources[0],
        lockccccIcon: sources[1]  
    })
);
4

1 回答 1

1

您需要在 componentDidMount 或在构造函数中与“this”绑定的任何函数中解决您的承诺。

componentDidMount(){
    Promise.all([
        Icon.getImageSource("md-person", 30),
        Icon.getImageSource("md-lock", 30)
    ]).then( sources => 
        this.setState({ 
            userIcon: sources[0],
            lockccccIcon: sources[1]  
        })
    );
}
于 2019-01-06T09:20:26.637 回答