Skip to content

Instantly share code, notes, and snippets.

@jacobp100
Created April 20, 2017 19:48
Show Gist options
  • Save jacobp100/6d674bec2cfc342a62d99914fe0a6f1c to your computer and use it in GitHub Desktop.
Save jacobp100/6d674bec2cfc342a62d99914fe0a6f1c to your computer and use it in GitHub Desktop.
/**
* 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