Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[No QA] [TS Migration] Migrate useReportScrollManager and ReportScreenContext to TypeScript #29315

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
@@ -1,27 +1,30 @@
import {useContext, useCallback} from 'react';
import {ActionListContext} from '../../pages/home/ReportScreenContext';
import {ActionListContext, ActionListContextType} from '../../pages/home/ReportScreenContext';

function useReportScrollManager() {
function useReportScrollManager(): {
ref: ActionListContextType;
scrollToIndex: (index: number) => void;
scrollToBottom: () => void;
} {
roryabraham marked this conversation as resolved.
Show resolved Hide resolved
const flatListRef = useContext(ActionListContext);

/**
* Scroll to the provided index.
*
* @param {Object} index
*/
const scrollToIndex = (index) => {
if (!flatListRef.current) {
const scrollToIndex = (index: number) => {
if (!flatListRef?.current) {
return;
}

flatListRef.current.scrollToIndex(index);
flatListRef.current.scrollToIndex({index});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this change?
If its necessary please make sure its not causing any regressions

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⬆️ exactly 😄

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it wasn't correct before, and it can cause a regression. Please test it 🙌

};

/**
* Scroll to the bottom of the flatlist.
*/
const scrollToBottom = useCallback(() => {
if (!flatListRef.current) {
if (!flatListRef?.current) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
import {useContext, useCallback} from 'react';
import {ActionListContext} from '../../pages/home/ReportScreenContext';
import {ActionListContext, ActionListContextType} from '../../pages/home/ReportScreenContext';

function useReportScrollManager() {
function useReportScrollManager(): {
ref: ActionListContextType;
scrollToIndex: (index: number, isEditing: boolean) => void;
scrollToBottom: () => void;
} {
roryabraham marked this conversation as resolved.
Show resolved Hide resolved
const flatListRef = useContext(ActionListContext);

/**
* Scroll to the provided index. On non-native implementations we do not want to scroll when we are scrolling because
* we are editing a comment.
*
roryabraham marked this conversation as resolved.
Show resolved Hide resolved
* @param {Object} index
* @param {Boolean} isEditing
*/
const scrollToIndex = (index, isEditing) => {
if (!flatListRef.current || isEditing) {
const scrollToIndex = (index: number, isEditing: boolean) => {
if (!flatListRef?.current || isEditing) {
return;
}

flatListRef.current.scrollToIndex(index);
flatListRef.current.scrollToIndex({index});
};

/**
* Scroll to the bottom of the flatlist.
*/
const scrollToBottom = useCallback(() => {
if (!flatListRef.current) {
if (!flatListRef?.current) {
return;
}

Expand Down
6 changes: 0 additions & 6 deletions src/pages/home/ReportScreenContext.js

This file was deleted.

17 changes: 17 additions & 0 deletions src/pages/home/ReportScreenContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {RefObject, createContext} from 'react';
import {FlatList, GestureResponderEvent} from 'react-native';

type ReactionListRefType = {
roryabraham marked this conversation as resolved.
Show resolved Hide resolved
showReactionList: (event: GestureResponderEvent | undefined, reactionListAnchor: Element, emojiName: string, reportActionID: string) => void;
hideReactionList: () => void;
isActiveReportAction: (actionID: number | string) => boolean;
};

type ActionListContextType = RefObject<FlatList<unknown>> | null;
type ReactionListContextType = RefObject<ReactionListRefType> | null;

const ActionListContext = createContext<ActionListContextType>(null);
const ReactionListContext = createContext<ReactionListContextType>(null);

export {ActionListContext, ReactionListContext};
export type {ReactionListRefType, ActionListContextType, ReactionListContextType};
Loading