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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FXcrACM5sok3M1KQJ8kByy
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) },
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user