From 1c67182187a3a6e8683998d17de6c09f762c096d Mon Sep 17 00:00:00 2001 From: Terry Yiu Date: Wed, 9 Sep 2026 23:50:05 +0300 Subject: [PATCH] Hide currency row controls when there's only one currency With a single currency shown there's nothing to reorder or remove, so the per-row "..." menu (Compose) and the Edit button plus swipe-to- delete/drag-to-reorder (iOS) no longer appear. This also covers Manual, which always shows just the default currency. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01FXcrACM5sok3M1KQJ8kByy --- iosApp/iosApp/ContentView.swift | 25 ++++++--- .../xyz/tyiu/satsprice/ui/PriceScreen.kt | 56 ++++++++++--------- 2 files changed, 45 insertions(+), 36 deletions(-) diff --git a/iosApp/iosApp/ContentView.swift b/iosApp/iosApp/ContentView.swift index 6d42e89..ad281db 100644 --- a/iosApp/iosApp/ContentView.swift +++ b/iosApp/iosApp/ContentView.swift @@ -18,16 +18,25 @@ struct ContentView: View { .navigationTitle("SatsPrice") #if os(iOS) // macOS Lists support drag-to-reorder directly; iOS only shows reorder handles - // once edit mode is active, which this toggles. + // once edit mode is active, which this toggles. Nothing to reorder or delete with + // only one currency shown, so the button itself is pointless then. .toolbar { ToolbarItem(placement: .navigationBarTrailing) { - EditButton() + if let state = viewModel.state, displayedRows(for: state).count > 1 { + EditButton() + } } } #endif } } + private func displayedRows(for state: IosConverterState) -> [FiatRow] { + state.isManualSource + ? state.fiatRows.filter { $0.code == state.defaultCurrencyCode } + : state.fiatRows + } + @ViewBuilder private func form(for state: IosConverterState) -> some View { Form { @@ -130,9 +139,7 @@ struct ContentView: View { } } - let displayedRows = state.isManualSource - ? state.fiatRows.filter { $0.code == state.defaultCurrencyCode } - : state.fiatRows + let displayedRows = displayedRows(for: state) ForEach(Array(displayedRows.enumerated()), id: \.element.code) { index, row in amountRow( @@ -157,17 +164,17 @@ struct ContentView: View { ) .deleteDisabled(row.code == state.defaultCurrencyCode) } - .onMove { indices, newOffset in + .onMove(perform: displayedRows.count > 1 ? { indices, newOffset in var codes = displayedRows.map(\.code) codes.move(fromOffsets: indices, toOffset: newOffset) viewModel.onFiatCurrenciesReordered(codes) - } + } : nil) #if os(iOS) - .onDelete { indexSet in + .onDelete(perform: displayedRows.count > 1 ? { indexSet in for index in indexSet { viewModel.onFiatCurrencyToggled(displayedRows[index].code) } - } + } : nil) #endif } } diff --git a/shared/src/commonMain/kotlin/xyz/tyiu/satsprice/ui/PriceScreen.kt b/shared/src/commonMain/kotlin/xyz/tyiu/satsprice/ui/PriceScreen.kt index 4e370c1..bec13c8 100644 --- a/shared/src/commonMain/kotlin/xyz/tyiu/satsprice/ui/PriceScreen.kt +++ b/shared/src/commonMain/kotlin/xyz/tyiu/satsprice/ui/PriceScreen.kt @@ -359,33 +359,35 @@ fun PriceScreen( visualTransformation = DigitGroupingTransformation, modifier = Modifier.weight(1f), ) - CurrencyRowMenu( - code = code, - canMoveUp = index > 0, - canMoveDown = index < displayedCurrencies.lastIndex, - canRemove = code != state.defaultCurrencyCode, - onMoveUp = { - viewModel.onFiatCurrenciesReordered( - state.selectedFiatCurrencies.moved(index, index - 1), - ) - }, - onMoveDown = { - viewModel.onFiatCurrenciesReordered( - state.selectedFiatCurrencies.moved(index, index + 1), - ) - }, - onMoveToTop = { - viewModel.onFiatCurrenciesReordered( - state.selectedFiatCurrencies.moved(index, 0), - ) - }, - onMoveToBottom = { - viewModel.onFiatCurrenciesReordered( - state.selectedFiatCurrencies.moved(index, state.selectedFiatCurrencies.lastIndex), - ) - }, - onRemove = { viewModel.onFiatCurrencyToggled(code) }, - ) + if (displayedCurrencies.size > 1) { + CurrencyRowMenu( + code = code, + canMoveUp = index > 0, + canMoveDown = index < displayedCurrencies.lastIndex, + canRemove = code != state.defaultCurrencyCode, + onMoveUp = { + viewModel.onFiatCurrenciesReordered( + state.selectedFiatCurrencies.moved(index, index - 1), + ) + }, + onMoveDown = { + viewModel.onFiatCurrenciesReordered( + state.selectedFiatCurrencies.moved(index, index + 1), + ) + }, + onMoveToTop = { + viewModel.onFiatCurrenciesReordered( + state.selectedFiatCurrencies.moved(index, 0), + ) + }, + onMoveToBottom = { + viewModel.onFiatCurrenciesReordered( + state.selectedFiatCurrencies.moved(index, state.selectedFiatCurrencies.lastIndex), + ) + }, + onRemove = { viewModel.onFiatCurrencyToggled(code) }, + ) + } } } }