How react native scroll text?
I have a long text in a fixed height container. I want to show a part of text in that container and scroll it when I want to see more.
I have try overflow scroll but react native seems not support overflow scroll.
Thanks.
You can use ScrollView for this case. Just put your text inside it and set height to scroll view.
I'm used the following code. Take ScrollView and put your any element inside ScrollView.
render() {
return(
<View style={styles.container}>
<ScrollView>
<Text>
Add your text
</Text>
</ScrollView>
</View>
);
}
There is currently a limitation in React Native where you can't set height directly on the ScrollView style prop. So, I suggest you do the following if you also want to set the height:
<View style={{ height: 100 }}>
<ScrollView>
<Text>
Your text goes here.
</Text>
</ScrollView>
</View>
Or alternatively using flexGrow:
<ScrollView style={{ flexGrow: 0.2 }}>
<Text>
Your text goes here.
</Text>
</ScrollView>
Relevant issue I found: https://github.com/facebook/react-native/issues/3422
<View style={{ height: hp(3)}}>
<ScrollView>
<Text style={{ fontSize: hp(2) }}>
Your text goes here
</Text>
</ScrollView>
Related
I am trying to align image on top of its container in react native, especially on landscape.
<View style={{flexDirection: 'row', justifyContent: 'center',alignItems: 'center'}}>
<View style={{flex:1,backgroundColor: 'green'}} >
<Image resizeMode='contain'style={{ flex:1,width:"100%",height:"100%"}} source={{uri:"https://www.tageblatt.lu/wp-content/uploads/2020/09/250112_cx__cy__cw__ch_-1-739x493.jpeg"}} />
</View>
<View style={{width:"15%",backgroundColor: 'blue' }}>
<Text style={{color:"white",padding:7}}>{caption}</Text>
</View>
</View>
The output of this code is :
And on landscape:
The desired output is:
Which I get on landscape orientation if I press control+s (saving) on my editor.
I follow this question, but with no solution for me .
I tried different values for resizeMode also .
Have you tried to change the resizeMode ?
<Image resizeMode='cover' ... />
I am learning react-native, I am trying to give the Text some opacity, I wonder if is it possible in react native. Is there any RGBA for text color in react-native.
Thanks
You can specify the opacity of a control via styles.
i.e.
<Text style={{color: 'red', opacity: 0.5}} >Text here</Text>
In React Native you can use the opacity prop
Option 1) Directly in the Text
<Text style={{color: 'red', opacity: 0.5}} > Text here </Text>
Option 2) Within the View
<View style={{opacity: 0.5}}>
<Text style={{color: 'red'}}>Text here</Text>
<Text style={{color: 'black'}}>Some more text here</Text>
</View>
In case you are using React Native 0.59.X and lower opacity prop will not work so you may want to use backgroundColor prop to adjust the opacity as below. You will also have the same effect in
<View style={{backgroundColor: '#FFFFFF50'}} > </View>
<View style={{backgroundColor: 'rgba(0,0,0,0.5)'}} > </ View>
I am using scrollView component to scroll component. It works in local build. But after creating apk file it doesn't work. what can i do.
<View style={{ flex: 1 }}>
<ScrollView contentContainerStyle={{ flexGrow: 1 }} style={{ flex: 1 }}>
<View style={styles.container}>
{
submit ?
isPreview ?
<Text>Preview Page</Text> : <Text style={styles.text}>Thank you!</Text>
: <Questions />
}
<PoweredByPEX />
</View>
</ScrollView>
</View>
i have used View and scrollView component here. i can debug after APK build file. what can i do now. i have used flex layout here. is there any way to sort it out.
previously in the unit column can only scroll horizontally per each floor/block and I want to scroll units horizontally together.
this is my code :
<ScrollView style={{ width: "55%" }} horizontal>
<View style={styles.GridViewBlockStyle}>
<TouchableOpacity>
</TouchableOpacity>
</View>
</ScrollView>
I have created a dropdown. Its elements appearing on top of body, however, when I press them, it actually triggers onPress on elements underneath them.
You guys can see the issue:
Code for the Dropdown is:
<View style={[styles.container]}>
<TouchableOpacity style={styles.main_container} onPress={this.animate}>
<Text style={styles.text}>{this.state.selectedCategoryText}</Text>
<Image style={styles.image}
source={require('../../assets/icons/dropdown.png')}
/>
</TouchableOpacity>
<View >
<Animated.View style={[styles.animated_container,{opacity: this.opacity, zIndex:1, elevation:1}]}>
<ScrollView style={{height:60}}>
{ this.data.map( (item, i)=>
<TouchableOpacity
style={{}}
disabled={false}
key={i}
onPress={()=>this.selectItem(i)}>
<Text style={styles.item_text}>{item} </Text>
</TouchableOpacity>
)}
</ScrollView>
</Animated.View>
</View>
</View>
I have applied absolute positioning on the animated view which displays the dropdown items.
animated_container:{
backgroundColor: colors.secondaryWhiteColor,
position: 'absolute',
top: '100%',
width: '100%', height: 70
}
I have managed to know the source of the problem, however I still don't know what exactly is the problem. DrawerNavigator from React.Navigation is doing something. If I remove the screen containing dropdown from the DrawerNavigator, then it works properly.
try to use touchable opacity from gesture handler not react native