Last active
September 19, 2019 15:22
-
-
Save stnc/393e494d199f2b8a435f767e813e2408 to your computer and use it in GitHub Desktop.
React-native, render a button click dynamically
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
want to generate a button click dynamically for a TouchableOpacity in react-native, i didn't find anything about that, | |
all i want is to call the TouchableOpacity onPress from a fuction (or see its effect on the button) | |
in titanium we were doing $.button.click i tried using Animated but no luck https://facebook.github.io/react-native/docs/animations.html | |
so can anybody help? thanks in advance | |
*/ | |
import React, { Component } from 'react'; | |
import { View, Text, Dimensions } from 'react-native'; | |
export default class About extends Component { | |
simulatePress() { | |
this.runAs.props.onPress(); | |
} | |
render() { | |
return ( | |
<View style={styles.containerTop}> | |
<TouchableOpacity ref={runAs} onPress={() => console.log('onPress')}> | |
<Text>Tap me</Text> | |
</TouchableOpacity> | |
<Button onPress={() => this.simulatePress()} title="run" color="#841584"/> | |
</View> | |
) | |
} | |
} | |
const styles = { | |
containerTop: { | |
flex: 1, | |
justifyContent: 'center', | |
alignItems: 'center', | |
marginBottom:15 | |
}, | |
container: { | |
flex: 1, | |
borderRadius: 12, | |
overflow: 'hidden', | |
}, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment