I am trying to shift drawer from left to right, but it isn't working. However when I am trying to shift from right to left, its working fine. I have already tried in physical device and running in emulator, but nothing worked.
Here is my package.json:
{
"name": "Practice",
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"start": "react-native start",
"test": "jest",
"lint": "eslint ."
},
"dependencies": {
"#react-native-community/masked-view": "^0.1.10",
"#react-navigation/core": "^5.10.0",
"#react-navigation/drawer": "^5.8.2",
"#react-navigation/native": "^5.5.1",
"react": "16.11.0",
"react-native": "0.62.2",
"react-native-gesture-handler": "^1.6.1",
"react-native-reanimated": "^1.9.0",
"react-native-safe-area-context": "^3.0.5",
"react-native-screens": "^2.8.0"
},
"devDependencies": {
"#babel/core": "^7.10.2",
"#babel/runtime": "^7.10.2",
"#react-native-community/eslint-config": "^2.0.0",
"babel-jest": "^26.0.1",
"eslint": "^7.2.0",
"jest": "^26.0.1",
"metro-react-native-babel-preset": "^0.59.0",
"react-test-renderer": "16.11.0"
},
"jest": {
"preset": "react-native"
}
}
Node Version: v10.19.0
NPM Version: 6.14.5
Code:
import React, {Component} from 'react';
import { Button, View, Text } from 'react-native';
import {createDrawerNavigator, DrawerItem} from '#react-navigation/drawer';
import { NavigationContainer } from '#react-navigation/native';
function HomeScreen({ navigation, route:{params: {changePosition}} }) {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Button
onPress={() => navigation.toggleDrawer()}
title="Open Drawer"
/>
<View style={{marginTop:20}}/>
<Button
onPress={changePosition}
title={'Change Drawer Position'}
/>
</View>
);
}
const Drawer = createDrawerNavigator();
export default class App extends Component {
state = {
position: 'left'
}
changePosition(){
this.setState({position: this.state.position==='right'?'left':'right'}, ()=>{
alert("Drawer Position: " + this.state.position);
});
}
render(){
return (
<NavigationContainer>
<Drawer.Navigator drawerPosition={this.state.position} initialRouteName="Home">
<Drawer.Screen name="Home" component={HomeScreen}
initialParams={{changePosition:this.changePosition.bind(this)}} />
</Drawer.Navigator>
</NavigationContainer>
);
}
}
Screenshot
I have submitted this issue to GitHub repo too track it here:
https://github.com/react-navigation/react-navigation/issues/8374
Related
I am trying to implement the same appBar bottom variant with react-native-material as in https://www.react-native-material.com/docs/components/app-bar#bottom-app-bar and I am getting the following error:
Attempting to run JS driven animation on animated node that has been moved to "native" earlier by starting an animation with useNativeDriver: true.
I cannot find any solution to this problem online.
Any help would be appreciated.
Here is my App component:
import { AppBar, IconButton, FAB } from "#react-native-material/core";
import Icon from "#expo/vector-icons/MaterialCommunityIcons";
export default function App() {
return (
<>
<AppBar
variant="bottom"
color="white"
leading={(props) => (
<IconButton
icon={(props) => <Icon name="menu" {...props} />}
{...props}
/>
)}
trailing={(props) => (
<IconButton
icon={(props) => <Icon name="magnify" {...props} />}
{...props}
/>
)}
style={{ position: "absolute", start: 0, end: 0, bottom: 0 }}
>
<FAB
color="black"
icon={(props) => <Icon name="plus" {...props} />}
style={{ position: "absolute", top: -28, alignSelf: "center" }}
/>
</AppBar>
</>
);
}
Here is package.json:
{
"name": "notetaker",
"version": "1.0.0",
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web"
},
"dependencies": {
"#react-native-material/core": "^1.3.7",
"#react-navigation/native": "^6.1.3",
"expo": "~47.0.12",
"expo-status-bar": "~1.4.2",
"react": "18.1.0",
"react-native": "0.70.5"
},
"devDependencies": {
"#babel/core": "^7.12.9",
"#types/react": "~18.0.14",
"#types/react-native": "~0.70.6",
"typescript": "^4.6.3"
},
"private": true
}
Spent few hours on the internet trying to find solution but did not get any luck
i've seen alot of people having the same problem but sadly without any solutions .
I'm using expo with react native gesture handler, i have added "react-native-reanimated/plugin" in babel.config.js but still not getting any response.
Here is my code:
babel.config.js
module.exports = function (api) {
api.cache(true);
return {
presets: ["babel-preset-expo"],
plugins: ["react-native-reanimated/plugin"],
};
};
App.js
import { PanGestureHandler } from "react-native-gesture-handler";
import "react-native-gesture-handler";
import Animated, {
useAnimatedGestureHandler,
useAnimatedStyle,
useSharedValue,
} from "react-native-reanimated";
import { StyleSheet, View } from "react-native";
const SIZE = 100.0;
export default function App() {
const translateX = useSharedValue(0);
const panGestureEvent = useAnimatedGestureHandler({
onStart: (event) => {
console.log("starting...");
},
onActive: (event) => {
// translateX.value = event.translationX;
console.log(event.translationX);
},
onEnd: (event) => {},
});
const rStyle = useAnimatedStyle(() => {
return {
transform: [{ translateX: translateX.value }],
};
});
return (
<View style={styles.container}>
<PanGestureHandler onGestureEvent={panGestureEvent}>
<Animated.View style={[styles.square, rStyle]} />
</PanGestureHandler>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff",
alignItems: "center",
justifyContent: "center",
},
square: {
width: SIZE,
height: SIZE,
backgroundColor: "dodgerblue",
borderRadius: 15,
},
});
i didn't do anything smart, simple and easy code, yet not getting any response.
package.json
{
"name": "a",
"version": "1.0.0",
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
"eject": "expo eject"
},
"dependencies": {
"expo": "~44.0.0",
"expo-status-bar": "~1.2.0",
"react": "17.0.1",
"react-dom": "17.0.1",
"react-native": "0.64.3",
"react-native-web": "0.17.1",
"react-native-gesture-handler": "~2.1.0",
"react-native-reanimated": "^2.3.1"
},
"devDependencies": {
"#babel/core": "^7.12.9"
},
"private": true
}
On Android you need to wrap everything with GestureHandlerRootView.
So do this below
import {
GestureHandlerRootView,
} from 'react-native-gesture-handler';
then
<GestureHandlerRootView style={{ flex: 1 }}>
<View style={styles.container}>
<PanGestureHandler onGestureEvent={panGestureEvent}>
<Animated.View style={[styles.square, rStyle]} />
</PanGestureHandler>
</View>
</GestureHandlerRootView>
Related documentation: https://docs.swmansion.com/react-native-gesture-handler/docs/installation#js
currency I am working with React Native and expo, yesterday I was working with WebView however my project it show blanck screen, when I compile my project, I see everything through of my phone, I already tried everything to solve it but I have not been successful, somebody can I help me plese?, i don't know what to do.
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { WebView } from 'react-native-webview';
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
export default function App(){
return (
<View style={styles.container}>
<h1>Test</h1>
<Text>Test text</Text>
<WebView
source={{ uri: 'https://www.youtube.com' }}
/>
</View>
);
}
Here is my package.json
{
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
"eject": "expo eject"
},
"dependencies": {
"expo": "~41.0.1",
"expo-status-bar": "~1.0.4",
"react": "17.0.2",
"react-dom": "17.0.2",
"react-native": "https://github.com/expo/react-native/archive/sdk-41.0.0.tar.gz",
"react-native-web": "~0.16.3",
"react-native-webview": "11.2.3"
},
"devDependencies": {
"#babel/core": "^7.14.3"
},
"private": true
Having this issue as well, I noticed if I use the example on the github docs it will load a video, but so far not able to render html or a webpage:
<WebView source={{ uri: 'https://facebook.github.io/react-native/' }} />
Copy and paste this into Snack.expo.io
I am a little unclear as to what exactly your problem is but this renders the webpage fine on both android and iphones.
The issue that causes the white screen is the styling. If you remove the styling besides flex: 1, it renders completely.
export default function App(){
return (
<WebView
source={{ uri: 'https://www.youtube.com' }}
/>
);
}
I'm building a web app using react-native-web with #react-navigation/bottom-tabs.
But the screen content doesn't appear on the web, it only shows the Tab Bar. It works fine on iOS and Android.
Here is the code:
import {createBottomTabNavigator} from '#react-navigation/bottom-tabs';
import {NavigationContainer} from '#react-navigation/native';
import React from 'react';
import {Text, View} from 'react-native';
const HomeScreen = () => {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text>This is the home screen</Text>
</View>
);
};
const RootView = () => {
const Tab = createBottomTabNavigator();
return (
<NavigationContainer>
<Tab.Navigator>
<Tab.Screen name="Home" component={HomeScreen} />
</Tab.Navigator>
</NavigationContainer>
);
};
export default React.memo(RootView);
Dependencies:
"dependencies": {
"#react-native-community/async-storage": "^1.12.1",
"#react-navigation/bottom-tabs": "^5.11.2",
"#react-navigation/native": "^5.8.10",
"#react-navigation/stack": "^5.12.8",
"#reduxjs/toolkit": "^1.5.0",
"axios": "^0.21.1",
"class-transformer": "^0.3.1",
"react": "16.13.1",
"react-dom": "^17.0.1",
"react-native": "0.63.3",
"react-native-safe-area-context": "^3.1.9",
"react-native-screens": "^2.16.1",
"react-native-web": "^0.14.10",
"react-redux": "^7.2.2",
"react-router-dom": "^5.2.0",
"redux": "^4.0.5",
"redux-logger": "^3.0.6",
"redux-observable": "^1.2.0",
"redux-persist": "^6.0.0",
"rxjs": "^6.6.3",
"styled-components": "^5.2.1"
},
And the result on web and iOS:
I finally can resolve this issue by setting these styles in public/index.html
<style>
/* These styles make the body full-height */
html,
body {
height: 100%;
}
/* These styles disable body scrolling if you are using <ScrollView> */
body {
overflow: hidden;
}
/* These styles make the root element full-height */
#root {
display: flex;
height: 100%;
}
</style>
I am developing news app using react native, and my problem is the launch or startup time of app is long(before the home screen shows), I would appreciate any advice to improve the speed.It takes around 4 seconds to load initially and 2 seconds for the js. I have 36 articles to show on home screen and the json response is big and maybe it is the reason of the problem.
My package.json looks like this :
{
"name": "tageblattapp",
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"start": "react-native start",
"test": "jest",
"lint": "eslint ."
},
"dependencies": {
"#react-native-community/masked-view": "^0.1.7",
"moment": "^2.24.0",
"native-base": "^2.13.12",
"react": "16.11.0",
"react-native": "0.62.0",
"react-native-gesture-handler": "^1.6.1",
"react-native-optimized-flatlist": "^1.0.4",
"react-native-reanimated": "^1.7.1",
"react-native-render-html": "^4.2.0",
"react-native-safe-area-context": "^0.7.3",
"react-native-safe-area-view": "^1.0.0",
"react-native-screens": "^2.7.0",
"react-native-vector-icons": "^6.6.0",
"react-native-webview": "^9.3.0",
"react-navigation": "^4.3.5",
"react-navigation-drawer": "^2.4.12",
"react-navigation-stack": "^2.3.9"
},
"devDependencies": {
"#babel/core": "7.9.0",
"#babel/runtime": "7.9.2",
"#react-native-community/eslint-config": "0.0.5",
"babel-jest": "24.9.0",
"eslint": "6.8.0",
"jest": "24.9.0",
"metro-react-native-babel-preset": "0.58.0",
"react-test-renderer": "16.11.0"
},
"jest": {
"preset": "react-native"
},
"rnpm": {
"assets": [
"../assets/fonts/"
]
}
}
My imports are:
import React,{PureComponent} from 'react';
import {AsyncStorage, Linking ,Share, View ,Image,ActivityIndicator ,StyleSheet, TouchableOpacity,Dimensions,ScrollView,SafeAreaView, TextInput ,FlatList} from 'react-native';
import Icon from 'react-native-vector-icons/FontAwesome';
import { createAppContainer } from 'react-navigation';
import {Container, Header, Left, Body, Right, Button, Title,Text,Content, List, ListItem,Thumbnail} from 'native-base';
import { createStackNavigator } from 'react-navigation-stack';
import { createDrawerNavigator } from 'react-navigation-drawer';
import { IMAGE } from '../constants/image';
import { getMenusideGategory} from '../services/news';
import HTML from 'react-native-render-html';
import Time from '../components/time';
import moment from 'moment';
import FeedDetail from './FeedDetail';
import ArticleLink from './ArticleLink';
import Comments from './Comments';
import AddComments from './AddComments';
The funcyion that gets articles:
export async function getArticles(){
try {
let articles = await fetch(`${articles_url}`,{
headers:{
'X-API-KEY':_api_key
}
});
let result = await articles.json();
return result.articles;
} catch (error) {
throw error
}
}
The home.js that display the articles is :
export class HomeScreen extends PureComponent {
constructor(props) {
super(props);
this._handleItemDataOnPress = this._handleItemDataOnPress.bind(this)
this.state = {
isLoading: true,
data: null,
isError: false,
setModalVisible: false,
modalArticleData: {}
}
}
_handleItemDataOnPress(articleData) {
this.setState({
setModalVisible: true,
modalArticleData: articleData
})
}
componentDidMount() {
getArticles().then(data => {
this.setState({
isLoading: false,
data: data
})
}, error => {
Alert.alert("Error", "Something happend, please try again")
})
}
render() {
let view = this.state.isLoading ? (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<ActivityIndicator animating={this.state.isLoading} color="#00f0ff" />
<Text style={{ marginTop: 8 }} children="Please wait..." />
</View>
) : (
<FlatList
dataArray={this.state.data}
renderRow={(item) => {
return (
<ListItem>
<ListDataItem onPress={this._handleItemDataOnPress} data={item} />
</ListItem>
)
}} />
)
return (
<Container>
<Header>
<Body>
<Title children="RN NewsApp" />
</Body>
</Header>
<Content
contentContainerStyle={{ flex: 1, backgroundColor: '#fff' }}
padder={false}>
{view}
</Content>
</Container>
)
}
}
The class ListDataItem that shows single data item inside the list renderRow:
export default class ListDataItem extends PureComponent{
constructor(props){
super(props);
this.data = props.data;
this._handlePress = this._handlePress.bind(this)
}
_handlePress(){
const {url, title} = this.data
this.props.onPress({url,title})
}
render(){
return(
<TouchableOpacity onPress={this._handlePress} style={{flexDirection:'row'}} activeOpacity={0.5}>
<Thumbnail style={{ backgroundColor: '#eee', alignSelf: 'center' }} square large source={{ cache:'force-cache', uri: this.data.urlToImage != null ? this.data.urlToImage : null }} />
<Body>
<Text style={{fontSize: 16 }} numberOfLines={2}>{this.data.title}</Text>
<Text note numberOfLines={3}>{this.data.description}</Text>
<View style={{ flex: 1, flexDirection: 'row', marginTop: 8, marginLeft: 8 }}>
<Text note>{this.data.source.name}</Text>
<TimeAgo date={this.data.publishedAt} />
</View>
</Body>
</TouchableOpacity>
)
}
}
I tried also to put the header inside the flatlist using LisHeaderComponent, but there was no difference.
Decrease your start up time and RAM memory consumption by an application via splitting JS bundle by components and navigation routes.
https://www.npmjs.com/package/react-native-bundle-splitter
Just by creating a release Apk/Build
In a release Apk, App loads in just half a second which means the Splash screen or Launch screen shows up for half a second only.