Does expo, problem with webview, it show page blank screen - react-native

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' }}
/>
);
}

Related

Attempting to run JS driven animation on animated node that has been moved to "native" earlier by starting an animation with useNativeDriver: true

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

React Native Gesture Handler / React Native animated 2: Tried to synchronously call function {_readOnlyError} from a different thread

Error
Im learning react native gesture handler and react native reanimated from the docs. I got this error when i got the gesture coordinates ,passed them to the useShared value translateX. Im running my app on a Samsung Galaxy A5 2017 running android 8.0.0. Please explain your answer.
App.js
// import { StatusBar } from 'expo-status-bar';
import { useEffect } from 'react';
import { StyleSheet, Text, View,StatusBar,TouchableOpacity } from 'react-native';
import Animated, {useSharedValue, useAnimatedStyle, withTiming,withSpring,withRepeat} from 'react-native-reanimated'
import { createNativeStackNavigator } from '#react-navigation/native-stack';
import { NavigationContainer } from '#react-navigation/native';
import Header from './components/Header';
import Gesture from './screens/Gesture';
const SimpleAnimation=({navigation})=>{
const SIZE=100.0
const handleRotation=(progress)=>{
"worklet";
return `${progress.value*2*Math.PI}rad`;
}
const progress=useSharedValue(0.5)
const scale=useSharedValue(0.5)
const reanimatedStyle=useAnimatedStyle(()=>{
return {
opacity: progress.value,
transform:[{scale:scale.value},{rotate:handleRotation(progress) }],
borderRadius:(progress.value*SIZE)/2,
};
},[])
useEffect(()=>{
progress.value=withRepeat(withSpring(1),-1,true);
scale.value=withRepeat(withSpring(2),-1,true)
},[]);
return (
<View style={{flex:1,marginTop:StatusBar.currentHeight}}>
<Header LeftComponent={()=>(<Text style={{color:"tomato",fontWeight:"bold",fontSize:20}}>Animation</Text>)} RightComponent={()=>(<TouchableOpacity onPress={()=>navigation.navigate("GestureScreen")} style={{backgroundColor:"tomato",padding:10,borderRadius:10,}}><Text style={{color:"white",fontWeight:"bold"}}>Go To Gestures</Text></TouchableOpacity>)} />
<View style={styles.container}>
<Animated.View style={[{width:SIZE,height:SIZE,backgroundColor:"blue"},reanimatedStyle]}>
</Animated.View>
</View>
</View>
);
}
const Stack = createNativeStackNavigator();
export default function App() {
const navigateTo=(screenname)=>{
}
return (
<NavigationContainer>
<Stack.Navigator initialRouteName='Animation' screenOptions={{headerShown:false}}>
<Stack.Screen name="Animation" component={SimpleAnimation}/>
<Stack.Screen name="GestureScreen" component={Gesture}/>
</Stack.Navigator>
</NavigationContainer>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
Gesture.js
import { StyleSheet, Text, View,StatusBar,TouchableOpacity } from 'react-native'
import React from 'react'
import Animated,{useSharedValue,useAnimatedStyle, runOnJS} from 'react-native-reanimated'
import Header from '../components/Header'
import { Gesture,GestureDetector,GestureHandlerRootView } from 'react-native-gesture-handler'
function ActualGesture() {
const translateX=useSharedValue(0);
// const translateY=useSharedValue(0);
const gesture=Gesture.Pan().onUpdate((event)=>{
translateX=event.translationX;
});
const rStyle=useAnimatedStyle(()=>{
return {
transform:[{translateX:translateX.value}],
};
});
return (
<GestureHandlerRootView style={styles.container}>
<GestureDetector gesture={gesture}>
<Animated.View style={[styles.circle,rStyle]}></Animated.View>
</GestureDetector>
</GestureHandlerRootView>
)
}
const GestureScreen = ({navigation}) => {
return (
<View style={{flex:1,marginTop:StatusBar.currentHeight}}>
<Header LeftComponent={()=>(<TouchableOpacity onPress={()=>navigation.navigate("Animation")} style={{backgroundColor:"tomato",padding:10,borderRadius:10,}}><Text style={{color:"white",fontWeight:"bold"}}>Return</Text></TouchableOpacity>)} RightComponent={()=>(<TouchableOpacity onPress={()=>navigation.navigate("GestureScreen")} style={{backgroundColor:"tomato",padding:10,borderRadius:10,}}><Text style={{color:"white",fontWeight:"bold"}}>Go To Gestures</Text></TouchableOpacity>)} />
<ActualGesture/>
</View>
)
}
export default GestureScreen
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
circle:{
height:60,aspectRatio:1,backgroundColor:"blue",borderRadius:50
}
});
package.json
{
"name": "animate",
"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": {
"#react-navigation/native": "^6.0.8",
"#react-navigation/native-stack": "^6.5.0",
"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-gesture-handler": "~2.1.0",
"react-native-reanimated": "~2.3.1",
"react-native-safe-area-context": "3.3.2",
"react-native-screens": "~3.10.1",
"react-native-web": "0.17.1"
},
"devDependencies": {
"#babel/core": "^7.12.9"
},
"private": true
}
From what i understand from the error is that the gesture function shouldve either been a JS thread or a worklet,i tried doing that to no avail by adding "worklet"; to the beginning of the functions code. Im guessing this is an android error, because based off youtube tutorials given an iOS emulator it works just fine. The gesture function is bringing the right coordinates, its just the changing of the styling to match the translatex value. Please help me i dont know how to carry on from here.
react-native-gesture-handler Gesture can run on js thread with .runOnJS(true) in your case it would be :
function ActualGesture() {
const translateX=useSharedValue(0);
// const translateY=useSharedValue(0);
const gesture=Gesture.Pan().runOnJS(true).onUpdate((event)=>{
translateX=event.translationX;
});
const rStyle=useAnimatedStyle(()=>{
return {
transform:[{translateX:translateX.value}],
};
});
return (
<GestureHandlerRootView style={styles.container}>
<GestureDetector gesture={gesture}>
<Animated.View style={[styles.circle,rStyle]}></Animated.View>
</GestureDetector>
</GestureHandlerRootView>
)
}

Drawer not changing position from left to right

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

How to decrease launch time of react native app

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.

Rendering error with Native-base and Swiper

I've been following this tutorial here https://www.youtube.com/watch?v=pgDOpIm6ozQ(#1 Snapchat UI Swipe Animation | React Native Layouts - Expo and Native Base)
However when I run it on expo it only shows a blank screen and I checked if there's any problem related to compatibility between versions and i didn't found anything
My Android Emulator Screen
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { Container, Content } from 'native-base';
import Swiper from 'react-native-swiper';
const styles = StyleSheet.create({
slideDefault: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#9DD6EB'
},
text: {
color: 'white',
fontSize: 30,
fontWeight: 'bold'
}
})
export default class App extends React.Component {
constructor() {
super()
this.state = {
outerScrollEnabled: true
}
}
verticalScroll = (index) => {
if (index !== 1) {
this.setState({
outerScrollEnabled: false
})
}
else {
this.setState({
outerScrollEnabled: true
})
}
}
render() {
return (
<Container>
<Content>
<Swiper
loop={false}
showsPagination={false}
index={1}
scrollEnabled={this.state.outerScrollEnabled}
>
<View style={styles.slideDefault}>
<Text style={styles.text}>Chat</Text>
</View>
<Swiper
loop={false}
showsPagination={false}
horizontal={false}
index={1}
onIndexChanged={(index) => this.verticalScroll(index)}
>
<View style={styles.slideDefault}>
<Text style={styles.text}>Search</Text>
</View>
<View style={styles.slideDefault}>
<Text style={styles.text}>Camera</Text>
</View>
<View style={styles.slideDefault}>
<Text style={styles.text}>Memories</Text>
</View>
</Swiper>
<View style={styles.slideDefault}>
<Text style={styles.text}>Stories</Text>
</View>
</Swiper>
</Content>
</Container>
);
}
}
{
"name": "empty-project-template",
"main": "node_modules/expo/AppEntry.js",
"private": true,
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"eject": "expo eject"
},
"dependencies": {
"expo": "^30.0.1",
"native-base": "^2.3.1",
"react": "16.3.1",
"react-native": "https://github.com/expo/react-native/archive/sdk-30.0.0.tar.gz",
"react-native-swiper": "^1.5.13",
"react-native-vector-icons": "^4.1.1"
}
}