Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement DatePicker view in the DOM renderer #320

Closed
MaxDesiatov opened this issue Dec 4, 2020 · 0 comments · Fixed by #394
Closed

Implement DatePicker view in the DOM renderer #320

MaxDesiatov opened this issue Dec 4, 2020 · 0 comments · Fixed by #394
Labels
SwiftUI compatibility Tokamak API differences with SwiftUI

Comments

@MaxDesiatov
Copy link
Collaborator

MaxDesiatov commented Dec 4, 2020

Relevant API:

public struct DatePickerComponents : OptionSet {
  public let rawValue: UInt
  public init(rawValue: UInt)
  public static let hourAndMinute: DatePickerComponents
  public static let date: DatePickerComponents
  public typealias Element = DatePickerComponents
  public typealias RawValue = UInt
  public typealias ArrayLiteralElement = DatePickerComponents
}

public struct DatePicker<Label> : View where Label : View {
  public typealias Components = DatePickerComponents
  public var body: some View {
    get
  }
}

public protocol DatePickerStyle {
  associatedtype _Body : View
  func _body(configuration: DatePicker<Self._Label>) -> Self._Body
  typealias _Label = _DatePickerStyleLabel
}

public struct _DatePickerStyleLabel : View {
  public typealias Body = Swift.Never
}

extension View {
  public func datePickerStyle<S>(_ style: S) -> some View where S : DatePickerStyle
}
@MaxDesiatov MaxDesiatov added the SwiftUI compatibility Tokamak API differences with SwiftUI label Dec 4, 2020
MaxDesiatov pushed a commit that referenced this issue Mar 28, 2021
This fixes #320 by adding a SwiftUI-compatible `DatePicker`. However, `DatePickerStyle` is not supported. 

This uses the HTML inputs `date`, `time`, or `datetime-local`, depending on the given `displayedComponents`. This means that not all browsers show the picker, as Mac Safari currently does not support them. Safari on Mac will just show an ISO-format text field. If the date is in an invalid format, the binding will not receive updates until it becomes parseable by JSDate.

On supported browsers, the binding gets updated in real time, as you would expect, with a Foundation.Date, just like SwiftUI.

* Add DatePicker to TokamakCore and TokamakDOM

* Fix crash on invalid date

* Update progress.md and add credit

* Fix time zone related issues with the DatePicker

* Add DatePickerDemo to the TokamakDemo

* Fix overview for DatePicker

* Fix NativeDemo build
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
SwiftUI compatibility Tokamak API differences with SwiftUI
Development

Successfully merging a pull request may close this issue.

1 participant