Created
August 18, 2020 21:34
-
-
Save nicolas-amabile/3b9fd47c896d8f807bd39b02bba8c159 to your computer and use it in GitHub Desktop.
A simple React Native component that detects outside tap events
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
import PropTypes from 'prop-types'; | |
import React from 'react'; | |
import styled from 'styled-components'; | |
const Modal = styled.Modal.attrs(() => ({ | |
transparent: true, | |
}))``; | |
const Wrapper = styled.TouchableOpacity` | |
flex: 1; | |
`; | |
const WatchOutsideTap = ({ children, onTapOutside }) => ( | |
<Modal> | |
<Wrapper onPress={onTapOutside}> | |
{children} | |
</Wrapper> | |
</Modal> | |
); | |
WatchOutsideTap.propTypes = { | |
children: PropTypes.oneOfType([ | |
PropTypes.arrayOf(PropTypes.node), | |
PropTypes.node, | |
]).isRequired, | |
onTapOutside: PropTypes.func.isRequired, | |
}; | |
export default WatchOutsideTap; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment