Skip to content

Commit f0eb557

Browse files
authored
fix(mobile): polish photo carousels and video viewer controls (#8079)
## Summary - Keep neighboring carousel photos visible, add page-change haptics, and reuse appearance-style dots with native iOS glass and grouped actions. - Refine full-screen video controls with fading transport, cycling speeds, pinch-to-zoom, and double-tap reset before swipe-to-dismiss. ### Related issue N/A. Checked recent open PRs; repository issue search was unavailable. ### Testing - Mobile analysis/format checks, file-size guards, and full Flutter suite passed (2,680 tests; 4 skipped). - Built, installed, and manually verified on the connected iPhone. - `just ci` was attempted but blocked fetching a Rust dependency because this Mac could not connect to GitHub. --------- Signed-off-by: kenny lopez <[email protected]> Signed-off-by: klopez4212 <[email protected]>
1 parent 5f2d801 commit f0eb557

28 files changed

Lines changed: 2722 additions & 728 deletions

‎.github/workflows/_ci-clients.yml‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,17 @@ jobs:
135135
run: swift build -c release --package-path mobile/ios/BuzzPushKit
136136
- name: Test
137137
run: swift test --package-path mobile/ios/BuzzPushKit
138+
- name: Test native pagination geometry
139+
run: /bin/bash scripts/test-mobile-pagination.sh
138140
- name: Build complete iOS simulator app
139141
run: cd mobile && flutter build ios --simulator --debug --no-pub
142+
- name: Test native pagination accessibility
143+
run: |
144+
device=$(xcrun simctl create "Pagination accessibility" "iPhone 16")
145+
trap 'xcrun simctl shutdown "$device"; xcrun simctl delete "$device"' EXIT
146+
xcrun simctl boot "$device"
147+
xcrun simctl bootstatus "$device" -b
148+
/bin/bash scripts/test-mobile-pagination-accessibility.sh "$device"
140149
- name: Build complete unsigned iOS release
141150
run: |
142151
/bin/bash scripts/test-mobile-gateway-recipes.sh
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import Flutter
2+
import UIKit
3+
4+
@main
5+
struct ThemePaginationAccessibilityTests {
6+
static func check(_ condition: Bool, _ message: String) {
7+
precondition(condition, message)
8+
}
9+
10+
@MainActor static func main() {
11+
let messenger = PaginationTestMessenger()
12+
let platform = ThemePaginationGlassControlPlatformView(
13+
frame: CGRect(x: 0, y: 0, width: 116, height: 54),
14+
viewIdentifier: 42,
15+
arguments: ["accessibilityLabel": "Photo", "count": 3, "selected": 1],
16+
messenger: messenger
17+
)
18+
let control = platform.view()
19+
control.layoutIfNeeded()
20+
func accessibleViews(_ view: UIView) -> [UIView] {
21+
(view.isAccessibilityElement ? [view] : []) + view.subviews.flatMap(accessibleViews)
22+
}
23+
check(accessibleViews(control).count == 1, "Exactly one native accessibility element")
24+
check(control.accessibilityTraits.contains(.adjustable), "Paginator must be adjustable")
25+
check(control.accessibilityLabel == "Photo", "Native label must match content")
26+
check(control.accessibilityValue == "2 of 3", "Initial page value")
27+
control.accessibilityIncrement()
28+
check(control.accessibilityValue == "3 of 3", "Increment updates value")
29+
check(messenger.selections == [2], "Increment is delivered to Flutter once")
30+
control.accessibilityIncrement()
31+
check(messenger.selections == [2], "Increment stops at last page")
32+
control.accessibilityDecrement()
33+
control.accessibilityDecrement()
34+
control.accessibilityDecrement()
35+
check(control.accessibilityValue == "1 of 3", "Decrement stops at first page")
36+
check(messenger.selections == [2, 1, 0], "Each decrement is delivered once")
37+
check(accessibleViews(control).count == 1, "Selection keeps a single owner")
38+
print("Native pagination accessibility passed")
39+
}
40+
}
41+
42+
private final class PaginationTestMessenger: NSObject, FlutterBinaryMessenger {
43+
var selections: [Int] = []
44+
func send(onChannel channel: String, message: Data?) {
45+
guard let message else { return }
46+
let call = FlutterStandardMethodCodec.sharedInstance().decodeMethodCall(message)
47+
if call.method == "selected", let selected = call.arguments as? Int {
48+
selections.append(selected)
49+
}
50+
}
51+
func send(onChannel channel: String, message: Data?, binaryReply callback: FlutterBinaryReply?) {
52+
send(onChannel: channel, message: message)
53+
callback?(nil)
54+
}
55+
func setMessageHandlerOnChannel(
56+
_ channel: String, binaryMessageHandler handler: FlutterBinaryMessageHandler?
57+
) -> FlutterBinaryMessengerConnection { 1 }
58+
func cleanUpConnection(_ connection: FlutterBinaryMessengerConnection) {}
59+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import Foundation
2+
3+
@main
4+
struct ThemePaginationGeometryTests {
5+
static func check(_ condition: Bool, _ message: String) {
6+
if !condition {
7+
print("FAIL: \(message)")
8+
exit(1)
9+
}
10+
}
11+
12+
static func main() {
13+
let windows = [(3, 1, 0), (20, 0, 0), (20, 10, 7), (20, 19, 13)]
14+
var checkedCenters = 0
15+
for isRTL in [false, true] {
16+
for (count, selected, firstPage) in windows {
17+
// Actual dot centers inside the 92-point padded track.
18+
let centers: [CGFloat] = count == 3 ? [34, 46, 58] : [10, 22, 34, 46, 58, 70, 82]
19+
let geometry = ThemePaginationGeometry(count: count, selected: selected, width: 92, isRTL: isRTL)
20+
check(geometry.windowStart == firstPage, "wrong window at \(selected)")
21+
for (slot, center) in centers.enumerated() {
22+
let page = firstPage + (isRTL ? centers.count - 1 - slot : slot)
23+
check(geometry.centerX(for: page) == center, "wrong rendered center for page \(page)")
24+
for offset: CGFloat in [-2, 0, 2] {
25+
check(geometry.page(at: center + offset) == page,
26+
"count=\(count), selected=\(selected), RTL=\(isRTL), tap=\(center + offset), expected=\(page)")
27+
}
28+
checkedCenters += 1
29+
}
30+
check(geometry.page(at: -100) == firstPage + (isRTL ? centers.count - 1 : 0), "left edge")
31+
check(geometry.page(at: 200) == firstPage + (isRTL ? 0 : centers.count - 1), "right edge")
32+
}
33+
}
34+
for isRTL in [false, true] {
35+
for cancel in [false, true] {
36+
var selected = 10
37+
func current() -> ThemePaginationGeometry {
38+
ThemePaginationGeometry(count: 20, selected: selected, width: 92, isRTL: isRTL)
39+
}
40+
var scrub = ThemePaginationScrub()
41+
let target = current().centerX(for: 12)
42+
scrub.begin(current())
43+
for _ in 0..<8 {
44+
selected = scrub.page(at: target, current: current())
45+
check(selected == 12, "held pan cascaded in RTL=\(isRTL), cancel=\(cancel)")
46+
check(scrub.geometry?.centerX(for: 12) == target, "rendered window moved")
47+
}
48+
// The UIKit ended path consumes its last coordinate before clearing;
49+
// cancelled/failed paths clear without introducing another selection.
50+
if !cancel { selected = scrub.page(at: target, current: current()) }
51+
scrub.end()
52+
check(scrub.geometry == nil, "end/cancel retained window")
53+
let nextTarget = current().centerX(for: 14)
54+
scrub.begin(current())
55+
selected = scrub.page(at: nextTarget, current: current())
56+
check(selected == 14, "next gesture reused stale geometry")
57+
scrub.end()
58+
check(current().page(at: current().centerX(for: 15)) == 15, "tap after scrub")
59+
}
60+
}
61+
print("PASS: held scrubs, final events, cancellation and fresh gestures in LTR/RTL")
62+
print("PASS: \(checkedCenters) rendered centers, neighboring taps and clamped edges in LTR/RTL")
63+
}
64+
}

‎mobile/ios/Runner.xcodeproj/project.pbxproj‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
4A71C0192F40D00100A17E01 /* NativeProfileTextEditor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A71C01A2F40D00100A17E01 /* NativeProfileTextEditor.swift */; };
3232
4A71C01B2F40E00100A17E01 /* NativeSkinToneControl.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A71C01C2F40E00100A17E01 /* NativeSkinToneControl.swift */; };
3333
4A71C01D2F40F00100A17E01 /* ThemePaginationGlassControl.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A71C01E2F40F00100A17E01 /* ThemePaginationGlassControl.swift */; };
34+
AC7400012F50000100A17E01 /* ThemePaginationGeometry.swift in Sources */ = {isa = PBXBuildFile; fileRef = AC7400022F50000100A17E01 /* ThemePaginationGeometry.swift */; };
3435
4A71C01F2F4100100A17E01 /* VoiceNotePackager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A71C0202F4100100A17E01 /* VoiceNotePackager.swift */; };
3536
4A71C0212F4110100A17E01 /* MP4Canonicalizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A71C0222F4110100A17E01 /* MP4Canonicalizer.swift */; };
3637
4A71C0232F4120100A17E01 /* NativeAttachmentPopoverMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A71C0242F4120100A17E01 /* NativeAttachmentPopoverMenu.swift */; };
@@ -116,6 +117,7 @@
116117
4A71C01A2F40D00100A17E01 /* NativeProfileTextEditor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NativeProfileTextEditor.swift; sourceTree = "<group>"; };
117118
4A71C01C2F40E00100A17E01 /* NativeSkinToneControl.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NativeSkinToneControl.swift; sourceTree = "<group>"; };
118119
4A71C01E2F40F00100A17E01 /* ThemePaginationGlassControl.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThemePaginationGlassControl.swift; sourceTree = "<group>"; };
120+
AC7400022F50000100A17E01 /* ThemePaginationGeometry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThemePaginationGeometry.swift; sourceTree = "<group>"; };
119121
4A71C0202F4100100A17E01 /* VoiceNotePackager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VoiceNotePackager.swift; sourceTree = "<group>"; };
120122
4A71C0222F4110100A17E01 /* MP4Canonicalizer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MP4Canonicalizer.swift; sourceTree = "<group>"; };
121123
4A71C0242F4120100A17E01 /* NativeAttachmentPopoverMenu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NativeAttachmentPopoverMenu.swift; sourceTree = "<group>"; };
@@ -283,6 +285,7 @@
283285
4A71C01A2F40D00100A17E01 /* NativeProfileTextEditor.swift */,
284286
4A71C01C2F40E00100A17E01 /* NativeSkinToneControl.swift */,
285287
4A71C01E2F40F00100A17E01 /* ThemePaginationGlassControl.swift */,
288+
AC7400022F50000100A17E01 /* ThemePaginationGeometry.swift */,
286289
4A71C0202F4100100A17E01 /* VoiceNotePackager.swift */,
287290
4A71C0222F4110100A17E01 /* MP4Canonicalizer.swift */,
288291
4A71C0242F4120100A17E01 /* NativeAttachmentPopoverMenu.swift */,
@@ -616,6 +619,7 @@
616619
4A71C0192F40D00100A17E01 /* NativeProfileTextEditor.swift in Sources */,
617620
4A71C01B2F40E00100A17E01 /* NativeSkinToneControl.swift in Sources */,
618621
4A71C01D2F40F00100A17E01 /* ThemePaginationGlassControl.swift in Sources */,
622+
AC7400012F50000100A17E01 /* ThemePaginationGeometry.swift in Sources */,
619623
4A71C01F2F4100100A17E01 /* VoiceNotePackager.swift in Sources */,
620624
4A71C0212F4110100A17E01 /* MP4Canonicalizer.swift in Sources */,
621625
4A71C0232F4120100A17E01 /* NativeAttachmentPopoverMenu.swift in Sources */,

‎mobile/ios/Runner/JumpToLatestGlassButton.swift‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,8 @@ final class NavigationGlassButtonPlatformView: NSObject, FlutterPlatformView {
411411
case "shutter": buttonIconName = "circle.fill"
412412
case "sun": buttonIconName = "sun.max"
413413
case "moon": buttonIconName = "moon"
414+
case "more": buttonIconName = "ellipsis"
415+
case "reply": buttonIconName = "arrowshape.turn.up.left"
414416
case "systemAppearance": buttonIconName = "circle.lefthalf.filled"
415417
case "colorSwatch": buttonIconName = "circle.fill"
416418
default: buttonIconName = "chevron.backward"
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import Foundation
2+
3+
/// Shared geometry for native pagination drawing and pointer selection.
4+
struct ThemePaginationGeometry {
5+
static let dotSize: CGFloat = 6
6+
static let pitch: CGFloat = 12
7+
let count: Int
8+
let selected: Int
9+
let width: CGFloat
10+
let isRTL: Bool
11+
12+
var visibleCount: Int { min(count, 7) }
13+
var windowStart: Int { min(max(0, selected - visibleCount / 2), count - visibleCount) }
14+
var hasEarlierDots: Bool { windowStart > 0 }
15+
var hasLaterDots: Bool { windowStart + visibleCount < count }
16+
private var firstCenter: CGFloat {
17+
let trackWidth = CGFloat(visibleCount - 1) * Self.pitch + Self.dotSize
18+
return (width - trackWidth) / 2 + Self.dotSize / 2
19+
}
20+
21+
func slot(for page: Int) -> Int {
22+
let logicalSlot = page - windowStart
23+
return isRTL ? visibleCount - 1 - logicalSlot : logicalSlot
24+
}
25+
26+
func centerX(for page: Int) -> CGFloat {
27+
firstCenter + CGFloat(slot(for: page)) * Self.pitch
28+
}
29+
30+
func page(at x: CGFloat) -> Int {
31+
let slot = Int(((x - firstCenter) / Self.pitch).rounded())
32+
let boundedSlot = min(max(0, slot), visibleCount - 1)
33+
return windowStart + (isRTL ? visibleCount - 1 - boundedSlot : boundedSlot)
34+
}
35+
}
36+
37+
/// Freezes the rendered window for one continuous pan, including its final event.
38+
struct ThemePaginationScrub {
39+
private(set) var geometry: ThemePaginationGeometry?
40+
41+
mutating func begin(_ geometry: ThemePaginationGeometry) {
42+
self.geometry = geometry
43+
}
44+
45+
func page(at x: CGFloat, current: ThemePaginationGeometry) -> Int {
46+
(geometry ?? current).page(at: x)
47+
}
48+
49+
mutating func end() {
50+
geometry = nil
51+
}
52+
}

‎mobile/ios/Runner/ThemePaginationGlassControl.swift‎

Lines changed: 54 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ final class ThemePaginationGlassControlFactory: NSObject, FlutterPlatformViewFac
2828
}
2929

3030
private final class ThemePaginationControl: UIControl {
31-
private static let maximumVisibleDots = 7
32-
private static let fullDotSize: CGFloat = 6
31+
private static let fullDotSize = ThemePaginationGeometry.dotSize
3332
private static let selectedDotSize: CGFloat = 10
34-
private static let dotSpacing: CGFloat = 6
3533
private let glassView: UIVisualEffectView
3634
private let dotsContainer = UIView()
35+
private var glassHeightConstraint: NSLayoutConstraint?
3736
private var dots: [UIView] = []
3837
private var totalCount = 1
3938
private var selectedIndex = 0
39+
private var scrub = ThemePaginationScrub()
4040
private var activeColor = UIColor.label
4141
private var inactiveColor = UIColor.secondaryLabel.withAlphaComponent(0.32)
4242
var onSelectionChanged: ((Int) -> Void)?
@@ -53,6 +53,7 @@ private final class ThemePaginationControl: UIControl {
5353

5454
backgroundColor = .clear
5555
isOpaque = false
56+
isAccessibilityElement = true
5657
accessibilityTraits = [.adjustable]
5758
accessibilityLabel = "Theme"
5859

@@ -67,11 +68,13 @@ private final class ThemePaginationControl: UIControl {
6768
dotsContainer.isUserInteractionEnabled = false
6869
glassView.contentView.addSubview(dotsContainer)
6970

71+
let glassHeightConstraint = glassView.heightAnchor.constraint(equalToConstant: 30)
72+
self.glassHeightConstraint = glassHeightConstraint
7073
NSLayoutConstraint.activate([
7174
glassView.leadingAnchor.constraint(equalTo: leadingAnchor),
7275
glassView.trailingAnchor.constraint(equalTo: trailingAnchor),
7376
glassView.centerYAnchor.constraint(equalTo: centerYAnchor),
74-
glassView.heightAnchor.constraint(equalToConstant: 30),
77+
glassHeightConstraint,
7578
dotsContainer.leadingAnchor.constraint(equalTo: glassView.contentView.leadingAnchor, constant: 12),
7679
dotsContainer.trailingAnchor.constraint(equalTo: glassView.contentView.trailingAnchor, constant: -12),
7780
dotsContainer.topAnchor.constraint(equalTo: glassView.contentView.topAnchor),
@@ -108,6 +111,15 @@ private final class ThemePaginationControl: UIControl {
108111
inactiveColor = Self.color(fromARGB: value.uint32Value)
109112
}
110113

114+
accessibilityLabel = arguments["accessibilityLabel"] as? String ?? accessibilityLabel
115+
if let height = arguments["containerHeight"] as? NSNumber {
116+
glassHeightConstraint?.constant = max(10, CGFloat(height.doubleValue))
117+
setNeedsLayout()
118+
}
119+
if let isRTL = arguments["isRTL"] as? Bool {
120+
semanticContentAttribute = isRTL ? .forceRightToLeft : .forceLeftToRight
121+
}
122+
if count != totalCount { scrub.end() }
111123
totalCount = count
112124
if count != dots.count {
113125
rebuildDots(count: count)
@@ -126,11 +138,39 @@ private final class ThemePaginationControl: UIControl {
126138
select(index: max(selectedIndex - 1, 0))
127139
}
128140

141+
private var geometry: ThemePaginationGeometry {
142+
ThemePaginationGeometry(
143+
count: totalCount, selected: selectedIndex, width: dotsContainer.bounds.width,
144+
isRTL: effectiveUserInterfaceLayoutDirection == .rightToLeft
145+
)
146+
}
147+
129148
@objc private func handleGesture(_ recognizer: UIGestureRecognizer) {
130-
guard totalCount > 0 else { return }
131-
let location = recognizer.location(in: glassView)
132-
let progress = max(0, min(0.999_999, location.x / max(1, glassView.bounds.width)))
133-
select(index: Int(progress * CGFloat(totalCount)))
149+
guard dotsContainer.bounds.width > 0 else { return }
150+
let location = recognizer.location(in: dotsContainer)
151+
if recognizer is UIPanGestureRecognizer {
152+
switch recognizer.state {
153+
case .began:
154+
scrub.begin(geometry)
155+
case .changed:
156+
guard scrub.geometry != nil else { return }
157+
case .ended:
158+
let page = scrub.page(at: location.x, current: geometry)
159+
scrub.end()
160+
select(index: page)
161+
updateDots(animated: true)
162+
return
163+
case .cancelled, .failed:
164+
scrub.end()
165+
updateDots(animated: true)
166+
return
167+
default:
168+
return
169+
}
170+
select(index: scrub.page(at: location.x, current: geometry))
171+
} else if recognizer.state == .ended {
172+
select(index: geometry.page(at: location.x))
173+
}
134174
}
135175

136176
private func select(index: Int) {
@@ -163,20 +203,13 @@ private final class ThemePaginationControl: UIControl {
163203

164204
private func updateDots(animated: Bool) {
165205
guard !dots.isEmpty, dotsContainer.bounds.width > 0 else { return }
166-
let visibleCount = min(totalCount, Self.maximumVisibleDots)
167-
let maximumStart = max(0, totalCount - visibleCount)
168-
let centerSlot = visibleCount / 2
169-
let windowStart = min(max(0, selectedIndex - centerSlot), maximumStart)
170-
let windowEnd = windowStart + visibleCount - 1
171-
let hasEarlierDots = windowStart > 0
172-
let hasLaterDots = windowEnd < totalCount - 1
173-
let pitch = Self.fullDotSize + Self.dotSpacing
174-
let trackWidth = CGFloat(visibleCount) * Self.fullDotSize
175-
+ CGFloat(max(0, visibleCount - 1)) * Self.dotSpacing
176-
let trackOrigin = (dotsContainer.bounds.width - trackWidth) / 2
206+
let geometry = scrub.geometry ?? self.geometry
207+
let visibleCount = geometry.visibleCount
208+
let hasEarlierDots = geometry.isRTL ? geometry.hasLaterDots : geometry.hasEarlierDots
209+
let hasLaterDots = geometry.isRTL ? geometry.hasEarlierDots : geometry.hasLaterDots
177210
let changes = {
178211
for (page, dot) in self.dots.enumerated() {
179-
let slot = page - windowStart
212+
let slot = geometry.slot(for: page)
180213
let isVisible = (0..<visibleCount).contains(slot)
181214
var diameter = Self.fullDotSize
182215
if page == self.selectedIndex {
@@ -191,7 +224,7 @@ private final class ThemePaginationControl: UIControl {
191224
diameter = 4
192225
}
193226
dot.center = CGPoint(
194-
x: trackOrigin + Self.fullDotSize / 2 + CGFloat(slot) * pitch,
227+
x: geometry.centerX(for: page),
195228
y: self.dotsContainer.bounds.midY
196229
)
197230
dot.alpha = isVisible ? 1 : 0

0 commit comments

Comments
 (0)