You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

functions.native.js 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // @flow
  2. import { useEffect, useState } from 'react';
  3. import { Keyboard } from 'react-native';
  4. import { toState } from '../../redux';
  5. export const useKeyboardHeight = () => {
  6. const [ keyboardHeight, setKeyboardHeight ] = useState(0);
  7. const onKeyboardDidShow = e => {
  8. setKeyboardHeight(e.endCoordinates.height);
  9. };
  10. const onKeyboardDidHide = () => {
  11. setKeyboardHeight(0);
  12. };
  13. useEffect(() => {
  14. const keyboardShow = Keyboard.addListener('keyboardDidShow', onKeyboardDidShow);
  15. const keyboardHide = Keyboard.addListener('keyboardDidHide', onKeyboardDidHide);
  16. return () => {
  17. keyboardShow.remove();
  18. keyboardHide.remove();
  19. };
  20. }, []);
  21. return keyboardHeight;
  22. };
  23. /**
  24. *
  25. * Returns the client width.
  26. *
  27. * @param {(Function|Object)} stateful - The (whole) redux state, or redux's
  28. * {@code getState} function to be used to retrieve the state
  29. * features/base/config.
  30. * @returns {number}.
  31. */
  32. export function getClientWidth(stateful: Object) {
  33. const state = toState(stateful['features/base/responsive-ui']);
  34. return state.clientWidth;
  35. }
  36. /**
  37. *
  38. * Returns the client height.
  39. *
  40. * @param {(Function|Object)} stateful - The (whole) redux state, or redux's
  41. * {@code getState} function to be used to retrieve the state
  42. * features/base/config.
  43. * @returns {number}.
  44. */
  45. export function getClientHeight(stateful: Object) {
  46. const state = toState(stateful['features/base/responsive-ui']);
  47. return state.clientHeight;
  48. }