From 6730892be9bad6683f211b77aa5d611458cf825c Mon Sep 17 00:00:00 2001 From: fun Date: Mon, 10 Oct 2022 15:30:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96SystemRow=20=E8=AE=BE?= =?UTF-8?q?=E7=BD=AEdetail?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/Jenga/Core/Row/System/SystemRow.swift | 47 ++++++++++++------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/Sources/Jenga/Core/Row/System/SystemRow.swift b/Sources/Jenga/Core/Row/System/SystemRow.swift index 02d16a7..2630bff 100644 --- a/Sources/Jenga/Core/Row/System/SystemRow.swift +++ b/Sources/Jenga/Core/Row/System/SystemRow.swift @@ -28,17 +28,17 @@ public extension SystemRow { reform { $0.icon = .constant(value) } } - func detailText(_ value: Binding) -> Self { - reform { $0.detailText = value } - } - func detailText(_ value: DetailText) -> Self { - reform { $0.detailText = .constant(value) } + reform { + $0.detailText = detailText.map(value) { detailText, value in + return value + } + } } func detailText(_ value: String) -> Self { reform { - $0.detailText = detailText.map { detailText in + $0.detailText = detailText.map(value) { detailText, value in var temp = detailText temp.type = .value1 temp.text.string = value @@ -47,10 +47,10 @@ public extension SystemRow { } } - func detailText(_ value: Binding) -> Self { - var temp = detailText.wrappedValue - return reform { - $0.detailText = value.map { value in + func detailText(_ binding: Binding) -> Self { + reform { + $0.detailText = detailText.join(binding) { detail, value in + var temp = detail temp.type = .value1 temp.text.string = value return temp @@ -58,13 +58,21 @@ public extension SystemRow { } } + func detailText(_ binding: Binding) -> Self { + reform { + $0.detailText = detailText.join(binding) { detail, value in + return value + } + } + } + func text(_ keyPath: WritableKeyPath, _ value: Value) -> Self { - reform { $0.text = text.map { $0.with(keyPath, value) } } + reform { $0.text = text.map(value) { $0.with(keyPath, $1) } } } func detail(_ keyPath: WritableKeyPath, _ value: Value) -> Self { reform { - $0.detailText = detailText.map { detailText in + $0.detailText = detailText.map(value) { detailText, value in var temp = detailText temp.text = temp.text.with(keyPath, value) return temp @@ -73,14 +81,17 @@ public extension SystemRow { } func text(_ keyPath: WritableKeyPath, _ binding: Binding) -> Self { - let temp = text.wrappedValue - return reform { $0.text = binding.map { temp.with(keyPath, $0) } } + reform { + $0.text = text.join(binding) { text, value in + text.with(keyPath, value) + } + } } func detail(_ keyPath: WritableKeyPath, _ binding: Binding) -> Self { - var temp = detailText.wrappedValue - return reform { - $0.detailText = binding.map { value in + reform { + $0.detailText = detailText.join(binding) { detail, value in + var temp = detail temp.text = temp.text.with(keyPath, value) return temp } @@ -89,7 +100,7 @@ public extension SystemRow { func detail(_ value: DetailText.`Type`) -> Self { reform { - $0.detailText = detailText.map { detailText in + $0.detailText = detailText.map(value) { detailText, value in var temp = detailText temp.type = value return temp