From 8fe64da60745000fd58c524f916442b90c6d6aa4 Mon Sep 17 00:00:00 2001 From: Agung Watanabe Date: Sat, 14 May 2022 22:30:46 +0700 Subject: [PATCH] fix: force close when navigating back from search --- .../mejiboard/presentation/search/SearchScreen.kt | 6 ++++++ .../mejiboard/presentation/search/SearchViewModel.kt | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/app-alpha/src/main/java/com/github/uragiristereo/mejiboard/presentation/search/SearchScreen.kt b/app-alpha/src/main/java/com/github/uragiristereo/mejiboard/presentation/search/SearchScreen.kt index 6c60bb5..61fd57f 100644 --- a/app-alpha/src/main/java/com/github/uragiristereo/mejiboard/presentation/search/SearchScreen.kt +++ b/app-alpha/src/main/java/com/github/uragiristereo/mejiboard/presentation/search/SearchScreen.kt @@ -67,6 +67,12 @@ fun SearchScreen( onDispose { } } + DisposableEffect(key1 = viewModel) { + onDispose { + viewModel.cancelSearch() + } + } + DisposableEffect(key1 = query.text) { if (query.text.isEmpty()) { viewModel.clearSearches() diff --git a/app-alpha/src/main/java/com/github/uragiristereo/mejiboard/presentation/search/SearchViewModel.kt b/app-alpha/src/main/java/com/github/uragiristereo/mejiboard/presentation/search/SearchViewModel.kt index 706433f..bc7efa1 100644 --- a/app-alpha/src/main/java/com/github/uragiristereo/mejiboard/presentation/search/SearchViewModel.kt +++ b/app-alpha/src/main/java/com/github/uragiristereo/mejiboard/presentation/search/SearchViewModel.kt @@ -116,4 +116,8 @@ class SearchViewModel @Inject constructor( parsedQuery = SearchUtil.parseSearchQuery(query = query), ) } + + fun cancelSearch() { + job?.cancel() + } } \ No newline at end of file