I am sorry if this is such a newbie question but I am really frustrated with setting up a background-video in my react native app.
Starting off with the documentation of the react native video library.
Is it bad documentation or am I having a really hard time understanding how to set it up?
I did npm install --save react-native-video.
I ran react-native link
I checked the other java files and they already have what he notes out.
And his reference to Windows, I have no idea what or which user case scenario should do what he states.
To the code:
In my Log In Component I want to have a background video.
This is my code so far:
import React, { Component } from 'react';
import { Text, View, TouchableOpacity } from 'react-native';
import Video from 'react-native-video';
class LoginComponent extends Component {
render() {
const {
containerStyle,
introTextContainerStyle,
introTextStyle,
introTextHighlightStyle,
loginButtonsContainerStyle,
backgroundVideo
} = styles;
return (
<View style={ containerStyle }>
<Video source={{uri: "../assets/background.mp4"}}
ref={(ref) => {
this.player = ref
}}
rate={1.0}
volume={1.0}
muted={false}
resizeMode="cover"
repeat={true}
style={backgroundVideo}
/>
<View style={ introTextContainerStyle }>
<Text style={ introTextStyle }>
Tus problemas
</Text>
<Text style={ introTextHighlightStyle }>
Lisdos's
</Text>
<Text style={ introTextStyle }>
en un abrir y cerrar de ojos
</Text>
</View>
<View style={ loginButtonsContainerStyle }>
<TouchableOpacity>
<Text>Log In with Facebook</Text>
</TouchableOpacity>
</View>
</View>
);
}
}
const styles = {
containerStyle: {
height: '100%',
padding: 20
},
introTextContainerStyle: {
borderColor: 'black',
borderWidth: 1,
justifyContent: 'center',
alignItems: 'center',
height: '50%'
},
introTextStyle: {
fontSize: 24,
textAlign: 'center',
lineHeight: 40
},
introTextHighlightStyle: {
fontSize: 24,
textAlign: 'center',
fontWeight: '700',
color:'gold'
},
loginButtonsContainerStyle: {
borderColor: 'blue',
borderWidth: 1,
height: '50%',
justifyContent: 'center',
alignItems: 'center'
},
backgroundVideo: {
position: 'absolute',
top: 0,
left: 0,
bottom: 0,
right: 0,
}
}
export default LoginComponent;
Without the tag the component renders just fine but I keep hitting the infamous red screen stating:
Cannot read property 'Constants' of undefined
Am I missing something in the setup or in the tag? I my uri wrong?
Any help is appreciated.
The problem is your sourcetag. Since you load a file with the RN Asset system, you need to directly import your file instead of using uri.
I usually do it this way (and I recommend you to do so):
import background from '../assets/background.mp4';
...
<Video source={background}
...
/>
Or you can import your file directly in your source tag :
<Video source={require('../assets/background.mp4')}
...
/>
Related
What are the APIs that's available to do this, I've only found Wallet Connect that can do this, are there any other that I've missed ?
I've try integrating with Wallet Connect V1 sdk, but encounter a problem
TypeError: null is not an object (evaluating 'RNRandomBytes.seed')
is there any workaround on this ? did I missing something ?
the error triggers right after I imported Wallet Connect V1 sdk
the code :
import { useState, useEffect, useRef } from 'react';
import { StyleSheet, Text, View, Button, TextInput } from 'react-native';
import { WebView } from 'react-native-webview';
import { SafeAreaView } from "react-native-safe-area-context";
import WalletConnect from "#walletconnect/client";
export default function Login({ navigation }) {
return (
<SafeAreaView style={styles.container}>
<Text style={{ alignSelf: "center", marginTop: 10 }}>{secret?.address}</Text>
<View style={{ padding: 10, flexDirection: "row", alignItems: "center" }}>
<TextInput style={{ padding: 10, borderWidth: 1, borderRadius: 10, flex: 2, margin: 5 }} placeholder='WC Connection...' onChangeText={(e) => setWc(e)} />
<View style={{ margin: 5, flex: 1 }}>
<Button title='Connect'/>
</View>
</View>
<View style={{ margin: 10 }}>
<Button title='Generate Wallet' />
</View>
<WebView
source={{ uri: 'https://app.uniswap.org/#/swap' }}
style={styles.container}
/>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1
},
});
I'm new using React Native and I'm trying to map the following component (made in web) but for React Native with no success:
Elevation and shadow properties does not do the trick because they add some blur to the resulting shadow. Which would be the proper way to handle this?
Regards
Use react-native-cardview
import React, { Component } from 'react';
import {
View,
ScrollView,
TextInput,
} from 'react-native';
import CardView from 'react-native-cardview';
import styles from './styles';
export default class Signup extends Component {
render() {
return (
<View style={{ flex: 1, backgroundColor: colors.whiteColor }}>
<ScrollView contentContainerStyle={styles.signupContainer}>
<View style={styles.signupInputs}>
<CardView
style={styles.cardStyle}
cardElevation={2}
cardMaxElevation={2}
cornerRadius={5}
>
<TextInput
underlineColorAndroid="transparent"
style={[styles.signupInput, styles.commonsignupStyle]}
placeholder="Nom *"
placeholderTextColor={colors.primaryColor}
/>
</CardView>
<CardView
style={styles.cardStyle}
cardElevation={2}
cardMaxElevation={2}
cornerRadius={5}
>
<TextInput
underlineColorAndroid="transparent"
style={[styles.signupInput, styles.commonsignupStyle]}
placeholder="Prénom *"
placeholderTextColor={colors.primaryColor}
/>
</CardView>
</View>
</ScrollView>
</View>
);
}
}
Edit:
For dynamic height, two lines or more of text, as asked for in the comments, I had to use another workaround.
https://snack.expo.io/7bVXvbmE0
const Label = () => {
return <View style={{width: 100, height: 50}}>
<View style={styles.topView}>
<Text>Hello world</Text>
<Text>Hi world</Text>
</View>
<View style={styles.shadowView} >
<Text style={{color: 'transparent'}}>Hello world</Text>
<Text style={{color: 'transparent'}}>Hi world</Text>
</View>
</View>;
}
Whatever dynamic text you have on the label, duplicate for the shadow label, but make it transparent. That way you are guaranteed that the shadow follows the top view.
Also, get rid of the hardcoded heights in the styles. For both top view and shadow view, their heights are informed by the text input, and the wrapper container's height is informed by the two views.
Lastly, change shadow view style's top to be just a few points above 0 to make sure you it peeks from under topview. You can adjust borderRadius of the shadow view to fit your preferences.
const styles = StyleSheet.create({
topView: {
width: '100%',
position: 'absolute',
top: 0, backgroundColor: 'white',
justifyContent: 'center',
alignItems: 'center',
borderRadius: 25,
},
shadowView: {
position: 'absolute',
top: 3,
width: '100%',
zIndex: -10,
borderRadius: 17,
backgroundColor: '#ddd'}
});
Previous Post
A little bit hacky, but you can do this if you absolutely don't want any blur.
https://snack.expo.io/pWyPplcm3
const Label = () => {
return <View style={{width: 100, height: 30}}>
<View style={styles.topView}>
<Text>Hello world</Text>
</View>
<View style={styles.shadowView} />
</View>;
}
styles:
const styles = StyleSheet.create({
topView: {
height: 25,
width: '100%',
position: 'absolute',
top: 0, backgroundColor: 'white',
justifyContent: 'center',
alignItems: 'center',
borderRadius: 15,
},
shadowView: {
position: 'absolute',
top: 0,
height: 28,
width: '100%',
zIndex: -10,
borderRadius: 13,
backgroundColor: '#ddd'}
});
I get the error when i trie to run this app on my Android Emulator. I changed "Component" to "React.Component" but then i get other Problems.
My versions of React, Node and JS are the newest.
The Problem is that im new and have this Code from a Viedo and he didnt got thet Mistake.
Without React.Component:
With React.Component:
import React from 'react';
import {
StyleSheet,
Text,
View,
TextInput,
TouchableOpacity,
StatusBar,
Component,
} from 'react-native';
export default class App extends React.Component {
render() {
return (
<View style={styles.container}>
<StatusBar backgroundColor="#1e90ff" barStyle="light-content" />,
<Text style={styles.login}>Login</Text>,
<TextInput style={styles.input} placeholder="Username" />,
<TextInput
style={styles.input}
placeholder="Password"
secureTextEntry
/>
<View style={styles.btnContainer}>
<TouchableOpacity style={styles.userBtn}>
<text style={styles.btnText}>Login</text>
</TouchableOpacity>
<TouchableOpacity style={styles.userBtn}>
<text style={styles.btnText}>Text</text>
</TouchableOpacity>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
backgroundColor: '#1e90ff',
},
login: {
textAlign: 'center',
fontSize: 35,
margin: 10,
color: '#fff',
},
input: {
width: '80%',
backgroundColor: '#fff',
padding: 10,
marginBottom: 10,
height: 30,
},
btnContainer: {
flexDirection: 'row',
justifyContent: 'space-between',
width: '90%',
},
userBtn: {
backgroundColor: '#fff',
padding: 15,
width: '40%',
margin: 10,
},
btnText: {
fontSize: 25,
textAlign: 'center',
color: '#1e90ff',
},
});
Can someone help me?
1. TypeError: Super expression must either be null or a function
To fix this
import React, { Component } from 'react';
Then you can use
export default class App extends Component
2. Invariant Violation: Text strings must be rendered within a component
To fix this remove , & change
<text style={styles.btnText}>Login</text>
to
<Text style={styles.btnText}>Login</Text>
EDIT
export default class App extends React.Component {
render() {
return (
<View style={styles.container}>
<StatusBar backgroundColor="#1e90ff" barStyle="light-content" />
<Text style={styles.login}>Login</Text>
<TextInput style={styles.input} placeholder="Username" />
<TextInput
style={styles.input}
placeholder="Password"
secureTextEntry
/>
<View style={styles.btnContainer}>
<TouchableOpacity style={styles.userBtn}>
<Text style={styles.btnText}>Login</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.userBtn}>
<Text style={styles.btnText}>Text</Text>
</TouchableOpacity>
</View>
</View>
);
}
}
Hope this helps you. Feel free for doubts.
this is my genymotion screen !!!!
this is my code . Just react-native program And the trouble in my photo.Android is Not , IOS is great .how hack in android to make it right .
import React, { Component } from 'react';
import { View, Text, StyleSheet } from 'react-native';
export default class TestScreen extends Component {
render() {
return (
<View style={styles.container}>
<Text></Text>
<View style={styles.parent}>
<View style={styles.children}>
<Text>my content </Text>
</View>
</View>
</View>
)
}
}
const styles = StyleSheet.create({
container: {
flex:1,
alignItems: 'center',
justifyContent: 'center',
},
parent: {
width:300,
height: 40,
backgroundColor: 'yellow',
alignItems:'center',
position:'absolute',
},
children:{
height:20,
justifyContent: 'center',
top:-10
}
})
How should I Fix it
Overflow is not supported on Android: https://github.com/facebook/react-native/issues/6802
You can try this library:
https://github.com/entria/react-native-view-overflow
Or you could try to do some sort of absolute positioning with your view, but it might not be perfect. The below example puts all of the views in one parent, and then offsets the text to overlap both with an absolute position.
render() {
return (
<View style={styles.container}>
<View style={{ height: 40}}/>
<View style={{ height: 40, backgroundColor: "yellow"}}/>
<View style={{ position: "absolute", top: 30}}>
<Text>my content </Text>
</View>
</View>
)
}
I have tried to create react native app for android where child image and name will display in one line. You can check it on rawgit.
import React, { Component } from 'react'
import { AppRegistry, Text, View, Image } from 'react-native'
export default class App extends Component {
render() {
return (
<View>
<Text style={{ textAlign: 'left', fontSize: 15, backgroundColor:'grey'}}>
<Image source={{uri: 'https://leaderbord-552b1.firebaseapp.com/AdminLTE%202%20_%20User%20Profile_files/mount-carmel-logo.png'}} style={{width: 70, height: 70, borderRadius:70}} />
<Text style={{ backgroundColor:'lightblue', }}>Vindhyachal</Text>
</Text>
</View>
)
}
}
AppRegistry.registerComponent('App', () => App)
I am getting below output which is wrong, text is displaying at bottom instead of same line at middle.
Note:- I can't change the component structure because I am using it in react-native-material-ui-demo-app Drawer as below.
<Drawer.Section
divider
items={[
{ value: <Text style={{ textAlign: 'left', fontSize: 15, backgroundColor:'grey'}}>
<Image source={{uri: child.image'}} style={{width: 70, height: 70, borderRadius:70}} />
<Text style={{ backgroundColor:'lightblue', }}>{child.name}</Text>
</Text> },
{ value: <Text style={{ textAlign: 'left', fontSize: 15, backgroundColor:'grey'}}>
<Image source={{uri: child.image'}} style={{width: 70, height: 70, borderRadius:70}} />
<Text style={{ backgroundColor:'lightblue', }}>{child.name}</Text>
</Text> }
]}
/>
Below is screenshot of my app where I am facing this issue.
I'll be grateful if someone can help me out with this issue. Thanks in advance.
It can be achieved by two ways as follows:
1] With inner Text block removed (Just need to add alignSelf: "center" to your Text) as follows:
<View style={{flexDirection: 'row', textAlign: 'left', fontSize: 15, backgroundColor:'grey'}}>
<Image source={{uri: 'https://leaderbord-552b1.firebaseapp.com/AdminLTE%202%20_%20User%20Profile_files/mount-carmel-logo.png'}} style={{width: 70, height: 70, borderRadius:70}} />
<Text style={{ backgroundColor:'lightblue', alignSelf: "center" }}>Vindhyachal</Text>
</View>
2] Without Text removed using your existing Drawer.Section code (Need to provide float:"left" style and positioning your Text as absolute with top value) as follows:
<Text style={{ textAlign: 'left', fontSize: 15, backgroundColor:'grey', alignItems:"center", float:"left", position:"absolute"}}>
<Image source={{uri: 'https://leaderbord-552b1.firebaseapp.com/AdminLTE%202%20_%20User%20Profile_files/mount-carmel-logo.png'}} style={{width: 70, height: 70, borderRadius:70, float:"left"}} />
<Text style={{ backgroundColor:'lightblue', float:"left", position:"absolute", top:"45%"}}>{child.name}</Text>
</Text>
Here's an example I've used to handle what you need:
import React, { Component } from 'react';
import {
Text, View, Image
} from 'react-native';
import Dimensions from 'Dimensions';
const DeviceWidth = Dimensions.get('window').width;
const DeviceHeight = Dimensions.get('window').height;
class MyClass extends React.Component {
render() {
return (
<View style={{flexDirection:'row', width:DeviceWidth, height:DeviceWidth*0.5, alignItems:'center'}}>
<Image source={{uri : 'someUrl'}}
style={{width:DeviceWidth*0.5, height:DeviceWidth*0.5, resizeMode:'contain'}}/>
<Text>Next to Image</Text>
</View>
);
}
}
export default MyClass;
Here goes the updated code where moving the flex styling to the View tag. Sharing a URL where you can play with flex.
export default class App extends Component {
render() {
return (
<View style={{flexDirection:'row',alignItems:'center',justifyContent:'center'}}>
<Text style={{ textAlign: 'left', fontSize: 15, backgroundColor:'grey'}}>
<Image source={{uri: 'https://leaderbord-552b1.firebaseapp.com/AdminLTE%202%20_%20User%20Profile_files/mount-carmel-logo.png'}} style={{width: 70, height: 70, borderRadius:70}} />
<Text style={{ backgroundColor:'lightblue', }}>Vindhyachal</Text>
</Text>
</View>
)
}
}
AppRegistry.registerComponent('App', () => App)