TypeError in reactnative Image tag - react-native

I'm trying to add a logo to react-native code using Image tag but after I add Image tag it gives me below error
TypeError: (0, _reactNative.default) is not a function. (In '(0, _reactNative.default)("./../assets/logo.png")', '(0, _reactNative.default)' is an instance of Object)
* component\Login.js:12:34 in render
- node_modules\react-native\Libraries\Renderer\oss\ReactNativeRenderer-dev.js:11581:21 in finishClassComponent
- node_modules\react-native\Libraries\Renderer\oss\ReactNativeRenderer-dev.js:11509:4 in updateClassComponent
- ... 18 more stack frames from framework internals
below is my code
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import Image from "react-native";
import require from 'react-native'
import {ImageBackground} from "react-native";
export default class Login extends React.Component {
render() {
return (
<View style={styles.container}>
<View style={styles.logoContainer}>
<Image sorce={require('./../assets/logo.png')}/>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
logoContainer:{
alignItems:'center',
justifyContent:'center',
},
});
my App.js
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import Login from './component/Login'
export default function App() {
return (
<View style={styles.container}>
<Login/>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
so what is wrong here?

You have a wrong Image import.
Use it like this:
import { StyleSheet, Text, View, Image } from 'react-native';
const myImageSource = require('./../assets/logo.png'); // Double check that you have the image at that path
Fix the typo from image source:
<Image source={myImageSource}/>
If still not working add full content of your files and RN version to your question.

Related

Problem when run onpress fonction : react navigation

I would just like to be redirected to my "Profile" page when I click on the "Enter" button. I don't know if this is the correct method but my homepage is App.js and it contains my button and my image. Sorry for the mistakes I am a beginner and moreover French!
app.js
import 'react-native-gesture-handler';
import React from 'react';
import DisplayAnImage from './Components/DisplayAnImage';
import Profile from './Components/Profile';
import { Enter } from './Components/Enter';
import { StyleSheet, Text, ScrollView } from 'react-native';
import { NavigationContainer } from '#react-navigation/native';
import { createStackNavigator } from '#react-navigation/stack';
export default class App extends React.Component {
render() {
return (
<ScrollView style={{ flex: 1 }}>
<DisplayAnImage/>
<Enter/>
</ScrollView>
)
}
}
enter.js
import React from 'react';
import { Platform, StyleSheet, Text, View, Image, Button, Alert, SafeAreaView } from 'react-native';
import Profile from './Profile.js';
import { createStackNavigator } from '#react-navigation/stack';
import { StackNavigator } from 'react-navigation';
export const Enter = ({ navigation }) => {
return (
<SafeAreaView style={styles.Button}>
<View>
<Button
title="Entrer"
color="#FFFFFF"
onPress={() => this.props.navigation.navigate('Profile')}
/>
</View>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
Button: {
flex: 1,
marginHorizontal: 120,
borderRadius: 20,
backgroundColor: '#1067b3'
},
title: {
textAlign: 'center',
marginVertical: 8,
},
fixToText: {
flexDirection: 'row',
justifyContent: 'space-between',
},
separator: {
marginVertical: 8,
borderBottomColor: '#737373',
borderBottomWidth: StyleSheet.hairlineWidth,
},
});
profile.js
import React, {Component} from 'react';
import { View, Text } from 'react-native';
export default class Profile extends React.Component {
render() {
return (
<View>
<Text>Profile</Text>
</View>
);
}
}
Thank you very much for your help
You are calling "this" from your functional component. Please change this
onPress={() => this.props.navigation.navigate('Profile')}
to
onPress={() => navigation.navigate('Profile')}

getting error when passing through path in image in react native

I have created a card component when I pass title and subtitle its work when I add the image it's giving me an error this is my cardcomponent code
import React from "react";
import {
View,
Text,
StyleSheet,
Button,
Image,
ImageBackground,
} from "react-native";
import colors from "../config/colors";
import AppText from "./AppText";
export default function CardList({ title, subtitle, image }) {
return (
<View style={styles.card}>
<Image source={require(image)} />
<AppText>{title}</AppText>
<AppText>{subtitle}</AppText>
</View>
);
}
const styles = StyleSheet.create({
card: {
backgroundColor: colors.white,
borderRadius: 15,
marginBottom: 20,
paddingTop: 100,
},
});
this is my app file
import React from "react";
import WelcomeScreen from "./app/screen/WelcomeScreen";
import { View, Text, StyleSheet, Button } from "react-native";
import AppText from "./app/components/AppText";
import AppButton from "./app/components/AppButton";
import CardList from "./app/components/CardList";
export default function App() {
return (
<View style={styles.cardStyle}>
<CardList
title="need blood"
subtitle="$100"
image={require("./app/assets/child.png")}
/>
</View>
);
}
const styles = StyleSheet.create({
cardStyle: {
backgroundColor: "#f8f4f4",
padding: 20,
paddingTop: 100,
},
});
I am adding some pictures here which before adding image prop
when I add image its giving me error

React-native error while importing another files

I am just importing my files from a custom created folder component to App.js file and import key in not working on manually created files while working on other imports on React and React native.
I am making an application of React-Native using Expo CliCode Image
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import test from './component/test'; // This line is producing error
export default function App() {
return (
<View style={styles.container}>
<test/>
<Text>Open up App.js to start working on your app!</Text>
</View>
);
}
const styles = StyleSheet.create({`enter code here`
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
TEST COMPONENT :----
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
export default class Test extends React.Component {
render(){
return (
<View style={styles.container}>
<Text>Login js file</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
PLEASE VISIT CODE IMAGE line 3 is causing error
https://i.stack.imgur.com/WRYAt.png

expo linearGradient not working correctly

Problem:
I have created a react-native application. There are I am using a linear gradient.
This is my code.
import React, { Component } from "react";
import {
StyleSheet,
KeyboardAvoidingView,
View,
ActivityIndicator,
TouchableOpacity,
TextInput,
Text,
Image,
ImageBackground
} from "react-native";
import { LinearGradient } from "expo";
class Login extends Component {
render() {
return (
<View style={styles.container}>
<View style={styles.loginHeader}>
<LinearGradient colors={["#fdc830", "#ff9a00"]} style={{ flex: 1 }}>
<Image
source={require("../../../assets/logo-02.png")}
style={styles.image}
/>
</LinearGradient>
</View>
<Text>Login</Text>
</View>
);
}
}
export default Login;
const styles = StyleSheet.create({
container: {
top: 0,
flex: 3,
alignItems: "center"
},
loginHeader: {},
image: {}
});
The error which I was facing is
Invarient Violation:Element type is invalid: expected a string (for built-in-components) or a class/function (for composite components) but got:undefined. you likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports
I tried a lot to find a solution to this problem but I was unable to do so. Can you help me to find a solution to this problem It would be great? Thank you.
if you are using expo:34,35:
Add the package expo-linear-gradient and modify import to
import { LinearGradient } from 'expo-linear-gradient'

React-native Expo: Invariant Violation: View config not found for name

I was trying a module located on npm on snack.expo.
But the following error is given to me.
Invariant Violation: View config not found for name RNMaterialLetterIcon
Where am I doing wrong?
Link: https://snack.expo.io/SyZa8lUEQ
import React, { Component } from 'react';
import {
Platform,
StyleSheet,
Text,
View
} from 'react-native';
import RNMaterialLetterIcon from 'react-native-material-letter-icon';
type Props = {};
export default class App extends Component<Props> {
render() {
return (
<View style={styles.container}>
<RNMaterialLetterIcon
size={80}
border={true}
borderColor={"#dd2c00"}
borderSize={2}
/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
}
});