Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -97,13 +97,13 @@ const STATE_MACHINE: StateMachine<ValueOf<typeof States>, ValueOf<typeof Actions
},
[States.KEYBOARD_POPOVER_OPEN]: {
[Actions.MEASURE_POPOVER]: States.KEYBOARD_POPOVER_OPEN,
[Actions.CLOSE_POPOVER]: States.KEYBOARD_CLOSED_POPOVER,
[Actions.CLOSE_POPOVER]: States.KEYBOARD_CLOSING_POPOVER,
[Actions.OPEN_KEYBOARD]: States.KEYBOARD_OPEN,
},
[States.KEYBOARD_POPOVER_CLOSED]: {
[Actions.OPEN_KEYBOARD]: States.KEYBOARD_OPEN,
},
[States.KEYBOARD_CLOSED_POPOVER]: {
[States.KEYBOARD_CLOSING_POPOVER]: {
[Actions.OPEN_KEYBOARD]: States.KEYBOARD_OPEN,
[Actions.END_TRANSITION]: States.KEYBOARD_OPEN,
},
Expand Down
22 changes: 12 additions & 10 deletions src/components/ActionSheetAwareScrollView/index.ios.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import type {PropsWithChildren} from 'react';
import React, {forwardRef, useCallback} from 'react';
// eslint-disable-next-line no-restricted-imports
import type {ScrollView, ScrollViewProps} from 'react-native';
import Reanimated, {useAnimatedRef, useScrollViewOffset} from 'react-native-reanimated';
import type {ScrollView} from 'react-native';
import Reanimated, {useAnimatedRef, useAnimatedStyle} from 'react-native-reanimated';
import {Actions, ActionSheetAwareScrollViewContext, ActionSheetAwareScrollViewProvider} from './ActionSheetAwareScrollViewContext';
import useActionSheetKeyboardSpace from './useActionSheetKeyboardSpace';
import type {ActionSheetAwareScrollViewProps, RenderActionSheetAwareScrollViewComponent} from './types';
import useActionSheetKeyboardSpacing from './useActionSheetKeyboardSpacing';

const ActionSheetAwareScrollView = forwardRef<ScrollView, PropsWithChildren<ScrollViewProps>>(({style, children, ...rest}, ref) => {
const ActionSheetAwareScrollView = forwardRef<ScrollView, ActionSheetAwareScrollViewProps>(({style, children, ...props}, ref) => {
const scrollViewAnimatedRef = useAnimatedRef<Reanimated.ScrollView>();
const position = useScrollViewOffset(scrollViewAnimatedRef);

const onRef = useCallback(
(assignedRef: Reanimated.ScrollView) => {
Expand All @@ -24,13 +23,16 @@ const ActionSheetAwareScrollView = forwardRef<ScrollView, PropsWithChildren<Scro
[ref, scrollViewAnimatedRef],
);

const {animatedStyle} = useActionSheetKeyboardSpace({position});
const spacing = useActionSheetKeyboardSpacing(scrollViewAnimatedRef);
const animatedStyle = useAnimatedStyle(() => ({
paddingTop: spacing.get(),
}));

return (
<Reanimated.ScrollView
ref={onRef}
// eslint-disable-next-line react/jsx-props-no-spreading
{...rest}
{...props}
style={[style, animatedStyle]}
>
{children}
Expand All @@ -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 <ActionSheetAwareScrollView {...props} />;
}
};

export {renderScrollComponent, ActionSheetAwareScrollViewContext, ActionSheetAwareScrollViewProvider, Actions};
7 changes: 3 additions & 4 deletions src/components/ActionSheetAwareScrollView/index.tsx
Original file line number Diff line number Diff line change
@@ -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<ScrollView, PropsWithChildren<ScrollViewProps>>((props, ref) => (
const ActionSheetAwareScrollView = forwardRef<ScrollView, ActionSheetAwareScrollViewProps>((props, ref) => (
<ScrollView
ref={ref}
// eslint-disable-next-line react/jsx-props-no-spreading
Expand All @@ -26,6 +25,6 @@ export default ActionSheetAwareScrollView;
* @param {Object} props - props that will be passed to the ScrollView from FlatList
* @returns {React.ReactElement} - ActionSheetAwareScrollView
*/
const renderScrollComponent = undefined;
const renderScrollComponent: RenderActionSheetAwareScrollViewComponent = undefined;

export {renderScrollComponent, ActionSheetAwareScrollViewContext, ActionSheetAwareScrollViewProvider, Actions};
6 changes: 6 additions & 0 deletions src/components/ActionSheetAwareScrollView/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type {PropsWithChildren} from 'react';
import type {ScrollViewProps} from 'react-native';

type ActionSheetAwareScrollViewProps = PropsWithChildren<ScrollViewProps>;
type RenderActionSheetAwareScrollViewComponent = ((props: ActionSheetAwareScrollViewProps) => React.ReactElement<ScrollViewProps>) | undefined;
export type {ActionSheetAwareScrollViewProps, RenderActionSheetAwareScrollViewComponent};
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -59,17 +59,13 @@ const useAnimatedKeyboard = () => {
return {state, height, heightWhenOpened};
};

type ActionSheetKeyboardSpaceProps = ViewProps & {
/** scroll offset of the parent ScrollView */
position?: SharedValue<number>;
};
function useActionSheetKeyboardSpacing(scrollViewAnimatedRef: AnimatedRef<Reanimated.ScrollView>) {
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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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});

Expand All @@ -247,11 +243,7 @@ function useActionSheetKeyboardSpace(props: ActionSheetKeyboardSpaceProps) {
}
}, []);

const animatedStyle = useAnimatedStyle(() => ({
paddingTop: translateY.get(),
}));

return {animatedStyle};
return spacing;
}

export default useActionSheetKeyboardSpace;
export default useActionSheetKeyboardSpacing;
4 changes: 2 additions & 2 deletions src/pages/home/report/ReportActionsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -785,7 +785,7 @@ function ReportActionsList({
style={styles.overscrollBehaviorContain}
data={sortedVisibleReportActions}
renderItem={renderItem}
renderScrollComponent={renderScrollComponent}
renderScrollComponent={renderActionSheetAwareScrollView}
contentContainerStyle={styles.chatContentScrollView}
keyExtractor={keyExtractor}
initialNumToRender={initialNumToRender}
Expand Down