react native text horizontal cutting, need full text in one line how to do that? - react-native

react-native version: "0.62.0", I tried this code
ui coming like this:
React Native
</View>
<View style={{flex:8}}>
<View style={{padding: 20, height: 200, backgroundColor: 'red'}}>
<Text style={fonts.bold}>View 1</Text>
</View>
<View style={{padding: 20, height: 200, backgroundColor: 'red'}}>
<Text style={fonts.bold}>View 1</Text>
</View>
<View style={{padding: 20, height: 200, backgroundColor: 'yellow'}}>
<Text>View 1</Text>
</View>
<View style={{padding: 20, height: 200, backgroundColor: 'green'}}>
<Text>View 1</Text>
</View>
</View>
</View>
How to do it?

give Text width greater than space occupied by characters with some padding

It looks like you did not provide the code for intended green view. The green view in your code is different. It is under yellow view.
Tip: For intended view try to remove height and width properties.

Created a sample according to your problem
import * as React from 'react';
import { Text, View, StyleSheet } from 'react-native';
export default function App() {
return (
<View style={styles.container}>
<View style={styles.wrapperStyle}>
<View style={styles.leftStyle}>
<Text style={styles.textStyle}>Trending</Text>
</View>
<View style={styles.rightStyle}>
<Text>View 1</Text>
</View>
</View>
<View style={styles.wrapperStyle}>
<View style={[styles.leftStyle, { backgroundColor: 'green' }]}>
<Text style={styles.textStyle}>Top_games</Text>
</View>
<View style={[styles.rightStyle, { backgroundColor: 'yellow' }]}>
<Text>View 2</Text>
</View>
</View>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
paddingTop: 20,
},
wrapperStyle: {
height: 200,
flexDirection: 'row'
},
leftStyle: {
flex: 2,
backgroundColor: 'gray',
alignItems: 'center',
justifyContent: 'center'
},
rightStyle: {
flex: 8,
backgroundColor: 'red',
alignItems: 'center',
justifyContent: 'center'
},
textStyle: {
transform: [{ rotate: '-90deg' }]
}
});
Somtetimes you have to change flex value according to your requirements.
Hope this helps you. Feel free for doubts.

Related

React-native: position elements in the center and flex-end

Is it possible to have the following layout (without resorting to absolute positioning)?
|...........centreElement.......RightElement|
So as if the justifyContent was 'space-between' but without the first element. I also thought to 'justifyContent: 'centre'' and then try 'justifySelf: 'flex-end' on the RightElement but this property does not exist.
<View styles={styles.container}>
<Text>centreElement</Text>
<Text>RightElement</Text>
</View>
container: {
flexDirection: 'row',
justifyContent: 'center'
}
There is mistake in your code please update code from <View styles={styles.container}> to <View style={styles.container}>
Please try the following code:
<View style={styles.container}>
<View style={{ flex: 1 }} />
<View style={{ flex: 1 }}>
<Text>centreElement</Text>
</View>
<View style={{ flex: 1 }}>
<Text>RightElement</Text>
</View>
</View>
An ideal solution without using absolute. The CentreElement text might not comes at the center, but without absolute, you cannot align it either, since you are not giving the content to take up the 100% width which is needed to rightly align the content to center. Following steps can give you the satisfying results:
Just give out flexDirection: 'row' to the container
Give both the text CentreElement and RightElement 50% width
Align both of them to right, and done!!
Code:
export default function App() {
return (
<View style={styles.container}>
{/* Txt container*/}
<View style={styles.textContainer}>
<Text style={styles.text}>
CentreElement
</Text>
<Text style={styles.text}>
RightElement
</Text>
</View>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
paddingTop: Constants.statusBarHeight,
backgroundColor: '#ecf0f1',
padding: 8,
},
textContainer: {
width: '100%',
flexDirection: 'row'
},
text: {
textAlign: 'right',
width: '50%',
fontSize: 16,
fontWeight: 'bold'
}
});
Result:

ScrollView not scrolling all components properly

I have cards written like this, they scroll horizontal but the last card, whenever I scroll it's not shown, below, is the image of the current code.
They are price cards that scroll horizontally, kindly help me fix this. I have banged my head around it and it seems I have failed
Please help me guys am in need of real help
class Pricing extends React.Component {
state = {
...
};
render() {
return (
<ScrollView
showsHorizontalScrollIndicator={false}
horizontal={true}
scrollEnabled
pagingEnabled
scrollEnabled
showsHorizontalScrollIndicator={false}
scrollEventThrottle={16}
snapToAlignment="center"
>
{this.state.FlatListItems.map(item => (
<View style={styles.subContainer} key={item.id}>
<View style={{
justifyContent: "center",
alignItems: "center",
}}>
<View>
<Image
source={item.image}
/></View>
<View>
<Text style={styles.subType}>{item.subType}</Text>
<Text style={styles.textSub}>{item.textSub}</Text>
</View>
<View>
<Text style={styles.currency}>{item.amount}<Text style={styles.currencyText}> Month</Text></Text>
</View>
</View>
<TouchableOpacity style={styles.button}>
<Text style={styles.buttonText}>Subscribe</Text>
</TouchableOpacity>
</View>
))}
</ScrollView>
);
}
}
const styles = StyleSheet.create({
subContainer: {
justifyContent: "center",
alignItems: "center",
backgroundColor: "transparent",
shadowColor: "#000",
shadowOffset: {
width: 0,
height: 0,
},
shadowOpacity: 0.22,
shadowRadius: 10,
elevation: 1,
borderRadius: 10,
padding: 15,
marginTop: 20,
width: '50%'
},
})
Pricing.navigationOptions = {
header: null
}
export default withNavigation(Pricing);

I am trying to add Instagram type filter to add some effect to my image using React-native?

I am creating an Image Editing Application & I have to put put image effect filters to change brightness, hue, saturation, etc with the help of Range Slider?Is there any possibilities to do it with Css properties?
I need something like Instagram Filters.
import React from 'react';
import { StyleSheet,
Text,
View,
Image,
SafeAreaView,
ScrollView } from 'react-native';
import {Asset } from 'expo-asset';
export default class App extends React.Component {
state={
ready: false,
image: null,
value: 0,
angle: 0,
deg: 'deg',
Vflipangle: 0,
Hflipangle:0,
positivevalue: 0,
};
//--- this function brings the contains the image locaiton to show inside <Image/>----------
//---------------This function runs automatically on mounting----------------------------
componentDidMount(){
const image = Asset.fromModule(require('./assets/girl.jpg'));
this.setState({
ready: true,
image,
});
}
//------------------------------------------------------------------------------
//Function to Render Image to show on Application Screen---------------------------
_renderImage =()=> {
return(
// <View style = {{margin: 20, alignItems: 'center',backgroundColor: 'black', overflow: 'hidden'}}>
// </View>
<Image source= {{uri: this.state.image.localUri || this.state.image.uri}}
style={{width:300+this.state.positivevalue,height:400+this.state.positivevalue, resizeMode:'cover',
transform: [{ rotate: this.state.value+this.state.deg}]
}}
/>
)
}
filteredImage =()=> {
return(
<Image source={{uri: this.state.image.localUri || this.state.image.uri}}
style={{flex: 1,
width: null,
height: null,
resizeMode: 'cover',}}/>
)
}
render(){
return (
<SafeAreaView style={styles.container}>
<View style={{alignItems: 'center',
justifyContent: 'center',
flex: 2}}>
<View style={{transform: [{ rotate: this.state.angle+this.state.deg},
{rotateY: this.state.Vflipangle + this.state.deg},
{rotateX: this.state.Hflipangle + this.state.deg}],
overflow: 'hidden',
width: 300,
height: 400,
alignItems: 'flex-end',
justifyContent: 'center',
//
}}>
{this.state.ready && this._renderImage()}
</View>
</View>
<ScrollView scrollEventThrottle= {16} style={{flex: 1}}>
<View style={{height: 150, marginTop: 20}}>
<ScrollView horizontal={true}>
<View style={{height: 150, width: 100, marginLeft: 20, borderWidth: 0.5,
borderColor: '#dddddd'}}>
<View style={{flex:4,}}>
{this.state.ready && this.filteredImage()}
</View>
<View style={{flex:0.5,alignItems: 'center'}}>
<Text style={{color: '#ffffff'}}>Reset</Text>
</View>
</View>
<View style={{height: 150, width: 100, marginLeft: 20, borderWidth: 0.5,
borderColor: '#dddddd'}}>
<View style={{flex:4,}}>
{this.state.ready && this.filteredImage()}
</View>
<View style={{flex: 0.5,alignItems: 'center'}}>
<Text style={{color: '#ffffff'}}>Brightness</Text>
</View>
</View>
<View style={{height: 150, width: 100, marginLeft: 20, borderWidth: 0.5,
borderColor: '#dddddd'}}>
<View style={{flex:4,}}>
{this.state.ready && this.filteredImage()}
</View>
<View style={{flex: 0.5,alignItems: 'center'}}>
<Text style={{color: '#ffffff'}}>Contrast</Text>
</View>
</View>
<View style={{height: 150, width: 100, marginLeft: 20, borderWidth: 0.5,
borderColor: '#dddddd'}}>
<View style={{flex:4,}}>
{this.state.ready && this.filteredImage()}
</View>
<View style={{flex: 0.5,alignItems: 'center'}}>
<Text style={{color: '#ffffff'}}>Exposure</Text>
</View>
</View>
<View style={{height: 150, width: 100, marginLeft: 20, borderWidth: 0.5,
borderColor: '#dddddd'}}>
<View style={{flex:4,}}>
{this.state.ready && this.filteredImage()}
</View>
<View style={{flex: 0.5,alignItems: 'center'}}>
<Text style={{color: '#ffffff'}}>Saturation</Text>
</View>
</View>
<View style={{height: 150, width: 100, marginLeft: 20, borderWidth: 0.5,
borderColor: '#dddddd'}}>
<View style={{flex:4,}}>
{this.state.ready && this.filteredImage()}
</View>
<View style={{flex: 0.5, alignItems: 'center',height:10}}>
<Text style={{color: '#ffffff'}}>Temperature</Text>
</View>
</View>
</ScrollView>
</View>
</ScrollView>
</SafeAreaView>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#000000',
// alignItems: 'center',
//justifyContent: 'center',
},
})
;
Here my code looks like , i will add slider later in it
You can achieve these effects using this library: gl-react-native-v2
It's a little more complicated than CSS effects, but you just can't use CSS in React Native. So this is most likely the best option.

ScrollView not showing everything and is cut off

I need this screen to show all the contents that is inside the scrollview, I've tried everything setting ScrollView's flexGrow to 1, parent view's flex to 100. The scrollview is scrolling down until iteration of Bark Central Dog Park & Cafe but it is cut off to half and can't scroll any further, also I noticed that the text HELP ME can not be found too. Thank you so much, as this problem has been bothering me and my progress in react native.
Please tell me what I should do and where I have gone wrong. Thank you again!
NotificationScreen.js
export default class NotificationScreen extends Component
{
static navigationOptions = ({ navigation }) => {
const { state } = navigation;
const {} = state;
return {
header: null,
};
}
render() {
return (
<View style={styles.parentContainer}>
<View style={{flexDirection: 'row', marginLeft: '5%', marginTop: '5%'}}>
<TouchableOpacity onPress={() => this.props.navigation.navigate('JobFeedScreen')}>
<Entypo name="chevron-thin-left" color={Colors.red} size={30} />
</TouchableOpacity>
<View style={{marginLeft: 80,}}>
<Text style={{ fontFamily: 'CoreSansD65Heavy',color: Colors.semiGray, fontSize: 25,}}> Ty, Next</Text>
</View>
<TouchableOpacity onPress={()=> this.props.navigation.navigate('LaunchScreenStack')} style={{marginLeft: 87,marginRight: '5%',}}>
<SimpleLineIcons name='bubbles' color={Colors.red} size={30} />
</TouchableOpacity>
</View>
<View style={{marginLeft: '5%'}}>
<Text style={styles.notificationHeader}> Notifications</Text>
</View>
<ScrollView horizontal={false} overScrollMode={'auto'}>
<TouchableOpacity style={styles.notifPlace}>
<View style={styles.notifTextPlace}>
</View>
<Text style ={styles.text}>Anteriore, Inc.</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.notifPlace}>
<View style={styles.notifTextPlace}>
</View>
<Text style ={styles.text}>The Palace Manila</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.notifPlace}>
<View style={styles.notifTextPlace}>
</View>
<Text style ={styles.text}>Boozy.ph</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.notifPlace}>
<View style={styles.notifTextPlace}>
</View>
<Text style ={styles.text}>Pet warehouse PH</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.notifPlace}>
<View style={styles.notifTextPlace}>
</View>
<Text style ={styles.text}>Bark Central Dog Park & Cafe</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.notifPlace}>
<View style={styles.notifTextPlace}>
</View>
<Text style ={styles.text}>Pet warehouse PH</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.notifPlace}>
<View style={styles.notifTextPlace}>
</View>
<Text style ={styles.text}>Bark Central Dog Park & Cafe</Text>
</TouchableOpacity>
<Text> PLEASE HELP ME </Text>
<Text> PLEASE HELP ME </Text>
<Text> PLEASE HELP ME </Text>
<Text> PLEASE HELP ME </Text>
</ScrollView>
</View>
);
}
NotificationScreenStyles.js
import { StyleSheet } from 'react-native'
import { Metrics, ApplicationStyles, Colors } from '../../Themes/'
export default StyleSheet.create({
...ApplicationStyles.screen,
container: {
paddingBottom: Metrics.baseMargin
},
logo: {
marginTop: Metrics.doubleSection,
height: Metrics.images.logo,
width: Metrics.images.logo,
resizeMode: 'contain'
},
centered: {
alignItems: 'center'
},
parentContainer: {
flex:1,
backgroundColor: Colors.white
},
notificationHeader: {
justifyContent: 'flex-start',
fontFamily: 'CoreSansD45Medium',
marginTop: 40,
marginBottom: 20,
fontSize: 20,
color: Colors.gray,
textAlign: 'left',
},
notifPlace: {
flexGrow: 0,
flexDirection: 'row',
backgroundColor: Colors.white,
width: '100%',
height: '12%',
borderWidth: 0.5,
borderColor: Colors.buttonGray,
},
notifTextPlace: {
width:60,
height:60,
borderRadius: 60/2,
backgroundColor:Colors.buttonGray ,
alignSelf: 'center',
justifyContent: 'flex-start',
marginLeft: '5%',
marginRight: 10,
marginBottom: 20,
marginTop: 20,
},
text: {
fontFamily: 'CoreSansD45Medium',
fontSize: 15,
alignSelf: 'center',
color: Colors.gray,
marginBottom: 10,
},
text2: {
alignSelf: 'center',
fontFamily: 'CoreSansD35Regular',
fontSize: 15,
marginBottom: 10,
},
})
Screenshot 1:
SC1
Screenshot 2: ( it only scrolls up to here )
SC2
This is a known issue in scroll view of react native, use a paddingBottom : 100 in the styles of the scroll view.
The 100 can be set to any value according the content you have
Please provide your StyleSheet and screenshot of what you are seeing.
Test to add
height = Dimensions.get('window').height
to your parentContainer
Also try paddingBottom to your scrollview StyleSheet
Just ran into this problem and what finally fixed it for me was making sure my scrollview wasn't the last component in my layout. So I added an invisible component (with a set height to offset the amount of scrollview content I couldn't see) right after my scrollview.
In my case, I have added a height to the wrapped component of the ScrollView.It worked for me
eg:-
<View style={{ height: hp(500) }}>
<ScrollView showsVerticalScrollIndicator={false}>
{filteredItems.map((item) => <Text style={styles.listItemText}>{item.title}</Text>)}
</ScrollView>
</View>
What fixed it for me was adding contentContainerStyle={{flexGrow: 1,paddingRight:100}} to my scrollview.
Hope it helps someone too!!
just add like this :
<ScrollView contentContainerStyle={{ width:'100%',height:'500%'}}>

How to set arrow icon center to the screen end in list item in react native

I am new to react native, In my application I have list. So that i have taken flatlist. I have designed the list item. But arrow icon need to set end of the item. I have tried many ways how to do this.
This is the my code
<View style={styles.MainContainer}>
<FlatList
data={ this.state.FlatListItems }
ItemSeparatorComponent = {this.FlatListItemSeparator}
renderItem={
({item}) =>
<View style={styles.main}>
<View style={styles.itemContainer}>
<View>
<Image source={require('./resource/ic_drawer.png')} />
<Text style={styles.item} onPress={this.GetItem.bind(this, item.key)} >
{item.key}
</Text>
</View>
<View style={styles.balanceItem}>
<View>
<Text >Balance</Text>
<Text >$89.04</Text>
</View>
<View style={styles.subItem}>
<View>
<Text >Account number</Text>
<Text >743509-001</Text>
</View>
<View style={styles.balanceItem}>
<Text >Meter number</Text>
<Text >17976849</Text>
</View>
</View>
</View>
<View style={styles.balanceItem}>
<View style={styles.duenbuttonItem}>
<View>
<Text >Due Date</Text>
<Text >30/09/2016</Text>
</View>
</View>
<TouchableOpacity style={styles.btn} onPress={this.login}><Text style={{color: 'white'}}>PAY NOW</Text></TouchableOpacity>
</View>
</View>
<Image source={require('./resource/arrow_24.png')} style={styles.arrowImage}/>
</View>
}
/>
</View>
and this is my styles
const styles = StyleSheet.create({
MainContainer :{
// Setting up View inside content in Vertically center.
justifyContent: 'center',
flex:1,
margin: 10
},
item: {
padding: 0,
fontSize: 18,
},
itemContainer :{
flex: 1,
flexDirection: 'row',
padding : 10,
},
subItem: {
marginTop: 10,
flexDirection: 'row',
},
btn:{
borderRadius: 10,
alignSelf: 'stretch',
backgroundColor: '#003366',
padding: 10,
marginTop: 10,
alignItems: 'center',
},
balanceItem: {
marginLeft: 5,
},
duenbuttonItem: {
marginLeft: 10,
flexDirection: 'row',
},
arrowImage: {
justifyContent: 'flex-end',
justifyContent: 'center',
},
main:{
flex: 1,
}
});
And this the output of the above code
Here my requirement is the arrow image end of the item in center. So please guide me how to do this?