Skip to content

Commit

Permalink
fix: 修复竖向模式下,翻页指示器颜色的问题 #89
Browse files Browse the repository at this point in the history
  • Loading branch information
qwertyyb committed Nov 5, 2022
1 parent 4208491 commit 5e8f0a9
Showing 1 changed file with 34 additions and 61 deletions.
95 changes: 34 additions & 61 deletions Fire/CandidatesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ struct CandidateView: View {
.foregroundColor(Color(codeColor))
}
}
// .fixedSize()
.onTapGesture {
NotificationCenter.default.post(
name: Fire.candidateSelected,
Expand Down Expand Up @@ -88,69 +87,43 @@ struct CandidatesView: View {
}
}

func getIndicatorIcon(imageName: String, direction: CandidatesDirection, disabled: 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 disabled { return }
NotificationCenter.default.post(
name: eventName,
object: nil
)
}
.foregroundColor(Color(disabled
? themeConfig[colorScheme].pageIndicatorDisabledColor
: themeConfig[colorScheme].pageIndicatorColor
))
}

var _indicator: some View {
let arrowUp = getIndicatorIcon(
imageName: "arrowUp",
direction: direction,
disabled: !hasPrev,
eventName: Fire.prevPageBtnTapped
)
let arrowDown = getIndicatorIcon(
imageName: "arrowDown",
direction: direction,
disabled: !hasNext,
eventName: Fire.nextPageBtnTapped
)
if direction == CandidatesDirection.horizontal {
return AnyView(VStack(spacing: 0) {
Image("arrowUp")
.renderingMode(.template)
.resizable()
.frame(width: 10, height: 10, alignment: .center)
.onTapGesture {
if !hasPrev { return }
NotificationCenter.default.post(
name: Fire.prevPageBtnTapped,
object: nil
)
}
.foregroundColor(Color(hasPrev
? themeConfig[colorScheme].pageIndicatorColor
: themeConfig[colorScheme].pageIndicatorDisabledColor
))
Image("arrowDown")
.renderingMode(.template)
.resizable()
.frame(width: 10, height: 10, alignment: .center)
.onTapGesture {
if !hasNext { return }
print("next")
NotificationCenter.default.post(
name: Fire.nextPageBtnTapped,
object: nil
)
}
.foregroundColor(Color(hasNext
? themeConfig[colorScheme].pageIndicatorColor
: themeConfig[colorScheme].pageIndicatorDisabledColor
))
})
return AnyView(VStack(spacing: 0) { arrowUp; arrowDown })
} else {
return AnyView(HStack(spacing: 4) { arrowUp; arrowDown })
}
return AnyView(HStack(spacing: 4) {
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
)
}
})
}

var body: some View {
Expand Down

0 comments on commit 5e8f0a9

Please sign in to comment.