I am newbie in react native and I am trying to use the panGestureHandler , guided by the documentation the code was written as follow:
import { GestureHandlerRootView,PanGestureHandler } from "react-native-gesture-
handler";
import { useEffect } from "react";
import { Animated,Button,Dimensions,StyleSheet,ScrollView ,View,Text} from "react-
native";
import { useAnimatedGestureHandler, useAnimatedStyle, useSharedValue, withSpring,
withTiming } from "react-native-reanimated";
export default function App () {
const progress= useSharedValue(2)
const panHandler=useAnimatedGestureHandler({
onStart:(event,context)=>{},
onActive:(event,context)=>{},
onEnd:(event,context)=>{}
})
const animatedStyle=useAnimatedStyle(()=>{
return{
borderRadius:progress.value*30
}
})
return(
<GestureHandlerRootView >
<PanGestureHandler onGestureEvent={panHandler}>
<Animated.View style={[styles.container,animatedStyle]}><Text>test</Text>
</Animated.View>
</PanGestureHandler>
</GestureHandlerRootView>
)}
but I always get the following error:
ERROR Error: Expected `onGestureHandlerEvent` listener to be a function, instead got a value of `object` type.
import Animated from react-native-reanimated will fix this issue.
import Animated, {
useSharedValue,
withSpring,
useAnimatedStyle,
useAnimatedGestureHandler,
} from 'react-native-reanimated';
Related
the code is not showing an error:
import { View, SafeAreaView, Image, TextInput, Button, Text, StyleSheet } from "react-native";
import { IonIcon } from '#ionic/react';
import { addOutline } from 'ionicons/icons';
export default function signIn(){
const UI = (
<SafeAreaView style={styels.createNewProfile}>
<View>
<IonIcon slot="addOutline" icon={addOutline}></IonIcon>
</View>
</SafeAreaView>
);
return UI;
};
const styels = StyleSheet.create({
createNewProfile: {
flex: 1
},
AppProfilePicture: {
width: 100,
height: 100
}
});
but after I run the code for android app on windows with the command of npx react-native run-android
the error message is:
Error: node_modules\#stencil\core\internal\client\index.js:Invalid call at line 3229: import(
/* #vite-ignore */
/* webpackInclude: /\.entry\.js$/ */
/* webpackExclude: /\.system\.entry\.js$/ */
/* webpackMode: "lazy" */
"./" + bundleId + ".entry.js" + (require("#stencil/core/internal/app-data").BUILD.hotModuleReplacement && hmrVersionId ? '?s-hmr=' + hmrVersionId : ''))
at transformJS (D:\react-native-practice\app1\node_modules\metro-transform-worker\src\index.js:237:15)
at transformJSWithBabel (D:\react-native-practice\app1\node_modules\metro-transform-worker\src\index.js:372:16)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Object.transform (D:\react-native-practice\app1\node_modules\metro-transform-worker\src\index.js:518:12)
I just tried import Icon from 'react-native-ionicons' this library... it's not showing any error but it's not output any icon:
app.tsx:
import React from "react";
import { SafeAreaView, View, Text, TextInput } from "react-native";
import Icon from 'react-native-ionicons'
const IconBar = () => (
<View>
<Icon name="add-outline" size={10}/>
</View>
)
export default IconBar;
Check your package.json, for me with "react-native-vector-icons": "^9.2.0", :
I need to add the import at the top:
import Ionicons from "react-native-vector-icons/Ionicons";
Load fonts with:
Ionicons.loadFont();
In first line after all imports.
Good luck for your project!
you can use this way it's working
import React from 'react';
import Ionicons from '#expo/vector-icons/Ionicons';
export default class IconExample extends React.Component {
render() {
return <Ionicons name='rocket' size={32} color='green' />;
}
}
I am very new to programming with React-native, and I was wondering if anyone could explain how I should fix this error? I was following along with a tutorial and had an error come up due to this section of code, even though it matched the tutorial code.
Here is the section of code:
import React, { createContext, useContext } from "react";
import * as Google from "expo-google-app-auth";
const AuthContext = createContext({});
export const AuthProvider = ({ children }) => {
const signInWithGoogle = async() => {
await Google.logInAsync
}
return (
<AuthContext.Provider
value={{
user: null,
}}
>
{children}
</AuthContext.Provider>
);
};
export default function useAuth() {
return useContext(AuthContext);
}
These other two sections may be relevant as well:
Root of the App:
import React from 'react';
import { Text, View, SafeAreaView, Button, Alert } from 'react-native';
import AuthProvider from "./hooks/useAuth";
import StackNavigator from "./StackNavigator";
import { NavigationContainer} from "#react-navigation/native";
// Function for creating button
export default function App() {
return (
<NavigationContainer>
<AuthProvider>
<StackNavigator />
</AuthProvider>
</NavigationContainer>
);
}
This is my code for the Login Screen:
import React from 'react';
import { View, Text } from 'react-native';
import useAuth from '../hooks/useAuth';
const LoginScreen = () => {
const { user } = useAuth();
console.log(user);
return (
<View>
<Text>
Login to the app
</Text>
</View>
);
};
export default LoginScreen
This is the error that appears:
Error: Objects are not valid as a React child (found: object with keys {}). If you meant to render a collection of children, use an array instead.
I suggest you auth with firebase. it makes easier this things.
I am having a lot of trouble figuring out what React Native's cryptic error messages mean. I've had the following error for about thirty minutes and after all my googling I still don't know how to fix it: Couldn't find a 'component', 'getComponent', or 'children' prop for the screen 'User'.
My App module:
import React, { useEffect, useState } from 'react';
import { ActivityIndicator, FlatList, Button, View, Text, Image, StyleSheet } from 'react-native';
import { NavigationContainer } from '#react-navigation/native';
import { createStackNavigator } from '#react-navigation/stack';
import { UserDetailScreen } from './app/screens/UserDetailScreen';
const Stack = createStackNavigator();
function MyStack() {
return (
<Stack.Navigator>
<Stack.Screen name="User" component={UserDetailScreen} />
</Stack.Navigator>
);
}
export default function App() {
console.log("test");
console.log(UserDetailScreen);
return (
<NavigationContainer>
<MyStack />
</NavigationContainer>
);
}
My UserDetailScreen
import React from 'react';
import { SafeAreaView, View, StyleSheet } from 'react-native';
import { ActivityIndicator, FlatList, Button, Text, Image } from 'react-native';
import {styles} from '../assets/stylesheets/UserDetailStyles';
export default class UserDetailScreen extends React.Component<Props> {
render = ({ navigation }) => {...return components}
}
You are exporting a default class in UserDetailScreen.js. Import a default class like so: import UserDetailScreen from './app/screens/UserDetailScreen';
Error:
[#RNC/AsyncStorage]: NativeModule: AsyncStorage is null.
I got it when I try to run my app in expo with npm start
I got it last night, I fixed it and it worked till one hour ago, but now it’s here again.
I read other topics about the same error, but it doesn’t work for me.
my app.js code
import React from 'react';
import { Platform, StatusBar, StyleSheet, View, AsyncStorage} from 'react-native';
import { AppLoading, Asset, Font, Icon } from 'expo';
import AppNavigator from './navigation/AppNavigator';
import MainTabNavigator from './navigation/MainTabNavigator';
import * as firebase from 'firebase';
export default class App extends React.Component {
state = {
isLoadingComplete: false,
isAuthenticationReady: false,
isAuthenticated: false,
};
render() {
if (!this.state.isLoadingComplete && !this.props.skipLoadingScreen) {
return (
<AppLoading
startAsync={this._loadResourcesAsync}
onError={this._handleLoadingError}
onFinish={this._handleFinishLoading}
/>
);
} else {
return (
<View style={styles.container}>
{Platform.OS === 'ios' && <StatusBar barStyle="default" />}
<AppNavigator />
</View>
);
}
}
_loadResourcesAsync = async () => {
return Promise.all([
Asset.loadAsync([
require('./assets/images/robot-dev.png'),
require('./assets/images/robot-prod.png'),
]),
Font.loadAsync({
// This is the font that we are using for our tab bar
...Icon.Ionicons.font,
// We include SpaceMono because we use it in HomeScreen.js. Feel free
// to remove this if you are not using it in your app
'space-mono': require('./assets/fonts/SpaceMono-Regular.ttf'),
}),
]);
};
AsyncStorage no longer in react-native library:
import { Platform, StatusBar, StyleSheet, View, AsyncStorage} from 'react-native';
remove AsyncStorage as a module and do npm install --save #react-native-community/async-storage
and then import into your file like so:
import AsyncStorage from '#react-native-community/async-storage';
I'm using React Router for a React Native app. Not sure what I'm missing here but I install react-router-native and require the history package, and setup a couple methods that just push a new route onto the stack but nothing happens. I console.log('clicked'); to check that it's firing and it is so not sure what's wrong.
import React, { Component } from 'react';
import { View } from 'react-native';
import Splash from './Splash';
import createHistory from 'history/createMemoryHistory';
const history = createHistory();
class SplashContainer extends Component {
goToLogin = () => {
history.push('/Login');
}
goToRegister = () => {
history.push('/SignUp');
}
render () {
console.log(history)
return (
<Splash
goToLogin={this.goToLogin}
goToRegister={this.goToRegister}
/>
);
}
}
export default SplashContainer;
import React from 'react';
import { StyleSheet, View, Text } from 'react-native';
import { Button } from 'native-base';
import { Link } from 'react-router-native';
import PropTypes from 'prop-types';
const Splash = (props) => {
console.log(props)
return (
<View style={styles.container}>
<Button light block onPress={props.goToLogin}>
<Text>Login</Text>
</Button>
<Button dark block bordered style={{marginTop: 10}} onPress={props.goToRegister}>
<Text>Register</Text>
</Button>
</View>
);
}
Splash.propTypes = {
goToLogin: PropTypes.func.isRequired,
goToRegister: PropTypes.func.isRequired
}
export default Splash;
I don't know your Router config, but your methods should be:
goToLogin = () => {
const { history } = this.props
history.push('/Login');
}
history will passed down via props of component inside Router's stack.