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
8 changes: 4 additions & 4 deletions examples/SampleApp/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8354,10 +8354,10 @@ stream-chat-react-native-core@8.1.0:
version "0.0.0"
uid ""

stream-chat@^9.30.1:
version "9.30.1"
resolved "https://registry.yarnpkg.com/stream-chat/-/stream-chat-9.30.1.tgz#86d152e4d0894854370512d17530854541f7990b"
integrity sha512-8f58tCo3QfgzaNhWHpRQzEfglSPPn4lGRn74FFTr/pn53dMJwtcKDSohV6NTHBrkYWTXYObRnHgh2IhGFUKckw==
stream-chat@^9.33.0:
version "9.34.0"
resolved "https://registry.yarnpkg.com/stream-chat/-/stream-chat-9.34.0.tgz#e92c3262e1b6fbe92b1b1148286ee152849250dc"
integrity sha512-b65Z+ufAtygAwT2dCQ8ImgMx01b9zgS1EZ8OK5lRHhSJKYKSsSa1pS3USbbFq6QpuwGZwXM3lovGXLYoWiG84g==
dependencies:
"@types/jsonwebtoken" "^9.0.8"
"@types/ws" "^8.5.14"
Expand Down
9 changes: 8 additions & 1 deletion package/src/components/MessageList/MessageList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import { ThreadContextValue, useThreadContext } from '../../contexts/threadConte

import { useStableCallback } from '../../hooks';
import { useStateStore } from '../../hooks/useStateStore';
import { bumpOverlayLayoutRevision } from '../../state-store';
import { MessageInputHeightState } from '../../state-store/message-input-height-store';
import { primitives } from '../../theme';
import { MessageWrapper } from '../Message/MessageSimple/MessageWrapper';
Expand Down Expand Up @@ -1171,7 +1172,13 @@ const MessageListWithContext = (props: MessageListPropsWithContext) => {
if (additionalFlatListProps?.onLayout) {
additionalFlatListProps.onLayout(event);
}
viewportHeightRef.current = event.nativeEvent.layout.height;
const nextViewportHeight = event.nativeEvent.layout.height;
if (viewportHeightRef.current !== nextViewportHeight) {
const previousViewportHeight = viewportHeightRef.current ?? nextViewportHeight;
const closeCorrectionDeltaY = nextViewportHeight - previousViewportHeight;
bumpOverlayLayoutRevision(closeCorrectionDeltaY);
}
viewportHeightRef.current = nextViewportHeight;
});

if (!ListComponent) {
Expand Down
16 changes: 12 additions & 4 deletions package/src/contexts/overlayContext/MessageOverlayHostLayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const MessageOverlayHostLayer = () => {
const messageH = useSharedValue<Rect>(undefined);
const topH = useSharedValue<Rect>(undefined);
const bottomH = useSharedValue<Rect>(undefined);
const closeCorrectionY = useSharedValue(0);

const topInset = insets.top;
// Due to edge-to-edge in combination with various libraries, Android sometimes reports
Expand All @@ -50,10 +51,17 @@ export const MessageOverlayHostLayer = () => {
useEffect(
() =>
registerOverlaySharedValueController({
incrementCloseCorrectionY: (deltaY) => {
closeCorrectionY.value += deltaY;
},
resetCloseCorrectionY: () => {
closeCorrectionY.value = 0;
},
reset: () => {
messageH.value = undefined;
topH.value = undefined;
bottomH.value = undefined;
closeCorrectionY.value = 0;
},
setBottomH: (rect) => {
bottomH.value = rect;
Expand All @@ -65,7 +73,7 @@ export const MessageOverlayHostLayer = () => {
topH.value = rect;
},
}),
[bottomH, messageH, topH],
[bottomH, closeCorrectionY, messageH, topH],
);

useEffect(() => {
Expand Down Expand Up @@ -163,7 +171,7 @@ export const MessageOverlayHostLayer = () => {
});

const topItemTranslateStyle = useAnimatedStyle(() => {
const target = isActive ? (closing ? 0 : shiftY.value) : 0;
const target = isActive ? (closing ? closeCorrectionY.value : shiftY.value) : 0;
return {
transform: [
{ scale: backdrop.value },
Expand All @@ -184,7 +192,7 @@ export const MessageOverlayHostLayer = () => {
});

const bottomItemTranslateStyle = useAnimatedStyle(() => {
const target = isActive ? (closing ? 0 : shiftY.value) : 0;
const target = isActive ? (closing ? closeCorrectionY.value : shiftY.value) : 0;
return {
transform: [
{ scale: backdrop.value },
Expand All @@ -205,7 +213,7 @@ export const MessageOverlayHostLayer = () => {
});

const hostTranslateStyle = useAnimatedStyle(() => {
const target = isActive ? (closing ? 0 : shiftY.value) : 0;
const target = isActive ? (closing ? closeCorrectionY.value : shiftY.value) : 0;

return {
transform: [
Expand Down
17 changes: 14 additions & 3 deletions package/src/state-store/message-overlay-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const DefaultState = {
};

type OverlaySharedValueController = {
incrementCloseCorrectionY: (deltaY: number) => void;
resetCloseCorrectionY: () => void;
reset: () => void;
setBottomH: (rect: Rect) => void;
setMessageH: (rect: Rect) => void;
Expand Down Expand Up @@ -46,10 +48,19 @@ export const setOverlayBottomH = (bottomH: Rect) => {
sharedValueController?.setBottomH(bottomH);
};

export const openOverlay = (id: string) => overlayStore.partialNext({ closing: false, id });
export const bumpOverlayLayoutRevision = (closeCorrectionDeltaY = 0) => {
sharedValueController?.incrementCloseCorrectionY(closeCorrectionDeltaY);
};

export const openOverlay = (id: string) => {
sharedValueController?.resetCloseCorrectionY();
overlayStore.partialNext({ closing: false, id });
};

export const closeOverlay = () => {
requestAnimationFrame(() => overlayStore.partialNext({ closing: true }));
requestAnimationFrame(() => {
overlayStore.partialNext({ closing: true });
});
};

let actionQueue: Array<() => void | Promise<void>> = [];
Expand All @@ -64,8 +75,8 @@ export const scheduleActionOnClose = (action: () => void | Promise<void>) => {
};

export const finalizeCloseOverlay = () => {
sharedValueController?.reset();
overlayStore.partialNext(DefaultState);
sharedValueController?.reset();
};

export const overlayStore = new StateStore<OverlayState>(DefaultState);
Expand Down