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

JitsiKeyboardAvoidingView.js 2.1KB

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