I want to break the line of text in TextInput when reaches to end of TextInput.
I don't want to increase the height of TextInput. It will be scrollable inside TextInput.
I did try FlexWrap but it didn't work for me.
Thanks!!!
use multiline={true}:
<TextInput
multiline={true}
numberOfLines={4}
style={{ height:200, textAlignVertical: 'top',}}
...
/>
Related
I am trying to render an element that is positioned absolutely behind a flatlist and it will be revealed once the user scrolls to the bottom. The issue I am facing is that the element needs to be interactable, and the flatlist root element takes all pointerevents instead of the background element.
const FlatlistOverElement: FC = () => (
<View style={{ flex: 1, width: '100%' }}>
<FlatList
data={data}
style={{ flexGrow: 1 }}
ListFooterComponent={() => (
<View style={{ height: BACKGROUND_ELEMENT_HEIGHT, opacity: 0 }} />
)}
renderItem={RenderItem}
/>
<AbsolutelyPositionedElementBehindFlatList />
</View>
)
I have tried to remove pointerevents from the flatlist, then the flatlist is not scrollable.
I have tried to set the height of the flatlist smaller, and let the content overflow. This allows the user to interact with the element, but for that part of the screen, the user can not scroll the flatlist.
What other approach can I utilise in order to solve this issue ?
You can use zIndex property on the scroll completion. Just provide a higher zIndex value than that of FlatList to absolute component whenever the scroll is completed.
zIndex Layout Props
Thanks for the suggestions. I ended up using a zIndex to put the interactable content in front of the flatlist when having scrolled to the end, as well as adding snap points on both sides of the element. To prevent the user from half revealing the element and not be able to interact with it.
For example i have a TextInput like this
<ScrollView style={{flex: 1}}>
<TextInput
placeholder="Input"
style={{fontSize: 50}}
value={'Sample text'}
/>
</ScrollView>
So normally, when we click on the TextInput, it will automatic show caret at the end of text ( on android ), no matter where we click, at the first time, it will have the caret at the end, like this
BUT HOW can we set the caret in where we click, for example when we click the "m" letter, it will have caret after the "m", like this
Problem is, as i said, on android we always have the the caret at the end first, then if we click other, the caret will more to that, like this
I mean, it not a problem when text is short, but imagine, the text will like this
And we want to edit some text that already exist, so it scroll all the way down to the bottom (because the bottom contain the lastest text)
So my question is
HOW CAN WE SET THE CARET ON WHERE WE TOUCH (OR CLICK), NOT FROM LASTEST WORD IN TEXTINPUT?
You need to request focus to this TextInput.
<TextInput
placeholder="Input"
autofocus={true}
style={{fontSize: 50}}
value={'Sample text'}
/>
Or if it will not be working, write this please
https://github.com/react-native-modal/react-native-modal/issues/516
I have a basic text input with multiline set to true. Additionally it has selection and onSelectionChange props set which causes cursor to move to initial position whenever there is change in onChangeText.
Here it's the video : https://streamable.com/bchsz4
Here it's the repro : https://github.com/VivekNeel/IOS_SELECTION_CHANGE
Here it's the sample code :
<TextInput
onChangeText={handleChange}
value={value}
multiline
selection={selection}
onSelectionChange={handleSelection}
placeholder="Enter a text"
style={{marginTop: 100, marginHorizontal: 16}}
/>
Just not using selection props fixes this!
I have a small component and I seem to have an issue with the font size. When the fontSize is 179 the text loads correctly. When the font size is 180 and above it seems to vanish.
return (<View style={{flexDirection:'row'}}>
<Text numberOfLines={1} style={{
textAlignVertical: "center",
fontSize: 179,
textAlign: "center",
backgroundColor:'rgba(0,0,0,0)',
color:'rgba(0,0,0,.3)',
flex: 1,
flexWrap: 'wrap',
}}>A</Text>
</View>);
I can still see the element in dev tools:
Has anybody come across this before?
Am I just missing something?
Thanks, James
You shouldn't have numberOfLines={1} and flexWrap together; They contradict each other.
If you want it the text to wrap around, remove numberOfLines or have it be more than 1.
If you don't want text to wrap remove flex and flexWrap properties from the style object.
What is your goal with those styles? I recommend you start with unstyled (default) styled . Add styles one by one and see what works or doesn't work to give you your desired results.
I want to render 7 buttons in a row with equal width to fill up all the available space horizontally.
render() {
return (
<FlatList
data={this.state.days}
renderItem={({ item }) => <View style={styles.button}><Button title={item.getDate().toString()} /></View>}
keyExtractor={item => item.getDate().toString()}
horizontal={true}
style={styles.list}
/>
);
}
const styles = StyleSheet.create({
list: {
display: 'flex'
},
button: {
flex: 1
}
});
They are inside a flatlist, wrapped in a view because I cannot style buttons directly.
In regular flexbox in an HTML page this approach works.
This what I get in React Native:
Maybe there are some flatlist behaviour I'm not familiar with?
First of all when you are styling in react native everything is already in flex so you don't have to do display : flex
If you want to render 7 buttons with the same width in a row make sure that all of them have the same parent. Then use flex:1 in each one of them.
What is happening when you do flex:1 when you put a number in front of flex in your styles in this particular situation it divides your parent into those many parts and give it to the child.
So all your button will have 1/7th of the width. If you put flex:2 in one of the styles then that button will have 2/7th of the width and the rest will have 1/7th.
Please feel free to ask for more clarity on the above said.
I got the same issue, I have added View component cover for each Button like the code below:
<View style={{flexDirection:"row"}}>
<View style={{flex:1}}>
<Button title="Add" />
</View>
<View style={{flex:1}}>
<Button title="Clear" />
</View>
//....
</View>
Have you tried adding flex: 1 to the list so that it takes up the entire horizontal space?
in my point of view, try adding justifyContent as space-between in the style object list
in each item ,set this style:
width:width/7