-
Notifications
You must be signed in to change notification settings - Fork 1
Added portal above content area #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import { useEffect, useState } from "react"; | ||
| import { createPortal } from "react-dom"; | ||
| import { View, Pressable, StyleSheet } from "react-native"; | ||
|
|
||
| import { ToastMessage } from "./types"; | ||
|
|
@@ -17,6 +18,19 @@ export default function ToastContainer({ | |
| children, | ||
| }: Props) { | ||
| const [slide, setSlide] = useState(false); | ||
| const [portalEl, setPortalEl] = useState<HTMLDivElement | null>(null); | ||
|
|
||
| useEffect(() => { | ||
| const el = document.createElement("div"); | ||
| el.style.zIndex = "10000"; | ||
| el.style.position = "relative"; | ||
|
Comment on lines
+25
to
+26
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are these necessary? they might be, look down at my styles you'll notice similar zIndex stuff, but this needs to be as vanilla as possible so I don't want to add these unless we need to |
||
| document.body.appendChild(el); | ||
| setPortalEl(el); | ||
|
|
||
| return () => { | ||
| document.body.removeChild(el); | ||
| }; | ||
| }, []); | ||
|
|
||
| function onDismiss() { | ||
| setSlide(false); | ||
|
|
@@ -34,7 +48,7 @@ export default function ToastContainer({ | |
| setSlide(true); | ||
| }, []); | ||
|
|
||
| return ( | ||
| const content = ( | ||
| <View | ||
| pointerEvents="none" | ||
| style={[styles.container, position === "bottom" && styles.positionBottom]} | ||
|
|
@@ -64,6 +78,12 @@ export default function ToastContainer({ | |
| </Pressable> | ||
| </View> | ||
| ); | ||
|
|
||
| if (portalEl) { | ||
| return createPortal(content, portalEl); | ||
| } | ||
|
|
||
| return content; | ||
|
Comment on lines
+82
to
+86
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if we don't have the portal, we should return null. |
||
| } | ||
|
|
||
| const styles = StyleSheet.create({ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be a ref, not state