export class on new files not working (react native) - reactjs

I'm trying to build an app and it was working but for some reason now everytime I try to export something it no longer works (stays greyed out).
I have copy and pasted a page and just change the file name and the export class still stays greyed out.
I have deleted the node folder, cleared the cache, and reinstall the cache. Still won't work
Created a new file in the screen and component folder, copy pasted a working page (screen file to a screen file & component file to component file). The export class still stays greyed out.
example of a button component
import React, { Component } from 'react';
import {View, StyleSheet, Dimensions} from 'react-native';
export default function Timer(props) {
return(
<View style={styles.Button}>
<View>
{ props.children }
</View>
</View>
)
}
const styles = StyleSheet.create({
Button: {
height:31,
width: 87,
borderRadius: 10,
backgroundColor: '#E0F7EF',
display: 'flex',
justifyContent: 'center', /* center items vertically, in this case */
alignItems: 'center', /* center items horizontally, in this case */
},
})
Example of a screen component
import React, {Component} from 'react';
import * as firebase from 'firebase';
import { NavigationActions, StackNavigator } from 'react-navigation';
import{ ImageBackground, Dimensions, View, ScrollView, SafeAreaView, TextInput, Picker } from 'react-native';
import { SimpleLineIcons } from '#expo/vector-icons';
import { Container, Header, Content, Card, CardItem, Body, Text } from 'native-base';
import { MaterialCommunityIcons, FontAwesome, MaterialIcons, Ionicons} from '#expo/vector-icons';
import Strings from '../utils/Strings';
var styles = require('../../assets/files/Styles');
var {height, width} = Dimensions.get('window');
//NAVIGATION AT TOP
export default class Cardio extends Component {
static navigationOptions = {
title: `${Strings.ST201}`,
};
navigateToScreen = (route) => () => {
const navigateAction = NavigationActions.navigate({
routeName: route,
});
this.props.navigation.dispatch(navigateAction);
}
render () {
return (
<Container style={styles.background_general}>
<ScrollView>
<View style={{flexDirection:'column', backgroundColor: '#000000', height: height * 0.25}}>
<ImageBackground
source={require('../../assets/images/header.jpg')}
style={{flex: 1, width: null, height: null}}>
</ImageBackground>
</View>
<View style={styles.cardslayout}>
<TextInput
style={styles.CommentBox}
placeholder = 'sets'
returnKeyType="done"
/>
<TextInput
style={styles.CommentBox}
placeholder = 'Reps'
returnKeyType="done"
/>
</View>
<View>
<TextInput />
</View>
<View style={styles.cardslayout}>
<Content horizontal={true}>
{/*Bike*/}
<Card>
<CardItem style={styles.card}>
<Text>
<MaterialIcons name="directions-bike" size={32} color="white"/>
</Text>
</CardItem>
</Card>
<Card>
<CardItem style={styles.card}>
<Text>
<MaterialCommunityIcons name="run-fast" size={32} color="white"/>
</Text>
</CardItem>
</Card>
<Card>
<CardItem style={styles.card}>
<Text>
<Ionicons name="ios-walk" size={32} color="white"/>
</Text>
</CardItem>
</Card>
</Content>
</View>
{/*END OF CUSTOM INPUT*/}
</ScrollView>
</Container>
)
}
}
This is what I mean by it being grayed out.
This is a custom button file in the component folder.
You can see the export default function working in the custom button file. Now am going to create a test file and copy and paste the same code into it and simply change the function name. Now before I change the function name the "export default function" turns grey but I change the name to reduce confusion here.

Related

invarient voilation: resources are not useable as native method argument

i am new here and stuck because of this error. please help me to solve this error.
import React from "react";
import { View, Image, StyleSheet, Text, TouchableOpacity } from "react-native";
function ListItem({ image, title, subtitle }) {
return (
<TouchableOpacity>
<View style={styles.container}>
{image && <Image style={styles.img} source={image} />}
<View>
<Text>{title}</Text>
<Text>{subtitle}</Text>
</View>
</View>
</TouchableOpacity>
);
}
const styles = StyleSheet.create({
container: {
flexDirection: "row"
},
img: {
width: 70,
height: 70,
borderRadius: 35
}
});
export default ListItem;
and invoke it in other component with passing arguments
import * as React from "react";
import Icon from "./Components/Icon";
export default function App() {
return (
<SafeAreaView style={styles.screen}>
<ListItem
title="My title"
subtitle="subtitle"
imgComponent={<Icon name="email" />}
/>
</SafeAreaView>
);
}
and i am facing this error

How to play a segment of a Lottie Animation (.json file ) in React Native

I want to play only a segment of the animation in react native using lottie view
the length is about 5 seconds while in speed={1} I wanna play only the first 3 seconds and then go to the next screen
the code is down below
LogoScreen.js :
import React from 'react';
import { StyleSheet, View, Image, TextInput, StatusBar, Text } from "react-native";
import Icons from 'react-native-vector-icons/Ionicons';
import LottieView from "lottie-react-native";
export default class ChatScreen extends React.Component {
onAnimationFinish = () => {
this.props.navigation.navigate("Login")
}
render () {
return (
<View style={styles.container}>
<StatusBar barStyle="light-content" backgroundColor="#161f3d" />
<View>
<LottieView
source={require('../assets/animations/lottie/MotionCorpse-Jrcanest.json')}
style={{ justifyContent: "center", alignSelf: "center", height: "100%", width: "100%" }}
autoPlay
loop={false}
speed={1}
onAnimationFinish={this.onAnimationFinish}
/>
</View>
</View>
)
}
Well you can do it by several ways, one of the way would be like below.
You can use ref to play it manually and then after 3 seconds just redirect to next screen.
import React from 'react';
import { StyleSheet, View, Image, TextInput, StatusBar, Text } from "react-native";
import Icons from 'react-native-vector-icons/Ionicons';
import LottieView from "lottie-react-native";
export default class ChatScreen extends React.Component {
componentDidMount() {
this.anim.play();
setTimeout(() => {
this.props.navigation.navigate("Login")
}, 3000);
}
render() {
return (
<View style={styles.container}>
<StatusBar barStyle="light-content" backgroundColor="#161f3d" />
<View>
<LottieView
source={require('../assets/animations/lottie/MotionCorpse-Jrcanest.json')}
style={{ justifyContent: "center", alignSelf: "center", height: "100%", width: "100%" }}
autoPlay={false}
loop={false}
speed={1}
ref={animation => { this.anim = animation; }}
/>
</View>
</View>
)
}
}
Another way is if you know exact frame numbers then you can play animation till that frame which completes at 3 seconds. It is already mentioned in Lottie documentation.
this.animation.play(30, 120);

Flex.Item not working in Ant Design Mobile React Native

I'm trying to use Flex feature of Ant Design Mobile to position the buttons with flex direction of column. It seems like the Flex and Flex.Item are not working. The buttons positions are stacked together.
App.js
import React from 'react';
import {Text, View, StyleSheet, Image, TouchableOpacity, SafeAreaView} from 'react-native';
import {Provider, Button, WhiteSpace, Flex} from '#ant-design/react-native';
import customTheme from './src/styles/customTheme';
const App = () => {
return (
<Provider theme={customTheme}>
<SafeAreaView>
<View>
<Flex direction='column'>
<Flex.Item>
<TouchableOpacity style={styles.facebookLoginButton} activeOpacity={0.5}>
<Image
source={require('./img/facebookLoginButton.png')}
style={styles.img}
/>
</TouchableOpacity>
</Flex.Item>
<Flex.Item>
<TouchableOpacity style={styles.googleLoginButton} activeOpacity={0.5}>
<Image
source={require('./img/googleLoginButton.png')}
/>
</TouchableOpacity>
</Flex.Item>
</Flex>
</View>
</SafeAreaView>
</Provider>
);
};
export default App;
const styles = StyleSheet.create({
facebookLoginButton: {
width: 240,
height: 40
},
googleLoginButton: {
borderColor: '#D3D3D3',
borderWidth: 0.5,
width: 240,
height: 40
}
});

How can i fix this, my login page wont connect and i keep on getting this error

import React, { Component } from 'react';
import { AppRegistry, StyleSheet, Text, View, Image, TextInput, TouchableOpacity, background, ImageBackground,} from 'react-native';
import { navigate, navigation, } from 'react-navigation';
const lockIcon = require("./assets/images/lock.png");
const personIcon = require("./assets/images/person.png");
export default class screens extends Component {
render() {
return (
<ImageBackground
style={[styles.background, styles.container]}
source={background}
resizeMode="cover"
>
<View style={styles.container} />
<View style={styles.wrapper}>
<View style={styles.inputWrap}>
<View style={styles.iconWrap}>
<Image
source={personIcon}
style={styles.icon}
resizeMode="contain"
/>
</View>
<TextInput
placeholder="Username"
style={styles.input}
underlineColorAndroid="transparent"
/>
</View>
<View style={styles.inputWrap}>
<View style={styles.iconWrap}>
<Image
source={lockIcon}
style={styles.icon}
resizeMode="contain"
/>
</View>
<TextInput
placeholder="Password"
secureTextEntry
style={styles.input}
underlineColorAndroid="transparent"
/>
</View>
<TouchableOpacity activeOpacity={.5} style={styles.button}
title="Go to Jane's profile"
onPress={() => navigation.navigate('Profile')}
/>
<TouchableOpacity activeOpacity={.5}>
<View>
<Text style={styles.forgotPasswordText}>Forgot Password?</Text>
</View>
</TouchableOpacity>
</View>
<View style={styles.container} />
</ImageBackground>
);
}
}
TypeError: Cannot read property 'navigate' of undefined
You seem to be confused with react-navigation API.
First, you need to understand one thing: you can not just make import { navigation } from 'react-navigation' and then call navigation.navigate('YourRoute'), because the library (react-navigation) has no idea about your screens (routes). To make it understand what YourRoute (in your case it's Profile) actually is, you need to provide it some information.
Create separate file and call it Navigation. Then paste this code into it:
import React from 'react';
import { View, Text } from 'react-native';
import { createAppContainer } from 'react-navigation';
import { createStackNavigator } from 'react-navigation-stack';
import LoginScreen from './pathToYourLoginScreenGoesHere';
import ProfileScreen from './pathToYourProfileScreenGoesHere';
const AppNavigator = createStackNavigator(
{
Login: {
screen: LoginScreen,
},
Profile: {
screen: ProfileScreen,
},
},
{
initialRouteName: 'Login',
},
);
export default AppNavigator;
By doing that, you create your basic navigation stack with two screens (Login and Profile) and have your Login screen as initial. But now it's just a separate file and your application knows nothing about it. Now you should connect this file with your app. Modify your App.js file:
import AppNavigator from './hereGoesRouteToThePreviousFile';
const AppContainer = createAppContainer(AppNavigator);
export default class App extends React.Component {
render() {
return <AppContainer />;
}
}
Providing AppContainer as a root component of your app you pass all necessary props to child screens. Now you have navigation prop in your child screens under the hood.
Now you should modify your file in 2 steps:
Delete import { navigate, navigation, } from 'react-navigation'; string
Right before return word you should paste this line of code: const { navigation } = this.props;
So now your file should look like this:
import React, { Component } from 'react';
import { StyleSheet, Text, View, Image, TextInput, TouchableOpacity, ImageBackground,} from 'react-native';
import styles from './pathToYourStylesFile';
const background = require("./assets/images/yourBackgroundImageFile.png");
const lockIcon = require("./assets/images/lock.png");
const personIcon = require("./assets/images/person.png");
export default class screens extends Component {
render() {
const { navigation } = this.props;
return (
<ImageBackground
style={[styles.background, styles.container]}
source={background}
resizeMode="cover"
>
<View style={styles.container}>
<View style={styles.wrapper}>
<View style={styles.inputWrap}>
<View style={styles.iconWrap}>
<Image
source={personIcon}
style={styles.icon}
resizeMode="contain"
/>
</View>
<TextInput
placeholder="Username"
style={styles.input}
underlineColorAndroid="transparent"
/>
</View>
<View style={styles.inputWrap}>
<View style={styles.iconWrap}>
<Image
source={lockIcon}
style={styles.icon}
resizeMode="contain"
/>
</View>
<TextInput
placeholder="Password"
secureTextEntry
style={styles.input}
underlineColorAndroid="transparent"
/>
</View>
<TouchableOpacity activeOpacity={.5} style={styles.button}
title="Go to Jane's profile"
onPress={() => navigation.navigate('Profile')}
/>
<TouchableOpacity activeOpacity={.5}>
<View>
<Text style={styles.forgotPasswordText}>Forgot Password?</Text>
</View>
</TouchableOpacity>
</View>
<View style={styles.container} />
</ImageBackground>
);
}
}
Also pay attention at these moments: I deleted import of background property from 'react-native' lib, because there is no exported property like that in react-native. Instead, provide real path to const background = require("./assets/images/yourBackgroundImageFile.png");, it should be a real image you want to use as a background image.

React native stack navigation goBack() not working

I created common header for all pages, so create header component then i include that header in signup.js component goback navigation function working in signup.js page but not working header component getting undefined object navigate.goback error
Anyone give a solution for that like that i include component
sample code:
import React from 'react';
import { StyleSheet, Text, View, Image, ScrollView, TextInput,KeyboardAvoidingView, StatusBar } from 'react-native';
import {Icon,Body,Button,Title,Left,Right} from 'native-base';
import Expo from "expo";
import { Constants } from 'expo';
import Headerbar from "./../Header/header";
import Statusbar from "./../statusbar";
const googleIcon=require('../../../img/google_icon.png');
const fbIcon=require('../../../img/fb_icon.png');
export default class Socialsignup extends React.Component {
constructor(props) {
super(props);
this.state = {
};
}
render() {
return (
<ScrollView style={styles.socialContainer} scrollEnabled={true}>
<Statusbar/>
<Headerbar title="Social Login" />
<View style={styles.socialText}>
<Text style={styles.accountText}>Choose an account</Text>
</View>
<View style={styles.socialIconsBase}>
<View style={styles.socialIconsGoogle}>
<Image source={googleIcon} style={styles.googleIcon}/>
<Text style={styles.iconText}>
Google
</Text>
</View>
<View style={styles.socialIconsGoogle}>
<Image source={fbIcon} style={styles.fbIcon}/>
<Text style={styles.iconText}>
Facebook
</Text>
</View>
</View>
</ScrollView>
);
}
}
const styles = StyleSheet.create({
socialContainer: {
backgroundColor: '#fff',
},
accountText: {
marginTop:25,
fontSize:20,
padding:20
},
socialIconsBase:
{
flexDirection:'row',
flex:1,
marginTop:40,
borderBottomWidth:1,
borderBottomColor:'#a8c0ce'
},
socialIconsGoogle:
{
flex:1,
alignItems:'center',
paddingTop:25,
paddingBottom:25,
borderRightWidth:1,
borderRightColor:'#a8c0ce',
marginBottom:8,
},
fbIcon:{
height:50,
width:50,
},
googleIcon:{
height:50,
width:50,
},
iconText:{
fontSize:15,
marginTop:15
}
});
you need to use this inside the header component :
import { withRouter } from 'react-router'
and then instead of export default HeaderClassName
use export default withRouter(HeaderClassName)
and you can go back by this.props.history.goBack()
You need to use this too:
<BrowserRouter>
<App />
and then add the pages like that
<Route path='/page' component={Page} />

Resources