diff --git a/native/chat/message-result.react.js b/native/chat/message-result.react.js --- a/native/chat/message-result.react.js +++ b/native/chat/message-result.react.js @@ -14,6 +14,7 @@ import type { NavigationRoute } from '../navigation/route-names'; import { useStyles } from '../themes/colors.js'; import type { ChatMessageInfoItemWithHeight } from '../types/chat-types.js'; +import type { VerticalBounds } from '../types/layout-types.js'; type MessageResultProps = { +item: ChatMessageInfoItemWithHeight, @@ -24,6 +25,7 @@ +route: | NavigationRoute<'TogglePinModal'> | NavigationRoute<'MessageResultsScreen'>, + +messageVerticalBounds: ?VerticalBounds, }; function MessageResult(props: MessageResultProps): React.Node { @@ -41,7 +43,7 @@ navigation={props.navigation} route={props.route} toggleFocus={onToggleFocus} - verticalBounds={null} + verticalBounds={props.messageVerticalBounds} /> {longAbsoluteDate(props.item.messageInfo.time)} diff --git a/native/chat/message-results-screen.react.js b/native/chat/message-results-screen.react.js --- a/native/chat/message-results-screen.react.js +++ b/native/chat/message-results-screen.react.js @@ -36,6 +36,9 @@ const measureMessages = useHeightMeasurer(); const [measuredMessages, setMeasuredMessages] = React.useState([]); + const [messageVerticalBounds, setMessageVerticalBounds] = React.useState(); + const scrollViewContainerRef = React.useRef(); + const callFetchPinnedMessages = useServerCall(fetchPinnedMessages); const userInfos = useSelector(state => state.userStore.userInfos); @@ -155,6 +158,23 @@ [measuredMessages], ); + const onLayout = React.useCallback(() => { + scrollViewContainerRef.current?.measure( + (x, y, width, height, pageX, pageY) => { + if ( + height === null || + height === undefined || + pageY === null || + pageY === undefined + ) { + return; + } + + setMessageVerticalBounds({ height, y: pageY }); + }, + ); + }, []); + const messageResultsToDisplay = React.useMemo( () => modifiedItems.map(item => ( @@ -164,13 +184,14 @@ threadInfo={threadInfo} navigation={navigation} route={route} + messageVerticalBounds={messageVerticalBounds} /> )), - [modifiedItems, threadInfo, navigation, route], + [modifiedItems, threadInfo, navigation, route, messageVerticalBounds], ); return ( - + {messageResultsToDisplay} ); diff --git a/native/chat/toggle-pin-modal.react.js b/native/chat/toggle-pin-modal.react.js --- a/native/chat/toggle-pin-modal.react.js +++ b/native/chat/toggle-pin-modal.react.js @@ -140,6 +140,7 @@ threadInfo={threadInfo} navigation={navigation} route={route} + messageVerticalBounds={null} />