Can I add an animation to a React Native navigation button? - reactjs

I have a button in react native, that I am using to navigate to another screen in my Drawer navigator (in addition to using the drawer screen itself). However, the transition is very abrupt. It it possible to have some kind of animation to make it smoother?
I have seen the docs for the transitioner, but these do not appear to be for a functional component like the screen the button is on. Is there any help?
Here is my button:
<TouchableOpacity
style={styles.buttonContainer}
onPress={() => this.props.navigation.navigate("SocialScreen")}>
<Text style={styles.buttonText}>Socials</Text>
</TouchableOpacity>
Any help is appreciated!

Of course you can add animation there.
I am attaching link of library with detail explanation react-native-navigation
Kindly comment if you face any error.

Related

React Native: Cannot scroll <ScrollView> when touching anything that does not have `onPress` function

In short: Is ScrollView supposed to scroll only when pressing component that has onPress function or is something preventing it working as expected?
I noticed ScrollView works when touching on Buttons or other components with onPress function. But when trying to scroll it touching on for example <Text> component nothing happens. I noticed this by then adding onPress to <Text> component (as it has this functionality) and then scrolling works perfectly. Same could be applied to <View> components by changing them to <TouchableWithoutFeedback> with empty onPress: onPress={() => { }}.
But this should not be the case and it increases the workload.
There are tons of question regarding why React Native ScrollView is not working. I tried to found out if this question is answered already but did not come across.
"expo": "^43.0.1",
"react-native": "0.64.2
It seems that in ScrollView there needs to be main child component that has onPress functionality so that it can recognizes touch event.

Why Pressable component's ripple effect only trigger on long press

I'm using new pressable component of react native thinking that it's easy to add ripple effect to it.
But, I found that the ripple effect is being triggered only on long press.
i.e To see the ripple, I need to touch the button for atleast 120ms to 150ms. a rough guess.
I tried to recreate the issue on snack.expo.io but i'm getting Minified React error #130; I think snack won't support pressable.
I didn't found answer anywhere. And there is a active issue on github about this. But no where I found any workaround for this issue.
So, If anyone has a workaround for this kindly share here as it will help so many like me.
This is the code to add pressable with ripple effect
<Pressable
style={styles.buttonStyle}
android_ripple={{color: 'black', borderless: true}}>
<Text style={styles.buttonText}>Login</Text>
</Pressable>
I just explored different links followed by the GitHub link you provided and finally found a workaround.
Accordingly, you just have to add a prop onPress={() => {}} on your code even if you don't use it.
This will solve the ripple delay problem.

Button On press is working only on certain areas of the button in React Native

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)

How to use navigation properly in React native

I just started using React Native and at the moment I am trying to learn how to build a simple mobile application (testing on Andriod emulator). I got two screens/scenes at the moment (Home and Graph). this is what it should look like: header nav. design
I've been searching all over the internet, but can't seem to find the best way on how to implement this kind of header-navigation --> When pressed on the graph icon: the VIEW on the Home screen needs to swipe to the left (out of the screen) and the graphVIEW needs to come in from the right of the screen (like an animation).
I 've looked at react-navigation Tabs / Stacks, but they all seem to have fixed layouts etc.
Can someone help me with this or point me in the right direction?
Thank you very much!
I hope this is what your looking for...
Each screen has its own navigationOptions which helps to configure how its is presented.As of v1.0.0-beta.9 Navigation options can now be a function that receives same props that are available to the screen component.
Add navigationOptions inside your Home screen.
Now set Custom headerRight, your graph image wrapped inside some touchable item and hook the navigation.navigate to onPress as shown below.
static navigationOptions = ({ navigation, screenProps }) => ({
title: 'Home',
headerRight:(
<TouchableHighlight onPress={() => navigation.navigate('GraphScreen')} >
<Image source={require('./my-graph-icon.png')} />
</TouchableHighlight>
)
});
Note: The navigationOptions list are different for tab and stack navigators to which the screen is added to, the above should work for stack navigator.
Check React-Navigation docs for navigation options here

Prevent re-initializing when moving react element

I'm trying to animate a MapView in React Native so that when it's pressed, it goes from being an element in a ScrollView to the map covering the entire screen (including navigation and status bars).
For the overlay view I'm using react-native-overlay
I've got it sort of working by:
measuring the map position with UIManager.measure
activating the overlay and rendering the same map but now inside an overlay
positioning the map relative to the overlay based on measurement
animating the map size to cover the entire screen
The problem is that when going to/from overlay, the entire map reloads which effectively kills the magic of the animation.
From what I understand, since I move the MapView pretty far in the VDOM tree, React kills it and inits a new one. I've tried to avoid this by passing the MapView as a prop to the component doing the animation. My idea was that since the prop is not be changed, the MapView shouldn't be re-instantiated. Unfortunately this doesn't help..
I also tried wrapping the MapView in another component and having shouldComponentUpdate always returning false. Doesn't help either..
Is there someway I can prevent the MapView from re-initializing when I move it in the render tree?
My render tree looks like this:
var map = <MapView />;
When map in ScrollView:
<ScrollView>
...some other content...
{map}
</ScrollView>
when in Overlay:
<ScrollView>
...some other content..
<Overlay isVisible={true} aboveStatusBar={true}>
<View style={styles.fullScreen}>
<Animated.View style={[styles.mapContainer,{top: this.state.topValue, height: this.state.heightValue}]}>
{map}
</Animated.View>
</View>
</Overlay>
</ScrollView>
I believe you should add key property to the Map component. This is the only way to tell React that the particular components in two rendering passes are the same component in fact, so it will reorder the component rather than destroy/recreate. Without key, if the component moves in the tree, react will always destroy/recreate it as it does not know that it's actually the same component (there is nothing that could tell react it is). The key property works in lists/arrays but I think it should also work for more complex tree rearrangements.
See more details here: https://facebook.github.io/react/docs/multiple-components.html#dynamic-children
Note that the link above is for react.js not react-native, but I believe it should work in exactly the same way. I found that there are quite many concepts/details not explained in react-native tutorial, but they are clear in the react.js one (for example explanation about ref property). Actually the authors assume that you have experience with react (so I went on and learned React.js as well ;):
From https://facebook.github.io/react-native/docs/tutorial.html#content :
We assume you have experience writing websites with React. If not,
you can learn about it on the React website.

Resources