SwipeActions
SwipeActions copied to clipboard
If an action button text is based on a state change, when `addSwipeAction(menu: .swiped)` is used, it doesn't seem to rebuild correctly.
Thank you for your hard work.
I have a question: If an action button text is based on a state change, when addSwipeAction(menu: .swiped)
is used, it doesn't seem to rebuild correctly.
For example, in the following code for a conversation list cell, when the "pin" action is clicked, the text of this action changes to "unpin". However, the width of the action is not correct. How can I properly re-render the action button?
@State var swipeState = SwipeState.untouched
func contentCard(conversation: Conversation) -> some View {
HStack {
NetworkImage(url: conversation.couple.avatar, size: 80)
VStack(alignment: .leading, spacing: 3) {
HStack {
Text(conversation.couple.nickName)
.semibold(size: 12)
}
Text(conversation.couple.describe)
.regualr(size: 11)
.foregroundStyle(Color.black.opacity(0.5))
}
.lineLimit(1)
Spacer(minLength: 0)
}
.padding(.all, 15)
.background(Color.white)
.addSwipeAction(menu: .swiped, edge: .trailing, state: $swipeState) {
Button {
withAnimation {
swipeState = .swiped(UUID())
}
send(.userDidTapPinConversation(conversation), animation: .default)
} label: {
Text(conversation.isPinned ? "unpin" : "pin")
.foregroundStyle(Color.white)
.semibold(size: 12)
.padding(.horizontal, 8.ap)
}
.frame(maxHeight: .infinity)
.background(Color(hex: "#FF6599FF"))
Button {
withAnimation {
swipeState = .swiped(UUID())
}
send(.userDidTapDeleteConversation(conversation), animation: .default)
} label: {
Text("delete")
.foregroundStyle(Color.white)
.semibold(size: 12)
.padding(.horizontal, 8.ap)
}
.frame(maxHeight: .infinity)
.background(Color(hex: "#FFFF2C2C"))
}
.cornerRadius(15)
.padding(.horizontal, 15.ap)