File tree Expand file tree Collapse file tree
AndroidSwiftUICore/Sources/AndroidSwiftUICore/Primitives Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ //
2+ // DatePicker.swift
3+ // AndroidSwiftUICore
4+ //
5+ // A control for choosing a calendar date. The selection round-trips the
6+ // bridge as milliseconds since the Unix epoch — Compose's Material3
7+ // DatePickerState currency, and a trivial conversion from Foundation's Date.
8+ //
9+
10+ import Foundation
11+
12+ public struct DatePicker < Label: View > : View {
13+
14+ internal let label : Label
15+ internal let selection : Binding < Date >
16+
17+ public init ( selection: Binding < Date > , @ViewBuilder label: ( ) -> Label ) {
18+ self . label = label ( )
19+ self . selection = selection
20+ }
21+
22+ public typealias Body = Never
23+ }
24+
25+ public extension DatePicker where Label == Text {
26+ init < S: StringProtocol > ( _ title: S , selection: Binding < Date > ) {
27+ self . init ( selection: selection) { Text ( title) }
28+ }
29+ }
30+
31+ extension DatePicker : PrimitiveView {
32+ public func _render( in context: ResolveContext ) -> RenderNode {
33+ let binding = selection
34+ let callbackID = context. callbacks. register ( . double { millis in
35+ binding. wrappedValue = Date ( timeIntervalSince1970: millis / 1000 )
36+ } )
37+ return RenderNode (
38+ type: " DatePicker " ,
39+ id: context. path,
40+ props: [
41+ " millis " : . double( selection. wrappedValue. timeIntervalSince1970 * 1000 ) ,
42+ " onChange " : . int( Int ( callbackID) ) ,
43+ ] ,
44+ children: Evaluator . resolveChildren ( label, context. descending ( " label " ) )
45+ )
46+ }
47+ }
You can’t perform that action at this time.
0 commit comments