From 1f12d6fb2388e495752f439c79db68c34e34067b Mon Sep 17 00:00:00 2001 From: MadhavBhavsar Date: Tue, 20 Feb 2024 13:04:44 +0530 Subject: [PATCH] fixed issue 2938 --- screen/accounts/build.gradle.kts | 1 + .../src/main/java/com/ivy/accounts/AccountsTab.kt | 11 +++++++++++ screen/categories/build.gradle.kts | 1 + .../java/com/ivy/categories/CategoriesScreen.kt | 15 ++++++++++++++- .../src/main/java/com/ivy/legacy/IvyWalletCtx.kt | 8 ++++++++ 5 files changed, 35 insertions(+), 1 deletion(-) diff --git a/screen/accounts/build.gradle.kts b/screen/accounts/build.gradle.kts index 049b094d49..2c817d1d83 100644 --- a/screen/accounts/build.gradle.kts +++ b/screen/accounts/build.gradle.kts @@ -14,6 +14,7 @@ dependencies { implementation(projects.temp.oldDesign) implementation(projects.temp.legacyCode) implementation(projects.shared.data) + implementation(projects.shared.commonUi) testImplementation(projects.shared.testing) } diff --git a/screen/accounts/src/main/java/com/ivy/accounts/AccountsTab.kt b/screen/accounts/src/main/java/com/ivy/accounts/AccountsTab.kt index fb7f9673f7..c833f39a47 100644 --- a/screen/accounts/src/main/java/com/ivy/accounts/AccountsTab.kt +++ b/screen/accounts/src/main/java/com/ivy/accounts/AccountsTab.kt @@ -16,6 +16,7 @@ import androidx.compose.foundation.layout.statusBarsPadding import androidx.compose.foundation.layout.width import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items +import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment @@ -29,6 +30,7 @@ import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp +import com.ivy.common.ui.rememberScrollPositionListState import com.ivy.design.l0_system.UI import com.ivy.design.l0_system.style import com.ivy.legacy.IvyWalletPreview @@ -74,6 +76,14 @@ private fun BoxWithConstraintsScope.UI( val nav = navigation() val ivyContext = com.ivy.legacy.ivyWalletCtx() + var listState = rememberLazyListState() + if (!state.accountsData.isEmpty()){ + listState = rememberScrollPositionListState( + key = "accounts_lazy_column", + initialFirstVisibleItemIndex = ivyContext.accountsListState?.firstVisibleItemIndex ?: 0, + initialFirstVisibleItemScrollOffset = ivyContext.accountsListState?.firstVisibleItemScrollOffset ?: 0 + ) + } LazyColumn( modifier = Modifier .fillMaxSize() @@ -89,6 +99,7 @@ private fun BoxWithConstraintsScope.UI( ivyContext.selectMainTab(com.ivy.legacy.data.model.MainTab.HOME) } ), + state = listState, ) { item { Spacer(Modifier.height(32.dp)) diff --git a/screen/categories/build.gradle.kts b/screen/categories/build.gradle.kts index 3cbaeb6d14..25710483c7 100644 --- a/screen/categories/build.gradle.kts +++ b/screen/categories/build.gradle.kts @@ -14,6 +14,7 @@ dependencies { implementation(projects.shared.navigation) implementation(projects.temp.legacyCode) implementation(projects.shared.data) + implementation(projects.shared.commonUi) testImplementation(projects.shared.testing) } diff --git a/screen/categories/src/main/java/com/ivy/categories/CategoriesScreen.kt b/screen/categories/src/main/java/com/ivy/categories/CategoriesScreen.kt index ad30aab6a6..53496aeb33 100644 --- a/screen/categories/src/main/java/com/ivy/categories/CategoriesScreen.kt +++ b/screen/categories/src/main/java/com/ivy/categories/CategoriesScreen.kt @@ -19,6 +19,7 @@ import androidx.compose.foundation.layout.width import androidx.compose.foundation.layout.wrapContentHeight import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items +import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue @@ -38,6 +39,7 @@ import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp +import com.ivy.common.ui.rememberScrollPositionListState import com.ivy.design.l0_system.UI import com.ivy.design.l0_system.style import com.ivy.legacy.datamodel.Category @@ -89,12 +91,23 @@ private fun BoxWithConstraintsScope.UI( onEvent: (CategoriesScreenEvent) -> Unit = {} ) { val nav = navigation() - + val ivyContext = com.ivy.legacy.ivyWalletCtx() + + var listState = rememberLazyListState() + if (!state.categories.isEmpty()){ + listState = rememberScrollPositionListState( + key = "categories_lazy_column", + initialFirstVisibleItemIndex = ivyContext.categoriesListState?.firstVisibleItemIndex ?: 0, + initialFirstVisibleItemScrollOffset = ivyContext.categoriesListState?.firstVisibleItemScrollOffset ?: 0 + ) + } + LazyColumn( modifier = Modifier .fillMaxSize() .statusBarsPadding() .navigationBarsPadding(), + state = listState ) { item { Spacer(Modifier.height(32.dp)) diff --git a/temp/legacy-code/src/main/java/com/ivy/legacy/IvyWalletCtx.kt b/temp/legacy-code/src/main/java/com/ivy/legacy/IvyWalletCtx.kt index 6fcbea9ae8..b081b989da 100644 --- a/temp/legacy-code/src/main/java/com/ivy/legacy/IvyWalletCtx.kt +++ b/temp/legacy-code/src/main/java/com/ivy/legacy/IvyWalletCtx.kt @@ -77,6 +77,12 @@ class IvyWalletCtx @Inject constructor() : IvyContext() { @Deprecated("Legacy code. Don't use it, please.") var transactionsListState: LazyListState? = null + @Deprecated("Legacy code. Don't use it, please.") + var accountsListState: LazyListState? = null + + @Deprecated("Legacy code. Don't use it, please.") + var categoriesListState: LazyListState? = null + @Deprecated("Legacy code. Don't use it, please.") var mainTab by mutableStateOf(com.ivy.legacy.data.model.MainTab.HOME) private set @@ -143,5 +149,7 @@ class IvyWalletCtx @Inject constructor() : IvyContext() { startDayOfMonth = 1 isPremium = true transactionsListState = null + accountsListState= null + categoriesListState = null } }