Skip to content

ASViscosityStyle does not move #5

Open
@JLLJHD

Description

@JLLJHD

//
// AISongsSegmentView.swift
// AImphony
//
//

import SwiftUI
import AxisSegmentedView

class ViscosityValue: ObservableObject {

@Published var constant = ASConstant(divideLine: .init(color: Color(hex: 0x444444), scale: 0))

@Published var selectArea0: CGFloat = 0
@Published var selectArea1: CGFloat = 0
@Published var selectArea2: CGFloat = 0

}

struct AISongsSegmentView: View {
@binding var selection: Int
@StateObject private var viscosityValue: ViscosityValue = .init()

var body: some View {
    Button {
        selection = 1
    } label: {
        Text("Test")
            .foregroundColor(.white)
    }

    AxisSegmentedView(selection: $selection, constant: .init()) {
        Group {
            Text("Store")
                .font(.callout)
                .foregroundColor(Color.white.opacity(0.5))
                .itemTag(0, selectArea: viscosityValue.selectArea0) {
                    Text("Store")
                        .font(.callout)
                        .foregroundColor(Color.white)
                }
            Text("Library")
                .font(.callout)
                .foregroundColor(Color.white.opacity(0.5))
                .itemTag(1, selectArea: viscosityValue.selectArea1) {
                    Text("Library")
                        .font(.callout)
                        .foregroundColor(Color.white)
                }
            Text("Downloads")
                .font(.callout)
                .foregroundColor(Color.white.opacity(0.5))
                .itemTag(2, selectArea: viscosityValue.selectArea2) {
                    Text("Downloads")
                        .font(.callout)
                        .foregroundColor(Color.white)
                }
        }
    } style: {
        
        ASViscosityStyle(Animation.spring(response: 0.3, dampingFraction: 0.5, blendDuration: 0.5)) { _ in
            Capsule()
                .fill(LinearGradient(colors: [Color(hex: 0x222222), Color(hex: 0x111111)],
                                     startPoint: UnitPoint.leading,
                                     endPoint: UnitPoint.trailing))
                .overlay(
                    Capsule()
                        .stroke()
                        .fill(Color.black.opacity(0.4))
                )
                .padding(2)
        }
        .background(Color.white.opacity(0.1))
        .clipShape(Capsule())
        .innerShadow(Capsule(), radius: 1, opacity: 0.5, isDark: true)
        
    } onTapReceive: { selectionTap in
        /// Imperative syntax
        print("---------------------")
        print("Selection : ", selectionTap)
        print("self.selection : ", self.selection)
        print("Already selected : ", self.selection == selectionTap)
    }
    .frame(height: 84)
    .padding(.horizontal, 12)
    .padding(.top, 12)
}

}

#Preview {
AISongsSegmentView(selection: .constant(0))
}

When I click the button selection = 1, the mask of ASViscosityStyle does not move to the corresponding place. How can I modify it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions