How to change button styles on press? - reactjs

In react-native project I have next button:
import Icon from 'react-native-vector-icons/FontAwesome';
<Icon.Button
name='chevron-down'
backgroundColor='transparent'
color='#000000'
padding={0}
size={30}
onPress={() => setIsCollapsed(false)}
/>
Everything is fine except one thing - on button press for a fraction of a second, appears black square round the button element. How can I remove this styling element?

Wrap it inside TouchableOpacity and pass onPress method on touchable opacity's onPress props
Example :
<TouchableOpacity onPress={() => setIsCollapsed(false)} >
<Icon.Button
name='chevron-down'
backgroundColor='transparent'
color='#000000'
padding={0}
size={30}
/>
</TouchableOpacity>

Related

How i make a button text to lower case in react native

Anyone tell me how I make my button to lowercase in react native because I already get the answer in stack overflow but there is using touch opacity and that is the different component of button so I want the answer for button component
When I will type anything in under title props example
title='Hello'
[1]
[1]: https://i.stack.imgur.com/UmaBF.png
you can use TouchableOpacity for your button
like this:
<TouchableOpacity
onPress={() => onClick}
style={{}}>
<Text
style={{
fontSize: 20,
alignSelf: 'center',
}}>
Hello
</Text>
</TouchableOpacity>
Install react-native-paper and import Button from react-native-paper and make uppercase prop to false.
import { Button } from 'react-native-paper';
<Button
mode="contained"
uppercase={false}
onPress={() => console.log('Hello')}>
Hello
</Button>
From your question I just understood that you only need to convert the button text to lower case. For that just replace {title} with {title.toLowerCase()} and it will convert the titles text to lower case.

React Native TouchableOpacity scrolling

I have an old issue with scrolling some content inside TouchableOpacity (react-native). I've been trying to find any solution for months but nothing worked together with onPress/onPressIn/Out handlers. Any ideas?
<TouchableOpacity
activeOpacity={1}
delayPressIn={1}
onPress={handlePress}
onPressIn={handlePressIn}
onLongPress={handleLongPress}
onPressOut={handlePressOut}>
<ScrollView>
{/* some content to be scrolled here */}
</ScrollView>
</TouchableOpacity>
use TouchableOpacity inside the Scrollview
<ScrollView>
<TouchableOpacity
activeOpacity={1}
delayPressIn={1}
onPress={handlePress}
onPressIn={handlePressIn}
onLongPress={handleLongPress}
onPressOut={handlePressOut}>
{/* component to be displayed */}
</TouchableOpacity>
<TouchableOpacity
activeOpacity={1}
delayPressIn={1}
onPress={handlePress}
onPressIn={handlePressIn}
onLongPress={handleLongPress}
onPressOut={handlePressOut}>
{/* component to be displayed */}
</TouchableOpacity>
</ScrollView>

React Native button with no style

I have a horizontal view:
<View style={{flex: 1, flexDirection: 'row'}}>
<Text style={styles.bottomTextSignIn}>I'm already a member, </Text>
<Button
title="Sign In"
onPress={() => navigation.navigate("Login")}
/>
</View>
Im trying to make the the button look like the text, no styling, so it looks like its part of the sentence "I'm already a member, Sign In"
At the moment its a blue button next to the text. I tried changing the button colour to white which leaves a shadow around it. Is there a way to remove the styling for the button? or another way?
The button component is a "touchable/pressable" component with style. link
I think you are looking for pressable component.
<Pressable onPress={() => alert('hey')}>
<Text>I'm pressable!</Text>
</Pressable>
You can simply replace the button tag with and handle on onPress event on the text and different style to the text from the first one

TouchableNativeFeedback onpress Not Working ReactNative

I imported {TouchableNativeFeedback} from 'react-native'
In the render() function I am trying to use TouchableNativeFeedback; however, the function onpress is triggered only when the app reloads. When pressing the TouchableNativeFeedback the onpress function is not triggered. What's the problem? How can I have a TouchableNativeFeedback with onpress function working?
<View style={style.gameBody}>
{this.state.isMystery=='false'?
<View style={style.drinkBody}>
{/* BEER LOGO AND BEER COUNTER */}
<TouchableNativeFeedback style={style.beerText} onpress={console.log('this got preseed')}>
<View style={style.beerText}>
<Image
source={require('../img/beer.png')}
style={style.beerStyling}/>
<Feather style={style.beerCountXStyle} name='x'/>
<Text style={style.beerDrinkCounterStyle}>
{this.state.round1Drink[this.state.gameNum]}
</Text>
{/* Line Stlye */}
<Image
source={require('../img/line.png')}
style={style.lineStyle}/>
</View>
</TouchableNativeFeedback>
{/* BEER TEXT/CARD SCREEN HERE */}
<Text style={style.drinkText}
onPress={() => RandomChooseRound1()} // add this.startAnimation here
>
</Text>
</View>
: null
}
The onpress function in Works; however, the onpress function doesn not work for
<Text style={style.drinkText} onPress={() => RandomChooseRound1()}
When pressing on the text, the onpress function works.
Please Help! Thank you!
I think you're missing a 'this'.
<Text style={style.drinkText} onPress={() => this.RandomChooseRound1()}>

TextInput weird behaviour in React-Native

I have the following TextInput,
<TextInput
style={[
styles.inputField,
isEmailError && { borderColor: color.delete },
]}
placeholder={'E-mail'}
placeholderTextColor={color[colorScheme].textMuted}
autoCapitalize={'none'}
autoCorrect={false}
value={userCredentials.email}
onChangeText={onChangeEmail}
onSubmitEditing={passwordInput.current && passwordInput.current.focus}
blurOnSubmit={false}
returnKeyType={'next'}
keyboardType="email-address"
/>
When I click anywhere else outside the keyboard(let's say a button), the expected behaviour is that the button will get clicked, however, in here, first click always closes the keyboard then I have to press again for whatever element i was trying to reach.
This is because of scroll view. Add props keyboardShouldPersistTaps in your scrollview as below to solve error :
<ScrollView
keyboardShouldPersistTaps="handled"
keyboardDismissMode="interactive"
>
...
...
</ScrollView>
You can find more detail here
Maybe try this:
import DismissKeyboard from 'dismissKeyboard';
<TouchableWithoutFeedback onPress={()=>{DismissKeyboard()}}>
<View style={Styles.container}>
<TextInput />
</View>
</TouchableWithoutFeedback>

Resources