diff --git a/native/chat/chat-thread-list.react.js b/native/chat/chat-thread-list.react.js --- a/native/chat/chat-thread-list.react.js +++ b/native/chat/chat-thread-list.react.js @@ -138,6 +138,7 @@ pendingPersonalThreadUserInfo?: UserInfo, ) => void, +onPressSeeMoreSidebars: (threadInfo: ThreadInfo) => void, + +hardwareBack: () => boolean, }; class ChatThreadList extends React.PureComponent { @@ -164,7 +165,7 @@ invariant(tabNavigation, 'ChatNavigator should be within TabNavigator'); tabNavigation.addListener('tabPress', this.onTabPress); - BackHandler.addEventListener('hardwareBackPress', this.hardwareBack); + BackHandler.addEventListener('hardwareBackPress', this.props.hardwareBack); } componentWillUnmount() { @@ -178,25 +179,12 @@ invariant(tabNavigation, 'ChatNavigator should be within TabNavigator'); tabNavigation.removeListener('tabPress', this.onTabPress); - BackHandler.removeEventListener('hardwareBackPress', this.hardwareBack); + BackHandler.removeEventListener( + 'hardwareBackPress', + this.props.hardwareBack, + ); } - hardwareBack = () => { - if (!this.props.navigation.isFocused()) { - return false; - } - - const { searchStatus } = this.props; - const isActiveOrActivating = - searchStatus === 'active' || searchStatus === 'activating'; - if (!isActiveOrActivating) { - return false; - } - - this.props.onSearchCancel(); - return true; - }; - componentDidUpdate(prevProps: Props) { const { searchStatus } = this.props; const prevSearchStatus = prevProps.searchStatus; @@ -634,6 +622,20 @@ [navigation, onChangeSearchText], ); + const hardwareBack = React.useCallback(() => { + if (!navigation.isFocused()) { + return false; + } + const isActiveOrActivating = + searchStatus === 'active' || searchStatus === 'activating'; + if (!isActiveOrActivating) { + return false; + } + + onSearchCancel(); + return true; + }, [navigation, onSearchCancel, searchStatus]); + return ( ); }