calintamas / react-native-toast-message

Animated toast message component for React Native
MIT License
1.69k stars 261 forks source link

Toast behind keyboard issue #378

Open Hitarthbhatt opened 2 years ago

Hitarthbhatt commented 2 years ago

When keyboard is up and toast position is bottom, it's covered by keyboard! Is it possible to come upon keyboard view? (Specific Android Device)

Jigs6720 commented 11 months ago

same issue i am facing

seyedmostafahasani commented 9 months ago

@Hitarthbhatt @Jigs6720 I tested it, and it works correctly. Could you please share your React Native version as well as the version of the library you are using?

moooss commented 4 months ago

I have the same issue. In my case it is related to setting android:windowSoftInputMode to pan instead of resize. The toast is above keyboard with resize and behind with pan.

I need the pan option for other reasons. I tried to use a custom layout with KeyboardAvoidingView but it changes nothing.

Any idea would be great help, thanks !

ShubhamShingate-Futy commented 3 months ago

@Hitarthbhatt @Jigs6720 Did you guys found out any solution?

@moooss Doing this android:windowSoftInputMode="stateAlwaysHidden|adjustResize" is flickering the screen when opened the keyboard.

Jonuma commented 1 month ago

Hey! Using https://www.npmjs.com/package/patch-package to modify the code like is shown bellow seemed to to the trick.

--- a/node_modules/react-native-toast-message/lib/src/hooks/useKeyboard.js
+++ b/node_modules/react-native-toast-message/lib/src/hooks/useKeyboard.js
@@ -1,6 +1,5 @@
 import React from 'react';
 import { Keyboard } from 'react-native';
-import { isIOS } from '../utils/platform';
 export function useKeyboard() {
     const [keyboardHeight, setKeyboardHeight] = React.useState(0);
     const [isKeyboardVisible, setIsKeyboardVisible] = React.useState(false);
@@ -14,9 +13,6 @@ export function useKeyboard() {
         setIsKeyboardVisible(false);
     }, []);
     React.useEffect(() => {
-        if (!isIOS()) {
-            return () => { };
-        }
         const didShowListener = Keyboard.addListener('keyboardDidShow', onShow);
         const didHideListener = Keyboard.addListener('keyboardDidHide', onHide);
         return () => {

That way the Toast on Android is also keyboard aware. If you then play around with the bottomOffset and keyboardOffset with different values for each platform you can get it right.

@seyedmostafahasani do you know why is there a guard for (not) iOS?