import React, { ComponentProps } from 'react'; import { KeyboardAwareScrollView } from 'react-native-keyboard-controller'; import { getBottomFixedButtonHeight } from '../utils'; import { useSafeAreaInsets } from 'react-native-safe-area-context'; import { BottomFixedButton } from '../BottomFixedButton'; import { ScrollView } from 'react-native'; type OwnProps = { type: ComponentProps['type']; disableKeyboardSticky?: boolean; }; /** * ## KeyboardAwareScrollViewForBFB * * `KeyboardAwareScrollView` 컴포넌트를 프리즈마 `BottomFixedButton` 컴포넌트와 함께 사용할 때 * 올바른 동작을 위해 필요한 계산을 미리 적용한 유틸리티 컴포넌트입니다. * * `react-native-keyboard-controller` 라이브러리에 의존합니다. * * * ## Props * * ### `type` * - `BottomFixedButton`의 `type`과 동일합니다. * - 함께 사용하는 `BottomFixedButton` 컴포넌트의 `type`과 동일한 값을 전달하세요. * * ### `disableKeyboardSticky` (optional) * - `BottomFixedButton`의 `disableKeyboardSticky`와 동일합니다. * - 기본값 false * - 함께 사용하는 `BottomFixedButton` 컴포넌트의 `disableKeyboardSticky`와 동일한 값을 전달하세요. * * * @example * ```tsx * // `type`, `disableKeyboardSticky` 값을 `BottomFixedButton` 설정에 맞추어 동일하게 지정해주세요. * * * * * * * * * * * ``` * */ export const KeyboardAwareScrollViewForBFB = React.forwardRef< ScrollView, OwnProps & ComponentProps >(({ type, disableKeyboardSticky = false, ...props }, ref) => { const safeAreaInsets = useSafeAreaInsets(); const TYPES_WITH_STICKY_BUTTON = ['full', 'solid']; const hasNoStickyButton = !TYPES_WITH_STICKY_BUTTON.includes(type); const stickyButtonHeightIfExist = disableKeyboardSticky || hasNoStickyButton ? 0 : getBottomFixedButtonHeight('keyboard'); /** * bottomOffset 보정 * - (참고) bottomOffset: 키보드 상단과 `TextInput` 사이의 간격 * - 키보드가 붙는 경우라면, 'keyboard' 타입 높이만큼 간격을 줘야 인풋이 가려지지 않음. */ const bottomOffset = stickyButtonHeightIfExist; /** * extraKeyboardSpace 보정 * - (참고) extraKeyboardSpace: 스크롤 뷰 하단 여백 조정 (음수값을 주면 그만큼 키보드에 가려지고, 양수값을 주면 키보드 위로 여백이 생김) * - 바텀버튼 영역 높이에서 'keyboard' 타입 높이 뺀 만큼 스크롤뷰 크기를 키워야, 키보드 상단과 컨텐츠 하단이 딱 맞물림 */ const bottomButtonAreaHeight = safeAreaInsets.bottom + getBottomFixedButtonHeight(type); const extraKeyboardSpace = -(bottomButtonAreaHeight - stickyButtonHeightIfExist); return ( ); });