I am New to React Native and i am trying to build a app so for the testing purpose i am using Pixel 4 in Android Emulator so i designed my app as per the Pixel 4 resolution but when i checked my app in another device like Nexus 5 half of the content was not able to fit in the screen properly. So, how can i design the code which will set resolution automatically for different devices ?
I am attaching the images of problem as well:
On Pixel 4 (this one is perfect)
On Nexus 5
Here is what i tried
`import { View, Text, Image, StyleSheet, StatusBar } from "react-native";
import React from "react";
import { SafeAreaView } from "react-native-safe-area-context";
import { Button } from "react-native-paper";
import { useNavigation } from "#react-navigation/native";
`const SplashScreen = () => {
const navigation = useNavigation();
return (
<SafeAreaView
style={{
height: "auto",
}}
>
<StatusBar
translucent={true}
backgroundColor={"transparent"}
barStyle="dark-content"
/>
<View style={styles.container}>
<View className="w-[90%] flex items-center justify-center">
<Text
className="text-slate-500 text-2xl z-10"
style={{ fontFamily: "regular" }}
>
Taste of
</Text>
<Text
className="text-slate-500 text-2xl mt-3 z-10"
style={{ fontFamily: "regular" }}
>
Every Household
</Text>
</View>
<View>
<Image
source={require("../assets/logo.png")}
className="h-[380px] w-[380px] object-cover mt-5 ml-2"
/>
<View className="flex items-center justify-center -mt-5">
<Text
style={{
fontFamily: "rog",
fontSize: 23,
color: "#1D2044",
marginBottom: 10,
zIndex: 10,
}}
>
by
</Text>
<Text
style={{
fontFamily: "rog",
fontSize: 33,
color: "#1D2044",
zIndex: 10,
}}
>
imexture
</Text>
</View>
</View>
<View className="w-[90%] mt-24 z-10">
<Button
style={styles.radioButton}
onPress={() => navigation.navigate("Login")}
>
<Text
className="text-white text-xl tracking-widest"
style={{ fontFamily: "regular" }}
>
Let's Go
</Text>
</Button>
</View>
</View>
</SafeAreaView>
);
};
const styles = StyleSheet.create({
container: {
justifyContent: "center",
alignItems: "center",
height: "100%",
},
radioButton: {
backgroundColor: "#1D2044",
borderRadius: 10,
borderColor: "#1D2044",
padding: 8,
},
});
export default SplashScreen;`
`
and also i tried React-Native Dimensions but still the problem remains same
If you want to scroll to rest of content use ScrollView component. Just wrap content inside ScrollView. Here more info: https://reactnative.dev/docs/scrollview
If you want to make layout responsive for all devices (even tablets or whatever) try to start with getting familiar with flexbox layout for react native. Here you have documentation and examples https://reactnative.dev/docs/flexbox
You try to bring a lot of web css to react native. Things like className, zIndex, fontFamily: "rog" won't work.
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 creating a react native app and I need to create a curved screen design. How to create a curve design like the below screen.
This is what I tried here,
My sample codes,
import React from 'react';
import {
StyleSheet,
Text,
View,
StatusBar,
} from 'react-native';
import {
widthPercentageToDP as wp,
heightPercentageToDP as hp,
} from 'react-native-responsive-screen';
export default class Home extends React.Component {
render() {
return (
<View style={styles.container}>
<StatusBar hidden={true} />
<View style={styles.container1}>
<Text style={styles.name}>Container1</Text>
</View>
<View style={styles.container2}>
<Text style={styles.name}>Container1</Text>
</View>
<View style={styles.container3}>
<Text style={styles.name}>Container1</Text>
</View>
<View style={styles.container4}>
<Text style={styles.name}>Container1</Text>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
},
container1: {
backgroundColor: '#3d06d6',
height: hp('25%'),
padding: 10,
borderBottomLeftRadius:100,
},
container2: {
backgroundColor: '#0cad95',
height: hp('25%'),
padding: 10,
borderBottomLeftRadius:100,
},
container3: {
backgroundColor: '#d6a606',
height: hp('25%'),
padding: 10,
borderBottomLeftRadius:100,
},
container4: {
backgroundColor: '#06bad6',
height: hp('25%'),
padding: 10,
borderBottomLeftRadius:100,
},
});
I want to curve my container edges like the first picture. I am able to make curves of the bottom edges. And How can I make curve designs like the first image? and also how can I add some animations into the container when I touch the container to open another screen? Is there any way to do this design using any style with "borderRadius" or any other way? And I don't want to use any library like react-native-svg.
If you need a Linear Gradient as the background. Just giving the color of the next box will not be the best option.
Assume "value" as the border-radius. ie the curve
Give a marginTop and paddingTop for each container.
marginTop : -value,
paddingTop : value,
Also assign zIndex in decending order for each container.
You can set zIndex with respect to the index, if you are looping through an array.
Result
Sample code
import React from 'react';
import {View, StyleSheet, Text} from 'react-native';
import LinearGradient from 'react-native-linear-gradient';
const data = ['', '', ''];
const App = () => {
return (
<View style={styles.container}>
{data.map((item, index) => (
<View style={[styles.item, {zIndex: data.length - index}]}> // setting zIndex here
<LinearGradient
style={StyleSheet.absoluteFill}
colors={['#4c669f', '#3b5998', '#192f6a']}
/>
</View>
))}
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
zIndex: 1,
},
item: {
height: 250,
borderBottomLeftRadius: 100, // logic goes here
marginTop: -100, // move container
paddingTop: 100, // move inner item down
overflow: 'hidden',
},
});
export default App;
You can simply wrap your view inside a normal view and set the background colour of the next box which will give the output you need.
<View style={{ backgroundColor: '#0cad95' }}>
<View style={styles.container1}>
<Text style={styles.name}>Container1</Text>
</View>
</View>
<View style={{ backgroundColor: '#d6a606' }}>
<View style={styles.container2}>
<Text style={styles.name}>Container1</Text>
</View>
</View>
how can i create tab bar like this in react native?
google tasks tab bar
is there any sample like this?
Using an Image you can achieve it
Sample Snack : https://snack.expo.io/#msbot01/intelligent-croissant
import * as React from 'react';
import { Text, View, StyleSheet,Image } from 'react-native';
import Constants from 'expo-constants';
import Icon from 'react-native-vector-icons/FontAwesome';
export default class App extends React.Component {
render() {
return (
<View style={styles.container}>
<View style={{backgroundColor:'white', height:'10%', bottom:0, position:'absolute', zIndex:1, width:'100%', justifyContent:'space-between',paddingLeft:15,paddingRight:15, flexDirection:'row', alignItems:'center', shadowColor: '#000',
shadowOffset: { width: 0, height: 2 },
shadowOpacity: 0.8,
shadowRadius: 5 }}>
<View>
<Icon name="bars" size={25} color="grey" />
</View>
<View style={{height:'100%',width:100, backgroundColor:'white'}}>
<Image style={{width:100,paddingBottom:'20%', position:'absolute', zIndex:3, bottom:'61%' }} source={require('./bottom round 2.png')} />
</View>
<View>
<Icon name="ellipsis-v" size={25} color="grey" />
</View>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
paddingTop: Constants.statusBarHeight,
backgroundColor: 'white',
position:'relative',
}
});
I created one like this with an SVG in the middle. Left and right is an empty view with a width and a background color. In the middle the SVG component. The floating button is made with an absolute position. I don't know if there is a better way to do this, but that's my solution.
I have created one using SVG and path and I took help from following Code
https://itnext.io/reactnative-curved-tabbar-dc62e681c24d
also the github code : https://github.com/alex-melnyk/clipped-tabbar
Hope this is helpful. Thanks
Is there any conflict with native base and react-native-modal? I can't get my modal to display the content. I was wondering if it is because the Container tag of native base.
Code: https://snack.expo.io/rJbAI_Cxr
I've had the same issue. just remove the flex:1 from Modal style and you will end up with centered modal without any style. Then you need to set all the styles for the modal by yourself.
You can use Modal from react native component also ,no need to use third party library.
import {Modal} from 'react-native';
constructor(props) {
super(props);
this.state = {
modalVisibility: false,
};
ShowModalFunction(visible) {
this.setState({ modalVisibility: visible });
}
<Modal
transparent={true}
animationType={"slide"}
visible={this.state.modalVisibility}
onRequestClose={() => { this.ShowModalFunction(!this.state.modalVisibility) }} >
<View style={{ flex:1, justifyContent: 'center', alignItems: 'center' }}>
<View style={styles.ModalInsideView}>
<Text style={{color:'white',fontSize:14,fontWeight:'700'}}>Hello </Text>
</View>
</View>
</Modal>
const styles = StyleSheet.create({
ModalInsideView:{
justifyContent: 'center',
alignItems: 'center',
backgroundColor : "#00BCD4",
height: 245 ,
width: '90%',
borderRadius:10,
borderWidth: 1,
borderColor: '#fff'
},
});
Try this if you face issue in this ,let me know.
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')}
...
/>