Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

JitsiKeyboardAvoidingView.js 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // @flow
  2. import { useHeaderHeight } from '@react-navigation/elements';
  3. import React, { useEffect, useState } from 'react';
  4. import {
  5. KeyboardAvoidingView,
  6. Platform,
  7. StatusBar
  8. } from 'react-native';
  9. import { useSafeAreaInsets } from 'react-native-safe-area-context';
  10. import { StyleType } from '../../styles';
  11. type Props = {
  12. /**
  13. * The children component(s) of the Modal, to be rendered.
  14. */
  15. children: React$Node,
  16. /**
  17. * Additional style to be appended to the KeyboardAvoidingView content container.
  18. */
  19. contentContainerStyle?: StyleType,
  20. /**
  21. * Is a text input rendered at the bottom of the screen?
  22. */
  23. hasBottomTextInput: boolean,
  24. /**
  25. * Is the screen rendering a tab navigator?
  26. */
  27. hasTabNavigator: boolean,
  28. /**
  29. * Additional style to be appended to the KeyboardAvoidingView.
  30. */
  31. style?: StyleType
  32. }
  33. const JitsiKeyboardAvoidingView = (
  34. {
  35. children,
  36. contentContainerStyle,
  37. hasTabNavigator,
  38. hasBottomTextInput,
  39. style
  40. }: Props) => {
  41. const headerHeight = useHeaderHeight();
  42. const insets = useSafeAreaInsets();
  43. const [ bottomPadding, setBottomPadding ] = useState(insets.bottom);
  44. useEffect(() => {
  45. // This useEffect is needed because insets are undefined at first for some reason
  46. // https://github.com/th3rdwave/react-native-safe-area-context/issues/54
  47. setBottomPadding(insets.bottom);
  48. }, [ insets.bottom ]);
  49. const tabNavigatorPadding
  50. = hasTabNavigator ? headerHeight : 0;
  51. const noNotchDevicePadding = bottomPadding || 10;
  52. const iosVerticalOffset
  53. = headerHeight + noNotchDevicePadding + tabNavigatorPadding;
  54. const androidVerticalOffset = hasBottomTextInput
  55. ? headerHeight + StatusBar.currentHeight : headerHeight;
  56. return (
  57. <KeyboardAvoidingView
  58. behavior = { Platform.OS === 'ios' ? 'padding' : 'height' }
  59. contentContainerStyle = { contentContainerStyle }
  60. enabled = { true }
  61. keyboardVerticalOffset = {
  62. Platform.OS === 'ios'
  63. ? iosVerticalOffset
  64. : androidVerticalOffset
  65. }
  66. style = { style }>
  67. { children }
  68. </KeyboardAvoidingView>
  69. );
  70. };
  71. export default JitsiKeyboardAvoidingView;