Changeset View
Changeset View
Standalone View
Standalone View
native/chat/utils.js
// @flow | // @flow | ||||
import invariant from 'invariant'; | import invariant from 'invariant'; | ||||
import * as React from 'react'; | import * as React from 'react'; | ||||
import Animated from 'react-native-reanimated'; | import Animated from 'react-native-reanimated'; | ||||
import { useLoggedInUserInfo } from 'lib/hooks/account-hooks.js'; | import { useLoggedInUserInfo } from 'lib/hooks/account-hooks.js'; | ||||
import { useMessageListData } from 'lib/selectors/chat-selectors.js'; | |||||
import type { ChatMessageItem } from 'lib/selectors/chat-selectors.js'; | |||||
import { colorIsDark } from 'lib/shared/color-utils.js'; | import { colorIsDark } from 'lib/shared/color-utils.js'; | ||||
import { messageKey } from 'lib/shared/message-utils.js'; | import { messageKey } from 'lib/shared/message-utils.js'; | ||||
import { viewerIsMember } from 'lib/shared/thread-utils.js'; | import { viewerIsMember } from 'lib/shared/thread-utils.js'; | ||||
import type { ThreadInfo } from 'lib/types/thread-types.js'; | import type { ThreadInfo } from 'lib/types/thread-types.js'; | ||||
import { clusterEndHeight, inlineEngagementStyle } from './chat-constants.js'; | import { clusterEndHeight, inlineEngagementStyle } from './chat-constants.js'; | ||||
import { ChatContext, useHeightMeasurer } from './chat-context.js'; | import { ChatContext, useHeightMeasurer } from './chat-context.js'; | ||||
import { failedSendHeight } from './failed-send.react.js'; | import { failedSendHeight } from './failed-send.react.js'; | ||||
import { | |||||
useNativeMessageListData, | |||||
type NativeChatMessageItem, | |||||
} from './message-data.react.js'; | |||||
import { authorNameHeight } from './message-header.react.js'; | import { authorNameHeight } from './message-header.react.js'; | ||||
import { multimediaMessageItemHeight } from './multimedia-message-utils.js'; | import { multimediaMessageItemHeight } from './multimedia-message-utils.js'; | ||||
import { getUnresolvedSidebarThreadInfo } from './sidebar-navigation.js'; | import { getUnresolvedSidebarThreadInfo } from './sidebar-navigation.js'; | ||||
import textMessageSendFailed from './text-message-send-failed.js'; | import textMessageSendFailed from './text-message-send-failed.js'; | ||||
import { timestampHeight } from './timestamp.react.js'; | import { timestampHeight } from './timestamp.react.js'; | ||||
import { KeyboardContext } from '../keyboard/keyboard-state.js'; | import { KeyboardContext } from '../keyboard/keyboard-state.js'; | ||||
import { OverlayContext } from '../navigation/overlay-context.js'; | import { OverlayContext } from '../navigation/overlay-context.js'; | ||||
import { | import { | ||||
▲ Show 20 Lines • Show All 88 Lines • ▼ Show 20 Lines | function useMessageTargetParameters( | ||||
messageListVerticalBounds: VerticalBounds, | messageListVerticalBounds: VerticalBounds, | ||||
currentInputBarHeight: number, | currentInputBarHeight: number, | ||||
targetInputBarHeight: number, | targetInputBarHeight: number, | ||||
sidebarThreadInfo: ?ThreadInfo, | sidebarThreadInfo: ?ThreadInfo, | ||||
): { | ): { | ||||
+position: number, | +position: number, | ||||
+color: string, | +color: string, | ||||
} { | } { | ||||
const messageListData = useMessageListData({ | const messageListData = useNativeMessageListData({ | ||||
searching: false, | searching: false, | ||||
userInfoInputArray: [], | userInfoInputArray: [], | ||||
threadInfo: sidebarThreadInfo, | threadInfo: sidebarThreadInfo, | ||||
}); | }); | ||||
const [messagesWithHeight, setMessagesWithHeight] = | const [messagesWithHeight, setMessagesWithHeight] = | ||||
React.useState<?$ReadOnlyArray<ChatMessageItemWithHeight>>(null); | React.useState<?$ReadOnlyArray<ChatMessageItemWithHeight>>(null); | ||||
const measureMessages = useHeightMeasurer(); | const measureMessages = useHeightMeasurer(); | ||||
▲ Show 20 Lines • Show All 254 Lines • ▼ Show 20 Lines | ): number | Node { | ||||
}, [ | }, [ | ||||
chatContext?.currentTransitionSidebarSourceID, | chatContext?.currentTransitionSidebarSourceID, | ||||
chatContext?.sidebarAnimationType, | chatContext?.sidebarAnimationType, | ||||
overlayPosition, | overlayPosition, | ||||
]); | ]); | ||||
} | } | ||||
function chatMessageItemKey( | function chatMessageItemKey( | ||||
item: ChatMessageItemWithHeight | ChatMessageItem, | item: ChatMessageItemWithHeight | NativeChatMessageItem, | ||||
): string { | ): string { | ||||
if (item.itemType === 'loader') { | if (item.itemType === 'loader') { | ||||
return 'loader'; | return 'loader'; | ||||
} | } | ||||
return messageKey(item.messageInfo); | return messageKey(item.messageInfo); | ||||
} | } | ||||
export { | export { | ||||
Show All 9 Lines |