Skip to content

Commit

Permalink
digitalCrown support for watchOS 7 onwwards
Browse files Browse the repository at this point in the history
  • Loading branch information
fermoya committed Apr 5, 2022
1 parent b1eb844 commit bbe61ad
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions Sources/SwiftUIPager/PagerContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -246,25 +246,27 @@ extension Pager {
#endif

#if os(watchOS)
resultView = resultView
.focusable()
.digitalCrownRotation(
$digitalCrownPageOffset,
from: 0,
through: CGFloat(numberOfPages - 1),
by: 1,
sensitivity: .low
)
.onChange(of: digitalCrownPageOffset) { newValue in
print(newValue)
let increment = min(1, max(-1, Int(newValue - lastDigitalCrownPageOffset)))
guard abs(increment) > 0 else { return }
lastDigitalCrownPageOffset = newValue
withAnimation {
pagerModel.update(.move(increment: increment))
if #available(watchOSApplicationExtension 7.0, *) {
resultView = resultView
.focusable()
.digitalCrownRotation(
$digitalCrownPageOffset,
from: 0,
through: CGFloat(numberOfPages - 1),
by: 1,
sensitivity: .low
)
.onChange(of: digitalCrownPageOffset) { newValue in
print(newValue)
let increment = min(1, max(-1, Int(newValue - lastDigitalCrownPageOffset)))
guard abs(increment) > 0 else { return }
lastDigitalCrownPageOffset = newValue
withAnimation {
pagerModel.update(.move(increment: increment))
}
}
}
.eraseToAny()
.eraseToAny()
}
#endif

return resultView.contentShape(Rectangle())
Expand Down

0 comments on commit bbe61ad

Please sign in to comment.