Null is not an object imagepickerManager.launchCamera - ios

I'm struggling to find the good function with the new version of image picker.
i just wanna be able to pick a picture or take picture from the app.
My function :
function App (){
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
button: {
marginVertical: 24,
marginHorizontal: 24,
},
image: {
marginVertical: 24,
alignItems: 'center',
},
response: {
marginVertical: 16,
marginHorizontal: 8,
},
});
const [response, setResponse] = React.useState(null);
return (
<SafeAreaView>
<ScrollView>
<Button
title="Take image"
onPress={() =>
ImagePicker.launchCamera(
{
mediaType: 'photo',
includeBase64: false,
maxHeight: 200,
maxWidth: 200,
},
(response) => {
setResponse(response);
},
)
}
/>
<View style={styles.response}>
<Text>Res: {JSON.stringify(response)}</Text>
</View>
{response && (
<View style={styles.image}>
<Image
style={{width: 200, height: 200}}
source={{uri: response.uri}}
/>
</View>
)}
</ScrollView>
</SafeAreaView>
);
}
also my error :
TypeError: null is not an object (evaluating '_reactNative.NativeModules.ImagePickerManager.launchCamera')

Looks like a problem with your linking for the library.
Note : Make sure you are on version 3.x.x and to clean the cache
Steps to install
npm install react-native-image-picker
npx react-native run-android
And then use the launchCamera like
import {launchCamera} from 'react-native-image-picker'
Then launchCamera(options?, callback);

Related

react-native-gesture-handler not working on ios

I have yarn installed react-native-gesture-handler,I then cd'd into ios and pod installed. I then reran the react-native run-ios and still when I swipe nothing happens whatsoever. Im getting zero errors it just doesn't swipe whatsoever. Am i doing something wrong? I have tried to remedy this situation anyway possible and It just doesn't seem to swipe no matter what.
my code is as follows:
import React, {useState} from 'react';
import {
Platform,
View,
Text,
StyleSheet,
Image,
TouchableOpacity,
flatList,
} from 'react-native';
import Swipeable from 'react-native-gesture-handler/Swipeable';
const styles = StyleSheet.create({
container: {
padding: 20,
flexDirection: 'row',
backgroundColor: '#fff',
justifyContent: 'space-between',
alignItems: 'center',
},
text: {
fontSize: 18,
color: '#69696969',
},
icon: {
height: 30,
tintColor: '#69696969',
...Platform.select({
ios: {
tintColor: 'blue',
},
android: {
tintColor: 'red',
},
}),
},
separator: {
flex: 1,
height: 1,
backgroundColor: 'rgba(0, 0, 0, 0.2)',
},
});
export const Separator = () => <View style={styles.separator} />;
const LeftAction = () => {
<View>
<Text>test</Text>
</View>;
};
const ListItem = ({name, onFavoritePress}) => {
const [isFavorite, setIsFavorite] = useState(false);
let starIcon;
if (isFavorite) {
starIcon = Platform.select({
ios: require('../assets/icons/ios-star.png'),
android: require('../assets/icons/md-star.png'),
});
} else {
starIcon = Platform.select({
ios: require('../assets/icons/ios-star-outline.png'),
android: require('../assets/icons/md-star-outline.png'),
});
}
return (
<Swipeable renderLeftActions={LeftAction}>
<View style={styles.container}>
<Text style={styles.text}>{name}</Text>
{onFavoritePress && (
<TouchableOpacity
onPress={() => setIsFavorite((prevIsFavorite) => !prevIsFavorite)}>
<Image style={styles.icon} resizeMode="contain" source={starIcon} />
</TouchableOpacity>
)}
</View>
</Swipeable>
);
};
export default ListItem;
You need to link RNGH to RN
run react-native link react-native-gesture-handler
if this doesn't work maybe you don't have cocoapads dependencies
to install it
run cd <your-ios-code-directory> && pod install

TouchableOpacity is acting weird inside mapview in React Native

So i have 2 problems with TouchableOpacities inside my MapView:
The text and Icon inside my touchableopacities go outside of the touchableopacity, and in other components that doesn't happen.
One of the touchableopacities does nothing when clicked, it doesn't even change the opacity of the touchableopacity.
I haven't tried anything yet, except for revising my state and how it acts, and affects the elements, but nothing appears to be wrong.
this is my state:
this.state = {
lats: this.tempVars.homelat,
longs: this.tempVars.homelong,
latDs: [0.04],
longDs: [0.05],
numStores: this.tempVars.numStores,
StoreLats: this.tempVars.allLats,
StoreLongs: this.tempVars.allLongs,
StoreNames: this.tempVars.allNames,
createMarker: false,
placeMarker: false,
removeAmarker: false,
}
Helper Methods:
locChooser(){
if(this.state.createMarker){
console.log('Permanent Loc: '+JSON.stringify(this.MapLocs.permanentLoc));
return (
<Image style={{width: 65, height: 100, alignSelf: 'center', marginTop: Math.round(Dimensions.get('window').height/2)-150}} source={require('C:/Users/youse/FetcherApp/app/ping.png')}/>
);
}else if(this.state.placeMarker){
return (<Marker coordinate={this.MapLocs.permanentLoc} onPress={() => {if(this.state.removeAmarker){this.setState({placeMarker: false, removeAmarker: false})}}} image={{uri: 'https://i.pinimg.com/originals/30/98/49/309849c5815761081926477e5e872f1e.png'}}/>);
}else{
return null;
}
}
createHelpers(){
var bigarr = new Array(3);
if(this.state.createMarker){
bigarr[0] =
<View style={{flexDirection: 'column', justifyContent: 'space-between'}}>
<TouchableOpacity style={styles.DrawerOpener} onPress={() => this.props.navigation.dispatch(DrawerActions.openDrawer())}><Icon style={{marginTop: 20, marginLeft: 10}} name='reorder'/></TouchableOpacity>
<TouchableOpacity style={[styles.next, {borderColor: '#000000', backgroundColor: '#000000', marginLeft: 10}]} onPress={() => {this.setState({createMarker: false, placeMarker: true})}}><Text style={{color: '#fff', fontSize: 15}}>Select this Location</Text></TouchableOpacity>
</View>;
return bigarr[0];
}else{
bigarr[1] = <View key={0} style={{flexDirection: 'row', justifyContent: 'space-between'}}>
<TouchableOpacity style={styles.DrawerOpener} onPress={() => this.props.navigation.dispatch(DrawerActions.openDrawer())}><Icon style={{marginTop: 20, marginLeft: 10}} name='reorder'/></TouchableOpacity>
<TouchableOpacity style={[styles.next, {borderColor: '#000000', backgroundColor: '#000000', marginLeft: 10}]} onPress={() => {this.setState({createMarker: true})}}><Text style={{color: '#fff', fontSize: 15}}>Choose a location to order from</Text></TouchableOpacity>
</View>;
bigarr[2] =
<View key={1}>
<TouchableOpacity style={[styles.next, {borderColor: this.BtnColor(!this.state.placeMarker), backgroundColor: this.BtnColor(!this.state.placeMarker), marginLeft: 10}]} disabled={!this.state.placeMarker} onPress={() => {console.log('Placemarker: '+this.state.placeMarker+', removeMarker: '+this.state.removeAmarker+', createmarker: '+this.state.createMarker);this.setState({removeAmarker: true})}}><Text style={{color: '#fff', fontSize: 15}}>Remove a Marker</Text></TouchableOpacity>
</View>;
return [bigarr[1], bigarr[2]];
}
}
And the render method:
render(){
return (
<MapView style={{flex: 2}} onRegionChange={this.__ChangeRegion} showsUserLocation={true} style={{position: 'absolute', left: 0, bottom: 0, right: 0, top: 0}} initialRegion={this.MapLocs.startloc}>
<View>
{this.createHelpers()}
</View>
{this.locChooser()}
{this.AllStores()}
<Marker image={require('C:/Users/youse/FetcherApp/app/home.png')} coordinate={this.MapLocs.homeLoc}/>
{this.displayCars(1)}
</MapView>
)
}
So I figured it out, it appears that components act very abnormally inside a Mapview, however when i nested it inside a View with a width and height of the screen dimensions, and put the components outside of the Mapview they acted normal again and they stayed in their styling and formatting.

Undefined is not an object (evaluating 'CameraManager.Aspect') - react native

I get this error. I am in Windows 10 and using expo sumulator in iphone 6 plus when I try to make run Camera. I try to follow the steps in this tutorial:
1 - npm install react-native-camera --save
2 - In XCode, in the project navigator, right click Libraries ➜ Add Files to [your project's name]
3 - Go to node_modules ➜ react-native-camera and add RNCamera.xcodeproj
4 - In XCode, in the project navigator, select your project. Add libRNCamera.a to your project's Build Phases ➜ Link Binary With Libraries
5 - Click RNCamera.xcodeproj in the project navigator and go the Build Settings tab. Make sure 'All' is toggled on (instead of 'Basic'). In the Search Paths section, look for Header Search Paths and make sure it contains both $(SRCROOT)/../../react-native/React and $(SRCROOT)/../../../React - mark both as recursive.
The problem is that I am in Windows and in windows XCODE doesn't exist. How do i fix this in Windows?
Please Give to me Some help. thank you...
My code is:
import React, { Component } from 'react';
import {Text, View,TouchableOpacity,TouchableHighlight} from 'react-native';
import Camera from 'react-native-camera';
const myStyle = {
container: {
flex: 1,
flexDirection: 'row',
},
preview: {
flex: 1,
justifyContent: 'flex-end',
alignItems: 'center'
},
capture: {
flex: 0,
backgroundColor: '#fff',
borderRadius: 5,
color: 'red',
padding: 10,
margin: 40
}
};
export default class CameraAcess extends Component {
constructor(props){
super (props);
this.state = {hasCameraPermission: null, type: Camera.Constants.Type.back,};
}
async componentWillMount() {
const { status } = await Permissions.askAsync(Permissions.CAMERA);
this.setState({ hasCameraPermission: status === 'granted' });
}
render() {
const {container,capture,preview} = myStyle;
const { hasCameraPermission } = this.state;
if (hasCameraPermission === null) {
return <View/>;
} else if (hasCameraPermission === false) {
return <Text>No access to camera</Text>;
} else {
return (
<View style={{ flex: 1 }}>
<Camera style={{ flex: 1 }} type={this.state.type}>
<View style={{flex: 1, backgroundColor: 'transparent', flexDirection: 'row', justifyContent:'space-between'}}>
<TouchableOpacity style={{flex: 0.1, alignSelf: 'flex-end', alignItems: 'center',}}
onPress={() => {this.setState({type: this.state.type === Camera.Constants.Type.back
? Camera.Constants.Type.front : Camera.Constants.Type.back,});}
}>
<Text style={{ fontSize: 18, marginBottom: 10, color: 'white' }}>{' '}Flip{' '}
</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => {this.props.navigator.push({id: 'MenuPrincipal'});}}
style={{alignSelf: 'flex-end', alignItems: 'center', backgroundColor:'transparent'}}>
<Text style={{ fontSize: 18, marginBottom: 10, color: 'white' ,}}>[Back]</Text>
</TouchableOpacity>
</View>
</Camera>
</View>
);
}
}
}

Error: "Invalid data message - all must be length: 8" - PickerIOS

Edit: it seems that if I comment out the line "this.setState({logged_in: true});", line 63, that I don't get the error. My guess is that something about the way I'm trying to change the content being displayed in the render function based on if the user is logged in or not is what is the cause of this error. Any ideas?
I've been making some slight progress in understanding some very basics of React Native, I feel like. Although my code might not be pretty, up until some recent additions it worked. I'm recieving an error message in the IOS Simulator that reads "Invalid data message - all must be length: 8". It unfortunately isn't giving me any specifics that I understand, such as linenumbers.
I sincerely apologise if this is a repost, I've been looking like crazy on google and stackoverflow to find a solution to this error but have been unsuccessful in my searches.
I've censored the url I've using in fetch since it is an adress for testing within the company in very early stages, but I am 99,99% sure that's not where the problem lies.
My index.ios.js:
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
Button,
Alert,
TextInput,
TouchableHighlight,
Image,
AlertIOS,
PickerIOS,
} from 'react-native';
var REASONS = {
sick: {
name: "sjuk"
},
vacation: {
name: "semester"
},
child_care: {
name: "vård av barn"
},
parenting: {
name: "föräldraledig"
},
general: {
name: "övrigt"
},
};
export default class mbab_franvaro extends Component {
constructor(props) {
super(props);
this.state = {username: '', password: '', logged_in: false, reason: 'sjuk'};
}
logout(){
this.setState({logged_in: false});
this.username = ""; this.password = "";
}
login(){
if(this.state.username == "" || this.state.password == ""){
AlertIOS.alert("Fel", "Vänligen fyll i alla fält.");
}
else{
fetch("MY_PRIVATAE_COMPANY_URL", {
method: "POST",
headers: {
'Accept': 'application/x-www-form-urlencoded',
'Content-Type': 'application/x-www-form-urlencoded',
},
body: "username=" + this.state.username + "&password=" + this.state.password,
})
.then((response) => response.json())
.then((response) => {
if(JSON.stringify(response.body).replace(new RegExp('"', 'g'), '').match("Inloggad")){
this.username = this.state.username; this.password = this.state.password;
this.setState({logged_in: true});
//AlertIOS.alert("Hej!", "Välkommen " + this.username + "!");
}
else{
AlertIOS.alert(
"Fel",
JSON.stringify(response.body).replace(new RegExp('"', 'g'), '')
);
}
})
.catch((error) => {
AlertIOS.alert("error", error);
})
.done();
}
}
render(){
if(this.state.logged_in){
//sidan för frånvarorapportering
return (
<View style={styles.container}>
/*<TouchableHighlight style={styles.logout_button} onPress={() => this.logout()}>
<Text style={styles.login_button_text}>Logga ut</Text>
</TouchableHighlight>*/
<View style={styles.report_wrapper}>
<Text style={styles.header}>Frånvarorapportering</Text>
<Text>Ange anledning och hur stor del av dagen du blir frånvarande.</Text>
<PickerIOS
selectedValue={this.state.reason}
onValueChange={(reason) => this.setState({reason})}>
{Object.keys(REASONS).map((reason) => (
<PickerItemIOS
key={reason}
value={reason}
label={REASONS[reason].name}
/>
))}
</PickerIOS>
</View>
</View>
);
}
else{
//inloggningssidan
return (
<View style={styles.container}>
<Image resizeMode="center" style={styles.logo} source={require('./app/res/logo_cmyk.png')} />
<TextInput
placeholder="Namn"
autocorrect={false}
style={styles.text_box}
onChangeText={(username) => this.setState({username})}
/>
<TextInput
placeholder="Lösenord"
autocorrect={false}
secureTextEntry={true}
style={styles.text_box}
onChangeText={(password) => {this.setState({password})}}
/>
<TouchableHighlight style={styles.login_button} onPress={() => this.login()}>
<Text style={styles.login_button_text}>Logga in</Text>
</TouchableHighlight>
</View>
);
}
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F4F4F4',
},
report_wrapper: {
flex: 1,
},
logout_button: {
flex: 0,
flexDirection: "row",
justifyContent: "center",
alignItems: "center",
marginLeft: 10,
marginRight: 10,
marginTop: 30,
marginBottom: 2,
padding: 10,
backgroundColor: "#003878"
},
login_button: {
flex: 0,
flexDirection: "row",
justifyContent: "center",
alignItems: "center",
marginLeft: 10,
marginRight: 10,
marginTop: 2,
marginBottom: 2,
padding: 10,
backgroundColor: "#003878"
},
login_button_text: {
color: "white",
fontSize: 20,
flex: 1,
textAlign: "center",
},
logo: {
//flex: 1,
},
text_box: {
height: 40,
flex: 0,
backgroundColor: "white",
marginLeft: 10,
marginRight: 10,
marginTop: 2,
marginBottom: 2,
padding: 10
},
header: {
color: "#84754E",
fontSize: 25,
marginTop: 30,
},
});
AppRegistry.registerComponent('mbab_franvaro', () => mbab_franvaro);
Edit:
Add toString() to error did the trick for me:
.catch((error) => {
AlertIOS.alert("error", error.toString());
})
I was also getting the same error while using ScrollView.
Took me 2 days to figure out the solution.
I wasn't importing ScrollView from react-native.
Check if you've imported the Picker or not. :)

React Native Image URI Not Showing

While rendering a set of row components in ListView, my uri images seem not to be showing up at all. I have included Image in the react module. My custom component is the following:
var url = rowData.mediaGroups[0].contents[0].url;
if (url.indexOf('w=150') > -1)
{
url.replace("w=150", "w=500");
}
return <ArticlePreview
category={rowData.categories[0]}
key={sectionID}
heartText={'2.9k'}
categoryPress={this.onCategoryDetailsPress}
selected={false}
source={{ uri: url }}
text={rowData.title.toLowerCase().replace(' ','')}
onPress={this.onArticleDetailsPress} />
The component has multiple properties and is used throughout my app (and works there with link images). But for some reason the component just stopped working in the app for uri images. Not sure what to do. Here is the code for the component itself:
//component for article preview touchable image
/* will require the following
- rss feed and api
- user's keyword interests from parse In home.js
- parse db needs to be augmented to include what they heart
- parse db needs to be augmented to include what they press on (like google news)
*/
var React = require('react-native');
var {
View,
StyleSheet,
Text,
Image,
TouchableHighlight,
} = React;
//dimensions
var Dimensions = require('Dimensions');
var window = Dimensions.get('window');
var ImageButton = require('../../common/imageButton');
var KeywordBox = require('../../authentication/onboarding/keyword-box');
//additional libraries
module.exports = React.createClass({
//onPress function that triggers when button pressed
//this.props.text is property that can be dynamically filled within button
/* following props:
- source={this.props.source}
- onPress={this.props.onPress}
- {this.props.text}
- {this.props.heartText}
- key={this.props.key}
- text={this.props.category}
- this.props.selected
*/
render: function() {
return (
<TouchableHighlight
underlayColor={'transparent'}
onPress={this.props.onPress} >
<Image source={this.props.source} style={[styles.articlePreview, this.border('red')]}>
<View style={[styles.container, this.border('organge')]}>
<View style={[styles.header, this.border('blue')]}>
<Text style={[styles.previewText]}>{this.props.text}</Text>
</View>
<View style={[styles.footer, this.border('white')]}>
<View style={[styles.heartRow, this.border('black')]}>
<ImageButton
style={[styles.heartBtn, , this.border('red')]}
resizeMode={'contain'}
onPress={this.onHeartPress}
source={require('../../img/heart_btn.png')} />
<Text style={[styles.heartText]}>{this.props.heartText} favorites</Text>
</View>
<KeywordBox
style={[styles.category, this.border('blue')]}
key={this.props.key}
text={this.props.category}
onPress={this.props.categoryPress}
selected={this.props.selected} />
</View>
</View>
</Image>
</TouchableHighlight>
);
},
onHeartPress: function() {
//will move this function to a general module
},
border: function(color) {
return {
//borderColor: color,
//borderWidth: 4,
}
},
});
var styles = StyleSheet.create({
heartText: {
color: 'white',
fontSize: 12,
fontWeight: 'bold',
alignSelf: 'center',
marginLeft: 5,
},
heartRow: {
flexDirection: 'row',
justifyContent: 'space-around',
alignSelf: 'center',
justifyContent: 'center',
},
heartBtn: {
height: (92/97)*(window.width/13),
width: window.width/13,
alignSelf:'center',
},
category: {
fontFamily: 'Bebas Neue',
fontSize: 10,
fontWeight: 'bold'
},
header: {
flex: 3,
alignItems: 'center',
justifyContent: 'space-around',
marginTop: window.height/30,
},
footer: {
flex: 1,
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
margin: window.height/50,
},
container: {
flex: 1,
backgroundColor: 'black',
opacity: 0.6,
},
articlePreview: {
flex: 1,
height: window.height/3.2,
width: window.width,
flexDirection: 'column'
},
previewText: {
fontFamily: 'Bebas Neue',
fontSize: 23,
color: 'white',
alignSelf: 'center',
textAlign: 'center',
margin: 5,
position: 'absolute',
top: 0,
right: 0,
bottom: 0,
left: 0
},
});
The UI currently looks like this with not images (has black background):
Checked my rss feeds - some were unreliable resulting in messing with the way the images were being shown

Resources