Skip to content

Commit a49d3a8

Browse files
authored
fix: KCV onLayout issue (#3531)
## 🎯 Goal This PR addresses a very weird issue that could be noticed in some apps, where `onLayout` was not being invoked by the child view wrapper at all, making it impossible to remeasure translating views while the context menu is open (for example the keyboard closing). To combat this, we add one more measurement vector through invoking the sync function when we begin closing the context menu as well. Since this runs asynchronously and is controlled through shared values, the overhead is almost non-existent and we make sure that we measure as late as possible. ## 🛠 Implementation details <!-- Provide a description of the implementation --> ## 🎨 UI Changes <!-- Add relevant screenshots --> <details> <summary>iOS</summary> <table> <thead> <tr> <td>Before</td> <td>After</td> </tr> </thead> <tbody> <tr> <td> <!--<img src="" /> --> </td> <td> <!--<img src="" /> --> </td> </tr> </tbody> </table> </details> <details> <summary>Android</summary> <table> <thead> <tr> <td>Before</td> <td>After</td> </tr> </thead> <tbody> <tr> <td> <!--<img src="" /> --> </td> <td> <!--<img src="" /> --> </td> </tr> </tbody> </table> </details> ## 🧪 Testing <!-- Explain how this change can be tested (or why it can't be tested) --> ## ☑️ Checklist - [ ] I have signed the [Stream CLA](https://docs.google.com/forms/d/e/1FAIpQLScFKsKkAJI7mhCr7K9rEIOpqIDThrWxuvxnwUq2XkHyG154vQ/viewform) (required) - [ ] PR targets the `develop` branch - [ ] Documentation is updated - [ ] New code is tested in main example apps, including all possible scenarios - [ ] SampleApp iOS and Android - [ ] Expo iOS and Android
1 parent e261d00 commit a49d3a8

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

examples/ExpoMessaging/app.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@
101101
}
102102
}
103103
],
104-
"./plugins/keyboardInsetMainActivityListener.js",
105104
"./plugins/opSqliteSwiftPlugin.js",
106105
"expo-sharing"
107106
]

examples/ExpoMessaging/app/channel/[cid]/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { AppContext } from '../../../context/AppContext';
1313
import { useHeaderHeight } from '@react-navigation/elements';
1414
import InputButtons from '../../../components/InputButtons';
1515
import { MessageLocation } from '../../../components/LocationSharing/MessageLocation';
16-
import { Platform, StyleSheet, View } from 'react-native';
16+
import { StyleSheet, View } from 'react-native';
1717

1818
export default function ChannelScreen() {
1919
const { client } = useChatContext();
@@ -74,7 +74,7 @@ export default function ChannelScreen() {
7474
audioRecordingEnabled={true}
7575
channel={channel}
7676
onPressMessage={onPressMessage}
77-
keyboardVerticalOffset={Platform.OS === 'ios' ? headerHeight : undefined}
77+
keyboardVerticalOffset={headerHeight}
7878
MessageLocation={MessageLocation}
7979
thread={thread}
8080
>

package/src/components/UIComponents/PortalWhileClosingView.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
setClosingPortalLayout,
1313
useShouldTeleportToClosingPortal,
1414
useHasActiveId,
15+
useIsOverlayClosing,
1516
} from '../../state-store';
1617

1718
type PortalWhileClosingViewProps = {
@@ -116,9 +117,10 @@ const useSyncingApi = (portalHostName: string, registrationId: string) => {
116117
const placeholderLayout = useSharedValue({ h: 0, w: 0 });
117118
const insets = useSafeAreaInsets();
118119
const hasActiveId = useHasActiveId();
120+
const isClosing = useIsOverlayClosing();
119121

120122
const syncPortalLayout = useStableCallback(() => {
121-
if (!hasActiveId) {
123+
if (!hasActiveId && !isClosing) {
122124
return;
123125
}
124126

@@ -143,10 +145,10 @@ const useSyncingApi = (portalHostName: string, registrationId: string) => {
143145
});
144146

145147
useEffect(() => {
146-
if (hasActiveId) {
148+
if (hasActiveId || isClosing) {
147149
syncPortalLayout();
148150
}
149-
}, [insets.bottom, hasActiveId, syncPortalLayout]);
151+
}, [insets.bottom, isClosing, hasActiveId, syncPortalLayout]);
150152

151153
return useMemo(
152154
() => ({ syncPortalLayout, containerRef, placeholderLayout }),

0 commit comments

Comments
 (0)