so I am new to react native and know the basics about using onPress with buttons but since I have changed my button to this LinearGradient code below, I am kind of lost using onPress. Right now I only have onPress outputting to my terminal just to test and make sure its working.
In the end I want to navigate to another page which I am assuming I will use some navigation API for that. Anywho, I apologize for the ignorance and I really appreciate your time! Thank you!!
The place I put my onPress code now was teh only place I could think to put it.
Well now realizing LinearGradient does not work with onPress…How should I go about navigating that linearGradient to another page?
JavaScript
x
68
68
1
import React, { Component } from 'react';
2
import { StyleSheet, Text, View, TouchableOpacity, Animated } from 'react-native';
3
import { LinearGradient } from 'expo-linear-gradient';
4
5
export default class GetStartedButton extends Component {
6
7
constructor(props) {
8
super(props)
9
10
this.fadeAnimation = new Animated.Value(0)
11
}
12
componentDidMount() {
13
Animated.timing(this.fadeAnimation, {
14
toValue: 1,
15
duration: 5000,
16
useNativeDriver: true,
17
}).start()
18
}
19
20
render(){
21
return(
22
<Animated.View style={[styles.container, { opacity: this.fadeAnimation}]}>
23
<TouchableOpacity>
24
<LinearGradient
25
onPress={() => console.log("clicked")}
26
colors={['#DB004C','#FC008E']}
27
style={styles.linearGradient}
28
start={{ x: 0, y: 0.5 }}
29
end={{ x: 1, y: 0.5 }}
30
>
31
32
<Text style={styles.text}>
33
Get Started
34
</Text>
35
</LinearGradient>
36
</TouchableOpacity>
37
</Animated.View>
38
)
39
40
}
41
}
42
43
const styles = StyleSheet.create({
44
container: {
45
flex: 1,
46
alignItems: 'center',
47
justifyContent: 'center',
48
49
},
50
linearGradient: {
51
alignItems: 'center',
52
justifyContent: 'center',
53
borderRadius: 10,
54
width: 340,
55
padding: 20,
56
},
57
58
text: {
59
color: 'white',
60
fontSize: 20,
61
justifyContent: 'center',
62
alignItems: 'center',
63
}
64
});
65
66
67
68
Advertisement
Answer
About that ?
JavaScript
1
14
14
1
<LinearGradient
2
colors={['#DB004C', '#FC008E']}
3
style={styles.linearGradient}
4
start={{ x: 0, y: 0.5 }}
5
end={{ x: 1, y: 0.5 }}
6
>
7
<TouchableOpacity
8
onPress={() => console.log('clicked')}
9
style={{ alignItems: 'center', justifyContent: 'center' }}
10
>
11
<Text style={styles.text}>Get Started</Text>
12
</TouchableOpacity>
13
</LinearGradient>
14