Skip to content

Instantly share code, notes, and snippets.

@n-ii-ma
Created December 25, 2023 09:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save n-ii-ma/64267f6b78d3f23aeaf23290cabd7e0b to your computer and use it in GitHub Desktop.
Save n-ii-ma/64267f6b78d3f23aeaf23290cabd7e0b to your computer and use it in GitHub Desktop.
Expo Modal
import {
StyleSheet,
View,
Modal,
TouchableOpacity,
TouchableWithoutFeedback,
} from "react-native";
import { memo } from "react";
import { ms } from "react-native-size-matters";
import type { ModalProps } from "react-native";
import type { ReactNode } from "react";
interface CustomModalProps
extends Pick<ModalProps, "visible" | "onDismiss"> {
/** React children */
children: ReactNode;
}
const CustomModal = ({
visible = false,
onDismiss,
children,
}: CustomModalProps) => (
<Modal visible={visible} animationType="fade" transparent={true}>
<TouchableOpacity onPress={onDismiss} style={styles.centeredView}>
<TouchableWithoutFeedback>
<View style={styles.modalView}>{children}</View>
</TouchableWithoutFeedback>
</TouchableOpacity>
</Modal>
);
export default memo(CustomModal);
const styles = StyleSheet.create({
centeredView: {
flex: 1,
justifyContent: "center",
alignItems: "center",
backgroundColor: "#38383850",
},
modalView: {
width: "85%",
alignItems: "center",
backgroundColor: "#fff",
borderRadius: ms(20),
padding: ms(20),
shadowColor: "#000",
shadowOffset: {
width: 0,
height: 2,
},
shadowOpacity: 0.25,
shadowRadius: 3.84,
elevation: 5,
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment