Skip to content

Commit ff39900

Browse files
authored
fix(FabricExample): Add insets handling to prevent rendering toast behind navigation bar (#3942)
## Description Toasts were rendered behind the navigation bar on Android with the old navigation system; this PR is adding insets handling over Toast components. ## Changes - added inset handling ## Before & after - visual documentation | Before | After | | --- | --- | | <img width="673" height="1288" alt="Screenshot 2026-04-27 at 15 28 04" src="https://github.com/user-attachments/assets/7f4c46da-52a8-4c14-a68c-b42c20f97f3e" /> | <img width="674" height="1299" alt="Screenshot 2026-04-27 at 15 27 10" src="https://github.com/user-attachments/assets/465ee6b1-3a3b-4839-be10-8139af5f360f" /> | ## Test plan Any test with toast on android 10. ## Checklist - [ ] Included code example that can be used to test this change. - [ ] For visual changes, included screenshots / GIFs / recordings documenting the change. - [ ] For API changes, updated relevant public types. - [ ] Ensured that CI passes
1 parent 04f4a98 commit ff39900

1 file changed

Lines changed: 37 additions & 15 deletions

File tree

apps/src/shared/Toast.tsx

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ import {
88
ViewStyle,
99
} from 'react-native';
1010
import { nanoid } from 'nanoid/non-secure';
11+
import {
12+
SafeAreaProvider,
13+
useSafeAreaInsets,
14+
} from 'react-native-safe-area-context';
1115

1216
interface ToastProps {
1317
index: number;
@@ -63,6 +67,30 @@ const ToastContext = createContext({
6367
},
6468
});
6569

70+
const ToastContainer = ({
71+
toasts,
72+
remove,
73+
}: {
74+
toasts: IToast[];
75+
remove: (id: string) => void;
76+
}) => {
77+
const insets = useSafeAreaInsets();
78+
79+
return (
80+
<>
81+
{toasts.map((toast, i) => (
82+
<Toast
83+
index={i}
84+
key={toast.id}
85+
style={{ bottom: insets.bottom + 5 + i * 25 }}
86+
{...toast}
87+
remove={remove}
88+
/>
89+
))}
90+
</>
91+
);
92+
};
93+
6694
interface ToastProviderProps {
6795
children: React.ReactNode;
6896
}
@@ -80,20 +108,15 @@ export const ToastProvider = ({ children }: ToastProviderProps) => {
80108
};
81109

82110
return (
83-
<ToastContext.Provider value={{ push }}>
84-
<>
85-
{children}
86-
{toasts.map((toast, i) => (
87-
<Toast
88-
index={i}
89-
key={toast.id}
90-
style={{ marginBottom: i * 25 }}
91-
{...toast}
92-
remove={remove}
93-
/>
94-
))}
95-
</>
96-
</ToastContext.Provider>
111+
<SafeAreaProvider>
112+
<ToastContext.Provider value={{ push }}>
113+
<>
114+
{children}
115+
{/* Render the internal container */}
116+
<ToastContainer toasts={toasts} remove={remove} />
117+
</>
118+
</ToastContext.Provider>
119+
</SafeAreaProvider>
97120
);
98121
};
99122

@@ -104,7 +127,6 @@ const styles = StyleSheet.create({
104127
flex: 1,
105128
position: 'absolute',
106129
alignSelf: 'center',
107-
bottom: 5,
108130
},
109131
alert: {
110132
alignItems: 'center',

0 commit comments

Comments
 (0)