Files
buzz/mobile/ios/Runner/ActiveDaysWheel.swift
klopez4212 e9fdd1aef5 feat(mobile): add three-day and custom activity periods (#9964)
## Summary

Add a **3 days** preset and a **Custom…** option to the mobile Active
filter. Custom opens a wheel for 1–365 days, using UIKit on iOS.
Confirming returns to Display Options with the selected duration.
Canceling restores the previous duration. Both paths preserve the other
pending choices until Apply.

## Testing

- Exercised the picker on an iPhone Air and Pixel 10.
- Extended the section options test to cover the preset, canceling a
custom period, confirming 11 days, applying it, and reopening the saved
setting.
- Ran Flutter analysis, formatting, and the mobile test suite.

## Related issue

No duplicate found.

Signed-off-by: Terp <5856f6900e8e0a4e0ea1f4f8d2ee33e4753d2119bc122f94ecafc660b46c0511@buzz.block.builderlab.xyz>
Co-authored-by: Terp <5856f6900e8e0a4e0ea1f4f8d2ee33e4753d2119bc122f94ecafc660b46c0511@buzz.block.builderlab.xyz>
2026-11-30 08:25:20 +00:00

48 lines
2.0 KiB
Swift

import Flutter
import UIKit
final class ActiveDaysWheelFactory: NSObject, FlutterPlatformViewFactory {
private let messenger: FlutterBinaryMessenger
init(messenger: FlutterBinaryMessenger) {
self.messenger = messenger
}
func createArgsCodec() -> FlutterMessageCodec & NSObjectProtocol {
FlutterStandardMessageCodec.sharedInstance()
}
func create(withFrame frame: CGRect, viewIdentifier id: Int64, arguments args: Any?) -> FlutterPlatformView {
ActiveDaysWheel(frame: frame, id: id, messenger: messenger, options: args as? [String: Any] ?? [:])
}
}
private final class ActiveDaysWheel: NSObject, FlutterPlatformView, UIPickerViewDataSource, UIPickerViewDelegate {
private let picker: UIPickerView
private let channel: FlutterMethodChannel
private let maximum: Int
init(frame: CGRect, id: Int64, messenger: FlutterBinaryMessenger, options: [String: Any]) {
picker = UIPickerView(frame: frame)
maximum = max(1, options["maximum"] as? Int ?? 365)
channel = FlutterMethodChannel(name: "buzz/active_days_wheel/\(id)", binaryMessenger: messenger)
super.init()
picker.dataSource = self
picker.delegate = self
picker.overrideUserInterfaceStyle = options["dark"] as? Bool == true ? .dark : .light
picker.selectRow(min(maximum, max(1, options["initial"] as? Int ?? 1)) - 1, inComponent: 0, animated: false)
channel.setMethodCallHandler { [weak self] call, result in
guard call.method == "selection" else { result(FlutterMethodNotImplemented); return }
result(self.map { $0.picker.selectedRow(inComponent: 0) + 1 })
}
}
deinit { channel.setMethodCallHandler(nil) }
func view() -> UIView { picker }
func numberOfComponents(in pickerView: UIPickerView) -> Int { 1 }
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { maximum }
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
row == 0 ? "1 day" : "\(row + 1) days"
}
}