44package dev.icerock.moko.widgets.datetimepicker
55
66import cocoapods.mokoWidgetsDateTimePicker.DateBottomSheetController
7- import com.soywiz.klock.DateTime
8- import dev.icerock.moko.graphics.Color
9- import dev.icerock.moko.graphics.toUIColor
107import dev.icerock.moko.widgets.core.screen.Screen
11- import dev.icerock.moko.widgets.core.utils.setEventHandler
12- import platform.CoreGraphics.CGRectMake
13- import platform.Foundation.NSBundle
14- import platform.Foundation.NSDate
15- import platform.Foundation.NSTimeIntervalSince1970
16- import platform.UIKit.UIApplication
17- import platform.UIKit.UIButton
18- import platform.UIKit.UIColor
19- import platform.UIKit.UIControlEventTouchUpInside
20- import platform.UIKit.UIControlStateNormal
21- import platform.UIKit.UIDatePicker
22- import platform.UIKit.UIDatePickerMode
23- import platform.UIKit.UIView
24- import platform.UIKit.addSubview
25- import platform.UIKit.backgroundColor
26- import platform.UIKit.bottomAnchor
27- import platform.UIKit.heightAnchor
28- import platform.UIKit.leadingAnchor
29- import platform.UIKit.safeAreaLayoutGuide
30- import platform.UIKit.topAnchor
31- import platform.UIKit.trailingAnchor
32- import platform.UIKit.translatesAutoresizingMaskIntoConstraints
33- import kotlin.properties.ReadOnlyProperty
348
359actual fun Screen <* >.showDatePickerDialog (
3610 dialogId : Int ,
@@ -49,201 +23,3 @@ actual fun Screen<*>.showDatePickerDialog(
4923 onDismiss = { handler.negative?.invoke(dialogId) }
5024 )
5125}
52-
53- // actual class DatePickerDialogHandler(
54- // val positive: ((dialogId: Int, date: DateTime) -> Unit)?,
55- // val negative: ((dialogId: Int) -> Unit)?
56- // )
57- //
58- // actual fun Screen<*>.registerDatePickerDialogHandler(
59- // positive: ((dialogId: Int, date: DateTime) -> Unit)?,
60- // negative: ((dialogId: Int) -> Unit)?
61- // ): ReadOnlyProperty<Screen<*>, DatePickerDialogHandler> {
62- // val handler = DatePickerDialogHandler(
63- // positive = positive,
64- // negative = negative
65- // )
66- // return createConstReadOnlyProperty(handler)
67- // }
68- //
69- // actual class DatePickerDialogBuilder {
70- //
71- // private var accentColor: Color? = null
72- // private var startDate: DateTime? = null
73- // private var endDate: DateTime? = null
74- // private var selectedDate: DateTime? = null
75- //
76- // actual fun accentColor(color: Color) {
77- // accentColor = color
78- // }
79- //
80- // actual fun startDate(date: DateTime) {
81- // startDate = date
82- // }
83- //
84- // actual fun endDate(date: DateTime) {
85- // endDate = date
86- // }
87- //
88- // actual fun selectedDate(date: DateTime) {
89- // selectedDate = date
90- // }
91- //
92- // fun createView(
93- // handler: DatePickerDialogHandler,
94- // dialogId: Int,
95- // onDismiss: () -> Unit
96- // ): DatePickerView {
97- // return DatePickerView(
98- // accentColor = accentColor,
99- // startDate = startDate,
100- // endDate = endDate,
101- // selectedDate = selectedDate,
102- // handler = handler,
103- // dialogId = dialogId,
104- // onDismiss = onDismiss
105- // )
106- // }
107- //
108- // }
109- //
110- // class DatePickerView(
111- // private val accentColor: Color?,
112- // private val startDate: DateTime?,
113- // private val endDate: DateTime?,
114- // private val selectedDate: DateTime?,
115- // private val handler: DatePickerDialogHandler,
116- // private val dialogId: Int,
117- // onDismiss: () -> Unit
118- // ) : UIView(frame = CGRectMake(0.0, 0.0, 0.0, 276.0)) {
119- //
120- // init {
121- // val pickerBackground = UIView()
122- // addSubview(pickerBackground)
123- // pickerBackground.translatesAutoresizingMaskIntoConstraints = false
124- // pickerBackground.backgroundColor = UIColor.whiteColor
125- // pickerBackground.leadingAnchor.constraintEqualToAnchor(
126- // anchor = this.leadingAnchor
127- // ).active = true
128- // pickerBackground.trailingAnchor.constraintEqualToAnchor(
129- // anchor = this.trailingAnchor
130- // ).active = true
131- // pickerBackground.bottomAnchor.constraintEqualToAnchor(
132- // anchor = this.bottomAnchor
133- // ).active = true
134- //
135- // val datePicker = UIDatePicker()
136- // datePicker.translatesAutoresizingMaskIntoConstraints = false
137- // datePicker.datePickerMode = UIDatePickerMode.UIDatePickerModeDate
138- // addSubview(datePicker)
139- // datePicker.leadingAnchor.constraintEqualToAnchor(
140- // anchor = this.leadingAnchor
141- // ).active = true
142- // datePicker.trailingAnchor.constraintEqualToAnchor(
143- // anchor = this.trailingAnchor
144- // ).active = true
145- // datePicker.bottomAnchor.constraintEqualToAnchor(
146- // anchor = this.safeAreaLayoutGuide.bottomAnchor
147- // ).active = true
148- // datePicker.heightAnchor.constraintEqualToConstant(232.0)
149- //
150- //
151- // pickerBackground.topAnchor.constraintEqualToAnchor(
152- // anchor = datePicker.topAnchor
153- // ).active = true
154- //
155- //
156- // val controlPanel = UIView()
157- // controlPanel.translatesAutoresizingMaskIntoConstraints = false
158- // controlPanel.backgroundColor = UIColor(red = 0.97, green = 0.97, blue = 0.97, alpha = 1.0)
159- // addSubview(controlPanel)
160- // controlPanel.leadingAnchor.constraintEqualToAnchor(
161- // anchor = this.leadingAnchor
162- // ).active = true
163- // controlPanel.trailingAnchor.constraintEqualToAnchor(
164- // anchor = this.trailingAnchor
165- // ).active = true
166- // controlPanel.bottomAnchor.constraintEqualToAnchor(
167- // anchor = datePicker.topAnchor
168- // ).active = true
169- // controlPanel.heightAnchor.constraintEqualToConstant(44.0)
170- //
171- // val bundle = NSBundle.bundleForClass(UIApplication)
172- // val doneButton = UIButton()
173- // doneButton.translatesAutoresizingMaskIntoConstraints = false
174- // doneButton.setTitle(
175- // title = bundle.localizedStringForKey(
176- // key = "Done",
177- // value = "Done",
178- // table = null
179- // ) ?: "Done",
180- // forState = UIControlStateNormal
181- // )
182- // if (accentColor != null) {
183- // doneButton.setTitleColor(accentColor.toUIColor(), UIControlStateNormal)
184- // }
185- // controlPanel.addSubview(doneButton)
186- // doneButton.trailingAnchor.constraintEqualToAnchor(
187- // anchor = controlPanel.trailingAnchor,
188- // constant = -16.0
189- // ).active = true
190- // doneButton.bottomAnchor.constraintEqualToAnchor(
191- // anchor = controlPanel.bottomAnchor
192- // ).active = true
193- // doneButton.topAnchor.constraintEqualToAnchor(
194- // anchor = controlPanel.topAnchor
195- // ).active = true
196- //
197- // val cancelButton = UIButton()
198- // cancelButton.translatesAutoresizingMaskIntoConstraints = false
199- // cancelButton.setTitle(
200- // title = bundle.localizedStringForKey(
201- // key = "Cancel",
202- // value = "Cancel",
203- // table = null
204- // ) ?: "Cancel",
205- // forState = UIControlStateNormal
206- // )
207- // if (accentColor != null) {
208- // cancelButton.setTitleColor(accentColor.toUIColor(), UIControlStateNormal)
209- // }
210- // controlPanel.addSubview(cancelButton)
211- // cancelButton.leadingAnchor.constraintEqualToAnchor(
212- // anchor = controlPanel.leadingAnchor,
213- // constant = 16.0
214- // ).active = true
215- // cancelButton.bottomAnchor.constraintEqualToAnchor(
216- // anchor = controlPanel.bottomAnchor
217- // ).active = true
218- // cancelButton.topAnchor.constraintEqualToAnchor(
219- // anchor = controlPanel.topAnchor
220- // ).active = true
221- //
222- // datePicker.minimumDate = startDate?.toNSDate()
223- // datePicker.maximumDate = endDate?.toNSDate()
224- //
225- // if (selectedDate != null) {
226- // datePicker.setDate(selectedDate.toNSDate())
227- // }
228- //
229- // doneButton.setEventHandler(UIControlEventTouchUpInside) {
230- // onDismiss.invoke()
231- // handler.positive?.invoke(
232- // dialogId,
233- // datePicker.date.toKlock()
234- // )
235- // }
236- // cancelButton.setEventHandler(UIControlEventTouchUpInside) {
237- // onDismiss.invoke()
238- // handler.negative?.invoke(dialogId)
239- // }
240- // }
241- // }
242- //
243- // internal fun DateTime.toNSDate(): NSDate {
244- // return NSDate((unixMillis / 1000) - NSTimeIntervalSince1970)
245- // }
246- //
247- // internal fun NSDate.toKlock(): DateTime {
248- // return DateTime(unixMillis = (this.timeIntervalSinceReferenceDate() + NSTimeIntervalSince1970) * 1000)
249- // }
0 commit comments