Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vertical模式下pageIndicatorColor没有关联hasPrev和hasNext #89

Closed
AlienKevin opened this issue Oct 24, 2022 · 1 comment
Closed

Comments

@AlienKevin
Copy link

AlienKevin commented Oct 24, 2022

Image("arrowUp")
.renderingMode(.template)
.resizable()
.frame(width: 10, height: 10, alignment: .center)
.rotationEffect(Angle(degrees: -90), anchor: .center)
.onTapGesture {
if !hasPrev { return }
NotificationCenter.default.post(
name: Fire.prevPageBtnTapped,
object: nil
)
}
Image("arrowDown")
.renderingMode(.template)
.resizable()
.frame(width: 10, height: 10, alignment: .center)
.rotationEffect(Angle(degrees: -90), anchor: .center)
.onTapGesture {
if !hasNext { return }
print("next")
NotificationCenter.default.post(
name: Fire.nextPageBtnTapped,
object: nil
)

建议extract出来一个function给vertical和horizontal共用,这样就可以避免新功能out of sync的问题。这是一种写法:

var _indicator: some View {
        let arrowUp = getIndicatorIcon(imageName: "arrowUp", direction: direction, activeFlag: hasPrev, eventName: State.prevPageBtnTapped)
        let arrowDown = getIndicatorIcon(imageName: "arrowDown", direction: direction, activeFlag: hasNext, eventName: State.nextPageBtnTapped)
        if direction == CandidatesDirection.horizontal {
            return AnyView(VStack(spacing: 0) { arrowUp; arrowDown })
        } else {
            return AnyView(HStack(spacing: 4) { arrowUp; arrowDown })
        }
    }
    
    func getIndicatorIcon(imageName: String, direction: CandidatesDirection, activeFlag: Bool, eventName: Notification.Name) -> some View {
        return Image(imageName)
            .renderingMode(.template)
            .resizable()
            .frame(width: 10, height: 10, alignment: .center)
            .rotationEffect(Angle(degrees: direction == CandidatesDirection.horizontal ? 0 : -90), anchor: .center)
            .onTapGesture {
                if !activeFlag { return }
                NotificationCenter.default.post(
                    name: eventName,
                    object: nil
                )
            }
            .foregroundColor(Color(activeFlag
                                   ? themeConfig[colorScheme].pageIndicatorColor
                                   : themeConfig[colorScheme].pageIndicatorDisabledColor
                                  ))
    }
@qwertyyb
Copy link
Owner

qwertyyb commented Apr 5, 2023

再次感谢你的反馈 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants