drop iOS 17 and removed all #available and #unavaible checks for 17 and 18

This commit is contained in:
Mauro Romito
2025-11-28 14:37:37 +01:00
committed by Mauro
parent 7496f30966
commit 656648fc7c
12 changed files with 79 additions and 160 deletions
@@ -51,59 +51,52 @@ struct SwipeRightAction<Label: View>: ViewModifier {
@ViewBuilder
private func mainContent(content: Content) -> some View {
if #available(iOS 18, *) {
content
.offset(x: xOffset, y: 0.0)
.animation(.interactiveSpring().speed(0.5), value: xOffset)
.gesture(PanGestureRepresentable { gesture in
switch gesture.state {
case .ended, .cancelled, .failed:
if xOffset > actionThreshold {
action()
}
xOffset = 0.0
default:
guard shouldStartAction() else {
return
}
let translation = gesture.translation(in: nil)
// Due to https://forums.developer.apple.com/forums/thread/760035 we had to make
// the drag a simultaneous gesture otherwise it was impossible to scroll the timeline.
// Therefore we need to prevent the animation to run if the user is to scrolling vertically.
// It would be nice if we could somehow abort the gesture in this case.
let width: CGFloat = if translation.x > abs(translation.y) {
translation.x
} else {
0.0
}
// We want to add a spring like behaviour to the drag in which the view
// moves slower the more it's dragged. We use a circular easing function
// to generate those values up to the `swipeThreshold`
// The final translation will be between 0 and `swipeThreshold` with the action being enabled from
// `actionThreshold` onwards
let screenWidthNormalisedTranslation = max(0.0, min(width, swipeThreshold)) / swipeThreshold
let easedTranslation = circularEaseOut(screenWidthNormalisedTranslation)
xOffset = easedTranslation * xOffsetThreshold
if xOffset > actionThreshold {
if !hasReachedActionThreshold {
feedbackGenerator.impactOccurred()
hasReachedActionThreshold = true
}
} else {
hasReachedActionThreshold = false
}
content
.offset(x: xOffset, y: 0.0)
.animation(.interactiveSpring().speed(0.5), value: xOffset)
.gesture(PanGestureRepresentable { gesture in
switch gesture.state {
case .ended, .cancelled, .failed:
if xOffset > actionThreshold {
action()
}
})
} else {
content
.offset(x: xOffset, y: 0.0)
.animation(.interactiveSpring().speed(0.5), value: xOffset)
.gesture(oldGesture)
}
xOffset = 0.0
default:
guard shouldStartAction() else {
return
}
let translation = gesture.translation(in: nil)
// Due to https://forums.developer.apple.com/forums/thread/760035 we had to make
// the drag a simultaneous gesture otherwise it was impossible to scroll the timeline.
// Therefore we need to prevent the animation to run if the user is to scrolling vertically.
// It would be nice if we could somehow abort the gesture in this case.
let width: CGFloat = if translation.x > abs(translation.y) {
translation.x
} else {
0.0
}
// We want to add a spring like behaviour to the drag in which the view
// moves slower the more it's dragged. We use a circular easing function
// to generate those values up to the `swipeThreshold`
// The final translation will be between 0 and `swipeThreshold` with the action being enabled from
// `actionThreshold` onwards
let screenWidthNormalisedTranslation = max(0.0, min(width, swipeThreshold)) / swipeThreshold
let easedTranslation = circularEaseOut(screenWidthNormalisedTranslation)
xOffset = easedTranslation * xOffsetThreshold
if xOffset > actionThreshold {
if !hasReachedActionThreshold {
feedbackGenerator.impactOccurred()
hasReachedActionThreshold = true
}
} else {
hasReachedActionThreshold = false
}
}
})
}
private var oldGesture: some Gesture {
@@ -21,25 +21,19 @@ struct TimelineItemMacContextMenu: View {
if let menuActions = actionProvider.makeActions() {
Section {
if !menuActions.reactions.isEmpty {
if #available(iOS 17.0, *) {
let reactions = (item as? EventBasedTimelineItemProtocol)?.properties.reactions ?? []
ControlGroup {
ForEach(menuActions.reactions, id: \.key) {
ReactionToggle(reaction: $0, reactions: reactions) {
send(.toggleReaction(key: $0))
}
}
Button { send(.react) } label: {
CompoundIcon(\.reactionAdd)
let reactions = (item as? EventBasedTimelineItemProtocol)?.properties.reactions ?? []
ControlGroup {
ForEach(menuActions.reactions, id: \.key) {
ReactionToggle(reaction: $0, reactions: reactions) {
send(.toggleReaction(key: $0))
}
}
.controlGroupStyle(.palette)
} else {
Button { send(.react) } label: {
TimelineItemMenuAction.react.label
CompoundIcon(\.reactionAdd)
}
}
.controlGroupStyle(.palette)
}
ForEach(menuActions.actions) { action in
@@ -53,7 +53,7 @@ struct TimelineItemMenu: View {
}
}
.accessibilityIdentifier(A11yIdentifiers.roomScreen.timelineItemActionMenu)
.backportPresentationSizingPage()
.presentationSizing(.page)
.presentationDetents([.medium, .large])
.presentationBackground(Color.compound.bgCanvasDefault)
.presentationDragIndicator(.visible)
@@ -94,8 +94,7 @@ struct PollView: View {
private var optionsView: some View {
ForEach(poll.options, id: \.id) { option in
pollOption(option: option)
.backportAccessibilityHint(L10n.a11yPollsWillRemoveSelection,
isEnabled: isRemovePreviousSelectionHintEnabled(option: option))
.accessibilityHint(L10n.a11yPollsWillRemoveSelection, isEnabled: isRemovePreviousSelectionHintEnabled(option: option))
}
}
@@ -16,26 +16,19 @@ struct LongPressWithFeedback: ViewModifier {
private let feedbackGenerator = UIImpactFeedbackGenerator(style: .heavy)
func body(content: Content) -> some View {
if #available(iOS 18, *) {
mainContent(content: content)
.gesture(LongPressGestureRepresentable { gesture in
switch gesture.state {
case .began:
handleLongPress(isPressing: true)
case .ended, .cancelled, .failed:
handleLongPress(isPressing: false)
case .possible, .changed:
break
@unknown default:
break
}
})
} else {
mainContent(content: content)
.onLongPressGesture(minimumDuration: 0.25) { } onPressingChanged: { isPressing in
handleLongPress(isPressing: isPressing)
mainContent(content: content)
.gesture(LongPressGestureRepresentable { gesture in
switch gesture.state {
case .began:
handleLongPress(isPressing: true)
case .ended, .cancelled, .failed:
handleLongPress(isPressing: false)
case .possible, .changed:
break
@unknown default:
break
}
}
})
}
// The gesture's minimum duration doesn't actually invoke the perform block when elapsed (thus