Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
401 views
in Technique[技术] by (71.8m points)

react native - TypeError: undefined is not a function (near '..._reactNativeImagePicker.default.launchImageLibrary...')

I get the following error on the registration screen:

TypeError: undefined is not a function (near '..._reactNativeImagePicker.default.launchCamera...')
- node_modules
eact-nativeLibrariesLogBoxLogBox.js:148:8 in registerError
- node_modules
eact-nativeLibrariesLogBoxLogBox.js:59:8 in errorImpl
- node_modules
eact-nativeLibrariesLogBoxLogBox.js:33:4 in console.error
- node_modulesexpouildenvironment
eact-native-logs.fx.js:27:4 in error
- node_modules
eact-nativeLibrariesCoreExceptionsManager.js:104:6 in reportException
- node_modules
eact-nativeLibrariesCoreExceptionsManager.js:171:19 in handleException
- node_modules
eact-nativeLibrariesCoresetUpErrorHandling.js:24:6 in handleError
- node_modulesexpo-error-recoveryuildErrorRecovery.fx.js:9:32 in ErrorUtils.setGlobalHandler$argument_0
- node_modules
egenerator-runtime
untime.js:63:36 in tryCatch
- node_modules
egenerator-runtime
untime.js:293:29 in invoke
- node_modules
egenerator-runtime
untime.js:63:36 in tryCatch
- node_modules
egenerator-runtime
untime.js:154:27 in invoke
- node_modules
egenerator-runtime
untime.js:164:18 in PromiseImpl.resolve.then$argument_0
- node_modules
eact-native
ode_modulespromisesetimmediatecore.js:37:13 in tryCallOne
- node_modules
eact-native
ode_modulespromisesetimmediatecore.js:123:24 in setImmediate$argument_0
- node_modules
eact-nativeLibrariesCoreTimersJSTimers.js:130:14 in _callTimer
- node_modules
eact-nativeLibrariesCoreTimersJSTimers.js:181:14 in _callImmediatesPass
- node_modules
eact-nativeLibrariesCoreTimersJSTimers.js:441:30 in callImmediates
- node_modules
eact-nativeLibrariesBatchedBridgeMessageQueue.js:387:6 in __callImmediates
- node_modules
eact-nativeLibrariesBatchedBridgeMessageQueue.js:135:6 in __guard$argument_0
- node_modules
eact-nativeLibrariesBatchedBridgeMessageQueue.js:364:10 in __guard
- node_modules
eact-nativeLibrariesBatchedBridgeMessageQueue.js:134:4 in flushedQueue
* [native code]:null in flushedQueue
* [native code]:null in invokeCallbackAndReturnFlushedQueue

What is the wrong with my code?

My code snippet:

import { StatusBar } from "expo-status-bar";
import React, { useState, createRef, Component } from "react";
//import * as ImagePicker from 'react-native-image-picker';
import {
  StyleSheet,
  Text,
  View,
  Image,
  TextInput,
  Button,
  TouchableOpacity,
  KeyboardAvoidingView,
} from "react-native";
import {MaterialIcons} from '@expo/vector-icons';
import {MaterialCommunityIcons} from '@expo/vector-icons';
import { AntDesign } from '@expo/vector-icons';
import { FontAwesome } from '@expo/vector-icons'; 
import { ScrollView } from "react-native";
import Camera from 'react-native-camera';
import ImagePicker from 'react-native-image-picker';

const options = {
    storageOptions: {
      skipBackup: true,
      path: 'images',
    },
  };
  
class RegistrationPage extends Component {
    
    constructor(props) {
        super(props);
        this.state = {
          firstname: "",
          lastname: "",
          phonenumber: "",
          email: "",
          show: "false",
          visible: "true",
          isRegistrationSucces: "false",
          loading: "false",
          errortext:"",
          filepath: {
            data: '',
            uri: ''
          },
          fileData: '',
          fileUri: '',
          setErrortext: '',
        };
      }
      

  handleSubmitButton = () => {
    setErrortext('');
    if (!firstname) {
      alert('Please fill First Name');
      return;
    }
    if (!lastname) {
      alert('Please fill Last Name');
      return;
    }
    if (!email) {
      alert('Please fill Email');
      return;
    }
    if (!password) {
      alert('Please fill Password');
      return;
    }
    if (!confirmpassword) {
      alert('Please fill Confirm Password');
      return;
    }
    }

    launchCamera = () => {
        let options = {
          storageOptions: {
            skipBackup: true,
            path: 'images',
          },
        };
    
        ImagePicker.launchCamera(options, (response) => {
            console.log('Response = ', response);
      
            if (response.didCancel) {
              console.log('User cancelled image picker');
            } else if (response.error) {
              console.log('ImagePicker Error: ', response.error);
            } else if (response.customButton) {
              console.log('User tapped custom button: ', response.customButton);
              alert(response.customButton);
            } else {
              const source = { uri: response.uri };
              console.log('response', JSON.stringify(response));
              this.setState({
                filePath: response,
                fileData: response.data,
                fileUri: response.uri
              });
            }
          });
      }

      renderFileData() {
        if (this.state.fileData) {
          return <Image source={{ uri: 'data:image/jpeg;base64,' + this.state.fileData }}
            style={styles.images}
          />
        } else {
          return <Image source={require("../assets/screens/plane.png")}
            style={styles.images}
          />
        }
      }
    
      renderFileUri() {
        if (this.state.fileUri) {
          return <Image
            source={{ uri: this.state.fileUri }}
            style={styles.images}
          />
        } else {
          return <Image
            source={require("../assets/screens/plane.png")}
            style={styles.images}
          />
        }
      }

      launchImageLibrary = () => {
        let options = {
          storageOptions: {
            skipBackup: true,
            path: 'images',
          },
        };
        ImagePicker.launchCamera(options, (response) => {
          console.log('Response = ', response);
    
          if (response.didCancel) {
            console.log('User cancelled image picker');
          } else if (response.error) {
            console.log('ImagePicker Error: ', response.error);
          } else if (response.customButton) {
            console.log('User tapped custom button: ', response.customButton);
            alert(response.customButton);
          } else {
            const source = { uri: response.uri };
            console.log('response', JSON.stringify(response));
            this.setState({
              filePath: response,
              fileData: response.data,
              fileUri: response.uri
            });
          }
        });
    
      }


      
render() {
    //const [firstname, setFirstName] = useState("");
  return (
      
    <KeyboardAvoidingView style={styles.background} keyboardVerticalOffset={-50} behavior={Platform.OS === "ios" ? "padding" : "height"} >
    
        <Image style={styles.top} source={require("../assets/screens/top.png")} />
        <Image style={styles.plane} source={require("../assets/screens/plane.png")} />
        <Image style={styles.building} source={require("../assets/screens/building.png")} />
        
    
    <View style={styles.rectangle}>
    
    <TouchableOpacity onPress={this.launchImageLibrary} style={styles.btnSection} >
        <MaterialCommunityIcons
                name={'camera'}
                size={40}
                color={'white'}
                style={{flexDirection:"row", alignSelf:"center"}}
                />
        </TouchableOpacity>
    
        <View style={styles.container}>
       
       <ScrollView>
        <View style={styles.inputView}>
        <FontAwesome name="user" size={15} color="gray" />
            <TextInput
                style={styles.TextInput}
                placeholder="First Name"
                secureTextEntry={false}
                onChangeText={(text) => this.setState({firstname: text})}
                value={this.state.firstname}
            />
        </View>
        <View style={styles.inputView}>
        <FontAwesome name="user" size={15} color="gray" />
            <TextInput
                style={styles.TextInput}
                placeholder="Last Name"
                secureTextEntry={false}
                onChangeText={(text) => this.setState({lastname: text})}
                value={this.state.lastname}
            />
        </View>

        <View style={styles.inputView}>
            <MaterialCommunityIcons
                name={'email'}
                size={15}
                color={'gray'}
                />
            <TextInput
                style={styles.TextInput}
                placeholder="Email Address"
                secureTextEntry={false}
                onChangeText={(text) => this.setState({email: text})}
            />
            </View>
        <View style={styles.inputView}>
            <MaterialCommunityIcons
                name={'lock'}
                size={15}
                color={'gray'}
                />
            <TextInput
                style={styles.TextInput}
                placeholder="Password"
                secureTextEntry={this.visible}
                onChangeText={(text) => this.setState({password: text})}
                
            />
            <TouchableOpacity style={styles.btneye} onPress={
                ()=>{
                    setVisible(!this.visible),
                    setShow(!this.show)
                }
            }>
                <MaterialCommunityIcons
                name={this.show === false ? 'eye-outline' : 'eye-off-outline'}
                size={15}
                color={'gray'}
                />

            </TouchableOpacity>
            
        </View>
        <View style={styles.inputView}>
            <MaterialCommunityIcons
                name={'lock'}
                size={15}
                color={'gray'}
                />
            <TextInput
                style={styles.TextInput}
                placeholder="Re-Enter Password"
                secureTextEntry={this.visible}
                onChangeText={(text) => this.setState({password: text})}
                
            />
            <TouchableOpacity style={styles.btneye} onPress={
                ()=>{
                    setVisible(!this.visible),
                    setShow(!this.show)
                }
            }>
                <MaterialCommunityIcons
                name={this.show === false ? 'eye-outline' : 'eye-off-outline'}
                size={15}
                color={'gray'}
                />

            </TouchableOpacity>
            
        </View>
        <TouchableOpacity style={styles.signupBtn} activeOpacity={0.5} onPress={this.handleSubmitButton}>
            <Text style={styles.loginText}>Sign Up</Text>
        </TouchableOpacity>
        </ScrollView>        
        </View>
        
    </View>

        
        </KeyboardAvoidingView>


  );
}
}
 
const styles = StyleSheet.create({
  image:{
    marginBottom: 40,
  },
 container:{
     flex: 1,
    },
    containerAvoidingView:{
        flex: 1,
        alignItems: "center",
        padding: 10,
        
        
    },
  inputView: {
    flexDirection: "row",
    paddingHorizontal: 12,
    borderRadius: 1

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...