diff --git a/src/components/ActionSheetAwareScrollView/ActionSheetAwareScrollViewContext.tsx b/src/components/ActionSheetAwareScrollView/ActionSheetAwareScrollViewContext.tsx index cd5b20bbf10e..56419ea39af0 100644 --- a/src/components/ActionSheetAwareScrollView/ActionSheetAwareScrollViewContext.tsx +++ b/src/components/ActionSheetAwareScrollView/ActionSheetAwareScrollViewContext.tsx @@ -67,7 +67,7 @@ const States = { POPOVER_CLOSED: 'popoverClosed', KEYBOARD_POPOVER_CLOSED: 'keyboardPopoverClosed', KEYBOARD_POPOVER_OPEN: 'keyboardPopoverOpen', - KEYBOARD_CLOSED_POPOVER: 'keyboardClosingPopover', + KEYBOARD_CLOSING_POPOVER: 'keyboardClosingPopover', POPOVER_MEASURED: 'popoverMeasured', MODAL_WITH_KEYBOARD_OPEN_DELETED: 'modalWithKeyboardOpenDeleted', } as const; @@ -97,13 +97,13 @@ const STATE_MACHINE: StateMachine, ValueOf>(({style, children, ...rest}, ref) => { +const ActionSheetAwareScrollView = forwardRef(({style, children, ...props}, ref) => { const scrollViewAnimatedRef = useAnimatedRef(); - const position = useScrollViewOffset(scrollViewAnimatedRef); const onRef = useCallback( (assignedRef: Reanimated.ScrollView) => { @@ -24,13 +23,16 @@ const ActionSheetAwareScrollView = forwardRef ({ + paddingTop: spacing.get(), + })); return ( {children} @@ -45,9 +47,9 @@ export default ActionSheetAwareScrollView; * @param props - props that will be passed to the ScrollView from FlatList * @returns - ActionSheetAwareScrollView */ -function renderScrollComponent(props: ScrollViewProps) { +const renderScrollComponent: RenderActionSheetAwareScrollViewComponent = (props) => { // eslint-disable-next-line react/jsx-props-no-spreading return ; -} +}; export {renderScrollComponent, ActionSheetAwareScrollViewContext, ActionSheetAwareScrollViewProvider, Actions}; diff --git a/src/components/ActionSheetAwareScrollView/index.tsx b/src/components/ActionSheetAwareScrollView/index.tsx index d22f991ce4cf..f2fc64cda8bd 100644 --- a/src/components/ActionSheetAwareScrollView/index.tsx +++ b/src/components/ActionSheetAwareScrollView/index.tsx @@ -1,13 +1,12 @@ // this whole file is just for other platforms // iOS version has everything implemented -import type {PropsWithChildren} from 'react'; import React, {forwardRef} from 'react'; -import type {ScrollViewProps} from 'react-native'; // eslint-disable-next-line no-restricted-imports import {ScrollView} from 'react-native'; import {Actions, ActionSheetAwareScrollViewContext, ActionSheetAwareScrollViewProvider} from './ActionSheetAwareScrollViewContext'; +import type {ActionSheetAwareScrollViewProps, RenderActionSheetAwareScrollViewComponent} from './types'; -const ActionSheetAwareScrollView = forwardRef>((props, ref) => ( +const ActionSheetAwareScrollView = forwardRef((props, ref) => ( ; +type RenderActionSheetAwareScrollViewComponent = ((props: ActionSheetAwareScrollViewProps) => React.ReactElement) | undefined; +export type {ActionSheetAwareScrollViewProps, RenderActionSheetAwareScrollViewComponent}; diff --git a/src/components/ActionSheetAwareScrollView/useActionSheetKeyboardSpace.tsx b/src/components/ActionSheetAwareScrollView/useActionSheetKeyboardSpacing.ts similarity index 91% rename from src/components/ActionSheetAwareScrollView/useActionSheetKeyboardSpace.tsx rename to src/components/ActionSheetAwareScrollView/useActionSheetKeyboardSpacing.ts index cb97ffec117a..70c4e9a54838 100644 --- a/src/components/ActionSheetAwareScrollView/useActionSheetKeyboardSpace.tsx +++ b/src/components/ActionSheetAwareScrollView/useActionSheetKeyboardSpacing.ts @@ -1,8 +1,8 @@ import {useContext, useEffect} from 'react'; -import type {ViewProps} from 'react-native'; import {useKeyboardHandler} from 'react-native-keyboard-controller'; -import {useAnimatedReaction, useAnimatedStyle, useDerivedValue, useSharedValue, withSequence, withSpring, withTiming} from 'react-native-reanimated'; -import type {SharedValue} from 'react-native-reanimated'; +import type Reanimated from 'react-native-reanimated'; +import {useAnimatedReaction, useDerivedValue, useScrollViewOffset, useSharedValue, withSequence, withSpring, withTiming} from 'react-native-reanimated'; +import type {AnimatedRef} from 'react-native-reanimated'; import useSafeAreaPaddings from '@hooks/useSafeAreaPaddings'; import useWindowDimensions from '@hooks/useWindowDimensions'; import {Actions, ActionSheetAwareScrollViewContext, States} from './ActionSheetAwareScrollViewContext'; @@ -59,17 +59,13 @@ const useAnimatedKeyboard = () => { return {state, height, heightWhenOpened}; }; -type ActionSheetKeyboardSpaceProps = ViewProps & { - /** scroll offset of the parent ScrollView */ - position?: SharedValue; -}; +function useActionSheetKeyboardSpacing(scrollViewAnimatedRef: AnimatedRef) { + const position = useScrollViewOffset(scrollViewAnimatedRef); -function useActionSheetKeyboardSpace(props: ActionSheetKeyboardSpaceProps) { const { unmodifiedPaddings: {top: paddingTop = 0, bottom: paddingBottom = 0}, } = useSafeAreaPaddings(); const keyboard = useAnimatedKeyboard(); - const {position} = props; // Similar to using `global` in worklet but it's just a local object const syncLocalWorkletState = useSharedValue(KeyboardState.UNKNOWN); @@ -100,7 +96,7 @@ function useActionSheetKeyboardSpace(props: ActionSheetKeyboardSpaceProps) { [], ); - const translateY = useDerivedValue(() => { + const spacing = useDerivedValue(() => { const {current, previous} = currentActionSheetState.get(); // We don't need to run any additional logic. it will always return 0 for idle state @@ -134,7 +130,7 @@ function useActionSheetKeyboardSpace(props: ActionSheetKeyboardSpaceProps) { if (isClosedKeyboard || isOpeningKeyboard) { return lastKeyboardHeight - keyboardHeight; } - if (previous.state === States.KEYBOARD_CLOSED_POPOVER || (previous.state === States.KEYBOARD_OPEN && elementOffset < 0)) { + if (previous.state === States.KEYBOARD_CLOSING_POPOVER || (previous.state === States.KEYBOARD_OPEN && elementOffset < 0)) { const returnValue = Math.max(keyboard.heightWhenOpened.get() - keyboard.height.get() - paddingBottom, 0) + Math.max(elementOffset, 0); return returnValue; } @@ -220,7 +216,7 @@ function useActionSheetKeyboardSpace(props: ActionSheetKeyboardSpaceProps) { return lastKeyboardHeight; } - case States.KEYBOARD_CLOSED_POPOVER: { + case States.KEYBOARD_CLOSING_POPOVER: { if (elementOffset < 0) { transition({type: Actions.END_TRANSITION}); @@ -247,11 +243,7 @@ function useActionSheetKeyboardSpace(props: ActionSheetKeyboardSpaceProps) { } }, []); - const animatedStyle = useAnimatedStyle(() => ({ - paddingTop: translateY.get(), - })); - - return {animatedStyle}; + return spacing; } -export default useActionSheetKeyboardSpace; +export default useActionSheetKeyboardSpacing; diff --git a/src/pages/home/report/ReportActionsList.tsx b/src/pages/home/report/ReportActionsList.tsx index 4f10ad8cd953..19907122dd37 100644 --- a/src/pages/home/report/ReportActionsList.tsx +++ b/src/pages/home/report/ReportActionsList.tsx @@ -4,7 +4,7 @@ import React, {memo, useCallback, useContext, useEffect, useLayoutEffect, useMem import type {LayoutChangeEvent, NativeScrollEvent, NativeSyntheticEvent} from 'react-native'; import {DeviceEventEmitter, InteractionManager, View} from 'react-native'; import type {OnyxEntry} from 'react-native-onyx'; -import {renderScrollComponent} from '@components/ActionSheetAwareScrollView'; +import {renderScrollComponent as renderActionSheetAwareScrollView} from '@components/ActionSheetAwareScrollView'; import InvertedFlatList from '@components/InvertedFlatList'; import {AUTOSCROLL_TO_TOP_THRESHOLD} from '@components/InvertedFlatList/BaseInvertedFlatList'; import {PersonalDetailsContext, usePersonalDetails} from '@components/OnyxListItemProvider'; @@ -785,7 +785,7 @@ function ReportActionsList({ style={styles.overscrollBehaviorContain} data={sortedVisibleReportActions} renderItem={renderItem} - renderScrollComponent={renderScrollComponent} + renderScrollComponent={renderActionSheetAwareScrollView} contentContainerStyle={styles.chatContentScrollView} keyExtractor={keyExtractor} initialNumToRender={initialNumToRender}