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")
|
.navigationTitle("SatsPrice")
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
// macOS Lists support drag-to-reorder directly; iOS only shows reorder handles
|
// 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 {
|
.toolbar {
|
||||||
ToolbarItem(placement: .navigationBarTrailing) {
|
ToolbarItem(placement: .navigationBarTrailing) {
|
||||||
EditButton()
|
if let state = viewModel.state, displayedRows(for: state).count > 1 {
|
||||||
|
EditButton()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func displayedRows(for state: IosConverterState) -> [FiatRow] {
|
||||||
|
state.isManualSource
|
||||||
|
? state.fiatRows.filter { $0.code == state.defaultCurrencyCode }
|
||||||
|
: state.fiatRows
|
||||||
|
}
|
||||||
|
|
||||||
@ViewBuilder
|
@ViewBuilder
|
||||||
private func form(for state: IosConverterState) -> some View {
|
private func form(for state: IosConverterState) -> some View {
|
||||||
Form {
|
Form {
|
||||||
@@ -130,9 +139,7 @@ struct ContentView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let displayedRows = state.isManualSource
|
let displayedRows = displayedRows(for: state)
|
||||||
? state.fiatRows.filter { $0.code == state.defaultCurrencyCode }
|
|
||||||
: state.fiatRows
|
|
||||||
|
|
||||||
ForEach(Array(displayedRows.enumerated()), id: \.element.code) { index, row in
|
ForEach(Array(displayedRows.enumerated()), id: \.element.code) { index, row in
|
||||||
amountRow(
|
amountRow(
|
||||||
@@ -157,17 +164,17 @@ struct ContentView: View {
|
|||||||
)
|
)
|
||||||
.deleteDisabled(row.code == state.defaultCurrencyCode)
|
.deleteDisabled(row.code == state.defaultCurrencyCode)
|
||||||
}
|
}
|
||||||
.onMove { indices, newOffset in
|
.onMove(perform: displayedRows.count > 1 ? { indices, newOffset in
|
||||||
var codes = displayedRows.map(\.code)
|
var codes = displayedRows.map(\.code)
|
||||||
codes.move(fromOffsets: indices, toOffset: newOffset)
|
codes.move(fromOffsets: indices, toOffset: newOffset)
|
||||||
viewModel.onFiatCurrenciesReordered(codes)
|
viewModel.onFiatCurrenciesReordered(codes)
|
||||||
}
|
} : nil)
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
.onDelete { indexSet in
|
.onDelete(perform: displayedRows.count > 1 ? { indexSet in
|
||||||
for index in indexSet {
|
for index in indexSet {
|
||||||
viewModel.onFiatCurrencyToggled(displayedRows[index].code)
|
viewModel.onFiatCurrencyToggled(displayedRows[index].code)
|
||||||
}
|
}
|
||||||
}
|
} : nil)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -359,33 +359,35 @@ fun PriceScreen(
|
|||||||
visualTransformation = DigitGroupingTransformation,
|
visualTransformation = DigitGroupingTransformation,
|
||||||
modifier = Modifier.weight(1f),
|
modifier = Modifier.weight(1f),
|
||||||
)
|
)
|
||||||
CurrencyRowMenu(
|
if (displayedCurrencies.size > 1) {
|
||||||
code = code,
|
CurrencyRowMenu(
|
||||||
canMoveUp = index > 0,
|
code = code,
|
||||||
canMoveDown = index < displayedCurrencies.lastIndex,
|
canMoveUp = index > 0,
|
||||||
canRemove = code != state.defaultCurrencyCode,
|
canMoveDown = index < displayedCurrencies.lastIndex,
|
||||||
onMoveUp = {
|
canRemove = code != state.defaultCurrencyCode,
|
||||||
viewModel.onFiatCurrenciesReordered(
|
onMoveUp = {
|
||||||
state.selectedFiatCurrencies.moved(index, index - 1),
|
viewModel.onFiatCurrenciesReordered(
|
||||||
)
|
state.selectedFiatCurrencies.moved(index, index - 1),
|
||||||
},
|
)
|
||||||
onMoveDown = {
|
},
|
||||||
viewModel.onFiatCurrenciesReordered(
|
onMoveDown = {
|
||||||
state.selectedFiatCurrencies.moved(index, index + 1),
|
viewModel.onFiatCurrenciesReordered(
|
||||||
)
|
state.selectedFiatCurrencies.moved(index, index + 1),
|
||||||
},
|
)
|
||||||
onMoveToTop = {
|
},
|
||||||
viewModel.onFiatCurrenciesReordered(
|
onMoveToTop = {
|
||||||
state.selectedFiatCurrencies.moved(index, 0),
|
viewModel.onFiatCurrenciesReordered(
|
||||||
)
|
state.selectedFiatCurrencies.moved(index, 0),
|
||||||
},
|
)
|
||||||
onMoveToBottom = {
|
},
|
||||||
viewModel.onFiatCurrenciesReordered(
|
onMoveToBottom = {
|
||||||
state.selectedFiatCurrencies.moved(index, state.selectedFiatCurrencies.lastIndex),
|
viewModel.onFiatCurrenciesReordered(
|
||||||
)
|
state.selectedFiatCurrencies.moved(index, state.selectedFiatCurrencies.lastIndex),
|
||||||
},
|
)
|
||||||
onRemove = { viewModel.onFiatCurrencyToggled(code) },
|
},
|
||||||
)
|
onRemove = { viewModel.onFiatCurrencyToggled(code) },
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user