Created
April 20, 2017 19:48
-
-
Save jacobp100/6d674bec2cfc342a62d99914fe0a6f1c to your computer and use it in GitHub Desktop.
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
/** | |
* Sample React Native App | |
* https://github.com/facebook/react-native | |
* @flow | |
*/ | |
import React, { Component } from 'react'; | |
import { | |
AppRegistry, | |
StyleSheet, | |
Text, | |
View, | |
TabBarIOS | |
} from 'react-native'; | |
const DOUBLE_TAP_THRESHOLD = 300; | |
export default class TabBarDoubleTap extends Component { | |
state = { didDoubleTap: false } | |
tapTimeout = null | |
clearTapTimeout = () => { | |
clearTimeout(this.tapTimeout); | |
this.tapTimeout = null; | |
} | |
tap = () => { | |
if (this.tapTimeout !== null) { | |
this.clearTapTimeout() | |
this.setState({ didDoubleTap: true }); | |
} else { | |
this.tapTimeout = setTimeout(this.clearTapTimeout, DOUBLE_TAP_THRESHOLD); | |
} | |
} | |
render() { | |
const { didDoubleTap } = this.state; | |
return ( | |
<TabBarIOS style={styles.container}> | |
<TabBarIOS.Item | |
systemIcon="history" | |
title="Test" | |
onPress={this.tap} | |
selected | |
> | |
<View style={styles.container}> | |
<Text style={styles.message}> | |
You {didDoubleTap ? 'DID' : 'did not'} double tap | |
</Text> | |
</View> | |
</TabBarIOS.Item> | |
</TabBarIOS> | |
); | |
} | |
} | |
const styles = StyleSheet.create({ | |
container: { | |
flex: 1, | |
justifyContent: 'center', | |
alignItems: 'center', | |
backgroundColor: '#F5FCFF', | |
}, | |
message: { | |
fontSize: 20, | |
textAlign: 'center', | |
margin: 10, | |
}, | |
}); | |
AppRegistry.registerComponent('TabBarDoubleTap', () => TabBarDoubleTap); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment