Skip to content

Commit

Permalink
[native] Disable stack gestures while editing messages
Browse files Browse the repository at this point in the history
Summary:
See [ENG-4412](https://linear.app/comm/issue/ENG-4412/swipe-to-go-back-while-editing-message-on-native-breaks-navigation) to see the bug this diff solves.

I was unable to disable gestures using `gestureEnabled` for some reason. This appears to be a React Navigation bug reported [here](react-navigation/react-navigation#10394). I tried disabling gestures via `options` for `MessageList`, `screenOptions` for `Chat.Navigator`, and even using an effect that calls `setOptions` from `ChatInputBar`. None of them worked.

Instead, I found that setting `gestureResponseDistance` to 0 has the desired effect (disabling gestures).

Test Plan: Confirm that I can no longer use gestures to go back while in edit mode

Reviewers: atul, tomek, kamil

Reviewed By: kamil

Differential Revision: https://phab.comm.dev/D8543
  • Loading branch information
Ashoat committed Jul 19, 2023
1 parent f5dda1f commit e275bd0
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions native/chat/chat.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import ComposeSubchannel from './compose-subchannel.react.js';
import ComposeThreadButton from './compose-thread-button.react.js';
import FullScreenThreadMediaGallery from './fullscreen-thread-media-gallery.react.js';
import HomeChatThreadList from './home-chat-thread-list.react.js';
import { MessageEditingContext } from './message-editing-context.react.js';
import MessageListContainer from './message-list-container.react.js';
import MessageListHeaderTitle from './message-list-header-title.react.js';
import MessageResultsScreen from './message-results-screen.react.js';
Expand Down Expand Up @@ -341,6 +342,10 @@ export default function ChatComponent(props: Props): React.Node {
[props.navigation],
);

const messageEditingContext = React.useContext(MessageEditingContext);
const editState = messageEditingContext?.editState;
const editMode = !!editState?.editedMessage;

const { width: screenWidth } = useWindowDimensions();
const screenOptions = React.useMemo(
() => ({
Expand All @@ -352,9 +357,9 @@ export default function ChatComponent(props: Props): React.Node {
borderBottomWidth: 1,
},
gestureEnabled: true,
gestureResponseDistance: screenWidth,
gestureResponseDistance: editMode ? 0 : screenWidth,
}),
[colors.tabBarBackground, headerLeftButton, screenWidth],
[colors.tabBarBackground, headerLeftButton, screenWidth, editMode],
);

const chatThreadListOptions = React.useCallback(
Expand Down

0 comments on commit e275bd0

Please sign in to comment.