diff --git a/common/components/views/Toast.tsx b/common/components/views/Toast.tsx index 0513f5404..87f67513a 100644 --- a/common/components/views/Toast.tsx +++ b/common/components/views/Toast.tsx @@ -15,7 +15,7 @@ export default function () { const dispatch = useDispatch(); // state - const { message, type, autoHide } = useSelector(getToast); + const { message, type, autoHide, keyboardIsOpen } = useSelector(getToast); const [opacity] = useState(new Animated.Value(0)); // UI @@ -41,7 +41,7 @@ export default function () { - (dispatch: AppDispatch) => { - dispatch({ - type: SHOW_TOAST, - payload: { message: message.replace('Error: ', ''), type, autoHide }, - }); - }; + (message: string, type: ToastType = 'success', autoHide: boolean = true, keyboardIsOpen: boolean = false) => + (dispatch: AppDispatch) => { + dispatch({ + type: SHOW_TOAST, + payload: { message: message.replace('Error: ', ''), type, autoHide, keyboardIsOpen }, + }); + }; export const hideToast = () => (dispatch: AppDispatch) => { dispatch({ type: HIDE_TOAST }); @@ -20,14 +20,14 @@ export const hideToast = () => (dispatch: AppDispatch) => { export const awaitWithFeedback = (promise: Promise) => - async (dispatch: AppDispatch) => { - dispatch({ type: BUSY, payload: true }); - try { - const result = await promise; - dispatch({ type: BUSY, payload: false }); - return result; - } catch (error) { - dispatch({ type: BUSY, payload: false }); - throw error; - } - }; + async (dispatch: AppDispatch) => { + dispatch({ type: BUSY, payload: true }); + try { + const result = await promise; + dispatch({ type: BUSY, payload: false }); + return result; + } catch (error) { + dispatch({ type: BUSY, payload: false }); + throw error; + } + }; diff --git a/common/store/ui/types.ts b/common/store/ui/types.ts index 05a0c425e..6cabebbca 100644 --- a/common/store/ui/types.ts +++ b/common/store/ui/types.ts @@ -4,6 +4,7 @@ export interface ToastState { message?: string; type?: ToastType; autoHide?: boolean; + keyboardIsOpen?: boolean; } export interface UIState { diff --git a/common/utils/keyboardListener.tsx b/common/utils/keyboardListener.tsx new file mode 100644 index 000000000..b1f530afd --- /dev/null +++ b/common/utils/keyboardListener.tsx @@ -0,0 +1,28 @@ +import { Component } from 'react'; +import { Keyboard } from 'react-native'; + +export var keyboardStatus = "0"; + +export class KeyboardListener extends Component { + + componentWillMount() { + Keyboard.addListener('keyboardDidShow', (e) => { + keyboardStatus = "1"; + //alert(e.endCoordinates.height); + }); + Keyboard.addListener('keyboardDidHide', () => { + keyboardStatus = "0"; + }) + } + + componentWillUnmount() { + Keyboard.removeAllListeners; + } + + render() { + return false; + } +} + +export default KeyboardListener; +