Skip to content

Commit 6c4637a

Browse files
authored
regression: go back instead of closing app on rooms search (#6750)
1 parent 91967fc commit 6c4637a

File tree

2 files changed

+55
-2
lines changed

2 files changed

+55
-2
lines changed

.maestro/tests/room/search.yaml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
appId: chat.rocket.reactnative
2+
name: Search
3+
onFlowStart:
4+
- runFlow: '../../helpers/setup.yaml'
5+
tags:
6+
- test-13
7+
- android-only
8+
9+
---
10+
- evalScript: ${output.user = output.utils.createUser()}
11+
12+
- runFlow:
13+
file: '../../helpers/login-with-deeplink.yaml'
14+
env:
15+
USERNAME: ${output.user.username}
16+
PASSWORD: ${output.user.password}
17+
18+
- extendedWaitUntil:
19+
visible:
20+
id: 'rooms-list-view-search'
21+
timeout: 60000
22+
- tapOn:
23+
id: rooms-list-view-search
24+
- extendedWaitUntil:
25+
visible:
26+
id: 'rooms-list-view'
27+
timeout: 60000
28+
- extendedWaitUntil:
29+
visible:
30+
id: 'rooms-list-view-search-input'
31+
timeout: 60000
32+
- pressKey: Back
33+
- pressKey: Back
34+
- extendedWaitUntil:
35+
visible:
36+
id: 'rooms-list-view'
37+
timeout: 60000
38+
- extendedWaitUntil:
39+
notVisible:
40+
id: 'rooms-list-view-search-input'
41+
timeout: 60000

app/views/RoomsListView/index.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useNavigation } from '@react-navigation/native';
2-
import React, { memo, useContext } from 'react';
3-
import { FlatList, RefreshControl } from 'react-native';
2+
import React, { memo, useContext, useEffect } from 'react';
3+
import { BackHandler, FlatList, RefreshControl } from 'react-native';
44
import { useSafeAreaFrame } from 'react-native-safe-area-context';
55
import { shallowEqual } from 'react-redux';
66

@@ -51,6 +51,18 @@ const RoomsListView = memo(function RoomsListView() {
5151
const { refreshing, onRefresh } = useRefresh({ searching });
5252
const supportedVersionsStatus = useAppSelector(state => state.supportedVersions.status);
5353

54+
useEffect(() => {
55+
const subscription = BackHandler.addEventListener('hardwareBackPress', () => {
56+
if (searchEnabled) {
57+
stopSearch();
58+
navigation.goBack();
59+
return true;
60+
}
61+
return false;
62+
});
63+
return () => subscription.remove();
64+
}, [searchEnabled]);
65+
5466
const onPressItem = (item = {} as IRoomItem) => {
5567
if (!navigation.isFocused()) {
5668
return;

0 commit comments

Comments
 (0)