SwipeActions icon indicating copy to clipboard operation
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.

Open MorningStarJ opened this issue 7 months ago • 3 comments

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)

CleanShot 2024-07-04 at 15 21 46

CleanShot 2024-07-04 at 15 20 19

MorningStarJ avatar Jul 04 '24 07:07 MorningStarJ