Skip to content

Instantly share code, notes, and snippets.

@brunopk
Last active November 5, 2020 15:44
Show Gist options
  • Save brunopk/36e8d7241ce03df92b45ee8377714f58 to your computer and use it in GitHub Desktop.
Save brunopk/36e8d7241ce03df92b45ee8377714f58 to your computer and use it in GitHub Desktop.
A modal component using styled components https://styled-components.com/ and react-native-modal
import React from 'react';
import Modal from 'react-native-modal';
import styled from 'styled-components/native';
import {View, StyleSheet} from 'react-native';
const styles = StyleSheet.create({
primaryContainer: {
height: '30%',
justifyContent: 'center',
alignItems: 'center',
},
secondContainer: {
height: '100%',
},
});
const Body = styled.View`
background-color: white;
`;
const Buttons = styled(Body)`
flex-direction: row;
justify-content: flex-end;
padding: 10px;
`;
function CustomModal({
visible,
setVisible,
children,
positiveBtn,
negativeBtn,
}) {
return (
<Modal isVisible={visible} onBackButtonPress={() => setVisible(false)}>
<View style={styles.primaryContainer}>
<View style={styles.secondContainer}>
<Body>{children}</Body>
<Buttons>
{negativeBtn}
{positiveBtn}
</Buttons>
</View>
</View>
</Modal>
);
}
export {CustomModal as Modal};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment