Skip to content

Instantly share code, notes, and snippets.

@huang47
Created December 8, 2019 23:36
Show Gist options
  • Save huang47/7e43dfb54f9c7f5fde6347b78a6fda22 to your computer and use it in GitHub Desktop.
Save huang47/7e43dfb54f9c7f5fde6347b78a6fda22 to your computer and use it in GitHub Desktop.
// @flow
import * as React from 'react';
import { TouchableOpacity } from 'react-native';
type Props<TValue> = {
children: React.Node,
disabled: boolean,
value: TValue,
onPress: (*) => void,
};
export default class AbstractButton<T> extends React.PureComponent<Props<T>> {
static defaultProps = {
onPress: () => {},
};
handlePress = () => {
const { value, onPress } = this.props;
onPress(value);
};
render() {
return (
<TouchableOpacity disabled={this.props.disabled} onPress={this.handlePress}>
{this.props.children}
</TouchableOpacity>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment