I have a screen that has a large image with a text input and a button at the bottom. This screen essentially has three requirements:
When the user taps into the input, the input and button should be visible above the keyboard
The user should be able to tap the button to submit the text input
If the user taps anywhere outside of the input (including the button) the keyboard should be dismissed.
I've tried various solutions including using react-native-keyboard-aware-scroll-view but none of them work quite right. This particular library seems to eat taps, so you can't submit on the button press. Otherwise it's good.
The closest I've been able to come is by surrounding various screen elements with <TouchableWithoutFeedback onPress={Keyboard.dismiss}>. When I try to wrap the entire screen contents in <TouchableWithoutFeedback>, <KeyboardAvoidingView> stops working.
<KeyboardAvoidingView behavior="padding">
<TouchableWithoutFeedback onPress={Keyboard.dismiss}>
<Image source={require('./img.png')} />
</TouchableWithoutFeedback>
<TouchableWithoutFeedback onPress={Keyboard.dismiss}>
<View>
{error}
<Text>Search</Text>
<TextInput
value={this.state.search}
onChange={this.handleChange}
/>
<TouchableHighlight onPress={this.handleSubmit}>
<Text>SEARCH</Text>
</TouchableHighlight>
</View>
</TouchableWithoutFeedback>
</KeyboardAvoidingView>
This is the closest to a working solution, but it still has several problems. First of all, there doesn't seem to be way to add any additional height to KeyboardAvoidingView, so in some cases the button doesn't show above the keyboard. Second, in some cases if the screen is too tall the area underneath the button won't dismiss the keyboard on tap because there's nowhere to put a <TouchableWithoutFeedback> to hide it.
Is there a better way to display things to the user while the keyboard is up while allowing them to tap to dismiss the keyboard and still interact with some controls?
well I was able to solve this by adding
<KeyboardAwareScrollView
ref="scroller"
keyboardShouldPersistTaps={true}
>
Related
i had used this library for the draggable view for items
react-native-draggable-gridview
in that library i don't know how to stop two finger touches on the screen ,
i tried so many stuff but i didn't succeed.
here is the my code for gridView :-
<GridView
keyExtractor={(item) => item.id}
contentContainerStyle={styles.dragContainer}
showsVerticalScrollIndicator={false}
data={dragdata}
numColumns={2}
renderItem={renderItem}
onReleaseCell={onReleaseCell}
disableIntervalMomentum={true}
/>
below i shred the errors of the code when user touch the screen with two finger.
I am trying to create a controller for a robot for which it must handle multiple button tap events simultaneously
The Buttons are supposed to be Tapped Down and hold which would send repeated Commands to the robot on a timer.
<TouchableOpacity
activeOpacity={0.4}
{...otherProps}
delayPressOut={100}
onPressIn={onPressIn}
onPressOut={onPressOut}>
{children}
</TouchableOpacity>
There are multiple buttons That uses this component
I Have tried
onTouchStart={onPressIn} and onTouchEnd={onPressOut}
but when using this the second button is not triggered
Similar to this issue
https://github.com/facebook/react-native/issues/21912
import { TouchableOpacity } from 'react-native-gesture-handler';
Found the Solution
I am using a ScrollView to enable multiple pages in my application. On one page, I am trying to implement a custom made slider. However, I am facing problems as any sliding motion triggers the ScrollView to start changing pages.
In pseudo-code, it is something like this:
<ScrollView horizontal={true}>
<View style={styles.page}><Text>First Page</Text></View>
<View style={styles.page}>
<View style={styles.slider}>
<View style={styles.sliderRange}>
</View>
</View>
</View>
</ScrollView>
How can I disable this scroll when touching my custom Slider Range? I could probably manually reverse the ScrollView's scrolling effect by calculating and reversing X, but that seems like unnecessary effort.
Thanks!
This is from a Udacity flashcard project. Say I have this screen:
A "Next card" button appears conditionally upon the user hitting "Correct" or "Incorrect" (a value gets set in component state and the button is rendered conditional on that value being true):
All of this content is inside a <View> with alignItems: 'center' and justifyContent: 'center', so when the button appears, everything shifts slightly along the vertical axis.
I'd like to create some kind of "blank" placeholder that will have the exact same size as the "Next card" button and have it "render" before the Correct/Incorrect button is hit, so that this shift does not occur.
I recognize I could set a hard height/width on the button and make some kind of placeholder item with the same size, but this is a general question and I'd like to leave appearance to device defaults as much as possible.
Is this possible, and/or a sensible approach? If not, why not, and what would you suggest instead?
Thank you!
I assume you're doing something like this to render the Next Card button.
{this.state.answerSubmitted && (
<TouchableOpacity>
<Text>Next Card</Text>
</TouchableOpacity>
)}
Instead, you could do something like this, your button will be there, just not visible and clickable.
<TouchableOpacity
disabled={!this.state.answerSubmitted}
style={{opacity: this.state.answerSubmitted ? 1 : 0}}
>
<Text>Next Card</Text>
</TouchableOpacity>
If you already have a style for the button, you can use the array notation.
style={[styles.yourStyle, {opacity: this.state.answerSubmitted ? 1 : 0}]}
Hi Everyone,
I am fetching a few buttons from an API and displaying them in a view according to their names. Each of them is displayed as
<TouchableHighlight style={styles.button} onPress={this.onBtnClick.bind(this, item.apiurl)} >
<Text style={styles.Text}{item.displayName}</Text>
</TouchableHighlight>
The button click is not working all over the button except for the last one. It only works on specific areas. I have modified UI is several ways for the first few and checked. It still remains the same.
Any suggestions/Improvements are appreciated.
It's because you're binding the onBtnClick function everytime you click your button.
Simple fix would be onPress={() => this.onBtnClick(item.apiurl)